@times-components/ts-components 1.146.2-a0ffbb6bc2acbec91d140a39f6be06256e702094.5 → 1.146.2-c12ed7999a41984c2ba8c437357e7a5df1914881.48

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 (137) hide show
  1. package/dist/components/carousel-component/CarouselComponent.stories.d.ts +1 -0
  2. package/dist/components/carousel-component/CarouselComponent.stories.js +146 -0
  3. package/dist/components/carousel-component/CarouselItem.d.ts +3 -0
  4. package/dist/components/carousel-component/CarouselItem.js +12 -0
  5. package/dist/components/carousel-component/DefaultNavigationArrow.d.ts +8 -0
  6. package/dist/components/carousel-component/DefaultNavigationArrow.js +6 -0
  7. package/dist/components/carousel-component/DefaultPageDot.d.ts +8 -0
  8. package/dist/components/carousel-component/DefaultPageDot.js +4 -0
  9. package/dist/components/carousel-component/__tests__/CarouselComponent.test.d.ts +1 -0
  10. package/dist/components/carousel-component/__tests__/CarouselComponent.test.js +163 -0
  11. package/dist/components/carousel-component/__tests__/CarouselItem.test.d.ts +1 -0
  12. package/dist/components/carousel-component/__tests__/CarouselItem.test.js +80 -0
  13. package/dist/components/carousel-component/__tests__/DefaultNavigationArrow.test.d.ts +1 -0
  14. package/dist/components/carousel-component/__tests__/DefaultNavigationArrow.test.js +62 -0
  15. package/dist/components/carousel-component/__tests__/DefaultPageDot.test.d.ts +1 -0
  16. package/dist/components/carousel-component/__tests__/DefaultPageDot.test.js +68 -0
  17. package/dist/components/carousel-component/hooks/__tests__/useCarousel.test.d.ts +1 -0
  18. package/dist/components/carousel-component/hooks/__tests__/useCarousel.test.js +459 -0
  19. package/dist/components/carousel-component/hooks/useCarousel.d.ts +2 -0
  20. package/dist/components/carousel-component/hooks/useCarousel.js +167 -0
  21. package/dist/components/carousel-component/index.d.ts +4 -0
  22. package/dist/components/carousel-component/index.js +20 -0
  23. package/dist/components/carousel-component/styles.d.ts +28 -0
  24. package/dist/components/carousel-component/styles.js +172 -0
  25. package/dist/components/carousel-component/types.d.ts +53 -0
  26. package/dist/components/carousel-component/types.js +2 -0
  27. package/dist/components/social-embed/SocialMediaEmbed.js +15 -122
  28. package/dist/components/social-embed/SocialVendor.d.ts +16 -1
  29. package/dist/components/social-embed/SocialVendor.js +2 -41
  30. package/dist/components/social-embed/__tests__/SocialVendor.test.js +1 -8
  31. package/dist/components/social-embed/constants.d.ts +0 -1
  32. package/dist/components/social-embed/constants.js +2 -3
  33. package/dist/components/social-embed/helpers/socialMediaVendors.js +1 -6
  34. package/dist/components/social-embed/styles.d.ts +0 -1
  35. package/dist/components/social-embed/styles.js +1 -28
  36. package/dist/components/trip-cards/SkeletonCard.d.ts +7 -0
  37. package/dist/components/trip-cards/SkeletonCard.js +22 -0
  38. package/dist/components/trip-cards/TripCard.d.ts +3 -0
  39. package/dist/components/trip-cards/TripCard.js +61 -0
  40. package/dist/components/trip-cards/TripCards.stories.d.ts +1 -0
  41. package/dist/components/trip-cards/TripCards.stories.js +159 -0
  42. package/dist/components/trip-cards/TripCardsLayout.d.ts +3 -0
  43. package/dist/components/trip-cards/TripCardsLayout.js +63 -0
  44. package/dist/components/trip-cards/__tests__/SkeletonCard.test.d.ts +1 -0
  45. package/dist/components/trip-cards/__tests__/SkeletonCard.test.js +139 -0
  46. package/dist/components/trip-cards/__tests__/TripCard.test.d.ts +1 -0
  47. package/dist/components/trip-cards/__tests__/TripCard.test.js +165 -0
  48. package/dist/components/trip-cards/__tests__/TripCardsLayout.test.d.ts +1 -0
  49. package/dist/components/trip-cards/__tests__/TripCardsLayout.test.js +353 -0
  50. package/dist/components/trip-cards/__tests__/assets.test.d.ts +1 -0
  51. package/dist/components/trip-cards/__tests__/assets.test.js +165 -0
  52. package/dist/components/trip-cards/__tests__/helpers.test.d.ts +1 -0
  53. package/dist/components/trip-cards/__tests__/helpers.test.js +221 -0
  54. package/dist/components/trip-cards/__tests__/index.test.d.ts +1 -0
  55. package/dist/components/trip-cards/__tests__/index.test.js +482 -0
  56. package/dist/components/trip-cards/__tests__/mockData.test.d.ts +1 -0
  57. package/dist/components/trip-cards/__tests__/mockData.test.js +57 -0
  58. package/dist/components/trip-cards/__tests__/skeletonStyles.test.d.ts +1 -0
  59. package/dist/components/trip-cards/__tests__/skeletonStyles.test.js +194 -0
  60. package/dist/components/trip-cards/assets/BoatIcon.d.ts +1 -0
  61. package/dist/components/trip-cards/assets/BoatIcon.js +4 -0
  62. package/dist/components/trip-cards/assets/CalendarIcon.d.ts +1 -0
  63. package/dist/components/trip-cards/assets/CalendarIcon.js +4 -0
  64. package/dist/components/trip-cards/assets/ChevronRightIcon.d.ts +1 -0
  65. package/dist/components/trip-cards/assets/ChevronRightIcon.js +4 -0
  66. package/dist/components/trip-cards/assets/LocationIcon.d.ts +1 -0
  67. package/dist/components/trip-cards/assets/LocationIcon.js +4 -0
  68. package/dist/components/trip-cards/assets/MoonIcon.d.ts +1 -0
  69. package/dist/components/trip-cards/assets/MoonIcon.js +4 -0
  70. package/dist/components/trip-cards/assets/index.d.ts +6 -0
  71. package/dist/components/trip-cards/assets/index.js +7 -0
  72. package/dist/components/trip-cards/helpers.d.ts +11 -0
  73. package/dist/components/trip-cards/helpers.js +144 -0
  74. package/dist/components/trip-cards/index.d.ts +4 -0
  75. package/dist/components/trip-cards/index.js +68 -0
  76. package/dist/components/trip-cards/mockData.d.ts +3 -0
  77. package/dist/components/trip-cards/mockData.js +317 -0
  78. package/dist/components/trip-cards/skeletonStyles.d.ts +9 -0
  79. package/dist/components/trip-cards/skeletonStyles.js +37 -0
  80. package/dist/components/trip-cards/styles.d.ts +43 -0
  81. package/dist/components/trip-cards/styles.js +404 -0
  82. package/dist/components/trip-cards/types.d.ts +121 -0
  83. package/dist/components/trip-cards/types.js +2 -0
  84. package/dist/index.d.ts +1 -0
  85. package/dist/index.js +2 -1
  86. package/dist/utils/cookie.d.ts +1 -0
  87. package/dist/utils/cookie.js +8 -1
  88. package/package.json +3 -3
  89. package/rnw.js +1 -1
  90. package/src/components/carousel-component/CarouselComponent.stories.tsx +220 -0
  91. package/src/components/carousel-component/CarouselItem.tsx +26 -0
  92. package/src/components/carousel-component/DefaultNavigationArrow.tsx +37 -0
  93. package/src/components/carousel-component/DefaultPageDot.tsx +20 -0
  94. package/src/components/carousel-component/__tests__/CarouselComponent.test.tsx +259 -0
  95. package/src/components/carousel-component/__tests__/CarouselItem.test.tsx +140 -0
  96. package/src/components/carousel-component/__tests__/DefaultNavigationArrow.test.tsx +153 -0
  97. package/src/components/carousel-component/__tests__/DefaultPageDot.test.tsx +105 -0
  98. package/src/components/carousel-component/hooks/__tests__/useCarousel.test.ts +625 -0
  99. package/src/components/carousel-component/hooks/useCarousel.ts +229 -0
  100. package/src/components/carousel-component/index.tsx +92 -0
  101. package/src/components/carousel-component/styles.ts +188 -0
  102. package/src/components/carousel-component/types.ts +62 -0
  103. package/src/components/social-embed/SocialMediaEmbed.tsx +1 -111
  104. package/src/components/social-embed/SocialVendor.tsx +1 -46
  105. package/src/components/social-embed/__tests__/SocialVendor.test.tsx +0 -11
  106. package/src/components/social-embed/constants.ts +1 -2
  107. package/src/components/social-embed/helpers/socialMediaVendors.ts +0 -5
  108. package/src/components/social-embed/styles.ts +0 -30
  109. package/src/components/trip-cards/SkeletonCard.tsx +64 -0
  110. package/src/components/trip-cards/TripCard.tsx +172 -0
  111. package/src/components/trip-cards/TripCards.stories.tsx +224 -0
  112. package/src/components/trip-cards/TripCardsLayout.tsx +162 -0
  113. package/src/components/trip-cards/__tests__/SkeletonCard.test.tsx +169 -0
  114. package/src/components/trip-cards/__tests__/TripCard.test.tsx +255 -0
  115. package/src/components/trip-cards/__tests__/TripCardsLayout.test.tsx +671 -0
  116. package/src/components/trip-cards/__tests__/assets.test.tsx +206 -0
  117. package/src/components/trip-cards/__tests__/helpers.test.ts +273 -0
  118. package/src/components/trip-cards/__tests__/index.test.tsx +554 -0
  119. package/src/components/trip-cards/__tests__/mockData.test.ts +67 -0
  120. package/src/components/trip-cards/__tests__/skeletonStyles.test.tsx +256 -0
  121. package/src/components/trip-cards/assets/BoatIcon.tsx +17 -0
  122. package/src/components/trip-cards/assets/CalendarIcon.tsx +17 -0
  123. package/src/components/trip-cards/assets/ChevronRightIcon.tsx +20 -0
  124. package/src/components/trip-cards/assets/LocationIcon.tsx +17 -0
  125. package/src/components/trip-cards/assets/MoonIcon.tsx +17 -0
  126. package/src/components/trip-cards/assets/index.ts +7 -0
  127. package/src/components/trip-cards/helpers.ts +181 -0
  128. package/src/components/trip-cards/index.tsx +120 -0
  129. package/src/components/trip-cards/mockData.ts +345 -0
  130. package/src/components/trip-cards/skeletonStyles.ts +46 -0
  131. package/src/components/trip-cards/styles.ts +450 -0
  132. package/src/components/trip-cards/types.ts +130 -0
  133. package/src/index.ts +2 -0
  134. package/src/utils/cookie.ts +8 -0
  135. package/dist/components/social-embed/components/FacebookComponent.d.ts +0 -6
  136. package/dist/components/social-embed/components/FacebookComponent.js +0 -74
  137. package/src/components/social-embed/components/FacebookComponent.tsx +0 -93
