-
Notifications
You must be signed in to change notification settings - Fork 6
/
Copy pathCodeInput.spec.tsx
50 lines (42 loc) · 1.53 KB
/
CodeInput.spec.tsx
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
import React from 'react';
import {render, fireEvent, waitFor} from '@testing-library/react-native';
import {ThemeProvider} from 'shared/theme';
import {StorageServiceProvider} from 'services/StorageService';
import {CodeInput} from './CodeInput';
jest.setTimeout(10000);
jest.mock('react-native-localize', () => ({
getLocales: () => [{countryCode: 'US', languageTag: 'en-US', languageCode: 'en', isRTL: false}],
}));
describe('CodeInput', () => {
const changeMock = jest.fn();
let componentQuery: any;
beforeEach(async () => {
componentQuery = await waitFor(() =>
render(
<StorageServiceProvider>
<ThemeProvider>
<CodeInput value="" onChange={changeMock} accessibilityLabel="codeInput" />
</ThemeProvider>
</StorageServiceProvider>,
),
);
});
afterEach(() => {
jest.clearAllMocks();
jest.resetAllMocks();
});
it('returns trimmed text', async () => {
const textInput = componentQuery.getByTestId('textInput');
fireEvent.changeText(textInput, ' MYSECRETCODE ');
expect(changeMock).toHaveBeenCalledWith('MYSECRETCODE');
});
// eslint-disable-next-line jest/no-commented-out-tests
/* TODO: uncomment after https://github.com/cds-snc/covid-alert-app/pull/844 is merged
it('disallows special characters on input', () => {
const changeMock = jest.fn();
const textInput = componentQuery.getByHintText('codeInput');
fireEvent.changeText(textInput, ' MY💘SECRETCODE ');
expect(changeMock).toBeCalledWith('MYSECRETCODE');
});
*/
});