1
1
import React from 'react' ;
2
- import { Text , TextInput , View } from 'react-native' ;
2
+ import { View } from 'react-native' ;
3
3
import { render , screen } from '../..' ;
4
- import {
5
- getHostChildren ,
6
- getHostSelves ,
7
- getHostSiblings ,
8
- getUnsafeRootElement ,
9
- } from '../component-tree' ;
4
+ import { getHostSiblings , getUnsafeRootElement } from '../component-tree' ;
10
5
11
6
function MultipleHostChildren ( ) {
12
7
return (
@@ -18,98 +13,6 @@ function MultipleHostChildren() {
18
13
) ;
19
14
}
20
15
21
- describe ( 'getHostChildren()' , ( ) => {
22
- it ( 'returns host children for host component' , ( ) => {
23
- render (
24
- < View testID = "grandparent" >
25
- < View testID = "parent" >
26
- < View testID = "subject" />
27
- < Text testID = "sibling" > Hello</ Text >
28
- </ View >
29
- </ View > ,
30
- ) ;
31
-
32
- const hostSubject = screen . getByTestId ( 'subject' ) ;
33
- expect ( getHostChildren ( hostSubject ) ) . toEqual ( [ ] ) ;
34
-
35
- const hostSibling = screen . getByTestId ( 'sibling' ) ;
36
- expect ( getHostChildren ( hostSibling ) ) . toEqual ( [ ] ) ;
37
-
38
- const hostParent = screen . getByTestId ( 'parent' ) ;
39
- expect ( getHostChildren ( hostParent ) ) . toEqual ( [ hostSubject , hostSibling ] ) ;
40
-
41
- const hostGrandparent = screen . getByTestId ( 'grandparent' ) ;
42
- expect ( getHostChildren ( hostGrandparent ) ) . toEqual ( [ hostParent ] ) ;
43
- } ) ;
44
-
45
- it ( 'returns host children for composite component' , ( ) => {
46
- render (
47
- < View testID = "parent" >
48
- < MultipleHostChildren />
49
- < View testID = "subject" />
50
- < View testID = "sibling" />
51
- </ View > ,
52
- ) ;
53
-
54
- expect ( getHostChildren ( screen . getByTestId ( 'parent' ) ) ) . toEqual ( [
55
- screen . getByTestId ( 'child1' ) ,
56
- screen . getByTestId ( 'child2' ) ,
57
- screen . getByTestId ( 'child3' ) ,
58
- screen . getByTestId ( 'subject' ) ,
59
- screen . getByTestId ( 'sibling' ) ,
60
- ] ) ;
61
- } ) ;
62
- } ) ;
63
-
64
- describe ( 'getHostSelves()' , ( ) => {
65
- it ( 'returns passed element for host components' , ( ) => {
66
- render (
67
- < View testID = "grandparent" >
68
- < View testID = "parent" >
69
- < View testID = "subject" />
70
- < View testID = "sibling" />
71
- </ View >
72
- </ View > ,
73
- ) ;
74
-
75
- const hostSubject = screen . getByTestId ( 'subject' ) ;
76
- expect ( getHostSelves ( hostSubject ) ) . toEqual ( [ hostSubject ] ) ;
77
-
78
- const hostSibling = screen . getByTestId ( 'sibling' ) ;
79
- expect ( getHostSelves ( hostSibling ) ) . toEqual ( [ hostSibling ] ) ;
80
-
81
- const hostParent = screen . getByTestId ( 'parent' ) ;
82
- expect ( getHostSelves ( hostParent ) ) . toEqual ( [ hostParent ] ) ;
83
-
84
- const hostGrandparent = screen . getByTestId ( 'grandparent' ) ;
85
- expect ( getHostSelves ( hostGrandparent ) ) . toEqual ( [ hostGrandparent ] ) ;
86
- } ) ;
87
-
88
- test ( 'returns single host element for React Native composite components' , ( ) => {
89
- render (
90
- < View testID = "parent" >
91
- < Text testID = "text" > Text</ Text >
92
- < TextInput
93
- testID = "textInput"
94
- defaultValue = "TextInputValue"
95
- placeholder = "TextInputPlaceholder"
96
- />
97
- </ View > ,
98
- ) ;
99
-
100
- const compositeText = screen . getByText ( 'Text' ) ;
101
- const hostText = screen . getByTestId ( 'text' ) ;
102
- expect ( getHostSelves ( compositeText ) ) . toEqual ( [ hostText ] ) ;
103
-
104
- const compositeTextInputByValue = screen . getByDisplayValue ( 'TextInputValue' ) ;
105
- const compositeTextInputByPlaceholder = screen . getByPlaceholderText ( 'TextInputPlaceholder' ) ;
106
-
107
- const hostTextInput = screen . getByTestId ( 'textInput' ) ;
108
- expect ( getHostSelves ( compositeTextInputByValue ) ) . toEqual ( [ hostTextInput ] ) ;
109
- expect ( getHostSelves ( compositeTextInputByPlaceholder ) ) . toEqual ( [ hostTextInput ] ) ;
110
- } ) ;
111
- } ) ;
112
-
113
16
describe ( 'getHostSiblings()' , ( ) => {
114
17
it ( 'returns host siblings for host component' , ( ) => {
115
18
render (
0 commit comments