@@ -33,37 +33,92 @@ jest.mock("../recyclerview/utils/measureLayout", () => {
33
33
} ;
34
34
} ) ;
35
35
36
+ const renderRecyclerView = ( args : {
37
+ numColumns ?: number ;
38
+ masonry ?: boolean ;
39
+ horizontal ?: boolean ;
40
+ } ) => {
41
+ const { numColumns = 1 , masonry = false , horizontal = false } = args ;
42
+ return render (
43
+ < RecyclerView
44
+ data = { [
45
+ 0 , 1 , 2 , 3 , 4 , 5 , 6 , 7 , 8 , 9 , 10 , 11 , 12 , 13 , 14 , 15 , 16 , 17 , 18 , 19 ,
46
+ 20 , 21 ,
47
+ ] }
48
+ masonry = { masonry }
49
+ overrideProps = { { initialDrawBatchSize : 1 } }
50
+ drawDistance = { 0 }
51
+ numColumns = { numColumns }
52
+ horizontal = { horizontal }
53
+ renderItem = { ( { item } ) => < Text > { item } </ Text > }
54
+ />
55
+ ) ;
56
+ } ;
57
+
36
58
describe ( "RecyclerView" , ( ) => {
37
59
beforeEach ( ( ) => {
38
60
jest . clearAllMocks ( ) ;
39
61
jest . useFakeTimers ( ) ;
40
62
} ) ;
63
+ describe ( "Linear Layout" , ( ) => {
64
+ it ( "renders items " , ( ) => {
65
+ const result = renderRecyclerView ( { } ) ;
66
+
67
+ expect ( result ) . toContainReactComponent ( Text , { children : 0 } ) ;
68
+ expect ( result ) . not . toContainReactComponent ( Text , { children : 11 } ) ;
69
+ } ) ;
70
+ } ) ;
71
+
72
+ describe ( "Masonry Layout" , ( ) => {
73
+ it ( "renders items with masonry" , ( ) => {
74
+ const result = renderRecyclerView ( { masonry : true } ) ;
75
+
76
+ expect ( result ) . toContainReactComponent ( Text , { children : 0 } ) ;
77
+ } ) ;
78
+ it ( "should not render item 20, 21 with numColumns 2" , ( ) => {
79
+ const result = renderRecyclerView ( { numColumns : 2 , masonry : true } ) ;
80
+
81
+ expect ( result ) . toContainReactComponent ( Text , {
82
+ children : 17 ,
83
+ } ) ;
84
+ expect ( result ) . not . toContainReactComponent ( Text , {
85
+ children : 20 ,
86
+ } ) ;
87
+
88
+ expect ( result ) . not . toContainReactComponent ( Text , {
89
+ children : 21 ,
90
+ } ) ;
91
+ } ) ;
92
+ } ) ;
93
+
94
+ describe ( "Grid Layout" , ( ) => {
95
+ it ( "renders items with numColumns 2" , ( ) => {
96
+ const result = renderRecyclerView ( { numColumns : 2 } ) ;
97
+
98
+ expect ( result ) . toContainReactComponent ( Text , { children : 0 } ) ;
99
+ } ) ;
100
+ it ( "should not render item 18, 19 with numColumns 2" , ( ) => {
101
+ const result = renderRecyclerView ( { numColumns : 2 } ) ;
102
+
103
+ expect ( result ) . toContainReactComponent ( Text , {
104
+ children : 17 ,
105
+ } ) ;
106
+ expect ( result ) . not . toContainReactComponent ( Text , {
107
+ children : 20 ,
108
+ } ) ;
109
+
110
+ expect ( result ) . not . toContainReactComponent ( Text , {
111
+ children : 21 ,
112
+ } ) ;
113
+ } ) ;
114
+ } ) ;
41
115
42
- it ( "renders items " , ( ) => {
43
- const result = render (
44
- < RecyclerView
45
- data = { [
46
- "One" ,
47
- "Two" ,
48
- "Three" ,
49
- "Four" ,
50
- "Five" ,
51
- "Six" ,
52
- "Seven" ,
53
- "Eight" ,
54
- "Nine" ,
55
- "Ten" ,
56
- "Eleven" ,
57
- "Twelve" ,
58
- "Thirteen" ,
59
- "Fourteen" ,
60
- "Fifteen" ,
61
- ] }
62
- renderItem = { ( { item } ) => < Text > { item } </ Text > }
63
- />
64
- ) ;
116
+ describe ( "Horizontal Layout" , ( ) => {
117
+ it ( "renders items with horizontal" , ( ) => {
118
+ const result = renderRecyclerView ( { horizontal : true } ) ;
65
119
66
- expect ( result ) . toContainReactComponent ( Text , { children : "One" } ) ;
67
- expect ( result ) . not . toContainReactComponent ( Text , { children : "Eleven" } ) ;
120
+ expect ( result ) . toContainReactComponent ( Text , { children : 0 } ) ;
121
+ expect ( result ) . not . toContainReactComponent ( Text , { children : 5 } ) ;
122
+ } ) ;
68
123
} ) ;
69
124
} ) ;
0 commit comments