-
-
Notifications
You must be signed in to change notification settings - Fork 779
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
dde8409
commit c831bb2
Showing
2 changed files
with
55 additions
and
21 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,21 +1,21 @@ | ||
import React from 'react'; | ||
import { MockedProvider } from '@apollo/react-testing'; | ||
import { act, render, screen } from '@testing-library/react'; | ||
import { Provider } from 'react-redux'; | ||
import { BrowserRouter } from 'react-router-dom'; | ||
import userEvent from '@testing-library/user-event'; | ||
import 'jest-localstorage-mock'; | ||
import 'jest-location-mock'; | ||
import { I18nextProvider } from 'react-i18next'; | ||
import { Provider } from 'react-redux'; | ||
import { BrowserRouter } from 'react-router-dom'; | ||
|
||
import ForgotPassword from './ForgotPassword'; | ||
import { store } from 'state/store'; | ||
import { | ||
FORGOT_PASSWORD_MUTATION, | ||
GENERATE_OTP_MUTATION, | ||
} from 'GraphQl/Mutations/mutations'; | ||
import i18nForTest from 'utils/i18nForTest'; | ||
import { store } from 'state/store'; | ||
import { StaticMockLink } from 'utils/StaticMockLink'; | ||
import i18nForTest from 'utils/i18nForTest'; | ||
import ForgotPassword from './ForgotPassword'; | ||
|
||
const MOCKS = [ | ||
{ | ||
|
@@ -57,7 +57,9 @@ async function wait(ms = 100): Promise<void> { | |
}); | ||
}); | ||
} | ||
|
||
beforeEach(() => { | ||
localStorage.setItem('IsLoggedIn', 'FALSE'); | ||
}); | ||
afterEach(() => { | ||
localStorage.clear(); | ||
}); | ||
|
@@ -81,7 +83,9 @@ describe('Testing Forgot Password screen', () => { | |
await wait(); | ||
|
||
expect(screen.getByText(/Forgot Password/i)).toBeInTheDocument(); | ||
expect(screen.getByText(/Back to Home/i)).toBeInTheDocument(); | ||
expect(screen.getByText(/Registered Email/i)).toBeInTheDocument(); | ||
expect(screen.getByText(/Get Otp/i)).toBeInTheDocument(); | ||
expect(screen.getByText(/Back to Login/i)).toBeInTheDocument(); | ||
expect(window.location).toBeAt('/orglist'); | ||
}); | ||
|
||
|
@@ -128,13 +132,15 @@ describe('Testing Forgot Password screen', () => { | |
); | ||
|
||
userEvent.click(screen.getByText('Get OTP')); | ||
await wait(); | ||
}); | ||
|
||
test('Testing forgot password functionality', async () => { | ||
const formData = { | ||
userOtp: '12345', | ||
newPassword: 'johnDoe', | ||
confirmNewPassword: 'johnDoe', | ||
email: '[email protected]', | ||
}; | ||
|
||
render( | ||
|
@@ -151,18 +157,28 @@ describe('Testing Forgot Password screen', () => { | |
|
||
await wait(); | ||
|
||
userEvent.type( | ||
screen.getByPlaceholderText(/Registered email/i), | ||
formData.email | ||
); | ||
|
||
userEvent.click(screen.getByText('Get OTP')); | ||
await wait(); | ||
|
||
userEvent.type(screen.getByPlaceholderText('e.g. 12345'), formData.userOtp); | ||
userEvent.type(screen.getByTestId('newPassword'), formData.newPassword); | ||
userEvent.type( | ||
screen.getByTestId('confirmNewPassword'), | ||
formData.confirmNewPassword | ||
); | ||
|
||
localStorage.setItem('otpToken', 'lorem ipsum'); | ||
userEvent.click(screen.getByText('Change Password')); | ||
await wait(); | ||
}); | ||
|
||
test('Testing forgot password functionality, when new password and confirm password is not same', async () => { | ||
const formData = { | ||
email: '[email protected]', | ||
userOtp: '12345', | ||
newPassword: 'johnDoe', | ||
confirmNewPassword: 'doeJohn', | ||
|
@@ -182,6 +198,14 @@ describe('Testing Forgot Password screen', () => { | |
|
||
await wait(); | ||
|
||
userEvent.type( | ||
screen.getByPlaceholderText(/Registered email/i), | ||
formData.email | ||
); | ||
|
||
userEvent.click(screen.getByText('Get OTP')); | ||
await wait(); | ||
|
||
userEvent.type(screen.getByPlaceholderText('e.g. 12345'), formData.userOtp); | ||
userEvent.type(screen.getByTestId('newPassword'), formData.newPassword); | ||
userEvent.type( | ||
|
@@ -197,6 +221,7 @@ describe('Testing Forgot Password screen', () => { | |
userOtp: '12345', | ||
newPassword: 'johnDoe', | ||
confirmNewPassword: 'johnDoe', | ||
email: '[email protected]', | ||
}; | ||
|
||
localStorage.setItem('otpToken', ''); | ||
|
@@ -215,13 +240,20 @@ describe('Testing Forgot Password screen', () => { | |
|
||
await wait(); | ||
|
||
userEvent.type( | ||
screen.getByPlaceholderText(/Registered email/i), | ||
formData.email | ||
); | ||
|
||
userEvent.click(screen.getByText('Get OTP')); | ||
await wait(); | ||
|
||
userEvent.type(screen.getByPlaceholderText('e.g. 12345'), formData.userOtp); | ||
userEvent.type(screen.getByTestId('newPassword'), formData.newPassword); | ||
userEvent.type( | ||
screen.getByTestId('confirmNewPassword'), | ||
formData.confirmNewPassword | ||
); | ||
|
||
userEvent.click(screen.getByText('Change Password')); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters