@brightlayer-ui/react-native-auth-workflow
Version:
Re-usable workflow components for Authentication and Registration within Eaton applications.
50 lines (49 loc) • 2.76 kB
JavaScript
import React from 'react';
import '@testing-library/jest-dom';
import { cleanup, render, fireEvent, screen } from '@testing-library/react-native';
import { CreateAccountScreen } from '../../screens/CreateAccountScreen';
import { RegistrationWorkflow } from 'src/components';
import { RegistrationContextProvider } from 'src/contexts';
import { registrationContextProviderProps } from 'src/testUtils';
import { PaperProvider } from 'react-native-paper';
jest.useFakeTimers();
afterEach(cleanup);
describe('Create Account Base', () => {
it('renders correctly', () => {
render(React.createElement(PaperProvider, null,
React.createElement(RegistrationContextProvider, Object.assign({}, registrationContextProviderProps),
React.createElement(RegistrationWorkflow, { initialScreenIndex: 0 },
React.createElement(CreateAccountScreen, null)))));
expect(screen.getByTestId('blui-create-account-email-text-input')).toBeOnTheScreen();
});
it('should call onNext, when Next button clicked', () => {
const nextfn = jest.fn();
render(React.createElement(PaperProvider, null,
React.createElement(RegistrationContextProvider, Object.assign({}, registrationContextProviderProps),
React.createElement(RegistrationWorkflow, { initialScreenIndex: 0 },
React.createElement(CreateAccountScreen, { WorkflowCardActionsProps: {
onNext: () => nextfn(),
showNext: true,
nextLabel: 'NextButton',
} })))));
const emailInput = screen.getByTestId('blui-create-account-email-text-input');
fireEvent.changeText(emailInput, 'email@test.com');
fireEvent.press(screen.getByText('NextButton'));
expect(nextfn).toHaveBeenCalled();
});
it('should call onPrevious, when Back button clicked', () => {
const prevFn = jest.fn();
render(React.createElement(PaperProvider, null,
React.createElement(RegistrationContextProvider, Object.assign({}, registrationContextProviderProps),
React.createElement(RegistrationWorkflow, { initialScreenIndex: 0 },
React.createElement(CreateAccountScreen, { WorkflowCardActionsProps: {
onPrevious: prevFn(),
showPrevious: true,
previousLabel: 'Back',
} })))));
const emailInput = screen.getByTestId('blui-create-account-email-text-input');
fireEvent.changeText(emailInput, 'email@test.com');
fireEvent.press(screen.getByText('Back'));
expect(prevFn).toHaveBeenCalled();
});
});