|
1 | 1 | import { ReactTestInstance } from 'react-test-renderer'; |
2 | 2 | import { matches, TextMatch, TextMatchOptions } from '../../matches'; |
| 3 | +import { findAll } from '../findAll'; |
3 | 4 | import { matchTextContent } from './matchTextContent'; |
4 | 5 |
|
5 | 6 | export function matchLabelText( |
6 | | - rootInstance: ReactTestInstance, |
7 | | - node: ReactTestInstance, |
| 7 | + root: ReactTestInstance, |
| 8 | + element: ReactTestInstance, |
8 | 9 | text: TextMatch, |
9 | 10 | options: TextMatchOptions = {} |
10 | 11 | ) { |
11 | 12 | return ( |
12 | | - matchAccessibilityLabel(node, text, options) || |
| 13 | + matchAccessibilityLabel(element, text, options) || |
13 | 14 | matchAccessibilityLabelledBy( |
14 | | - rootInstance, |
15 | | - node.props.accessibilityLabelledBy, |
| 15 | + root, |
| 16 | + element.props.accessibilityLabelledBy, |
16 | 17 | text, |
17 | 18 | options |
18 | 19 | ) |
19 | 20 | ); |
20 | 21 | } |
21 | 22 |
|
22 | | -export function matchAccessibilityLabel( |
23 | | - node: ReactTestInstance, |
| 23 | +function matchAccessibilityLabel( |
| 24 | + element: ReactTestInstance, |
24 | 25 | text: TextMatch, |
25 | 26 | options: TextMatchOptions |
26 | 27 | ) { |
27 | 28 | const { exact, normalizer } = options; |
28 | | - return matches(text, node.props.accessibilityLabel, normalizer, exact); |
| 29 | + return matches(text, element.props.accessibilityLabel, normalizer, exact); |
29 | 30 | } |
30 | 31 |
|
31 | | -export function matchAccessibilityLabelledBy( |
32 | | - rootInstance: ReactTestInstance, |
33 | | - nativeID: string | undefined, |
| 32 | +function matchAccessibilityLabelledBy( |
| 33 | + root: ReactTestInstance, |
| 34 | + nativeId: string | undefined, |
34 | 35 | text: TextMatch, |
35 | 36 | options: TextMatchOptions |
36 | 37 | ) { |
37 | | - if (!nativeID) { |
| 38 | + if (!nativeId) { |
38 | 39 | return false; |
39 | 40 | } |
40 | 41 |
|
41 | | - const { exact, normalizer } = options; |
42 | | - return rootInstance |
43 | | - .findAll((node) => |
44 | | - matches(nativeID, node.props?.nativeID, normalizer, exact) |
45 | | - ) |
46 | | - .some((node) => matchTextContent(node, text)); |
| 42 | + return ( |
| 43 | + findAll( |
| 44 | + root, |
| 45 | + (element) => |
| 46 | + element.props?.nativeID === nativeId && |
| 47 | + matchTextContent(element, text, options) |
| 48 | + ).length > 0 |
| 49 | + ); |
47 | 50 | } |
0 commit comments