react-native-reanimated-carousel 5.0.0-beta.7 → 5.0.0-beta.8
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +32 -2
- package/lib/commonjs/components/CarouselLayout.js +1 -1
- package/lib/commonjs/components/CarouselLayout.js.map +1 -1
- package/lib/module/components/CarouselLayout.js +1 -1
- package/lib/module/components/CarouselLayout.js.map +1 -1
- package/lib/typescript/components/CarouselLayout.d.ts.map +1 -1
- package/package.json +4 -2
- package/src/components/CarouselLayout.tsx +3 -4
- package/src/components/Carousel.test.tsx +0 -1215
- package/src/components/LazyView.test.tsx +0 -61
- package/src/components/Pagination/Pagination.test.tsx +0 -178
- package/src/components/ScrollViewGesture.test.tsx +0 -155
- package/src/components/issue-899-parallax-reverse-loop.test.tsx +0 -131
- package/src/components/rnr-demo.test.tsx +0 -53
- package/src/hooks/useAutoPlay.test.ts +0 -194
- package/src/hooks/useCarouselController.test.tsx +0 -1158
- package/src/hooks/useCheckMounted.test.ts +0 -47
- package/src/hooks/useCommonVariables.test.tsx +0 -384
- package/src/hooks/useInitProps.test.tsx +0 -134
- package/src/hooks/useLayoutConfig.test.tsx +0 -247
- package/src/hooks/useOffsetX.test.ts +0 -54
- package/src/hooks/useOnProgressChange.test.tsx +0 -270
- package/src/hooks/usePanGestureProxy.test.tsx +0 -368
- package/src/hooks/usePropsErrorBoundary.test.tsx +0 -57
- package/src/hooks/useUpdateGestureConfig.test.ts +0 -89
- package/src/hooks/useVisibleRanges.test.tsx +0 -347
- package/src/layouts/parallax.test.ts +0 -239
- package/src/layouts/stack.test.ts +0 -252
- package/src/store/index.test.tsx +0 -314
- package/src/utils/compute-gesture-translation.test.ts +0 -70
- package/src/utils/compute-offset-if-data-changed.test.ts +0 -133
- package/src/utils/compute-offset-if-size-changed.test.ts +0 -78
- package/src/utils/computed-with-auto-fill-data.test.ts +0 -298
- package/src/utils/deal-with-animation.test.ts +0 -181
- package/src/utils/handleroffset-direction.test.ts +0 -124
- package/src/utils/index.test.ts +0 -90
- package/src/utils/log.test.ts +0 -134
- package/src/utils/sanitize-animation-style.test.ts +0 -40
|
@@ -1,194 +0,0 @@
|
|
|
1
|
-
import { act, renderHook } from "@testing-library/react-hooks";
|
|
2
|
-
|
|
3
|
-
import { useAutoPlay } from "./useAutoPlay";
|
|
4
|
-
|
|
5
|
-
describe("useAutoPlay", () => {
|
|
6
|
-
// Mock timer
|
|
7
|
-
beforeEach(() => {
|
|
8
|
-
jest.useFakeTimers();
|
|
9
|
-
jest.clearAllMocks();
|
|
10
|
-
});
|
|
11
|
-
|
|
12
|
-
afterEach(() => {
|
|
13
|
-
jest.clearAllTimers();
|
|
14
|
-
jest.useRealTimers();
|
|
15
|
-
});
|
|
16
|
-
|
|
17
|
-
// Mock carousel controller
|
|
18
|
-
const mockCarouselController = {
|
|
19
|
-
prev: jest.fn(),
|
|
20
|
-
next: jest.fn(),
|
|
21
|
-
getCurrentIndex: jest.fn(),
|
|
22
|
-
getSharedIndex: jest.fn(),
|
|
23
|
-
scrollTo: jest.fn(),
|
|
24
|
-
};
|
|
25
|
-
|
|
26
|
-
it("should start autoplay when autoPlay is true", () => {
|
|
27
|
-
renderHook(() =>
|
|
28
|
-
useAutoPlay({
|
|
29
|
-
autoPlay: true,
|
|
30
|
-
autoPlayInterval: 1000,
|
|
31
|
-
carouselController: mockCarouselController,
|
|
32
|
-
})
|
|
33
|
-
);
|
|
34
|
-
|
|
35
|
-
act(() => {
|
|
36
|
-
jest.runOnlyPendingTimers();
|
|
37
|
-
});
|
|
38
|
-
|
|
39
|
-
expect(mockCarouselController.next).toHaveBeenCalledTimes(1);
|
|
40
|
-
expect(mockCarouselController.next).toHaveBeenCalledWith(
|
|
41
|
-
expect.objectContaining({
|
|
42
|
-
onFinished: expect.any(Function),
|
|
43
|
-
})
|
|
44
|
-
);
|
|
45
|
-
});
|
|
46
|
-
|
|
47
|
-
it("should not start autoplay when autoPlay is false", () => {
|
|
48
|
-
renderHook(() =>
|
|
49
|
-
useAutoPlay({
|
|
50
|
-
autoPlay: false,
|
|
51
|
-
autoPlayInterval: 1000,
|
|
52
|
-
carouselController: mockCarouselController,
|
|
53
|
-
})
|
|
54
|
-
);
|
|
55
|
-
|
|
56
|
-
act(() => {
|
|
57
|
-
jest.runOnlyPendingTimers();
|
|
58
|
-
});
|
|
59
|
-
|
|
60
|
-
expect(mockCarouselController.next).not.toHaveBeenCalled();
|
|
61
|
-
});
|
|
62
|
-
|
|
63
|
-
it("should play in reverse when autoPlayReverse is true", () => {
|
|
64
|
-
renderHook(() =>
|
|
65
|
-
useAutoPlay({
|
|
66
|
-
autoPlay: true,
|
|
67
|
-
autoPlayReverse: true,
|
|
68
|
-
autoPlayInterval: 1000,
|
|
69
|
-
carouselController: mockCarouselController,
|
|
70
|
-
})
|
|
71
|
-
);
|
|
72
|
-
|
|
73
|
-
act(() => {
|
|
74
|
-
jest.runOnlyPendingTimers();
|
|
75
|
-
});
|
|
76
|
-
|
|
77
|
-
expect(mockCarouselController.prev).toHaveBeenCalledTimes(1);
|
|
78
|
-
expect(mockCarouselController.next).not.toHaveBeenCalled();
|
|
79
|
-
});
|
|
80
|
-
|
|
81
|
-
it("should clear timer on unmount", () => {
|
|
82
|
-
const { unmount } = renderHook(() =>
|
|
83
|
-
useAutoPlay({
|
|
84
|
-
autoPlay: true,
|
|
85
|
-
autoPlayInterval: 1000,
|
|
86
|
-
carouselController: mockCarouselController,
|
|
87
|
-
})
|
|
88
|
-
);
|
|
89
|
-
|
|
90
|
-
// Run the timer once to ensure it's set
|
|
91
|
-
act(() => {
|
|
92
|
-
jest.runOnlyPendingTimers();
|
|
93
|
-
});
|
|
94
|
-
|
|
95
|
-
// Clear previous call records
|
|
96
|
-
mockCarouselController.next.mockClear();
|
|
97
|
-
|
|
98
|
-
// Then unmount the component and run the timer again
|
|
99
|
-
act(() => {
|
|
100
|
-
unmount();
|
|
101
|
-
jest.runOnlyPendingTimers();
|
|
102
|
-
});
|
|
103
|
-
|
|
104
|
-
expect(mockCarouselController.next).not.toHaveBeenCalled();
|
|
105
|
-
});
|
|
106
|
-
|
|
107
|
-
it("should pause and resume autoplay", () => {
|
|
108
|
-
const { result } = renderHook(() =>
|
|
109
|
-
useAutoPlay({
|
|
110
|
-
autoPlay: true,
|
|
111
|
-
autoPlayInterval: 1000,
|
|
112
|
-
carouselController: mockCarouselController,
|
|
113
|
-
})
|
|
114
|
-
);
|
|
115
|
-
|
|
116
|
-
// Run the timer once to ensure it's set
|
|
117
|
-
act(() => {
|
|
118
|
-
jest.runOnlyPendingTimers();
|
|
119
|
-
});
|
|
120
|
-
|
|
121
|
-
// Clear previous call records
|
|
122
|
-
mockCarouselController.next.mockClear();
|
|
123
|
-
|
|
124
|
-
// Pause autoplay
|
|
125
|
-
act(() => {
|
|
126
|
-
result.current.pause();
|
|
127
|
-
jest.runOnlyPendingTimers();
|
|
128
|
-
});
|
|
129
|
-
|
|
130
|
-
expect(mockCarouselController.next).not.toHaveBeenCalled();
|
|
131
|
-
|
|
132
|
-
// Resume autoplay
|
|
133
|
-
act(() => {
|
|
134
|
-
result.current.start();
|
|
135
|
-
jest.runOnlyPendingTimers();
|
|
136
|
-
});
|
|
137
|
-
|
|
138
|
-
expect(mockCarouselController.next).toHaveBeenCalledTimes(1);
|
|
139
|
-
});
|
|
140
|
-
|
|
141
|
-
it("should respect autoPlayInterval timing", () => {
|
|
142
|
-
renderHook(() =>
|
|
143
|
-
useAutoPlay({
|
|
144
|
-
autoPlay: true,
|
|
145
|
-
autoPlayInterval: 2000,
|
|
146
|
-
carouselController: mockCarouselController,
|
|
147
|
-
})
|
|
148
|
-
);
|
|
149
|
-
|
|
150
|
-
// Advance less than interval
|
|
151
|
-
act(() => {
|
|
152
|
-
jest.advanceTimersByTime(1500);
|
|
153
|
-
});
|
|
154
|
-
expect(mockCarouselController.next).not.toHaveBeenCalled();
|
|
155
|
-
|
|
156
|
-
// Advance to complete interval
|
|
157
|
-
act(() => {
|
|
158
|
-
jest.advanceTimersByTime(500);
|
|
159
|
-
});
|
|
160
|
-
expect(mockCarouselController.next).toHaveBeenCalledTimes(1);
|
|
161
|
-
});
|
|
162
|
-
|
|
163
|
-
it("should chain autoplay calls correctly", () => {
|
|
164
|
-
renderHook(() =>
|
|
165
|
-
useAutoPlay({
|
|
166
|
-
autoPlay: true,
|
|
167
|
-
autoPlayInterval: 1000,
|
|
168
|
-
carouselController: mockCarouselController,
|
|
169
|
-
})
|
|
170
|
-
);
|
|
171
|
-
|
|
172
|
-
// First interval
|
|
173
|
-
act(() => {
|
|
174
|
-
jest.runOnlyPendingTimers();
|
|
175
|
-
});
|
|
176
|
-
expect(mockCarouselController.next).toHaveBeenCalledTimes(1);
|
|
177
|
-
|
|
178
|
-
// Trigger onFinished callback to start the next timer
|
|
179
|
-
const onFinished = mockCarouselController.next.mock.calls[0][0].onFinished;
|
|
180
|
-
act(() => {
|
|
181
|
-
onFinished();
|
|
182
|
-
jest.runOnlyPendingTimers();
|
|
183
|
-
});
|
|
184
|
-
expect(mockCarouselController.next).toHaveBeenCalledTimes(2);
|
|
185
|
-
|
|
186
|
-
// Trigger onFinished callback to start the next timer
|
|
187
|
-
const onFinished2 = mockCarouselController.next.mock.calls[1][0].onFinished;
|
|
188
|
-
act(() => {
|
|
189
|
-
onFinished2();
|
|
190
|
-
jest.runOnlyPendingTimers();
|
|
191
|
-
});
|
|
192
|
-
expect(mockCarouselController.next).toHaveBeenCalledTimes(3);
|
|
193
|
-
});
|
|
194
|
-
});
|