@times-components/ts-components 1.145.1-cfea81c4084e6f91221ea00fec9fc730d5b933cb.4 → 1.145.1-e871182934034874ea6a75e1e684090e5504df44.2

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