-
Notifications
You must be signed in to change notification settings - Fork 8
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
23a500d
commit 5eef96d
Showing
1 changed file
with
59 additions
and
0 deletions.
There are no files selected for viewing
59 changes: 59 additions & 0 deletions
59
login-workflow/src/screens/AccountDetailsScreen/testing.test.tsx
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 |
---|---|---|
@@ -0,0 +1,59 @@ | ||
import React from 'react'; | ||
import '@testing-library/jest-dom'; | ||
import { cleanup, render, screen, RenderResult, fireEvent, act } from '@testing-library/react'; | ||
import { AccountDetailsScreen } from './AccountDetailsScreen'; | ||
import { RegistrationContextProvider } from '../../contexts'; | ||
import { AccountDetailsScreenProps } from './types'; | ||
import { RegistrationWorkflow } from '../../components'; | ||
import { registrationContextProviderProps } from '../../testUtils'; | ||
|
||
afterEach(cleanup); | ||
|
||
describe('Account Details Screen', () => { | ||
let mockOnNext: any; | ||
let mockOnPrevious: any; | ||
|
||
afterEach(() => { | ||
jest.clearAllMocks(); | ||
}); | ||
|
||
beforeEach(() => { | ||
mockOnNext = jest.fn(); | ||
mockOnPrevious = jest.fn(); | ||
}); | ||
|
||
const renderer = (props?: AccountDetailsScreenProps): RenderResult => | ||
render( | ||
<RegistrationContextProvider {...registrationContextProviderProps}> | ||
<RegistrationWorkflow initialScreenIndex={0}> | ||
<AccountDetailsScreen {...props} /> | ||
</RegistrationWorkflow> | ||
</RegistrationContextProvider> | ||
); | ||
|
||
it('should call onNext, when Next button clicked', async () => { | ||
const { getByLabelText } = renderer({ | ||
WorkflowCardActionsProps: { | ||
onNext: mockOnNext(), | ||
showNext: true, | ||
nextLabel: 'Next', | ||
}, | ||
}); | ||
|
||
const firstNameInput = getByLabelText('First Name'); | ||
fireEvent.change(firstNameInput, { target: { value: 'Test First Name' } }); | ||
fireEvent.blur(firstNameInput); | ||
|
||
const lastNameInput = getByLabelText('Last Name'); | ||
fireEvent.change(lastNameInput, { target: { value: 'Test Last Name' } }); | ||
fireEvent.blur(lastNameInput); | ||
|
||
const nextButton = screen.getByText('Next'); | ||
expect(nextButton).toBeInTheDocument(); | ||
expect(screen.getByText(/Next/i)).toBeEnabled(); | ||
await act(async () => { | ||
fireEvent.click(nextButton); | ||
}); | ||
expect(mockOnNext).toHaveBeenCalled(); | ||
}); | ||
}); |