|
| 1 | +import React, { createRef } from 'react'; |
| 2 | +import { render } from '@testing-library/react-native'; |
| 3 | + |
| 4 | +import { generateSnapshots } from '../../../../.rnstorybook/generateSnapshots'; |
| 5 | +import Base, { type IBase } from '.'; |
| 6 | +import { TYPE } from '../constants'; |
| 7 | +import * as stories from './Base.stories'; |
| 8 | + |
| 9 | +const onEndProcessMock = jest.fn(); |
| 10 | + |
| 11 | +const TestBase = ({ ...props }) => { |
| 12 | + const ref = createRef<IBase>(); |
| 13 | + return <Base ref={ref} type={TYPE.ENTER} title='Test Title' onEndProcess={onEndProcessMock} {...props} />; |
| 14 | +}; |
| 15 | + |
| 16 | +describe('Base Passcode Component', () => { |
| 17 | + beforeEach(() => { |
| 18 | + onEndProcessMock.mockClear(); |
| 19 | + }); |
| 20 | + |
| 21 | + test('should render with title', () => { |
| 22 | + const { getByText } = render(<TestBase title='Enter Passcode' />); |
| 23 | + expect(getByText('Enter Passcode')).toBeTruthy(); |
| 24 | + }); |
| 25 | + |
| 26 | + test('should render with subtitle when provided', () => { |
| 27 | + const { getByText } = render(<TestBase title='Enter Passcode' subtitle='Authentication required' />); |
| 28 | + expect(getByText('Authentication required')).toBeTruthy(); |
| 29 | + }); |
| 30 | + |
| 31 | + test('should not render subtitle when not provided', () => { |
| 32 | + const { queryByText } = render(<TestBase title='Enter Passcode' />); |
| 33 | + expect(queryByText('Authentication required')).toBeNull(); |
| 34 | + }); |
| 35 | + |
| 36 | + test('should expose ref methods', () => { |
| 37 | + const ref = createRef<IBase>(); |
| 38 | + render(<Base ref={ref} type={TYPE.ENTER} title='Enter Passcode' onEndProcess={onEndProcessMock} />); |
| 39 | + expect(ref.current?.clearPasscode).toBeDefined(); |
| 40 | + expect(ref.current?.wrongPasscode).toBeDefined(); |
| 41 | + expect(ref.current?.animate).toBeDefined(); |
| 42 | + }); |
| 43 | + |
| 44 | + test('should render biometry button when showBiometry is true', () => { |
| 45 | + const { getByTestId } = render(<TestBase type={TYPE.ENTER} title='Enter Passcode' showBiometry onBiometryPress={() => {}} />); |
| 46 | + expect(getByTestId('biometry-button')).toBeTruthy(); |
| 47 | + }); |
| 48 | + |
| 49 | + test('should render all passcode buttons with testIDs', () => { |
| 50 | + const { getByTestId } = render(<TestBase type={TYPE.ENTER} title='Enter Passcode' />); |
| 51 | + // Number buttons 0-9 |
| 52 | + for (let i = 0; i <= 9; i++) { |
| 53 | + expect(getByTestId(`passcode-button-${i}`)).toBeTruthy(); |
| 54 | + } |
| 55 | + // backspace button |
| 56 | + expect(getByTestId('passcode-button-backspace')).toBeTruthy(); |
| 57 | + }); |
| 58 | +}); |
| 59 | + |
| 60 | +generateSnapshots(stories); |
0 commit comments