@react-native-ama/forms 1.2.1 → 2.0.0-beta.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/components/Form.d.ts +5 -2
- package/dist/components/Form.js +14 -31
- package/dist/components/FormSubmit.d.ts +7 -9
- package/dist/components/FormSubmit.js +2 -14
- package/dist/components/TextInput.d.ts +36 -4
- package/dist/components/TextInput.js +20 -73
- package/dist/hooks/useFocus.d.ts +4 -0
- package/dist/hooks/useFocus.js +69 -0
- package/dist/hooks/useFormField.d.ts +1 -7
- package/dist/hooks/useFormField.js +32 -25
- package/dist/hooks/useFormSubmit.d.ts +4 -0
- package/dist/hooks/useFormSubmit.js +14 -0
- package/dist/hooks/useTextInput.d.ts +59 -231
- package/dist/hooks/useTextInput.js +2 -37
- package/dist/index.d.ts +9 -12
- package/dist/index.js +3 -8
- package/dist/utils/checkFocusTrap.d.ts +8 -0
- package/dist/utils/checkFocusTrap.js +30 -0
- package/package.json +59 -18
- package/src/components/Form.test.tsx +63 -70
- package/src/components/Form.tsx +28 -52
- package/src/components/FormField.test.tsx +32 -16
- package/src/components/FormField.tsx +0 -1
- package/src/components/FormSubmit.test.tsx +17 -55
- package/src/components/FormSubmit.tsx +9 -36
- package/src/components/TextInput.test.tsx +83 -397
- package/src/components/TextInput.tsx +41 -109
- package/src/hooks/useFocus.test.ts +130 -0
- package/src/hooks/useFocus.ts +62 -0
- package/src/hooks/useFormField.test.tsx +183 -78
- package/src/hooks/useFormField.ts +36 -28
- package/src/hooks/useFormSubmit.test.tsx +18 -0
- package/src/hooks/useFormSubmit.ts +17 -0
- package/src/hooks/useTextInput.ts +10 -55
- package/src/index.ts +14 -19
- package/src/utils/checkFocusTrap.test.ts +80 -0
- package/src/utils/checkFocusTrap.ts +40 -0
- package/dist/components/FormSwitch.d.ts +0 -4
- package/dist/components/FormSwitch.js +0 -15
- package/src/components/FormSwitch.tsx +0 -17
|
@@ -1,241 +1,105 @@
|
|
|
1
|
-
import * as UseChecks from '@react-native-ama/core/src/hooks/useChecks';
|
|
2
|
-
import { ERROR_STYLE } from '@react-native-ama/internal';
|
|
3
1
|
import { fireEvent, render } from '@testing-library/react-native';
|
|
4
2
|
import * as React from 'react';
|
|
5
3
|
import { Text } from 'react-native';
|
|
6
|
-
|
|
7
4
|
import * as UseFormField from '../hooks/useFormField';
|
|
8
5
|
import { TextInput } from './TextInput';
|
|
9
6
|
|
|
10
7
|
beforeEach(() => {
|
|
11
8
|
jest.clearAllMocks();
|
|
9
|
+
(UseFormField.useFormField as jest.Mock).mockReturnValue({
|
|
10
|
+
isLastField: jest.fn().mockReturnValue(false),
|
|
11
|
+
focusNextFormField: jest.fn(),
|
|
12
|
+
});
|
|
12
13
|
});
|
|
13
14
|
|
|
14
15
|
describe('TextInput', () => {
|
|
15
|
-
it('
|
|
16
|
-
const useFormField = jest.spyOn(UseFormField, 'useFormField');
|
|
17
|
-
|
|
18
|
-
render(
|
|
19
|
-
<TextInput
|
|
20
|
-
labelComponent={<Text testID="text">Test</Text>}
|
|
21
|
-
hasValidation={false}
|
|
22
|
-
returnKeyType="done"
|
|
23
|
-
/>,
|
|
24
|
-
);
|
|
25
|
-
|
|
26
|
-
expect(useFormField.mock.calls[0][0]).toMatchObject({
|
|
27
|
-
ref: expect.objectContaining({ current: expect.any(Object) }),
|
|
28
|
-
errorMessage: undefined,
|
|
29
|
-
hasError: undefined,
|
|
30
|
-
hasValidation: false,
|
|
31
|
-
id: undefined,
|
|
32
|
-
nextFieldId: undefined,
|
|
33
|
-
nextFormFieldRef: undefined,
|
|
34
|
-
});
|
|
35
|
-
});
|
|
36
|
-
|
|
37
|
-
it('renders the given labelComponent before the text input when labelPosition is undefined', () => {
|
|
16
|
+
it('renders the given renderLabel before the text input when labelPosition is undefined', () => {
|
|
38
17
|
const renderAPI = render(
|
|
39
18
|
<TextInput
|
|
40
|
-
|
|
41
|
-
|
|
19
|
+
renderLabel={(a11yProps) => <Text {...a11yProps} testID="label">Label</Text>}
|
|
20
|
+
accessibilityLabel="First name"
|
|
42
21
|
hasValidation={false}
|
|
43
22
|
/>,
|
|
44
23
|
);
|
|
45
24
|
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
importantForAccessibility="no"
|
|
51
|
-
testID="text"
|
|
52
|
-
>
|
|
53
|
-
labelComponent
|
|
54
|
-
</Text>,
|
|
55
|
-
<TextInput
|
|
56
|
-
accessibilityHint=""
|
|
57
|
-
accessibilityLabel="labelComponent"
|
|
58
|
-
hasValidation={false}
|
|
59
|
-
onLayout={[Function]}
|
|
60
|
-
onSubmitEditing={[Function]}
|
|
61
|
-
returnKeyType="done"
|
|
62
|
-
style={Object {}}
|
|
63
|
-
/>,
|
|
64
|
-
]
|
|
65
|
-
`);
|
|
25
|
+
const json = renderAPI.toJSON() as any[];
|
|
26
|
+
expect(json[0].props.testID).toBe('label');
|
|
27
|
+
expect(json[0].props.importantForAccessibility).toBe('no-hide-descendants');
|
|
28
|
+
expect(json[0].props.accessibilityElementsHidden).toBe(true);
|
|
66
29
|
});
|
|
67
30
|
|
|
68
|
-
it('renders the given
|
|
31
|
+
it('renders the given renderLabel after the text input when labelPosition is "afterInput"', () => {
|
|
69
32
|
const renderAPI = render(
|
|
70
33
|
<TextInput
|
|
71
|
-
|
|
34
|
+
renderLabel={(a11yProps) => <Text {...a11yProps} testID="label">Label</Text>}
|
|
35
|
+
accessibilityLabel="First name"
|
|
72
36
|
labelPosition="afterInput"
|
|
73
|
-
returnKeyType="done"
|
|
74
37
|
hasValidation={false}
|
|
75
38
|
/>,
|
|
76
39
|
);
|
|
77
40
|
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
<TextInput
|
|
81
|
-
accessibilityHint=""
|
|
82
|
-
accessibilityLabel=" labelComponent after"
|
|
83
|
-
hasValidation={false}
|
|
84
|
-
onLayout={[Function]}
|
|
85
|
-
onSubmitEditing={[Function]}
|
|
86
|
-
returnKeyType="done"
|
|
87
|
-
style={Object {}}
|
|
88
|
-
/>,
|
|
89
|
-
<Text
|
|
90
|
-
accessibilityElementsHidden={true}
|
|
91
|
-
importantForAccessibility="no"
|
|
92
|
-
testID="text"
|
|
93
|
-
>
|
|
94
|
-
labelComponent after
|
|
95
|
-
</Text>,
|
|
96
|
-
]
|
|
97
|
-
`);
|
|
41
|
+
const json = renderAPI.toJSON() as any[];
|
|
42
|
+
expect(json[json.length - 1].props.testID).toBe('label');
|
|
98
43
|
});
|
|
99
44
|
|
|
100
|
-
it('renders the given
|
|
45
|
+
it('renders the given renderError after the text input when errorPosition is "afterInput"', () => {
|
|
101
46
|
const renderAPI = render(
|
|
102
47
|
<TextInput
|
|
103
|
-
|
|
104
|
-
|
|
48
|
+
renderLabel={(a11yProps) => <Text {...a11yProps}>Label</Text>}
|
|
49
|
+
renderError={(a11yProps) => <Text {...a11yProps} testID="error">Error</Text>}
|
|
50
|
+
accessibilityLabel="First name"
|
|
105
51
|
hasValidation={true}
|
|
106
|
-
errorComponent={<Text>This is the errorComponent</Text>}
|
|
107
|
-
errorPosition="belowLabel"
|
|
108
52
|
hasError={true}
|
|
53
|
+
errorPosition="afterInput"
|
|
109
54
|
/>,
|
|
110
55
|
);
|
|
111
56
|
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
<Text
|
|
115
|
-
accessibilityElementsHidden={true}
|
|
116
|
-
importantForAccessibility="no"
|
|
117
|
-
testID="text"
|
|
118
|
-
>
|
|
119
|
-
the labelComponent
|
|
120
|
-
</Text>,
|
|
121
|
-
<Text
|
|
122
|
-
accessibilityElementsHidden={true}
|
|
123
|
-
importantForAccessibility="no"
|
|
124
|
-
>
|
|
125
|
-
This is the errorComponent
|
|
126
|
-
</Text>,
|
|
127
|
-
<TextInput
|
|
128
|
-
accessibilityHint="This is the errorComponent"
|
|
129
|
-
accessibilityLabel="the labelComponent"
|
|
130
|
-
hasError={true}
|
|
131
|
-
hasValidation={true}
|
|
132
|
-
onLayout={[Function]}
|
|
133
|
-
onSubmitEditing={[Function]}
|
|
134
|
-
returnKeyType="done"
|
|
135
|
-
style={Object {}}
|
|
136
|
-
/>,
|
|
137
|
-
]
|
|
138
|
-
`);
|
|
57
|
+
const json = renderAPI.toJSON() as any[];
|
|
58
|
+
expect(json[json.length - 1].props.testID).toBe('error');
|
|
139
59
|
});
|
|
140
60
|
|
|
141
|
-
it('renders the given
|
|
61
|
+
it('renders the given renderError below the label when errorPosition is "belowLabel"', () => {
|
|
142
62
|
const renderAPI = render(
|
|
143
63
|
<TextInput
|
|
144
|
-
|
|
145
|
-
|
|
64
|
+
renderLabel={(a11yProps) => <Text {...a11yProps} testID="label">Label</Text>}
|
|
65
|
+
renderError={(a11yProps) => <Text {...a11yProps} testID="error">Error</Text>}
|
|
66
|
+
accessibilityLabel="First name"
|
|
146
67
|
hasValidation={true}
|
|
147
|
-
errorComponent={<Text>This is the errorComponent</Text>}
|
|
148
|
-
errorPosition="afterInput"
|
|
149
68
|
hasError={true}
|
|
69
|
+
errorPosition="belowLabel"
|
|
150
70
|
/>,
|
|
151
71
|
);
|
|
152
72
|
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
accessibilityElementsHidden={true}
|
|
157
|
-
importantForAccessibility="no"
|
|
158
|
-
testID="text"
|
|
159
|
-
>
|
|
160
|
-
the labelComponent
|
|
161
|
-
</Text>,
|
|
162
|
-
<TextInput
|
|
163
|
-
accessibilityHint="This is the errorComponent"
|
|
164
|
-
accessibilityLabel="the labelComponent"
|
|
165
|
-
hasError={true}
|
|
166
|
-
hasValidation={true}
|
|
167
|
-
onLayout={[Function]}
|
|
168
|
-
onSubmitEditing={[Function]}
|
|
169
|
-
returnKeyType="done"
|
|
170
|
-
style={Object {}}
|
|
171
|
-
/>,
|
|
172
|
-
<Text
|
|
173
|
-
accessibilityElementsHidden={true}
|
|
174
|
-
importantForAccessibility="no"
|
|
175
|
-
>
|
|
176
|
-
This is the errorComponent
|
|
177
|
-
</Text>,
|
|
178
|
-
]
|
|
179
|
-
`);
|
|
180
|
-
});
|
|
181
|
-
|
|
182
|
-
it('hides the labelComponent from the screen readers', () => {
|
|
183
|
-
const renderAPI = render(
|
|
184
|
-
<TextInput
|
|
185
|
-
labelComponent={<Text testID="text">Test</Text>}
|
|
186
|
-
labelPosition="afterInput"
|
|
187
|
-
returnKeyType="done"
|
|
188
|
-
hasValidation={false}
|
|
189
|
-
/>,
|
|
190
|
-
);
|
|
191
|
-
|
|
192
|
-
expect(renderAPI.getByTestId('text').props.importantForAccessibility).toBe(
|
|
193
|
-
'no',
|
|
194
|
-
);
|
|
195
|
-
expect(
|
|
196
|
-
renderAPI.getByTestId('text').props.accessibilityElementsHidden,
|
|
197
|
-
).toBe(true);
|
|
73
|
+
const json = renderAPI.toJSON() as any[];
|
|
74
|
+
expect(json[0].props.testID).toBe('label');
|
|
75
|
+
expect(json[1].props.testID).toBe('error');
|
|
198
76
|
});
|
|
199
77
|
|
|
200
|
-
it('
|
|
78
|
+
it('does not render errorComponent when hasError is false', () => {
|
|
201
79
|
const renderAPI = render(
|
|
202
80
|
<TextInput
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
81
|
+
renderLabel={(a11yProps) => <Text {...a11yProps}>Label</Text>}
|
|
82
|
+
renderError={(a11yProps) => <Text {...a11yProps} testID="error">Error</Text>}
|
|
83
|
+
accessibilityLabel="First name"
|
|
206
84
|
hasValidation={true}
|
|
207
|
-
|
|
208
|
-
<Text testID="errorComponent-test-id">
|
|
209
|
-
This is the errorComponent
|
|
210
|
-
</Text>
|
|
211
|
-
}
|
|
85
|
+
hasError={false}
|
|
212
86
|
errorPosition="afterInput"
|
|
213
|
-
hasError={true}
|
|
214
87
|
/>,
|
|
215
88
|
);
|
|
216
89
|
|
|
217
|
-
expect(
|
|
218
|
-
renderAPI.getByTestId('errorComponent-test-id').props
|
|
219
|
-
.importantForAccessibility,
|
|
220
|
-
).toBe('no');
|
|
221
|
-
expect(
|
|
222
|
-
renderAPI.getByTestId('errorComponent-test-id').props
|
|
223
|
-
.accessibilityElementsHidden,
|
|
224
|
-
).toBe(true);
|
|
90
|
+
expect(renderAPI.queryByTestId('error')).toBeNull();
|
|
225
91
|
});
|
|
226
92
|
|
|
227
93
|
describe('returnKeyType', () => {
|
|
228
94
|
it('sets the `returnKeyType="next"` if more fields have been registered', async () => {
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
} as any);
|
|
95
|
+
(UseFormField.useFormField as jest.Mock).mockReturnValue({
|
|
96
|
+
isLastField: jest.fn().mockReturnValue(false),
|
|
97
|
+
focusNextFormField: jest.fn(),
|
|
98
|
+
});
|
|
234
99
|
|
|
235
100
|
const renderAPI = render(
|
|
236
101
|
<TextInput
|
|
237
|
-
|
|
238
|
-
labelPosition="afterInput"
|
|
102
|
+
accessibilityLabel="First name"
|
|
239
103
|
testID="test-id"
|
|
240
104
|
hasValidation={false}
|
|
241
105
|
/>,
|
|
@@ -248,23 +112,21 @@ describe('TextInput', () => {
|
|
|
248
112
|
);
|
|
249
113
|
});
|
|
250
114
|
|
|
251
|
-
it('sets the `returnKeyType="done"` if is last field registered', () => {
|
|
252
|
-
|
|
253
|
-
|
|
254
|
-
|
|
255
|
-
|
|
256
|
-
} as any);
|
|
115
|
+
it('sets the `returnKeyType="done"` if is last field registered', async () => {
|
|
116
|
+
(UseFormField.useFormField as jest.Mock).mockReturnValue({
|
|
117
|
+
isLastField: jest.fn().mockReturnValue(true),
|
|
118
|
+
focusNextFormField: jest.fn(),
|
|
119
|
+
});
|
|
257
120
|
|
|
258
121
|
const renderAPI = render(
|
|
259
122
|
<TextInput
|
|
260
|
-
|
|
261
|
-
labelPosition="afterInput"
|
|
123
|
+
accessibilityLabel="First name"
|
|
262
124
|
testID="test-id"
|
|
263
125
|
hasValidation={false}
|
|
264
126
|
/>,
|
|
265
127
|
);
|
|
266
128
|
|
|
267
|
-
fireEvent(renderAPI.getByTestId('test-id'), 'onLayout');
|
|
129
|
+
await fireEvent(renderAPI.getByTestId('test-id'), 'onLayout');
|
|
268
130
|
|
|
269
131
|
expect(renderAPI.getByTestId('test-id').props.returnKeyType).toEqual(
|
|
270
132
|
'done',
|
|
@@ -274,16 +136,14 @@ describe('TextInput', () => {
|
|
|
274
136
|
it.each([true, false])(
|
|
275
137
|
'keeps the `returnKeyType` value passed as prop',
|
|
276
138
|
async isLastFieldValue => {
|
|
277
|
-
|
|
278
|
-
|
|
279
|
-
|
|
280
|
-
|
|
281
|
-
} as any);
|
|
139
|
+
(UseFormField.useFormField as jest.Mock).mockReturnValue({
|
|
140
|
+
isLastField: jest.fn().mockReturnValue(isLastFieldValue),
|
|
141
|
+
focusNextFormField: jest.fn(),
|
|
142
|
+
});
|
|
282
143
|
|
|
283
144
|
const renderAPI = render(
|
|
284
145
|
<TextInput
|
|
285
|
-
|
|
286
|
-
labelPosition="afterInput"
|
|
146
|
+
accessibilityLabel="First name"
|
|
287
147
|
testID="test-id"
|
|
288
148
|
returnKeyType="google"
|
|
289
149
|
hasValidation={false}
|
|
@@ -299,242 +159,68 @@ describe('TextInput', () => {
|
|
|
299
159
|
);
|
|
300
160
|
});
|
|
301
161
|
|
|
302
|
-
|
|
303
|
-
describe('Given no accessibility labelComponent is provided', () => {
|
|
304
|
-
it('Then applies the given labelComponent content as accessibilityLabel', () => {
|
|
305
|
-
const renderAPI = render(
|
|
306
|
-
<TextInput
|
|
307
|
-
labelComponent={<Text>First name:</Text>}
|
|
308
|
-
returnKeyType="done"
|
|
309
|
-
testID="text-input"
|
|
310
|
-
hasValidation={false}
|
|
311
|
-
/>,
|
|
312
|
-
);
|
|
313
|
-
|
|
314
|
-
expect(
|
|
315
|
-
renderAPI.getByTestId('text-input').props.accessibilityLabel,
|
|
316
|
-
).toBe('First name:');
|
|
317
|
-
});
|
|
318
|
-
|
|
319
|
-
it('strips the ending * from the labelComponent content before using as accessibility labelComponent', () => {
|
|
320
|
-
const renderAPI = render(
|
|
321
|
-
<TextInput
|
|
322
|
-
labelComponent={<Text>First name (required)*</Text>}
|
|
323
|
-
returnKeyType="done"
|
|
324
|
-
testID="text-input"
|
|
325
|
-
hasValidation={false}
|
|
326
|
-
/>,
|
|
327
|
-
);
|
|
328
|
-
|
|
329
|
-
expect(
|
|
330
|
-
renderAPI.getByTestId('text-input').props.accessibilityLabel,
|
|
331
|
-
).toBe('First name (required)');
|
|
332
|
-
});
|
|
333
|
-
});
|
|
334
|
-
|
|
335
|
-
it('uses the accessibilityLabel only if provided', () => {
|
|
336
|
-
const renderAPI = render(
|
|
337
|
-
<TextInput
|
|
338
|
-
labelComponent={<Text>First name (required)*</Text>}
|
|
339
|
-
returnKeyType="done"
|
|
340
|
-
testID="text-input"
|
|
341
|
-
accessibilityLabel="Please insert your first name"
|
|
342
|
-
hasValidation={false}
|
|
343
|
-
/>,
|
|
344
|
-
);
|
|
345
|
-
|
|
346
|
-
expect(renderAPI.getByTestId('text-input').props.accessibilityLabel).toBe(
|
|
347
|
-
'Please insert your first name',
|
|
348
|
-
);
|
|
349
|
-
});
|
|
350
|
-
});
|
|
351
|
-
|
|
352
|
-
it('calls focusNextFormField onSubmitEditing event', () => {
|
|
353
|
-
const focusNextFormField = jest.fn();
|
|
354
|
-
|
|
355
|
-
jest.spyOn(UseFormField, 'useFormField').mockReturnValue({
|
|
356
|
-
focusNextFormField,
|
|
357
|
-
} as any);
|
|
358
|
-
|
|
359
|
-
const fn = jest.fn();
|
|
360
|
-
|
|
361
|
-
const renderAPI = render(
|
|
362
|
-
<TextInput
|
|
363
|
-
labelComponent={<Text>First name (required)*</Text>}
|
|
364
|
-
returnKeyType="next"
|
|
365
|
-
testID="text-input"
|
|
366
|
-
accessibilityLabel="Please insert your first name"
|
|
367
|
-
onSubmitEditing={fn}
|
|
368
|
-
hasValidation={false}
|
|
369
|
-
/>,
|
|
370
|
-
);
|
|
371
|
-
|
|
372
|
-
fireEvent(
|
|
373
|
-
renderAPI.getByTestId('text-input'),
|
|
374
|
-
'onSubmitEditing',
|
|
375
|
-
'whatever',
|
|
376
|
-
);
|
|
377
|
-
|
|
378
|
-
expect(fn).toHaveBeenCalledWith('whatever');
|
|
379
|
-
});
|
|
380
|
-
|
|
381
|
-
it('ignores the errorComponent message if hasError is not true', () => {
|
|
162
|
+
it('uses the accessibilityLabel prop', () => {
|
|
382
163
|
const renderAPI = render(
|
|
383
164
|
<TextInput
|
|
384
|
-
labelComponent={<Text>First name (required)*</Text>}
|
|
385
|
-
returnKeyType="next"
|
|
386
|
-
testID="text-input"
|
|
387
165
|
accessibilityLabel="Please insert your first name"
|
|
388
|
-
hasValidation={true}
|
|
389
|
-
hasError={false}
|
|
390
|
-
errorMessage={'This is the errorComponent'}
|
|
391
|
-
errorComponent={<></>}
|
|
392
|
-
/>,
|
|
393
|
-
);
|
|
394
|
-
|
|
395
|
-
expect(renderAPI.getByTestId('text-input').props.accessibilityHint).toBe(
|
|
396
|
-
'',
|
|
397
|
-
);
|
|
398
|
-
});
|
|
399
|
-
|
|
400
|
-
it('when hasError uses the text from the errorComponent as part of the accessibilityHint', () => {
|
|
401
|
-
const renderAPI = render(
|
|
402
|
-
<TextInput
|
|
403
|
-
labelComponent={<Text>First name (required)*</Text>}
|
|
404
|
-
returnKeyType="next"
|
|
405
166
|
testID="text-input"
|
|
406
|
-
|
|
407
|
-
accessibilityHint="The hint"
|
|
408
|
-
hasValidation={true}
|
|
409
|
-
hasError={true}
|
|
410
|
-
errorComponent={<Text>The first name cannot be blank</Text>}
|
|
167
|
+
hasValidation={false}
|
|
411
168
|
/>,
|
|
412
169
|
);
|
|
413
170
|
|
|
414
|
-
expect(renderAPI.getByTestId('text-input').props.
|
|
415
|
-
'
|
|
171
|
+
expect(renderAPI.getByTestId('text-input').props.accessibilityLabel).toBe(
|
|
172
|
+
'Please insert your first name',
|
|
416
173
|
);
|
|
417
174
|
});
|
|
418
175
|
|
|
419
|
-
it('
|
|
176
|
+
it('uses aria-label when accessibilityLabel is not provided', () => {
|
|
420
177
|
const renderAPI = render(
|
|
421
178
|
<TextInput
|
|
422
|
-
|
|
423
|
-
returnKeyType="next"
|
|
179
|
+
aria-label="aria label value"
|
|
424
180
|
testID="text-input"
|
|
425
|
-
|
|
426
|
-
accessibilityHint="The hint"
|
|
427
|
-
hasValidation={true}
|
|
428
|
-
hasError={true}
|
|
429
|
-
errorMessage="This text will be used"
|
|
430
|
-
errorComponent={<Text>The first name cannot be blank</Text>}
|
|
181
|
+
hasValidation={false}
|
|
431
182
|
/>,
|
|
432
183
|
);
|
|
433
184
|
|
|
434
|
-
expect(renderAPI.getByTestId('text-input').props.
|
|
435
|
-
'
|
|
185
|
+
expect(renderAPI.getByTestId('text-input').props.accessibilityLabel).toBe(
|
|
186
|
+
'aria label value',
|
|
436
187
|
);
|
|
437
188
|
});
|
|
438
189
|
|
|
439
|
-
it('
|
|
190
|
+
it('calls focusNextFormField onSubmitEditing event', () => {
|
|
440
191
|
const focusNextFormField = jest.fn();
|
|
441
192
|
|
|
442
|
-
|
|
193
|
+
(UseFormField.useFormField as jest.Mock).mockReturnValue({
|
|
443
194
|
focusNextFormField,
|
|
444
|
-
|
|
445
|
-
}
|
|
195
|
+
isLastField: jest.fn().mockReturnValue(false),
|
|
196
|
+
});
|
|
197
|
+
|
|
198
|
+
const fn = jest.fn();
|
|
446
199
|
|
|
447
200
|
const renderAPI = render(
|
|
448
201
|
<TextInput
|
|
449
|
-
|
|
202
|
+
accessibilityLabel="Please insert your first name"
|
|
450
203
|
returnKeyType="next"
|
|
451
204
|
testID="text-input"
|
|
452
|
-
|
|
205
|
+
onSubmitEditing={fn}
|
|
453
206
|
hasValidation={false}
|
|
454
207
|
/>,
|
|
455
208
|
);
|
|
456
209
|
|
|
457
|
-
|
|
458
|
-
|
|
210
|
+
fireEvent(
|
|
211
|
+
renderAPI.getByTestId('text-input'),
|
|
212
|
+
'onSubmitEditing',
|
|
213
|
+
'whatever',
|
|
459
214
|
);
|
|
460
|
-
});
|
|
461
|
-
|
|
462
|
-
describe('When __DEV__ is false', () => {
|
|
463
|
-
let TextInputWithoutDev: typeof TextInput;
|
|
464
|
-
let accessibilityLabelChecker: jest.Mock;
|
|
465
|
-
let uppercaseChecker: jest.Mock;
|
|
466
|
-
let onLayout: jest.Mock;
|
|
467
|
-
let noUndefinedProperty: jest.Mock;
|
|
468
|
-
|
|
469
|
-
beforeEach(function () {
|
|
470
|
-
// @ts-ignore
|
|
471
|
-
global.__DEV__ = false;
|
|
472
|
-
|
|
473
|
-
accessibilityLabelChecker = jest.fn();
|
|
474
|
-
noUndefinedProperty = jest.fn();
|
|
475
|
-
uppercaseChecker = jest.fn();
|
|
476
|
-
onLayout = jest.fn();
|
|
477
|
-
|
|
478
|
-
// @ts-ignore
|
|
479
|
-
jest.spyOn(UseChecks, 'useChecks').mockReturnValue({
|
|
480
|
-
noUppercaseStringChecker: accessibilityLabelChecker,
|
|
481
|
-
noUndefinedProperty,
|
|
482
|
-
uppercaseChecker,
|
|
483
|
-
onLayout,
|
|
484
|
-
} as any);
|
|
485
|
-
|
|
486
|
-
TextInputWithoutDev = require('./TextInput').TextInput;
|
|
487
|
-
});
|
|
488
|
-
|
|
489
|
-
it('does not perform any check', () => {
|
|
490
|
-
render(
|
|
491
|
-
<TextInputWithoutDev
|
|
492
|
-
labelComponent={<Text>First name (required)*</Text>}
|
|
493
|
-
returnKeyType="next"
|
|
494
|
-
testID="text-input"
|
|
495
|
-
accessibilityLabel="Please insert your first name"
|
|
496
|
-
hasValidation={false}
|
|
497
|
-
/>,
|
|
498
|
-
);
|
|
499
|
-
|
|
500
|
-
expect(noUndefinedProperty).not.toHaveBeenCalled();
|
|
501
|
-
});
|
|
502
215
|
|
|
503
|
-
|
|
504
|
-
|
|
505
|
-
style: ERROR_STYLE,
|
|
506
|
-
} as any);
|
|
507
|
-
|
|
508
|
-
const { getByTestId } = render(
|
|
509
|
-
<TextInputWithoutDev
|
|
510
|
-
labelComponent={<Text>First name (required)*</Text>}
|
|
511
|
-
returnKeyType="next"
|
|
512
|
-
testID="text-input"
|
|
513
|
-
accessibilityLabel="Please insert your first name"
|
|
514
|
-
hasValidation={false}
|
|
515
|
-
/>,
|
|
516
|
-
);
|
|
517
|
-
|
|
518
|
-
expect(getByTestId('text-input').props.style).toEqual(undefined);
|
|
519
|
-
});
|
|
216
|
+
expect(fn).toHaveBeenCalledWith('whatever');
|
|
217
|
+
expect(focusNextFormField).toHaveBeenCalledWith();
|
|
520
218
|
});
|
|
521
219
|
});
|
|
522
220
|
|
|
523
|
-
jest.mock('../hooks/useFormField', () => {
|
|
524
|
-
|
|
525
|
-
|
|
526
|
-
|
|
527
|
-
})
|
|
528
|
-
|
|
529
|
-
jest.mock('@react-native-ama/core', () => {
|
|
530
|
-
const originalModule = jest.requireActual('@react-native-ama/core');
|
|
531
|
-
|
|
532
|
-
return {
|
|
533
|
-
...originalModule,
|
|
534
|
-
useAMAContext: () => {
|
|
535
|
-
return {
|
|
536
|
-
isScreenReaderEnabled: true,
|
|
537
|
-
};
|
|
538
|
-
},
|
|
539
|
-
};
|
|
540
|
-
});
|
|
221
|
+
jest.mock('../hooks/useFormField', () => ({
|
|
222
|
+
useFormField: jest.fn(() => ({
|
|
223
|
+
isLastField: jest.fn().mockReturnValue(false),
|
|
224
|
+
focusNextFormField: jest.fn(),
|
|
225
|
+
})),
|
|
226
|
+
}));
|