@times-components/ts-components 1.146.2-be27d508c972211ad80599875cd69c63bf67d4b1.45 → 1.146.2-e5795a0ef59e2adb61ba52aeb7332fda4405cb7a.4

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.
Files changed (156) hide show
  1. package/dist/components/opta/football/opta-match-stats/matchday-live/DesktopWidget.d.ts +10 -0
  2. package/dist/components/opta/football/opta-match-stats/matchday-live/DesktopWidget.js +69 -0
  3. package/dist/components/opta/football/opta-match-stats/matchday-live/MobileWidget.d.ts +12 -0
  4. package/dist/components/opta/football/opta-match-stats/matchday-live/MobileWidget.js +90 -0
  5. package/dist/components/opta/football/opta-match-stats/matchday-live/OptaMatchStatsMatchdayLive.d.ts +12 -0
  6. package/dist/components/opta/football/opta-match-stats/matchday-live/OptaMatchStatsMatchdayLive.js +10 -0
  7. package/dist/components/opta/football/opta-match-stats/matchday-live/OptaMatchStatsMatchdayLive.stories.js +24 -0
  8. package/dist/components/opta/football/opta-match-stats/matchday-live/__tests__/MobileWidget.test.js +57 -0
  9. package/dist/components/{carousel-component/__tests__/DefaultPageDot.test.d.ts → opta/football/opta-match-stats/matchday-live/__tests__/OptaMatchStatsMatchdayLive.test.d.ts} +1 -0
  10. package/dist/components/opta/football/opta-match-stats/matchday-live/__tests__/OptaMatchStatsMatchdayLive.test.js +48 -0
  11. package/dist/components/opta/football/opta-match-stats/matchday-live/styles/MatchdayLiveController.d.ts +1 -0
  12. package/dist/components/opta/football/opta-match-stats/matchday-live/styles/MatchdayLiveController.js +19 -0
  13. package/dist/components/opta/football/opta-match-stats/matchday-live/styles/NavigationWrapper.d.ts +12 -0
  14. package/dist/components/opta/football/opta-match-stats/matchday-live/styles/NavigationWrapper.js +67 -0
  15. package/dist/components/opta/football/opta-match-stats/matchday-live/styles/WidgetContainer.d.ts +6 -0
  16. package/dist/components/opta/football/opta-match-stats/matchday-live/styles/WidgetContainer.js +736 -0
  17. package/dist/components/opta/football/opta-match-stats/matchday-live/styles/__tests__/NavigationWrapper.test.js +33 -0
  18. package/dist/components/opta/football/opta-match-stats/matchday-live/styles/__tests__/WidgetContainer.test.js +36 -0
  19. package/dist/components/opta/football/opta-match-stats/shared/styles.js +8 -1
  20. package/dist/components/opta/football/opta-match-stats/summary/OptaMatchStatsSummary.js +2 -2
  21. package/dist/components/opta/football/opta-match-stats/summary/OptaMatchStatsSummary.stories.js +1 -1
  22. package/dist/components/opta/football/opta-match-stats/summary/WidgetContainer.js +19 -5
  23. package/dist/index.d.ts +1 -1
  24. package/dist/index.js +2 -2
  25. package/package.json +3 -3
  26. package/rnw.js +1 -1
  27. package/src/components/opta/football/opta-match-stats/commentary/__tests__/__snapshots__/OptaMatchStatsCommentary.test.tsx.snap +1 -1
  28. package/src/components/opta/football/opta-match-stats/matchday-live/DesktopWidget.tsx +108 -0
  29. package/src/components/opta/football/opta-match-stats/matchday-live/MobileWidget.tsx +158 -0
  30. package/src/components/opta/football/opta-match-stats/matchday-live/OptaMatchStatsMatchdayLive.stories.tsx +38 -0
  31. package/src/components/opta/football/opta-match-stats/matchday-live/OptaMatchStatsMatchdayLive.tsx +23 -0
  32. package/src/components/opta/football/opta-match-stats/matchday-live/__tests__/MobileWidget.test.tsx +69 -0
  33. package/src/components/opta/football/opta-match-stats/matchday-live/__tests__/OptaMatchStatsMatchdayLive.test.tsx +61 -0
  34. package/src/components/opta/football/opta-match-stats/matchday-live/__tests__/__snapshots__/OptaMatchStatsMatchdayLive.test.tsx.snap +61 -0
  35. package/src/components/opta/football/opta-match-stats/matchday-live/styles/MatchdayLiveController.tsx +19 -0
  36. package/src/components/opta/football/opta-match-stats/matchday-live/styles/NavigationWrapper.tsx +81 -0
  37. package/src/components/opta/football/opta-match-stats/matchday-live/styles/WidgetContainer.tsx +767 -0
  38. package/src/components/opta/football/opta-match-stats/matchday-live/styles/__tests__/NavigationWrapper.test.tsx +67 -0
  39. package/src/components/opta/football/opta-match-stats/matchday-live/styles/__tests__/WidgetContainer.test.tsx +64 -0
  40. package/src/components/opta/football/opta-match-stats/shared/styles.ts +8 -0
  41. package/src/components/opta/football/opta-match-stats/stats-graphs/__tests__/__snapshots__/OptaMatchStatsGraphs.test.tsx.snap +1 -1
  42. package/src/components/opta/football/opta-match-stats/summary/OptaMatchStatsSummary.stories.tsx +1 -1
  43. package/src/components/opta/football/opta-match-stats/summary/OptaMatchStatsSummary.tsx +1 -1
  44. package/src/components/opta/football/opta-match-stats/summary/WidgetContainer.tsx +18 -4
  45. package/src/components/opta/football/opta-match-stats/summary/__tests__/__snapshots__/OptaMatchStatsSummary.test.tsx.snap +1 -1
  46. package/src/index.ts +3 -2
  47. package/dist/components/carousel-component/CarouselComponent.stories.js +0 -146
  48. package/dist/components/carousel-component/CarouselItem.d.ts +0 -3
  49. package/dist/components/carousel-component/CarouselItem.js +0 -12
  50. package/dist/components/carousel-component/DefaultNavigationArrow.d.ts +0 -8
  51. package/dist/components/carousel-component/DefaultNavigationArrow.js +0 -6
  52. package/dist/components/carousel-component/DefaultPageDot.d.ts +0 -8
  53. package/dist/components/carousel-component/DefaultPageDot.js +0 -4
  54. package/dist/components/carousel-component/__tests__/CarouselComponent.test.js +0 -163
  55. package/dist/components/carousel-component/__tests__/CarouselItem.test.js +0 -80
  56. package/dist/components/carousel-component/__tests__/DefaultNavigationArrow.test.js +0 -62
  57. package/dist/components/carousel-component/__tests__/DefaultPageDot.test.js +0 -68
  58. package/dist/components/carousel-component/hooks/__tests__/useCarousel.test.d.ts +0 -1
  59. package/dist/components/carousel-component/hooks/__tests__/useCarousel.test.js +0 -459
  60. package/dist/components/carousel-component/hooks/useCarousel.d.ts +0 -2
  61. package/dist/components/carousel-component/hooks/useCarousel.js +0 -167
  62. package/dist/components/carousel-component/index.d.ts +0 -4
  63. package/dist/components/carousel-component/index.js +0 -20
  64. package/dist/components/carousel-component/styles.d.ts +0 -28
  65. package/dist/components/carousel-component/styles.js +0 -172
  66. package/dist/components/carousel-component/types.d.ts +0 -53
  67. package/dist/components/carousel-component/types.js +0 -2
  68. package/dist/components/trip-cards/SkeletonCard.d.ts +0 -7
  69. package/dist/components/trip-cards/SkeletonCard.js +0 -22
  70. package/dist/components/trip-cards/TripCard.d.ts +0 -3
  71. package/dist/components/trip-cards/TripCard.js +0 -49
  72. package/dist/components/trip-cards/TripCards.stories.d.ts +0 -1
  73. package/dist/components/trip-cards/TripCards.stories.js +0 -159
  74. package/dist/components/trip-cards/TripCardsLayout.d.ts +0 -3
  75. package/dist/components/trip-cards/TripCardsLayout.js +0 -56
  76. package/dist/components/trip-cards/__tests__/SkeletonCard.test.d.ts +0 -1
  77. package/dist/components/trip-cards/__tests__/SkeletonCard.test.js +0 -139
  78. package/dist/components/trip-cards/__tests__/TripCard.test.d.ts +0 -1
  79. package/dist/components/trip-cards/__tests__/TripCard.test.js +0 -95
  80. package/dist/components/trip-cards/__tests__/TripCardsLayout.test.d.ts +0 -1
  81. package/dist/components/trip-cards/__tests__/TripCardsLayout.test.js +0 -314
  82. package/dist/components/trip-cards/__tests__/assets.test.d.ts +0 -1
  83. package/dist/components/trip-cards/__tests__/assets.test.js +0 -165
  84. package/dist/components/trip-cards/__tests__/helpers.test.d.ts +0 -1
  85. package/dist/components/trip-cards/__tests__/helpers.test.js +0 -220
  86. package/dist/components/trip-cards/__tests__/index.test.d.ts +0 -1
  87. package/dist/components/trip-cards/__tests__/index.test.js +0 -478
  88. package/dist/components/trip-cards/__tests__/mockData.test.d.ts +0 -1
  89. package/dist/components/trip-cards/__tests__/mockData.test.js +0 -57
  90. package/dist/components/trip-cards/__tests__/skeletonStyles.test.d.ts +0 -1
  91. package/dist/components/trip-cards/__tests__/skeletonStyles.test.js +0 -194
  92. package/dist/components/trip-cards/assets/BoatIcon.d.ts +0 -1
  93. package/dist/components/trip-cards/assets/BoatIcon.js +0 -4
  94. package/dist/components/trip-cards/assets/CalendarIcon.d.ts +0 -1
  95. package/dist/components/trip-cards/assets/CalendarIcon.js +0 -4
  96. package/dist/components/trip-cards/assets/ChevronRightIcon.d.ts +0 -1
  97. package/dist/components/trip-cards/assets/ChevronRightIcon.js +0 -4
  98. package/dist/components/trip-cards/assets/LocationIcon.d.ts +0 -1
  99. package/dist/components/trip-cards/assets/LocationIcon.js +0 -4
  100. package/dist/components/trip-cards/assets/MoonIcon.d.ts +0 -1
  101. package/dist/components/trip-cards/assets/MoonIcon.js +0 -4
  102. package/dist/components/trip-cards/assets/index.d.ts +0 -6
  103. package/dist/components/trip-cards/assets/index.js +0 -7
  104. package/dist/components/trip-cards/helpers.d.ts +0 -11
  105. package/dist/components/trip-cards/helpers.js +0 -138
  106. package/dist/components/trip-cards/index.d.ts +0 -4
  107. package/dist/components/trip-cards/index.js +0 -68
  108. package/dist/components/trip-cards/mockData.d.ts +0 -3
  109. package/dist/components/trip-cards/mockData.js +0 -317
  110. package/dist/components/trip-cards/skeletonStyles.d.ts +0 -9
  111. package/dist/components/trip-cards/skeletonStyles.js +0 -37
  112. package/dist/components/trip-cards/styles.d.ts +0 -43
  113. package/dist/components/trip-cards/styles.js +0 -404
  114. package/dist/components/trip-cards/types.d.ts +0 -119
  115. package/dist/components/trip-cards/types.js +0 -2
  116. package/src/components/carousel-component/CarouselComponent.stories.tsx +0 -220
  117. package/src/components/carousel-component/CarouselItem.tsx +0 -26
  118. package/src/components/carousel-component/DefaultNavigationArrow.tsx +0 -37
  119. package/src/components/carousel-component/DefaultPageDot.tsx +0 -20
  120. package/src/components/carousel-component/__tests__/CarouselComponent.test.tsx +0 -259
  121. package/src/components/carousel-component/__tests__/CarouselItem.test.tsx +0 -140
  122. package/src/components/carousel-component/__tests__/DefaultNavigationArrow.test.tsx +0 -153
  123. package/src/components/carousel-component/__tests__/DefaultPageDot.test.tsx +0 -105
  124. package/src/components/carousel-component/hooks/__tests__/useCarousel.test.ts +0 -625
  125. package/src/components/carousel-component/hooks/useCarousel.ts +0 -229
  126. package/src/components/carousel-component/index.tsx +0 -92
  127. package/src/components/carousel-component/styles.ts +0 -188
  128. package/src/components/carousel-component/types.ts +0 -62
  129. package/src/components/trip-cards/SkeletonCard.tsx +0 -64
  130. package/src/components/trip-cards/TripCard.tsx +0 -140
  131. package/src/components/trip-cards/TripCards.stories.tsx +0 -224
  132. package/src/components/trip-cards/TripCardsLayout.tsx +0 -145
  133. package/src/components/trip-cards/__tests__/SkeletonCard.test.tsx +0 -169
  134. package/src/components/trip-cards/__tests__/TripCard.test.tsx +0 -120
  135. package/src/components/trip-cards/__tests__/TripCardsLayout.test.tsx +0 -583
  136. package/src/components/trip-cards/__tests__/assets.test.tsx +0 -206
  137. package/src/components/trip-cards/__tests__/helpers.test.ts +0 -272
  138. package/src/components/trip-cards/__tests__/index.test.tsx +0 -550
  139. package/src/components/trip-cards/__tests__/mockData.test.ts +0 -67
  140. package/src/components/trip-cards/__tests__/skeletonStyles.test.tsx +0 -256
  141. package/src/components/trip-cards/assets/BoatIcon.tsx +0 -17
  142. package/src/components/trip-cards/assets/CalendarIcon.tsx +0 -17
  143. package/src/components/trip-cards/assets/ChevronRightIcon.tsx +0 -20
  144. package/src/components/trip-cards/assets/LocationIcon.tsx +0 -17
  145. package/src/components/trip-cards/assets/MoonIcon.tsx +0 -17
  146. package/src/components/trip-cards/assets/index.ts +0 -7
  147. package/src/components/trip-cards/helpers.ts +0 -176
  148. package/src/components/trip-cards/index.tsx +0 -119
  149. package/src/components/trip-cards/mockData.ts +0 -345
  150. package/src/components/trip-cards/skeletonStyles.ts +0 -46
  151. package/src/components/trip-cards/styles.ts +0 -450
  152. package/src/components/trip-cards/types.ts +0 -128
  153. /package/dist/components/{carousel-component/CarouselComponent.stories.d.ts → opta/football/opta-match-stats/matchday-live/OptaMatchStatsMatchdayLive.stories.d.ts} +0 -0
  154. /package/dist/components/{carousel-component/__tests__/CarouselComponent.test.d.ts → opta/football/opta-match-stats/matchday-live/__tests__/MobileWidget.test.d.ts} +0 -0
  155. /package/dist/components/{carousel-component/__tests__/CarouselItem.test.d.ts → opta/football/opta-match-stats/matchday-live/styles/__tests__/NavigationWrapper.test.d.ts} +0 -0
  156. /package/dist/components/{carousel-component/__tests__/DefaultNavigationArrow.test.d.ts → opta/football/opta-match-stats/matchday-live/styles/__tests__/WidgetContainer.test.d.ts} +0 -0
