-
Notifications
You must be signed in to change notification settings - Fork 273
/
Copy pathhost-component-names.ts
58 lines (50 loc) · 2.04 KB
/
host-component-names.ts
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
import type { ReactTestInstance } from 'react-test-renderer';
import type { HostTestInstance } from './component-tree';
const HOST_TEXT_NAMES = ['Text', 'RCTText'];
const HOST_TEXT_INPUT_NAMES = ['TextInput'];
const HOST_IMAGE_NAMES = ['Image'];
const HOST_SWITCH_NAMES = ['RCTSwitch'];
const HOST_SCROLL_VIEW_NAMES = ['RCTScrollView'];
const HOST_MODAL_NAMES = ['Modal'];
/**
* Checks if the given element is a host Text element.
* @param element The element to check.
*/
export function isHostText(element: ReactTestInstance): element is HostTestInstance {
return typeof element?.type === 'string' && HOST_TEXT_NAMES.includes(element.type);
}
/**
* Checks if the given element is a host TextInput element.
* @param element The element to check.
*/
export function isHostTextInput(element: ReactTestInstance): element is HostTestInstance {
return typeof element?.type === 'string' && HOST_TEXT_INPUT_NAMES.includes(element.type);
}
/**
* Checks if the given element is a host Image element.
* @param element The element to check.
*/
export function isHostImage(element: ReactTestInstance): element is HostTestInstance {
return typeof element?.type === 'string' && HOST_IMAGE_NAMES.includes(element.type);
}
/**
* Checks if the given element is a host Switch element.
* @param element The element to check.
*/
export function isHostSwitch(element: ReactTestInstance): element is HostTestInstance {
return typeof element?.type === 'string' && HOST_SWITCH_NAMES.includes(element.type);
}
/**
* Checks if the given element is a host ScrollView element.
* @param element The element to check.
*/
export function isHostScrollView(element: ReactTestInstance): element is HostTestInstance {
return typeof element?.type === 'string' && HOST_SCROLL_VIEW_NAMES.includes(element.type);
}
/**
* Checks if the given element is a host Modal element.
* @param element The element to check.
*/
export function isHostModal(element: ReactTestInstance): element is HostTestInstance {
return typeof element?.type === 'string' && HOST_MODAL_NAMES.includes(element.type);
}