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