@@ -1,625 +0,0 @@
1
- import React from 'react';
2
- import { renderHook, act } from '@testing-library/react-hooks';
3
- import { useCarousel } from '../useCarousel';
4
-
5
- describe('useCarousel', () => {
6
- beforeEach(() => {
7
- jest.useFakeTimers();
8
- });
9
-
10
- afterEach(() => {
11
- jest.runOnlyPendingTimers();
12
- jest.useRealTimers();
13
- });
14
-
15
- it('initializes with correct default values', () => {
16
- const { result } = renderHook(() => useCarousel(10, { itemsPerPage: 2 }));
17
-
18
- expect(result.current.currentPage).toBe(0);
19
- expect(result.current.totalPages).toBe(5);
20
- expect(result.current.isScrolling).toBe(false);
21
- });
22
-
23
- it('calculates correct totalPages', () => {
24
- const { result } = renderHook(() => useCarousel(10, { itemsPerPage: 3 }));
25
-
26
- expect(result.current.totalPages).toBe(4);
27
- });
28
-
29
- it('provides navigation functions', () => {
30
- const { result } = renderHook(() => useCarousel(10, { itemsPerPage: 2 }));
31
-
32
- expect(typeof result.current.handleNext).toBe('function');
33
- expect(typeof result.current.handlePrevious).toBe('function');
34
- expect(typeof result.current.scrollToPage).toBe('function');
35
- });
36
-
37
- it('provides mouse event handlers for drag functionality', () => {
38
- const { result } = renderHook(() => useCarousel(10, { itemsPerPage: 2 }));
39
-
40
- expect(typeof result.current.handleMouseDown).toBe('function');
41
- expect(typeof result.current.handleMouseUp).toBe('function');
42
- expect(typeof result.current.handleMouseLeave).toBe('function');
43
- });
44
-
45
- it('handles single page correctly', () => {
46
- const { result } = renderHook(() => useCarousel(2, { itemsPerPage: 2 }));
47
-
48
- expect(result.current.totalPages).toBe(1);
49
-
50
- act(() => {
51
- result.current.handleNext();
52
- });
53
-
54
- expect(result.current.currentPage).toBe(0);
55
- });
56
-
57
- it('handles empty items', () => {
58
- const { result } = renderHook(() => useCarousel(0, { itemsPerPage: 2 }));
59
-
60
- expect(result.current.totalPages).toBe(0);
61
- expect(result.current.currentPage).toBe(0);
62
- });
63
-
64
- it('updates totalPages when totalItems changes', () => {
65
- const { result, rerender } = renderHook(
66
- ({ total }) => useCarousel(total, { itemsPerPage: 2 }),
67
- { initialProps: { total: 10 } }
68
- );
69
-
70
- expect(result.current.totalPages).toBe(5);
71
-
72
- rerender({ total: 6 });
73
-
74
- expect(result.current.totalPages).toBe(3);
75
- });
76
-
77
- it('cleans up timeout on unmount', () => {
78
- const { unmount } = renderHook(() => useCarousel(10, { itemsPerPage: 2 }));
79
-
80
- unmount();
81
-
82
- expect(jest.getTimerCount()).toBe(0);
83
- });
84
-
85
- it('defaults to itemsPerPage of 2 when not provided', () => {
86
- const { result } = renderHook(() => useCarousel(10, {}));
87
-
88
- expect(result.current.totalPages).toBe(5);
89
- });
90
-
91
- it('handles itemsPerPage of 1', () => {
92
- const { result } = renderHook(() => useCarousel(5, { itemsPerPage: 1 }));
93
-
94
- expect(result.current.totalPages).toBe(5);
95
- });
96
-
97
- it('handles large number of items', () => {
98
- const { result } = renderHook(() =>
99
- useCarousel(1000, { itemsPerPage: 10 })
100
- );
101
-
102
- expect(result.current.totalPages).toBe(100);
103
- });
104
-
105
- it('handles odd number of items with even itemsPerPage', () => {
106
- const { result } = renderHook(() => useCarousel(5, { itemsPerPage: 2 }));
107
-
108
- expect(result.current.totalPages).toBe(3);
109
- });
110
-
111
- it('provides carouselRef', () => {
112
- const { result } = renderHook(() => useCarousel(10, { itemsPerPage: 2 }));
113
-
114
- expect(result.current.carouselRef).toBeDefined();
115
- expect(typeof result.current.carouselRef).toBe('object');
116
- });
117
-
118
- it('updates when itemsPerPage option changes', () => {
119
- const { result, rerender } = renderHook(
120
- ({ itemsPerPage }) => useCarousel(10, { itemsPerPage }),
121
- { initialProps: { itemsPerPage: 2 } }
122
- );
123
-
124
- expect(result.current.totalPages).toBe(5);
125
-
126
- rerender({ itemsPerPage: 5 });
127
-
128
- expect(result.current.totalPages).toBe(2);
129
- });
130
-
131
- it('handles itemsPerPage greater than total items', () => {
132
- const { result } = renderHook(() => useCarousel(3, { itemsPerPage: 10 }));
133
-
134
- expect(result.current.totalPages).toBe(1);
135
- });
136
-
137
- it('calls onPageChange when provided in options', () => {
138
- const onPageChange = jest.fn();
139
- const { result } = renderHook(() =>
140
- useCarousel(10, { itemsPerPage: 2, onPageChange })
141
- );
142
-
143
- expect(result.current.currentPage).toBe(0);
144
- expect(onPageChange).not.toHaveBeenCalled();
145
- });
146
-
147
- it('handles mouseDown without carouselRef', () => {
148
- const { result } = renderHook(() => useCarousel(10, { itemsPerPage: 2 }));
149
-
150
- const mockEvent = ({
151
- preventDefault: jest.fn(),
152
- pageX: 100
153
- } as unknown) as React.MouseEvent;
154
-
155
- expect(result.current.carouselRef.current).toBeNull();
156
- act(() => {
157
- result.current.handleMouseDown(mockEvent);
158
- });
159
-
160
- expect(mockEvent.preventDefault).not.toHaveBeenCalled();
161
- });
162
-
163
- it('calls onPageChange when scrolling to a page', () => {
164
- const onPageChange = jest.fn();
165
- const { result } = renderHook(() =>
166
- useCarousel(10, { itemsPerPage: 2, onPageChange })
167
- );
168
-
169
- const mockCard1: Partial<HTMLElement> = { offsetLeft: 0 };
170
- const mockCard2: Partial<HTMLElement> = { offsetLeft: 400 };
171
- const mockChildren = [
172
- mockCard1,
173
- mockCard2,
174
- mockCard1,
175
- mockCard2,
176
- mockCard1
177
- ];
178
-
179
- const mockCarousel = {
180
- scrollLeft: 0,
181
- children: mockChildren,
182
- scrollTo: jest.fn(),
183
- addEventListener: jest.fn(),
184
- removeEventListener: jest.fn()
185
- };
186
-
187
- (result.current.carouselRef as any).current = mockCarousel;
188
-
189
- act(() => {
190
- result.current.scrollToPage(1);
191
- jest.runAllTimers();
192
- });
193
- expect(onPageChange).toHaveBeenCalledWith(1);
194
- expect(mockCarousel.scrollTo).toHaveBeenCalled();
195
- });
196
-
197
- it('returns undefined cleanup when carousel is not mounted', () => {
198
- const { result, unmount } = renderHook(() =>
199
- useCarousel(10, { itemsPerPage: 2 })
200
- );
201
-
202
- expect(result.current.carouselRef.current).toBeNull();
203
-
204
- unmount();
205
- });
206
-
207
- it('handles handleMouseUp when not dragging', () => {
208
- const { result } = renderHook(() => useCarousel(10, { itemsPerPage: 2 }));
209
-
210
- const mockEvent = ({
211
- pageX: 100
212
- } as unknown) as React.MouseEvent;
213
-
214
- act(() => {
215
- result.current.handleMouseUp(mockEvent);
216
- });
217
-
218
- expect(result.current.currentPage).toBe(0);
219
- });
220
-
221
- it('handles handleMouseLeave when not dragging', () => {
222
- const { result } = renderHook(() => useCarousel(10, { itemsPerPage: 2 }));
223
-
224
- const mockEvent = ({
225
- pageX: 100
226
- } as unknown) as React.MouseEvent;
227
-
228
- act(() => {
229
- result.current.handleMouseLeave(mockEvent);
230
- });
231
-
232
- expect(result.current.currentPage).toBe(0);
233
- });
234
-
235
- it('handles complete mouse drag interaction', () => {
236
- const { result } = renderHook(() => useCarousel(10, { itemsPerPage: 2 }));
237
-
238
- const mockCarousel = {
239
- scrollLeft: 0,
240
- children: [],
241
- scrollTo: jest.fn(),
242
- style: { cursor: 'grab' },
243
- addEventListener: jest.fn(),
244
- removeEventListener: jest.fn()
245
- };
246
-
247
- (result.current.carouselRef as any).current = mockCarousel;
248
-
249
- const mouseDownEvent = ({
250
- preventDefault: jest.fn(),
251
- pageX: 200
252
- } as unknown) as React.MouseEvent;
253
-
254
- const mouseUpEvent = ({
255
- pageX: 100
256
- } as unknown) as React.MouseEvent;
257
-
258
- act(() => {
259
- result.current.handleMouseDown(mouseDownEvent);
260
- });
261
-
262
- expect(mouseDownEvent.preventDefault).toHaveBeenCalled();
263
- expect(mockCarousel.style.cursor).toBe('grabbing');
264
-
265
- act(() => {
266
- result.current.handleMouseUp(mouseUpEvent);
267
- });
268
-
269
- expect(mockCarousel.style.cursor).toBe('grab');
270
- });
271
-
272
- it('handles mouseUp with small drag distance', () => {
273
- const { result } = renderHook(() => useCarousel(10, { itemsPerPage: 2 }));
274
-
275
- const mockCarousel = {
276
- scrollLeft: 0,
277
- children: [],
278
- scrollTo: jest.fn(),
279
- style: { cursor: 'grab' },
280
- addEventListener: jest.fn(),
281
- removeEventListener: jest.fn()
282
- };
283
-
284
- (result.current.carouselRef as any).current = mockCarousel;
285
-
286
- act(() => {
287
- result.current.handleMouseDown(({
288
- preventDefault: jest.fn(),
289
- pageX: 100
290
- } as unknown) as React.MouseEvent);
291
- });
292
-
293
- act(() => {
294
- result.current.handleMouseUp(({
295
- pageX: 90
296
- } as unknown) as React.MouseEvent);
297
- });
298
-
299
- expect(result.current.currentPage).toBe(0);
300
- });
301
-
302
- it('handles mouseLeave during active drag', () => {
303
- const { result } = renderHook(() => useCarousel(10, { itemsPerPage: 2 }));
304
-
305
- const mockCarousel = {
306
- scrollLeft: 0,
307
- children: [],
308
- scrollTo: jest.fn(),
309
- style: { cursor: 'grab' },
310
- addEventListener: jest.fn(),
311
- removeEventListener: jest.fn()
312
- };
313
-
314
- (result.current.carouselRef as any).current = mockCarousel;
315
-
316
- act(() => {
317
- result.current.handleMouseDown(({
318
- preventDefault: jest.fn(),
319
- pageX: 100
320
- } as unknown) as React.MouseEvent);
321
- });
322
-
323
- expect(mockCarousel.style.cursor).toBe('grabbing');
324
-
325
- const mouseLeaveEvent = ({
326
- pageX: 120
327
- } as unknown) as React.MouseEvent;
328
-
329
- act(() => {
330
- result.current.handleMouseLeave(mouseLeaveEvent);
331
- });
332
-
333
- expect(mockCarousel.style.cursor).toBe('grab');
334
- });
335
-
336
- it('scrollToPage handles case with no children', () => {
337
- const { result } = renderHook(() => useCarousel(10, { itemsPerPage: 2 }));
338
-
339
- const mockCarousel = {
340
- children: [],
341
- scrollTo: jest.fn(),
342
- addEventListener: jest.fn(),
343
- removeEventListener: jest.fn()
344
- };
345
-
346
- (result.current.carouselRef as any).current = mockCarousel;
347
-
348
- act(() => {
349
- result.current.scrollToPage(1);
350
- });
351
-
352
- expect(mockCarousel.scrollTo).not.toHaveBeenCalled();
353
- });
354
-
355
- it('handlePrevious and handleNext navigate correctly', () => {
356
- const { result } = renderHook(() => useCarousel(10, { itemsPerPage: 2 }));
357
-
358
- const mockCards = Array.from({ length: 5 }, (_, i) => ({
359
- offsetLeft: i * 200
360
- })) as HTMLElement[];
361
-
362
- const mockCarousel = {
363
- children: mockCards,
364
- scrollTo: jest.fn(),
365
- addEventListener: jest.fn(),
366
- removeEventListener: jest.fn()
367
- };
368
-
369
- (result.current.carouselRef as any).current = mockCarousel;
370
-
371
- act(() => {
372
- result.current.handleNext();
373
- jest.runAllTimers();
374
- });
375
-
376
- expect(result.current.currentPage).toBe(1);
377
-
378
- act(() => {
379
- result.current.handlePrevious();
380
- jest.runAllTimers();
381
- });
382
-
383
- expect(result.current.currentPage).toBe(0);
384
- });
385
-
386
- it('drag triggers navigation', () => {
387
- const { result } = renderHook(() => useCarousel(10, { itemsPerPage: 2 }));
388
-
389
- const mockCards = Array.from({ length: 5 }, (_, i) => ({
390
- offsetLeft: i * 200
391
- })) as HTMLElement[];
392
-
393
- const mockCarousel = {
394
- children: mockCards,
395
- scrollTo: jest.fn(),
396
- style: { cursor: 'grab' },
397
- addEventListener: jest.fn(),
398
- removeEventListener: jest.fn()
399
- };
400
-
401
- (result.current.carouselRef as any).current = mockCarousel;
402
-
403
- act(() => {
404
- result.current.handleMouseDown(({
405
- preventDefault: jest.fn(),
406
- pageX: 200
407
- } as unknown) as React.MouseEvent);
408
- });
409
-
410
- act(() => {
411
- result.current.handleMouseUp(({
412
- pageX: 100
413
- } as unknown) as React.MouseEvent);
414
- });
415
-
416
- act(() => {
417
- jest.runAllTimers();
418
- });
419
-
420
- expect(result.current.currentPage).toBe(1);
421
- });
422
-
423
- it('provides touch event handlers', () => {
424
- const { result } = renderHook(() => useCarousel(10, { itemsPerPage: 2 }));
425
-
426
- expect(typeof result.current.handleTouchStart).toBe('function');
427
- expect(typeof result.current.handleTouchMove).toBe('function');
428
- expect(typeof result.current.handleTouchEnd).toBe('function');
429
- });
430
-
431
- it('handles touch swipe right to left (next)', () => {
432
- const { result } = renderHook(() => useCarousel(10, { itemsPerPage: 2 }));
433
-
434
- const mockCards = Array.from({ length: 5 }, (_, i) => ({
435
- offsetLeft: i * 200
436
- })) as HTMLElement[];
437
-
438
- const mockCarousel = {
439
- children: mockCards,
440
- scrollTo: jest.fn(),
441
- addEventListener: jest.fn(),
442
- removeEventListener: jest.fn()
443
- };
444
-
445
- (result.current.carouselRef as any).current = mockCarousel;
446
-
447
- act(() => {
448
- result.current.handleTouchStart(({
449
- touches: [{ clientX: 200 }]
450
- } as unknown) as React.TouchEvent);
451
- });
452
-
453
- act(() => {
454
- result.current.handleTouchMove(({
455
- touches: [{ clientX: 150 }]
456
- } as unknown) as React.TouchEvent);
457
- });
458
-
459
- act(() => {
460
- jest.runAllTimers();
461
- });
462
-
463
- expect(result.current.currentPage).toBe(1);
464
-
465
- act(() => {
466
- result.current.handleTouchEnd();
467
- });
468
- });
469
-
470
- it('handles touch swipe left to right (previous)', () => {
471
- const { result } = renderHook(() => useCarousel(10, { itemsPerPage: 2 }));
472
-
473
- const mockCards = Array.from({ length: 5 }, (_, i) => ({
474
- offsetLeft: i * 200
475
- })) as HTMLElement[];
476
-
477
- const mockCarousel = {
478
- children: mockCards,
479
- scrollTo: jest.fn(),
480
- addEventListener: jest.fn(),
481
- removeEventListener: jest.fn()
482
- };
483
-
484
- (result.current.carouselRef as any).current = mockCarousel;
485
-
486
- // First navigate to page 1
487
- act(() => {
488
- result.current.scrollToPage(1);
489
- jest.runAllTimers();
490
- });
491
-
492
- expect(result.current.currentPage).toBe(1);
493
-
494
- // Then swipe left to right (previous)
495
- act(() => {
496
- result.current.handleTouchStart(({
497
- touches: [{ clientX: 100 }]
498
- } as unknown) as React.TouchEvent);
499
- });
500
-
501
- act(() => {
502
- result.current.handleTouchMove(({
503
- touches: [{ clientX: 150 }]
504
- } as unknown) as React.TouchEvent);
505
- });
506
-
507
- act(() => {
508
- jest.runAllTimers();
509
- });
510
-
511
- expect(result.current.currentPage).toBe(0);
512
-
513
- act(() => {
514
- result.current.handleTouchEnd();
515
- });
516
- });
517
-
518
- it('handles touch swipe with small distance (no navigation)', () => {
519
- const { result } = renderHook(() => useCarousel(10, { itemsPerPage: 2 }));
520
-
521
- const mockCarousel = {
522
- children: [],
523
- scrollTo: jest.fn(),
524
- addEventListener: jest.fn(),
525
- removeEventListener: jest.fn()
526
- };
527
-
528
- (result.current.carouselRef as any).current = mockCarousel;
529
-
530
- act(() => {
531
- result.current.handleTouchStart(({
532
- touches: [{ clientX: 100 }]
533
- } as unknown) as React.TouchEvent);
534
- });
535
-
536
- act(() => {
537
- result.current.handleTouchMove(({
538
- touches: [{ clientX: 115 }]
539
- } as unknown) as React.TouchEvent);
540
- });
541
-
542
- expect(result.current.currentPage).toBe(0);
543
-
544
- act(() => {
545
- result.current.handleTouchEnd();
546
- });
547
- });
548
-
549
- it('ignores touch move when no touch start', () => {
550
- const { result } = renderHook(() => useCarousel(10, { itemsPerPage: 2 }));
551
-
552
- const mockCarousel = {
553
- children: [],
554
- scrollTo: jest.fn(),
555
- addEventListener: jest.fn(),
556
- removeEventListener: jest.fn()
557
- };
558
-
559
- (result.current.carouselRef as any).current = mockCarousel;
560
-
561
- act(() => {
562
- result.current.handleTouchMove(({
563
- touches: [{ clientX: 150 }]
564
- } as unknown) as React.TouchEvent);
565
- });
566
-
567
- expect(result.current.currentPage).toBe(0);
568
- });
569
-
570
- it('ignores touch move when already swiping', () => {
571
- const { result } = renderHook(() => useCarousel(10, { itemsPerPage: 2 }));
572
-
573
- const mockCards = Array.from({ length: 5 }, (_, i) => ({
574
- offsetLeft: i * 200
575
- })) as HTMLElement[];
576
-
577
- const mockCarousel = {
578
- children: mockCards,
579
- scrollTo: jest.fn(),
580
- addEventListener: jest.fn(),
581
- removeEventListener: jest.fn()
582
- };
583
-
584
- (result.current.carouselRef as any).current = mockCarousel;
585
-
586
- act(() => {
587
- result.current.handleTouchStart(({
588
- touches: [{ clientX: 200 }]
589
- } as unknown) as React.TouchEvent);
590
- });
591
-
592
- act(() => {
593
- result.current.handleTouchMove(({
594
- touches: [{ clientX: 150 }]
595
- } as unknown) as React.TouchEvent);
596
- });
597
-
598
- // Second touch move should be ignored
599
- act(() => {
600
- result.current.handleTouchMove(({
601
- touches: [{ clientX: 100 }]
602
- } as unknown) as React.TouchEvent);
603
- });
604
-
605
- act(() => {
606
- jest.runAllTimers();
607
- });
608
-
609
- expect(result.current.currentPage).toBe(1);
610
- });
611
-
612
- it('handles touch start without carousel ref', () => {
613
- const { result } = renderHook(() => useCarousel(10, { itemsPerPage: 2 }));
614
-
615
- (result.current.carouselRef as any).current = null;
616
-
617
- act(() => {
618
- result.current.handleTouchStart(({
619
- touches: [{ clientX: 100 }]
620
- } as unknown) as React.TouchEvent);
621
- });
622
-
623
- expect(result.current.currentPage).toBe(0);
624
- });
625
- });