@@ -0,0 +1,554 @@
1
+ import React from 'react';
2
+ import { render, screen, waitFor } from '@testing-library/react';
3
+ import '@testing-library/jest-dom';
4
+ import { TripCards } from '../index';
5
+ import { TripCardsElement } from '../types';
6
+ import * as mockDataModule from '../mockData';
7
+
8
+ global.fetch = jest.fn();
9
+
10
+ // Mock ResizeObserver
11
+ global.ResizeObserver = class ResizeObserver {
12
+ public observe(): void {
13
+ // Mock implementation
14
+ }
15
+ public unobserve(): void {
16
+ // Mock implementation
17
+ }
18
+ public disconnect(): void {
19
+ // Mock implementation
20
+ }
21
+ };
22
+
23
+ describe('TripCards', () => {
24
+ const mockCards = [
25
+ {
26
+ cruise_id: '1',
27
+ image: 'image1.jpg',
28
+ headline: 'Mock Cruise 1',
29
+ date: 'Jan 2024',
30
+ duration: '7 nights',
31
+ route: 'Route 1',
32
+ ship: 'Ship 1',
33
+ price: '£1000',
34
+ original_price: undefined,
35
+ logo: 'logo1.png',
36
+ logo_url: 'https://example.com',
37
+ logo_name: 'Mock Line 1',
38
+ cta_url: 'link1',
39
+ cta_text: 'View'
40
+ },
41
+ {
42
+ cruise_id: '2',
43
+ image: 'image2.jpg',
44
+ headline: 'Mock Cruise 2',
45
+ date: 'Feb 2024',
46
+ duration: '14 nights',
47
+ route: 'Route 2',
48
+ ship: 'Ship 2',
49
+ price: '£2000',
50
+ original_price: undefined,
51
+ logo: 'logo2.png',
52
+ logo_url: 'https://example.com',
53
+ logo_name: 'Mock Line 2',
54
+ cta_url: 'link2',
55
+ cta_text: 'View'
56
+ },
57
+ {
58
+ cruise_id: '3',
59
+ image: 'image3.jpg',
60
+ headline: 'Mock Cruise 3',
61
+ date: 'Mar 2024',
62
+ duration: '10 nights',
63
+ route: 'Route 3',
64
+ ship: 'Ship 3',
65
+ price: '£1500',
66
+ original_price: undefined,
67
+ logo: 'logo3.png',
68
+ logo_url: 'https://example.com',
69
+ logo_name: 'Mock Line 3',
70
+ cta_url: 'link3',
71
+ cta_text: 'View'
72
+ }
73
+ ];
74
+
75
+ const mockElement: TripCardsElement = {
76
+ title: 'Test Cruises',
77
+ description: 'Test Description',
78
+ tripcards: btoa(JSON.stringify([1, 2, 3])),
79
+ titleurl: 'https://example.com'
80
+ };
81
+
82
+ beforeEach(() => {
83
+ jest.clearAllMocks();
84
+
85
+ // Mock matchMedia for each test
86
+ Object.defineProperty(window, 'matchMedia', {
87
+ writable: true,
88
+ configurable: true,
89
+ value: jest.fn().mockImplementation(query => ({
90
+ matches: false,
91
+ media: query,
92
+ onchange: null,
93
+ addListener: jest.fn(),
94
+ removeListener: jest.fn(),
95
+ addEventListener: jest.fn(),
96
+ removeEventListener: jest.fn(),
97
+ dispatchEvent: jest.fn()
98
+ }))
99
+ });
100
+
101
+ jest
102
+ .spyOn(mockDataModule, 'getMockTripCards')
103
+ .mockImplementation((count?: number) => {
104
+ return count ? mockCards.slice(0, count) : mockCards;
105
+ });
106
+ Object.defineProperty(window, 'innerWidth', {
107
+ writable: true,
108
+ configurable: true,
109
+ value: 1024
110
+ });
111
+ });
112
+
113
+ describe('Mock Data Mode', () => {
114
+ it('renders cards when useMockData is true', async () => {
115
+ render(<TripCards element={mockElement} useMockData={true} />);
116
+
117
+ await waitFor(() => {
118
+ expect(screen.getByText('Mock Cruise 1')).toBeInTheDocument();
119
+ expect(screen.getByText('Mock Cruise 2')).toBeInTheDocument();
120
+ });
121
+ });
122
+
123
+ it('renders title and description', async () => {
124
+ render(<TripCards element={mockElement} useMockData={true} />);
125
+
126
+ await waitFor(() => {
127
+ expect(screen.getByText('Test Cruises')).toBeInTheDocument();
128
+ expect(screen.getByText('Test Description')).toBeInTheDocument();
129
+ });
130
+ });
131
+
132
+ it('respects the number of IDs', async () => {
133
+ render(<TripCards element={mockElement} useMockData={true} />);
134
+
135
+ await waitFor(() => {
136
+ expect(mockDataModule.getMockTripCards).toHaveBeenCalledWith(3);
137
+ });
138
+ });
139
+ });
140
+
141
+ describe('Error Handling', () => {
142
+ it('returns null when no IDs are provided', async () => {
143
+ const emptyElement: TripCardsElement = {
144
+ title: 'Test',
145
+ description: 'Test',
146
+ tripcards: '',
147
+ titleurl: undefined
148
+ };
149
+
150
+ const { container } = render(<TripCards element={emptyElement} />);
151
+
152
+ await waitFor(() => {
153
+ expect(container.firstChild).toBeNull();
154
+ });
155
+ });
156
+
157
+ it('returns null when fetch fails', async () => {
158
+ (global.fetch as jest.Mock).mockRejectedValue(new Error('Network error'));
159
+
160
+ const { container } = render(<TripCards element={mockElement} />);
161
+
162
+ await waitFor(() => {
163
+ expect(container.firstChild).toBeNull();
164
+ });
165
+ });
166
+
167
+ it('returns null when response is not ok', async () => {
168
+ (global.fetch as jest.Mock).mockResolvedValue({
169
+ ok: false,
170
+ status: 404
171
+ });
172
+
173
+ const { container } = render(<TripCards element={mockElement} />);
174
+
175
+ await waitFor(() => {
176
+ expect(container.firstChild).toBeNull();
177
+ });
178
+ });
179
+
180
+ it('returns null when API response format is invalid', async () => {
181
+ (global.fetch as jest.Mock).mockResolvedValue({
182
+ ok: true,
183
+ json: async () => ({ invalid: 'data' })
184
+ });
185
+
186
+ const { container } = render(<TripCards element={mockElement} />);
187
+
188
+ await waitFor(() => {
189
+ expect(container.firstChild).toBeNull();
190
+ });
191
+ });
192
+ });
193
+
194
+ describe('API Data Fetching', () => {
195
+ it('fetches and displays cruise data from API', async () => {
196
+ const mockApiResponse = {
197
+ results: [
198
+ {
199
+ post_id: 1,
200
+ cruise_id: 1,
201
+ cruise_title: 'API Cruise 1',
202
+ cruise_line: {
203
+ name: 'API Line',
204
+ link: 'http://line.com',
205
+ logo: 'logo.png'
206
+ },
207
+ ship: {
208
+ name: 'API Ship',
209
+ link: 'http://ship.com',
210
+ image: 'api-image1.jpg'
211
+ },
212
+ departs: '2026-03-01',
213
+ ends: '2026-03-11',
214
+ date_label: 'March 2024',
215
+ destination: ['Port 1', 'Port 3'],
216
+ duration: 10,
217
+ itinerary: ['Port 1', 'Port 2', 'Port 3'],
218
+ prices: {
219
+ cheapest_price: 1500,
220
+ inside: 1500,
221
+ outside: 1800,
222
+ balcony: 2000,
223
+ suite: 2500
224
+ },
225
+ was_prices: {
226
+ inside: 2000,
227
+ outside: 2200,
228
+ balcony: 2500,
229
+ suite: 3000
230
+ },
231
+ link: 'api-link',
232
+ campaigns: ['Special'],
233
+ extras: {
234
+ date: 'March 2024',
235
+ duration: '10 nights',
236
+ destination: 'Mediterranean',
237
+ info: 'Additional info'
238
+ }
239
+ },
240
+ {
241
+ post_id: 2,
242
+ cruise_id: 2,
243
+ cruise_title: 'API Cruise 2',
244
+ cruise_line: {
245
+ name: 'API Line',
246
+ link: 'http://line.com',
247
+ logo: 'logo.png'
248
+ },
249
+ ship: {
250
+ name: 'API Ship 2',
251
+ link: 'http://ship.com',
252
+ image: 'api-image2.jpg'
253
+ },
254
+ departs: '2026-04-01',
255
+ ends: '2026-04-11',
256
+ date_label: 'April 2024',
257
+ destination: ['Port 2', 'Port 4'],
258
+ duration: 10,
259
+ itinerary: ['Port 2', 'Port 3', 'Port 4'],
260
+ prices: {
261
+ cheapest_price: 1600,
262
+ inside: 1600,
263
+ outside: 1900,
264
+ balcony: 2100,
265
+ suite: 2600
266
+ },
267
+ was_prices: {
268
+ inside: 0,
269
+ outside: 0,
270
+ balcony: 0,
271
+ suite: 0
272
+ },
273
+ link: 'api-link2',
274
+ campaigns: [],
275
+ extras: {
276
+ date: 'April 2024',
277
+ duration: '10 nights',
278
+ destination: 'Caribbean',
279
+ info: 'Additional info'
280
+ }
281
+ },
282
+ {
283
+ post_id: 3,
284
+ cruise_id: 3,
285
+ cruise_title: 'API Cruise 3',
286
+ cruise_line: {
287
+ name: 'API Line',
288
+ link: 'http://line.com',
289
+ logo: 'logo.png'
290
+ },
291
+ ship: {
292
+ name: 'API Ship 3',
293
+ link: 'http://ship.com',
294
+ image: 'api-image3.jpg'
295
+ },
296
+ departs: '2026-05-01',
297
+ ends: '2026-05-11',
298
+ date_label: 'May 2024',
299
+ destination: ['Port 3', 'Port 5'],
300
+ duration: 10,
301
+ itinerary: ['Port 3', 'Port 4', 'Port 5'],
302
+ prices: {
303
+ cheapest_price: 1700,
304
+ inside: 1700,
305
+ outside: 2000,
306
+ balcony: 2200,
307
+ suite: 2700
308
+ },
309
+ was_prices: {
310
+ inside: 2100,
311
+ outside: 2400,
312
+ balcony: 2600,
313
+ suite: 3100
314
+ },
315
+ link: 'api-link3',
316
+ campaigns: [],
317
+ extras: {
318
+ date: 'May 2024',
319
+ duration: '10 nights',
320
+ destination: 'Alaska',
321
+ info: 'Additional info'
322
+ }
323
+ }
324
+ ]
325
+ };
326
+
327
+ (global.fetch as jest.Mock).mockResolvedValue({
328
+ ok: true,
329
+ json: async () => mockApiResponse
330
+ });
331
+
332
+ render(<TripCards element={mockElement} />);
333
+
334
+ await waitFor(() => {
335
+ expect(screen.getByText('API Cruise 1')).toBeInTheDocument();
336
+ });
337
+ });
338
+
339
+ it('sends correct request to API', async () => {
340
+ const mockApiResponse = {
341
+ results: mockCards.map((card, index) => ({
342
+ post_id: index + 1,
343
+ cruise_id: parseInt(card.cruise_id, 10),
344
+ cruise_title: card.headline,
345
+ cruise_line: {
346
+ name: 'Test Line',
347
+ link: card.logo_url,
348
+ logo: card.logo
349
+ },
350
+ ship: {
351
+ name: card.ship,
352
+ link: 'http://ship.com',
353
+ image: card.image
354
+ },
355
+ departs: '2026-01-01',
356
+ ends: '2026-01-11',
357
+ date_label: card.date,
358
+ destination: ['Test Port'],
359
+ duration: 10,
360
+ itinerary: ['Port 1', 'Port 2', 'Port 3'],
361
+ prices: {
362
+ cheapest_price: 1500,
363
+ inside: 1500,
364
+ outside: 1800,
365
+ balcony: 2000,
366
+ suite: 2500
367
+ },
368
+ was_prices: {
369
+ inside: 0,
370
+ outside: 0,
371
+ balcony: 0,
372
+ suite: 0
373
+ },
374
+ link: card.cta_url,
375
+ campaigns: [],
376
+ extras: {
377
+ date: card.date,
378
+ duration: card.duration,
379
+ destination: 'Test',
380
+ info: 'Info'
381
+ }
382
+ }))
383
+ };
384
+
385
+ (global.fetch as jest.Mock).mockResolvedValue({
386
+ ok: true,
387
+ json: async () => mockApiResponse
388
+ });
389
+
390
+ render(<TripCards element={mockElement} />);
391
+
392
+ await waitFor(() => {
393
+ expect(global.fetch).toHaveBeenCalledWith(
394
+ 'https://www.staging-thetimes.com/holidays/wp-admin/admin-ajax.php',
395
+ expect.objectContaining({
396
+ method: 'POST',
397
+ body: expect.any(FormData)
398
+ })
399
+ );
400
+ });
401
+ });
402
+ });
403
+
404
+ describe('Layout', () => {
405
+ it('uses static grid for exactly 2 cards', async () => {
406
+ const twoCardElement: TripCardsElement = {
407
+ ...mockElement,
408
+ tripcards: btoa(JSON.stringify([1, 2]))
409
+ };
410
+
411
+ render(<TripCards element={twoCardElement} useMockData={true} />);
412
+
413
+ await waitFor(() => {
414
+ expect(screen.getByText('Mock Cruise 1')).toBeInTheDocument();
415
+ });
416
+
417
+ expect(screen.queryByLabelText('Previous items')).not.toBeInTheDocument();
418
+ });
419
+
420
+ it('uses carousel for more than 2 cards', async () => {
421
+ const threeCards = [
422
+ ...mockCards,
423
+ {
424
+ cruise_id: '3',
425
+ image: 'image3.jpg',
426
+ headline: 'Mock Cruise 3',
427
+ date: 'Mar 2024',
428
+ duration: '21 nights',
429
+ route: 'Route 3',
430
+ ship: 'Ship 3',
431
+ price: '£3000',
432
+ original_price: undefined,
433
+ logo: 'logo3.png',
434
+ logo_url: 'https://example.com',
435
+ logo_name: 'Mock Line 3',
436
+ cta_url: 'link3',
437
+ cta_text: 'View'
438
+ }
439
+ ];
440
+
441
+ jest
442
+ .spyOn(mockDataModule, 'getMockTripCards')
443
+ .mockReturnValue(threeCards);
444
+
445
+ render(<TripCards element={mockElement} useMockData={true} />);
446
+
447
+ await waitFor(() => {
448
+ expect(screen.getByText('Mock Cruise 1')).toBeInTheDocument();
449
+ expect(screen.getByLabelText('Previous items')).toBeInTheDocument();
450
+ expect(screen.getByLabelText('Next items')).toBeInTheDocument();
451
+ });
452
+ });
453
+ });
454
+
455
+ describe('Responsive Behavior', () => {
456
+ it('uses matchMedia for responsive breakpoint detection', () => {
457
+ const mockMediaQuery = {
458
+ matches: false,
459
+ media: '(max-width: 767px)',
460
+ onchange: null,
461
+ addListener: jest.fn(),
462
+ removeListener: jest.fn(),
463
+ addEventListener: jest.fn(),
464
+ removeEventListener: jest.fn(),
465
+ dispatchEvent: jest.fn()
466
+ };
467
+
468
+ const matchMediaSpy = jest
469
+ .spyOn(window, 'matchMedia')
470
+ .mockReturnValue(mockMediaQuery as any);
471
+
472
+ const { unmount } = render(
473
+ <TripCards element={mockElement} useMockData={true} />
474
+ );
475
+
476
+ // Verify matchMedia was called with the correct query
477
+ expect(matchMediaSpy).toHaveBeenCalledWith('(max-width: 767px)');
478
+
479
+ // Verify addEventListener was called on the media query
480
+ expect(mockMediaQuery.addEventListener).toHaveBeenCalledWith(
481
+ 'change',
482
+ expect.any(Function)
483
+ );
484
+
485
+ unmount();
486
+
487
+ // Verify removeEventListener was called on cleanup
488
+ expect(mockMediaQuery.removeEventListener).toHaveBeenCalledWith(
489
+ 'change',
490
+ expect.any(Function)
491
+ );
492
+
493
+ matchMediaSpy.mockRestore();
494
+ });
495
+ });
496
+
497
+ describe('Props', () => {
498
+ it('renders empty title when not provided', async () => {
499
+ const elementWithoutTitle: TripCardsElement = {
500
+ ...mockElement,
501
+ title: undefined
502
+ };
503
+
504
+ render(<TripCards element={elementWithoutTitle} useMockData={true} />);
505
+
506
+ await waitFor(() => {
507
+ const titleElement = screen.getByTestId('trip-cards-title');
508
+ expect(titleElement).toBeInTheDocument();
509
+ expect(titleElement).toBeEmptyDOMElement();
510
+ });
511
+ });
512
+
513
+ it('renders empty description when not provided', async () => {
514
+ const elementWithoutDesc: TripCardsElement = {
515
+ ...mockElement,
516
+ description: undefined
517
+ };
518
+
519
+ render(<TripCards element={elementWithoutDesc} useMockData={true} />);
520
+
521
+ await waitFor(() => {
522
+ const descElement = screen.getByTestId('trip-cards-subtitle');
523
+ expect(descElement).toBeInTheDocument();
524
+ expect(descElement).toBeEmptyDOMElement();
525
+ });
526
+ });
527
+
528
+ it('renders title link when provided', async () => {
529
+ render(<TripCards element={mockElement} useMockData={true} />);
530
+
531
+ await waitFor(() => {
532
+ const link = screen.getByTestId('title-link');
533
+ expect(link).toHaveAttribute('href', 'https://example.com');
534
+ expect(link).toHaveAttribute('target', '_blank');
535
+ });
536
+ });
537
+
538
+ it('does not render title link when not provided', async () => {
539
+ const elementWithoutLink: TripCardsElement = {
540
+ ...mockElement,
541
+ titleurl: undefined
542
+ };
543
+
544
+ render(<TripCards element={elementWithoutLink} useMockData={true} />);
545
+
546
+ await waitFor(() => {
547
+ expect(screen.getByText('Mock Cruise 1')).toBeInTheDocument();
548
+ });
549
+
550
+ const links = screen.getAllByRole('link');
551
+ expect(links.length).toBeGreaterThan(0);
552
+ });
553
+ });
554
+ });
@@ -0,0 +1,67 @@
1
+ import { getMockTripCards, mockApiResults } from '../mockData';
2
+
3
+ describe('mockData', () => {
4
+ describe('mockApiResults', () => {
5
+ it('contains 6 cruise results', () => {
6
+ expect(mockApiResults).toHaveLength(6);
7
+ });
8
+
9
+ it('each result has required fields', () => {
10
+ mockApiResults.forEach(result => {
11
+ expect(result).toHaveProperty('cruise_id');
12
+ expect(result).toHaveProperty('cruise_title');
13
+ expect(result).toHaveProperty('cruise_line');
14
+ expect(result).toHaveProperty('ship');
15
+ expect(result).toHaveProperty('prices');
16
+ expect(result).toHaveProperty('was_prices');
17
+ expect(result).toHaveProperty('extras');
18
+ });
19
+ });
20
+
21
+ it('extras object contains required fields', () => {
22
+ mockApiResults.forEach(result => {
23
+ expect(result.extras).toHaveProperty('date');
24
+ expect(result.extras).toHaveProperty('duration');
25
+ expect(result.extras).toHaveProperty('destination');
26
+ expect(result.extras).toHaveProperty('info');
27
+ });
28
+ });
29
+ });
30
+
31
+ describe('getMockTripCards', () => {
32
+ it('returns all transformed cards when no count specified', () => {
33
+ const cards = getMockTripCards();
34
+
35
+ expect(cards).toHaveLength(6);
36
+ });
37
+
38
+ it('returns specified number of cards', () => {
39
+ const cards = getMockTripCards(3);
40
+
41
+ expect(cards).toHaveLength(3);
42
+ });
43
+
44
+ it('returns transformed TripCardApiData objects', () => {
45
+ const cards = getMockTripCards(1);
46
+
47
+ expect(cards[0]).toHaveProperty('cruise_id');
48
+ expect(cards[0]).toHaveProperty('image');
49
+ expect(cards[0]).toHaveProperty('headline');
50
+ expect(cards[0]).toHaveProperty('date');
51
+ expect(cards[0]).toHaveProperty('duration');
52
+ expect(cards[0]).toHaveProperty('route');
53
+ expect(cards[0]).toHaveProperty('ship');
54
+ expect(cards[0]).toHaveProperty('price');
55
+ expect(cards[0]).toHaveProperty('logo');
56
+ expect(cards[0]).toHaveProperty('logo_url');
57
+ expect(cards[0]).toHaveProperty('cta_url');
58
+ expect(cards[0]).toHaveProperty('cta_text');
59
+ });
60
+
61
+ it('cruise_id is converted to string', () => {
62
+ const cards = getMockTripCards(1);
63
+
64
+ expect(typeof cards[0].cruise_id).toBe('string');
65
+ });
66
+ });
67
+ });