UNPKG

@brightlayer-ui/react-native-auth-workflow

Version:

Re-usable workflow components for Authentication and Registration within Eaton applications.

54 lines (53 loc) 3.02 kB
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) { function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); } return new (P || (P = Promise))(function (resolve, reject) { function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } } function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } } function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); } step((generator = generator.apply(thisArg, _arguments || [])).next()); }); }; import React from 'react'; import { cleanup, render, screen, renderHook } from '@testing-library/react-native'; import { useRegistrationWorkflowContext, } from '../../../contexts/RegistrationWorkflowContext'; import { RegistrationWorkflowContextProvider } from '../../../contexts/RegistrationWorkflowContext/provider'; import { Text } from 'react-native-paper'; import { registrationWorkflowContextProps } from '../../../testUtils'; afterEach(cleanup); describe('RegistrationWorkflowContext', () => { it('should render RegistrationWorkflowContextProvider without crashing', () => { render(React.createElement(RegistrationWorkflowContextProvider, Object.assign({}, registrationWorkflowContextProps), React.createElement(Text, null, "Test"))).toJSON(); expect(render).toBeTruthy(); expect(screen.getByText('Test')).toBeTruthy(); }); it('should set values in the context', () => __awaiter(void 0, void 0, void 0, function* () { let values; const RegisterComponent = () => (React.createElement(RegistrationWorkflowContextProvider, Object.assign({}, registrationWorkflowContextProps))); const CustomFlow = () => { const Screen1 = () => { values = renderHook(() => useRegistrationWorkflowContext()); return React.createElement(Text, null, "Screen 1"); }; return (React.createElement(RegisterComponent, null, React.createElement(Screen1, null))); }; render(React.createElement(CustomFlow, null)); // eslint-disable-next-line yield (() => expect(values.result.current.currentScreen).toBe(0)); // eslint-disable-next-line yield (() => expect(values.result.current.totalScreens).toBe(2)); // eslint-disable-next-line yield (() => expect(values.result.current.screenData['Eula'].accepted).toBeTruthy()); // eslint-disable-next-line yield (() => expect(values.result.current.screenData.CreateAccount.emailAddress).toBe('emailAddress@emailAddress.emailAddress')); })); it('should throw error, when context value is null', () => { try { renderHook(() => useRegistrationWorkflowContext()); } catch (error) { expect(error).toBeTruthy(); } }); });