1
1
import type { ReactTestInstance } from 'react-test-renderer' ;
2
- import { TextMatch } from '../matches' ;
3
- import { matchStringProp } from '../helpers/matchers/matchStringProp' ;
2
+ import { matches , TextMatch } from '../matches' ;
4
3
import { makeQueries } from './makeQueries' ;
5
4
import type {
6
5
FindAllByQuery ,
@@ -10,16 +9,27 @@ import type {
10
9
QueryAllByQuery ,
11
10
QueryByQuery ,
12
11
} from './makeQueries' ;
12
+ import { TextMatchOptions } from './text' ;
13
+
14
+ const getNodeByHintText = (
15
+ node : ReactTestInstance ,
16
+ text : TextMatch ,
17
+ options : TextMatchOptions = { }
18
+ ) => {
19
+ const { exact, normalizer } = options ;
20
+ return matches ( text , node . props . accessibilityHint , normalizer , exact ) ;
21
+ } ;
13
22
14
23
const queryAllByHintText = (
15
24
instance : ReactTestInstance
16
- ) : ( ( hint : TextMatch ) => Array < ReactTestInstance > ) =>
17
- function queryAllByA11yHintFn ( hint ) {
18
- return instance . findAll (
19
- ( node ) =>
20
- typeof node . type === 'string' &&
21
- matchStringProp ( node . props . accessibilityHint , hint )
22
- ) ;
25
+ ) : ( (
26
+ hint : TextMatch ,
27
+ queryOptions ?: TextMatchOptions
28
+ ) => Array < ReactTestInstance > ) =>
29
+ function queryAllByA11yHintFn ( hint , queryOptions ) {
30
+ return instance
31
+ . findAll ( ( node ) => getNodeByHintText ( node , hint , queryOptions ) )
32
+ . filter ( ( element ) => typeof element . type === 'string' ) ;
23
33
} ;
24
34
25
35
const getMultipleError = ( hint : TextMatch ) =>
@@ -34,28 +44,28 @@ const { getBy, getAllBy, queryBy, queryAllBy, findBy, findAllBy } = makeQueries(
34
44
) ;
35
45
36
46
export type ByHintTextQueries = {
37
- getByHintText : GetByQuery < TextMatch > ;
38
- getAllByHintText : GetAllByQuery < TextMatch > ;
39
- queryByHintText : QueryByQuery < TextMatch > ;
40
- queryAllByHintText : QueryAllByQuery < TextMatch > ;
41
- findByHintText : FindByQuery < TextMatch > ;
42
- findAllByHintText : FindAllByQuery < TextMatch > ;
47
+ getByHintText : GetByQuery < TextMatch , TextMatchOptions > ;
48
+ getAllByHintText : GetAllByQuery < TextMatch , TextMatchOptions > ;
49
+ queryByHintText : QueryByQuery < TextMatch , TextMatchOptions > ;
50
+ queryAllByHintText : QueryAllByQuery < TextMatch , TextMatchOptions > ;
51
+ findByHintText : FindByQuery < TextMatch , TextMatchOptions > ;
52
+ findAllByHintText : FindAllByQuery < TextMatch , TextMatchOptions > ;
43
53
44
54
// a11yHint aliases
45
- getByA11yHint : GetByQuery < TextMatch > ;
46
- getAllByA11yHint : GetAllByQuery < TextMatch > ;
47
- queryByA11yHint : QueryByQuery < TextMatch > ;
48
- queryAllByA11yHint : QueryAllByQuery < TextMatch > ;
49
- findByA11yHint : FindByQuery < TextMatch > ;
50
- findAllByA11yHint : FindAllByQuery < TextMatch > ;
55
+ getByA11yHint : GetByQuery < TextMatch , TextMatchOptions > ;
56
+ getAllByA11yHint : GetAllByQuery < TextMatch , TextMatchOptions > ;
57
+ queryByA11yHint : QueryByQuery < TextMatch , TextMatchOptions > ;
58
+ queryAllByA11yHint : QueryAllByQuery < TextMatch , TextMatchOptions > ;
59
+ findByA11yHint : FindByQuery < TextMatch , TextMatchOptions > ;
60
+ findAllByA11yHint : FindAllByQuery < TextMatch , TextMatchOptions > ;
51
61
52
62
// accessibilityHint aliases
53
- getByAccessibilityHint : GetByQuery < TextMatch > ;
54
- getAllByAccessibilityHint : GetAllByQuery < TextMatch > ;
55
- queryByAccessibilityHint : QueryByQuery < TextMatch > ;
56
- queryAllByAccessibilityHint : QueryAllByQuery < TextMatch > ;
57
- findByAccessibilityHint : FindByQuery < TextMatch > ;
58
- findAllByAccessibilityHint : FindAllByQuery < TextMatch > ;
63
+ getByAccessibilityHint : GetByQuery < TextMatch , TextMatchOptions > ;
64
+ getAllByAccessibilityHint : GetAllByQuery < TextMatch , TextMatchOptions > ;
65
+ queryByAccessibilityHint : QueryByQuery < TextMatch , TextMatchOptions > ;
66
+ queryAllByAccessibilityHint : QueryAllByQuery < TextMatch , TextMatchOptions > ;
67
+ findByAccessibilityHint : FindByQuery < TextMatch , TextMatchOptions > ;
68
+ findAllByAccessibilityHint : FindAllByQuery < TextMatch , TextMatchOptions > ;
59
69
} ;
60
70
61
71
export const bindByHintTextQueries = (
0 commit comments