1- import { useSharedValue } from ' react-native-reanimated' ;
1+ import { useSharedValue } from " react-native-reanimated" ;
22
3- import { renderHook } from ' @testing-library/react-hooks' ;
3+ import { renderHook } from " @testing-library/react-hooks" ;
44
5- import { useVisibleRanges } from ' ./useVisibleRanges' ;
5+ import { useVisibleRanges } from " ./useVisibleRanges" ;
66
77const viewSize = 393 ;
88
9- describe ( ' useVisibleRanges' , ( ) => {
10- it ( ' should only display the front of the list when loop is false' , async ( ) => {
11- const hook = renderHook ( ( ) => {
12- const translation = useSharedValue ( - 0 ) ;
13- const range = useVisibleRanges ( {
14- total : 10 ,
15- translation,
16- viewSize,
17- windowSize : 4 ,
18- loop : false ,
19- } ) ;
20-
21- return range ;
22- } ) ;
9+ describe ( " useVisibleRanges" , ( ) => {
10+ it ( " should only display the front of the list when loop is false" , async ( ) => {
11+ const hook = renderHook ( ( ) => {
12+ const translation = useSharedValue ( - 0 ) ;
13+ const range = useVisibleRanges ( {
14+ total : 10 ,
15+ translation,
16+ viewSize,
17+ windowSize : 4 ,
18+ loop : false ,
19+ } ) ;
20+
21+ return range ;
22+ } ) ;
2323
24- const expected = hook . result . current . value ;
24+ const expected = hook . result . current . value ;
2525
26- expect ( expected ) . toMatchInlineSnapshot ( `
26+ expect ( expected ) . toMatchInlineSnapshot ( `
2727 {
2828 "negativeRange": [
2929 -3,
@@ -35,25 +35,25 @@ describe('useVisibleRanges', () => {
3535 ],
3636 }
3737 ` ) ;
38+ } ) ;
39+
40+ it ( "should display the rear of the list and the front of the list when loop is true" , async ( ) => {
41+ const hook = renderHook ( ( ) => {
42+ const translation = useSharedValue ( - 0 ) ;
43+ const range = useVisibleRanges ( {
44+ total : 10 ,
45+ translation,
46+ viewSize,
47+ windowSize : 4 ,
48+ loop : true ,
49+ } ) ;
50+
51+ return range ;
3852 } ) ;
3953
40- it ( 'should display the rear of the list and the front of the list when loop is true' , async ( ) => {
41- const hook = renderHook ( ( ) => {
42- const translation = useSharedValue ( - 0 ) ;
43- const range = useVisibleRanges ( {
44- total : 10 ,
45- translation,
46- viewSize,
47- windowSize : 4 ,
48- loop : true ,
49- } ) ;
50-
51- return range ;
52- } ) ;
53-
54- const expected = hook . result . current . value ;
54+ const expected = hook . result . current . value ;
5555
56- expect ( expected ) . toMatchInlineSnapshot ( `
56+ expect ( expected ) . toMatchInlineSnapshot ( `
5757 {
5858 "negativeRange": [
5959 8,
@@ -65,63 +65,63 @@ describe('useVisibleRanges', () => {
6565 ],
6666 }
6767 ` ) ;
68- } ) ;
69-
70- it ( ' should shows the increased range of the list when the loop is false and swiped the carousel.' , async ( ) => {
71- const slide0hook = renderHook ( ( ) => {
72- const translation = useSharedValue ( - 0 * viewSize ) ;
73- const range = useVisibleRanges ( {
74- total : 10 ,
75- translation,
76- viewSize,
77- windowSize : 4 ,
78- loop : false ,
79- } ) ;
80-
81- return range ;
82- } ) . result . current . value ;
83-
84- const slide1hook = renderHook ( ( ) => {
85- const translation = useSharedValue ( - 1 * viewSize ) ;
86- const range = useVisibleRanges ( {
87- total : 10 ,
88- translation,
89- viewSize,
90- windowSize : 4 ,
91- loop : false ,
92- } ) ;
93-
94- return range ;
95- } ) . result . current . value ;
96-
97- const slide2hook = renderHook ( ( ) => {
98- const translation = useSharedValue ( - 2 * viewSize ) ;
99- const range = useVisibleRanges ( {
100- total : 10 ,
101- translation,
102- viewSize,
103- windowSize : 4 ,
104- loop : false ,
105- } ) ;
106-
107- return range ;
108- } ) . result . current . value ;
109-
110- const slide3hook = renderHook ( ( ) => {
111- const translation = useSharedValue ( - 3 * viewSize ) ;
112- const range = useVisibleRanges ( {
113- total : 10 ,
114- translation,
115- viewSize,
116- windowSize : 4 ,
117- loop : false ,
118- } ) ;
119-
120- return range ;
121- } ) . result . current . value ;
122-
123- // [0,3] Display the 0,1,2,3 items.
124- expect ( slide0hook ) . toMatchInlineSnapshot ( `
68+ } ) ;
69+
70+ it ( " should shows the increased range of the list when the loop is false and swiped the carousel." , async ( ) => {
71+ const slide0hook = renderHook ( ( ) => {
72+ const translation = useSharedValue ( - 0 * viewSize ) ;
73+ const range = useVisibleRanges ( {
74+ total : 10 ,
75+ translation,
76+ viewSize,
77+ windowSize : 4 ,
78+ loop : false ,
79+ } ) ;
80+
81+ return range ;
82+ } ) . result . current . value ;
83+
84+ const slide1hook = renderHook ( ( ) => {
85+ const translation = useSharedValue ( - 1 * viewSize ) ;
86+ const range = useVisibleRanges ( {
87+ total : 10 ,
88+ translation,
89+ viewSize,
90+ windowSize : 4 ,
91+ loop : false ,
92+ } ) ;
93+
94+ return range ;
95+ } ) . result . current . value ;
96+
97+ const slide2hook = renderHook ( ( ) => {
98+ const translation = useSharedValue ( - 2 * viewSize ) ;
99+ const range = useVisibleRanges ( {
100+ total : 10 ,
101+ translation,
102+ viewSize,
103+ windowSize : 4 ,
104+ loop : false ,
105+ } ) ;
106+
107+ return range ;
108+ } ) . result . current . value ;
109+
110+ const slide3hook = renderHook ( ( ) => {
111+ const translation = useSharedValue ( - 3 * viewSize ) ;
112+ const range = useVisibleRanges ( {
113+ total : 10 ,
114+ translation,
115+ viewSize,
116+ windowSize : 4 ,
117+ loop : false ,
118+ } ) ;
119+
120+ return range ;
121+ } ) . result . current . value ;
122+
123+ // [0,3] Display the 0,1,2,3 items.
124+ expect ( slide0hook ) . toMatchInlineSnapshot ( `
125125 {
126126 "negativeRange": [
127127 -3,
@@ -134,8 +134,8 @@ describe('useVisibleRanges', () => {
134134 }
135135 ` ) ;
136136
137- // [1,4] Display the 1,2,3,4 items.
138- expect ( slide1hook ) . toMatchInlineSnapshot ( `
137+ // [1,4] Display the 1,2,3,4 items.
138+ expect ( slide1hook ) . toMatchInlineSnapshot ( `
139139 {
140140 "negativeRange": [
141141 -2,
@@ -148,8 +148,8 @@ describe('useVisibleRanges', () => {
148148 }
149149 ` ) ;
150150
151- // [2,5] Display the 2,3,4,5 items.
152- expect ( slide2hook ) . toMatchInlineSnapshot ( `
151+ // [2,5] Display the 2,3,4,5 items.
152+ expect ( slide2hook ) . toMatchInlineSnapshot ( `
153153 {
154154 "negativeRange": [
155155 -1,
@@ -162,8 +162,8 @@ describe('useVisibleRanges', () => {
162162 }
163163 ` ) ;
164164
165- // [3.6] Display the 3,4,5,6 items.
166- expect ( slide3hook ) . toMatchInlineSnapshot ( `
165+ // [3.6] Display the 3,4,5,6 items.
166+ expect ( slide3hook ) . toMatchInlineSnapshot ( `
167167 {
168168 "negativeRange": [
169169 0,
@@ -175,5 +175,5 @@ describe('useVisibleRanges', () => {
175175 ],
176176 }
177177 ` ) ;
178- } ) ;
178+ } ) ;
179179} ) ;
0 commit comments