Skip to content

Commit

Permalink
review this one test
Browse files Browse the repository at this point in the history
  • Loading branch information
JeffGreiner-eaton committed Mar 4, 2024
1 parent 23a500d commit 5eef96d
Showing 1 changed file with 59 additions and 0 deletions.
59 changes: 59 additions & 0 deletions login-workflow/src/screens/AccountDetailsScreen/testing.test.tsx
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();
});
});

0 comments on commit 5eef96d

Please sign in to comment.