@times-components/ts-components 1.146.2-0831d531868ee6854720b5b42c0a1ccdbe6a4a70.45 → 1.146.2-784617dc4a33959b8795da1d7f425c9929322fae.24

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 (138) hide show
  1. package/dist/components/travel-mini-cta/__tests__/index.test.js +262 -0
  2. package/dist/components/travel-mini-cta/index.d.ts +10 -0
  3. package/dist/components/travel-mini-cta/index.js +93 -0
  4. package/dist/components/travel-mini-cta/styles.d.ts +42 -0
  5. package/dist/components/travel-mini-cta/styles.js +268 -0
  6. package/dist/components/travel-mini-cta/travel-mini-cta.stories.js +8 -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/__tests__/__snapshots__/index.test.tsx.snap +211 -0
  20. package/src/components/travel-mini-cta/__tests__/index.test.tsx +330 -0
  21. package/src/components/travel-mini-cta/index.tsx +190 -0
  22. package/src/components/travel-mini-cta/styles.ts +331 -0
  23. package/src/components/travel-mini-cta/travel-mini-cta.stories.tsx +23 -0
  24. package/src/components/travel-mini-cta/types.ts +10 -0
  25. package/src/index.ts +1 -2
  26. package/src/utils/applyDarkMode.ts +12 -0
  27. package/src/utils/getMediaQuery.ts +25 -0
  28. package/src/utils/index.ts +2 -0
  29. package/dist/components/carousel-component/CarouselComponent.stories.js +0 -146
  30. package/dist/components/carousel-component/CarouselItem.d.ts +0 -3
  31. package/dist/components/carousel-component/CarouselItem.js +0 -12
  32. package/dist/components/carousel-component/DefaultNavigationArrow.d.ts +0 -8
  33. package/dist/components/carousel-component/DefaultNavigationArrow.js +0 -6
  34. package/dist/components/carousel-component/DefaultPageDot.d.ts +0 -8
  35. package/dist/components/carousel-component/DefaultPageDot.js +0 -4
  36. package/dist/components/carousel-component/__tests__/CarouselComponent.test.d.ts +0 -1
  37. package/dist/components/carousel-component/__tests__/CarouselComponent.test.js +0 -163
  38. package/dist/components/carousel-component/__tests__/CarouselItem.test.d.ts +0 -1
  39. package/dist/components/carousel-component/__tests__/CarouselItem.test.js +0 -80
  40. package/dist/components/carousel-component/__tests__/DefaultNavigationArrow.test.d.ts +0 -1
  41. package/dist/components/carousel-component/__tests__/DefaultNavigationArrow.test.js +0 -62
  42. package/dist/components/carousel-component/__tests__/DefaultPageDot.test.d.ts +0 -1
  43. package/dist/components/carousel-component/__tests__/DefaultPageDot.test.js +0 -68
  44. package/dist/components/carousel-component/hooks/__tests__/useCarousel.test.d.ts +0 -1
  45. package/dist/components/carousel-component/hooks/__tests__/useCarousel.test.js +0 -459
  46. package/dist/components/carousel-component/hooks/useCarousel.d.ts +0 -2
  47. package/dist/components/carousel-component/hooks/useCarousel.js +0 -167
  48. package/dist/components/carousel-component/index.d.ts +0 -4
  49. package/dist/components/carousel-component/index.js +0 -20
  50. package/dist/components/carousel-component/styles.d.ts +0 -28
  51. package/dist/components/carousel-component/styles.js +0 -172
  52. package/dist/components/carousel-component/types.d.ts +0 -53
  53. package/dist/components/carousel-component/types.js +0 -2
  54. package/dist/components/trip-cards/SkeletonCard.d.ts +0 -7
  55. package/dist/components/trip-cards/SkeletonCard.js +0 -22
  56. package/dist/components/trip-cards/TripCard.d.ts +0 -3
  57. package/dist/components/trip-cards/TripCard.js +0 -62
  58. package/dist/components/trip-cards/TripCards.stories.d.ts +0 -1
  59. package/dist/components/trip-cards/TripCards.stories.js +0 -159
  60. package/dist/components/trip-cards/TripCardsLayout.d.ts +0 -3
  61. package/dist/components/trip-cards/TripCardsLayout.js +0 -63
  62. package/dist/components/trip-cards/__tests__/SkeletonCard.test.d.ts +0 -1
  63. package/dist/components/trip-cards/__tests__/SkeletonCard.test.js +0 -139
  64. package/dist/components/trip-cards/__tests__/TripCard.test.d.ts +0 -1
  65. package/dist/components/trip-cards/__tests__/TripCard.test.js +0 -95
  66. package/dist/components/trip-cards/__tests__/TripCardsLayout.test.d.ts +0 -1
  67. package/dist/components/trip-cards/__tests__/TripCardsLayout.test.js +0 -351
  68. package/dist/components/trip-cards/__tests__/assets.test.d.ts +0 -1
  69. package/dist/components/trip-cards/__tests__/assets.test.js +0 -165
  70. package/dist/components/trip-cards/__tests__/helpers.test.d.ts +0 -1
  71. package/dist/components/trip-cards/__tests__/helpers.test.js +0 -220
  72. package/dist/components/trip-cards/__tests__/index.test.js +0 -478
  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 -12
  90. package/dist/components/trip-cards/helpers.js +0 -158
  91. package/dist/components/trip-cards/index.d.ts +0 -4
  92. package/dist/components/trip-cards/index.js +0 -68
  93. package/dist/components/trip-cards/mockData.d.ts +0 -3
  94. package/dist/components/trip-cards/mockData.js +0 -317
  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 -43
  98. package/dist/components/trip-cards/styles.js +0 -404
  99. package/dist/components/trip-cards/types.d.ts +0 -122
  100. package/src/components/carousel-component/CarouselComponent.stories.tsx +0 -220
  101. package/src/components/carousel-component/CarouselItem.tsx +0 -26
  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 -625
  109. package/src/components/carousel-component/hooks/useCarousel.ts +0 -229
  110. package/src/components/carousel-component/index.tsx +0 -92
  111. package/src/components/carousel-component/styles.ts +0 -188
  112. package/src/components/carousel-component/types.ts +0 -62
  113. package/src/components/trip-cards/SkeletonCard.tsx +0 -64
  114. package/src/components/trip-cards/TripCard.tsx +0 -187
  115. package/src/components/trip-cards/TripCards.stories.tsx +0 -224
  116. package/src/components/trip-cards/TripCardsLayout.tsx +0 -169
  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 -669
  120. package/src/components/trip-cards/__tests__/assets.test.tsx +0 -206
  121. package/src/components/trip-cards/__tests__/helpers.test.ts +0 -272
  122. package/src/components/trip-cards/__tests__/index.test.tsx +0 -550
  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 -207
  132. package/src/components/trip-cards/index.tsx +0 -122
  133. package/src/components/trip-cards/mockData.ts +0 -345
  134. package/src/components/trip-cards/skeletonStyles.ts +0 -46
  135. package/src/components/trip-cards/styles.ts +0 -450
  136. package/src/components/trip-cards/types.ts +0 -131
  137. /package/dist/components/{trip-cards → travel-mini-cta}/__tests__/index.test.d.ts +0 -0
  138. /package/dist/components/{carousel-component/CarouselComponent.stories.d.ts → travel-mini-cta/travel-mini-cta.stories.d.ts} +0 -0
@@ -1,669 +0,0 @@
1
- import React from 'react';
2
- import { render, screen, fireEvent } from '@testing-library/react';
3
- import '@testing-library/jest-dom';
4
- import { TripCardsLayout } from '../TripCardsLayout';
5
- import { TripCardApiData } from '../types';
6
- import { tealiumTrackingHandler } from '../../../helpers/tracking/TrackingHandler';
7
-
8
- jest.mock('../../../helpers/tracking/TrackingHandler', () => ({
9
- tealiumTrackingHandler: jest.fn()
10
- }));
11
-
12
- const mockElement = {
13
- class: 'trip-cards',
14
- tripcards: btoa(JSON.stringify([1, 2])),
15
- title: 'Test Cruises',
16
- titleurl: 'https://example.com',
17
- description: 'Test Description'
18
- };
19
-
20
- const MockCard = ({ card }: { card?: TripCardApiData }) => (
21
- <div data-testid="mock-card">
22
- {card ? card.headline || 'Mock Card' : 'Mock Card'}
23
- </div>
24
- );
25
-
26
- // Mock ResizeObserver
27
- global.ResizeObserver = class ResizeObserver {
28
- public observe(): void {
29
- // Mock implementation
30
- }
31
- public unobserve(): void {
32
- // Mock implementation
33
- }
34
- public disconnect(): void {
35
- // Mock implementation
36
- }
37
- };
38
-
39
- describe('TripCardsLayout', () => {
40
- beforeEach(() => {
41
- jest.clearAllMocks();
42
- Element.prototype.scrollTo = jest.fn();
43
-
44
- // Mock matchMedia for each test
45
- Object.defineProperty(window, 'matchMedia', {
46
- writable: true,
47
- configurable: true,
48
- value: jest.fn().mockImplementation(query => ({
49
- matches: false,
50
- media: query,
51
- onchange: null,
52
- addListener: jest.fn(),
53
- removeListener: jest.fn(),
54
- addEventListener: jest.fn(),
55
- removeEventListener: jest.fn(),
56
- dispatchEvent: jest.fn()
57
- }))
58
- });
59
- });
60
-
61
- afterEach(() => {
62
- jest.clearAllMocks();
63
- });
64
-
65
- describe('Rendering', () => {
66
- it('renders with title and description', () => {
67
- const items = [
68
- { id: '1', data: undefined },
69
- { id: '2', data: undefined }
70
- ];
71
-
72
- render(
73
- <TripCardsLayout
74
- element={mockElement}
75
- items={items}
76
- CardComponent={MockCard}
77
- itemsPerPage={2}
78
- />
79
- );
80
-
81
- expect(screen.getByText('Test Cruises')).toBeInTheDocument();
82
- expect(screen.getByText('Test Description')).toBeInTheDocument();
83
- });
84
-
85
- it('renders empty title when not provided', () => {
86
- const elementWithoutTitle = {
87
- ...mockElement,
88
- title: undefined
89
- };
90
-
91
- const items = [{ id: '1', data: undefined }];
92
-
93
- const { container } = render(
94
- <TripCardsLayout
95
- element={elementWithoutTitle}
96
- items={items}
97
- CardComponent={MockCard}
98
- itemsPerPage={2}
99
- />
100
- );
101
-
102
- const title = container.querySelector('h2');
103
- expect(title).toBeInTheDocument();
104
- expect(title).toBeEmptyDOMElement();
105
- });
106
-
107
- it('renders empty description when not provided', () => {
108
- const elementWithoutDesc = {
109
- ...mockElement,
110
- description: undefined
111
- };
112
-
113
- const items = [{ id: '1', data: undefined }];
114
-
115
- const { container } = render(
116
- <TripCardsLayout
117
- element={elementWithoutDesc}
118
- items={items}
119
- CardComponent={MockCard}
120
- itemsPerPage={2}
121
- />
122
- );
123
-
124
- const description = container.querySelector('p');
125
- expect(description).toBeInTheDocument();
126
- expect(description).toBeEmptyDOMElement();
127
- });
128
-
129
- it('renders title link when provided', () => {
130
- const items = [{ id: '1', data: undefined }];
131
-
132
- render(
133
- <TripCardsLayout
134
- element={mockElement}
135
- items={items}
136
- CardComponent={MockCard}
137
- itemsPerPage={2}
138
- />
139
- );
140
-
141
- const link = screen.getByTestId('trip-cards-title-link');
142
- expect(link).toHaveAttribute('href', 'https://example.com');
143
- expect(link).toHaveAttribute('target', '_blank');
144
- expect(link).toHaveAttribute('rel', 'noopener noreferrer');
145
- });
146
-
147
- it('renders two links when titleurl is provided', () => {
148
- const items = [{ id: '1', data: undefined }];
149
-
150
- render(
151
- <TripCardsLayout
152
- element={mockElement}
153
- items={items}
154
- CardComponent={MockCard}
155
- itemsPerPage={2}
156
- />
157
- );
158
-
159
- const links = screen.getAllByRole('link');
160
- expect(links).toHaveLength(2);
161
-
162
- const titleLink = screen.getByTestId('trip-cards-title-link');
163
- const iconLink = screen.getByTestId('title-link');
164
-
165
- expect(titleLink).toHaveAttribute('href', 'https://example.com');
166
- expect(iconLink).toHaveAttribute('href', 'https://example.com');
167
- });
168
-
169
- it('does not render title link when not provided', () => {
170
- const elementWithoutLink = {
171
- ...mockElement,
172
- titleurl: undefined
173
- };
174
-
175
- const items = [{ id: '1', data: undefined }];
176
-
177
- render(
178
- <TripCardsLayout
179
- element={elementWithoutLink}
180
- items={items}
181
- CardComponent={MockCard}
182
- itemsPerPage={2}
183
- />
184
- );
185
-
186
- const links = screen.queryAllByRole('link');
187
- expect(links.length).toBe(0);
188
- });
189
-
190
- it('renders ChevronRightIcon in title link', () => {
191
- const items = [{ id: '1', data: undefined }];
192
-
193
- const { container } = render(
194
- <TripCardsLayout
195
- element={mockElement}
196
- items={items}
197
- CardComponent={MockCard}
198
- itemsPerPage={2}
199
- />
200
- );
201
-
202
- const svg = container.querySelector('svg');
203
- expect(svg).toBeInTheDocument();
204
- });
205
- });
206
-
207
- describe('Static Grid Layout', () => {
208
- it('renders static grid for exactly 2 items', () => {
209
- const items = [
210
- { id: '1', data: undefined },
211
- { id: '2', data: undefined }
212
- ];
213
-
214
- render(
215
- <TripCardsLayout
216
- element={mockElement}
217
- items={items}
218
- CardComponent={MockCard}
219
- itemsPerPage={2}
220
- />
221
- );
222
-
223
- const staticGrid = screen.getByTestId('static-cards-grid');
224
- expect(staticGrid).toBeInTheDocument();
225
- });
226
-
227
- it('renders correct number of cards in static grid', () => {
228
- const items = [
229
- { id: '1', data: undefined },
230
- { id: '2', data: undefined }
231
- ];
232
-
233
- render(
234
- <TripCardsLayout
235
- element={mockElement}
236
- items={items}
237
- CardComponent={MockCard}
238
- itemsPerPage={2}
239
- />
240
- );
241
-
242
- const cards = screen.getAllByTestId('mock-card');
243
- expect(cards.length).toBe(2);
244
- });
245
-
246
- it('passes correct props to CardComponent in static grid', () => {
247
- const mockData: TripCardApiData = {
248
- cruise_id: '1',
249
- image: 'test.jpg',
250
- headline: 'Test Cruise',
251
- date: 'Jan 2024',
252
- duration: '7 nights',
253
- route: 'Test Route',
254
- ship: 'Test Ship',
255
- price: '£1000',
256
- logo: 'logo.png',
257
- logo_url: 'https://example.com',
258
- cta_url: 'https://example.com',
259
- cta_text: 'View'
260
- };
261
-
262
- const items = [{ id: '1', data: mockData }, { id: '2', data: undefined }];
263
-
264
- render(
265
- <TripCardsLayout
266
- element={mockElement}
267
- items={items}
268
- CardComponent={MockCard}
269
- itemsPerPage={2}
270
- />
271
- );
272
-
273
- expect(screen.getByText('Test Cruise')).toBeInTheDocument();
274
- });
275
- });
276
-
277
- describe('Carousel Layout', () => {
278
- it('renders carousel for more than 2 items', () => {
279
- const items = [
280
- { id: '1', data: undefined },
281
- { id: '2', data: undefined },
282
- { id: '3', data: undefined }
283
- ];
284
-
285
- render(
286
- <TripCardsLayout
287
- element={mockElement}
288
- items={items}
289
- CardComponent={MockCard}
290
- itemsPerPage={2}
291
- />
292
- );
293
-
294
- const cards = screen.getAllByTestId('mock-card');
295
- expect(cards.length).toBe(3);
296
- });
297
-
298
- it('renders navigation arrows in carousel', () => {
299
- const items = [
300
- { id: '1', data: undefined },
301
- { id: '2', data: undefined },
302
- { id: '3', data: undefined }
303
- ];
304
-
305
- render(
306
- <TripCardsLayout
307
- element={mockElement}
308
- items={items}
309
- CardComponent={MockCard}
310
- itemsPerPage={2}
311
- />
312
- );
313
-
314
- expect(screen.getByLabelText('Previous items')).toBeInTheDocument();
315
- expect(screen.getByLabelText('Next items')).toBeInTheDocument();
316
- });
317
-
318
- it('renders page dots in carousel', () => {
319
- const items = [
320
- { id: '1', data: undefined },
321
- { id: '2', data: undefined },
322
- { id: '3', data: undefined },
323
- { id: '4', data: undefined }
324
- ];
325
-
326
- render(
327
- <TripCardsLayout
328
- element={mockElement}
329
- items={items}
330
- CardComponent={MockCard}
331
- itemsPerPage={2}
332
- />
333
- );
334
-
335
- expect(screen.getByLabelText('Previous items')).toBeInTheDocument();
336
- expect(screen.getByLabelText('Next items')).toBeInTheDocument();
337
-
338
- // With 4 items and 2 per page, we have 2 pages, so we should have 2 dot buttons
339
- const pageDots = screen.getAllByLabelText(/Go to page/i);
340
- expect(pageDots.length).toBe(2);
341
- });
342
-
343
- it('renders carousel for 1 item', () => {
344
- const items = [{ id: '1', data: undefined }];
345
-
346
- render(
347
- <TripCardsLayout
348
- element={mockElement}
349
- items={items}
350
- CardComponent={MockCard}
351
- itemsPerPage={2}
352
- />
353
- );
354
-
355
- const cards = screen.getAllByTestId('mock-card');
356
- expect(cards.length).toBe(1);
357
- });
358
-
359
- it('wraps cards in CarouselItem with correct widthConfig', () => {
360
- const items = [
361
- { id: '1', data: undefined },
362
- { id: '2', data: undefined },
363
- { id: '3', data: undefined }
364
- ];
365
-
366
- render(
367
- <TripCardsLayout
368
- element={mockElement}
369
- items={items}
370
- CardComponent={MockCard}
371
- itemsPerPage={2}
372
- />
373
- );
374
-
375
- // Verify carousel is rendering by checking for cards
376
- const cards = screen.getAllByTestId('mock-card');
377
- expect(cards.length).toBe(3);
378
- });
379
- });
380
-
381
- describe('Card Rendering', () => {
382
- it('renders each item with unique key', () => {
383
- const items = [
384
- { id: 'card-1', data: undefined },
385
- { id: 'card-2', data: undefined }
386
- ];
387
-
388
- render(
389
- <TripCardsLayout
390
- element={mockElement}
391
- items={items}
392
- CardComponent={MockCard}
393
- itemsPerPage={2}
394
- />
395
- );
396
-
397
- const cards = screen.getAllByTestId('mock-card');
398
- expect(cards.length).toBe(2);
399
- });
400
-
401
- it('passes data to CardComponent', () => {
402
- const mockData: TripCardApiData = {
403
- cruise_id: '123',
404
- image: 'image.jpg',
405
- headline: 'Specific Cruise',
406
- date: 'Feb 2024',
407
- duration: '10 nights',
408
- route: 'Route A',
409
- ship: 'Ship X',
410
- price: '£2000',
411
- logo: 'logo.png',
412
- logo_url: 'https://example.com',
413
- cta_url: 'https://example.com',
414
- cta_text: 'Book'
415
- };
416
-
417
- const items = [
418
- { id: '1', data: mockData },
419
- { id: '2', data: undefined },
420
- { id: '3', data: undefined }
421
- ];
422
-
423
- render(
424
- <TripCardsLayout
425
- element={mockElement}
426
- items={items}
427
- CardComponent={MockCard}
428
- itemsPerPage={2}
429
- />
430
- );
431
-
432
- expect(screen.getByText('Specific Cruise')).toBeInTheDocument();
433
- });
434
-
435
- it('handles empty items array', () => {
436
- const { container } = render(
437
- <TripCardsLayout
438
- element={mockElement}
439
- items={[]}
440
- CardComponent={MockCard}
441
- itemsPerPage={2}
442
- />
443
- );
444
-
445
- expect(container.firstChild).toBeInTheDocument();
446
- const cards = screen.queryAllByTestId('mock-card');
447
- expect(cards.length).toBe(0);
448
- });
449
- });
450
-
451
- describe('Container Structure', () => {
452
- it('renders main container', () => {
453
- const items = [{ id: '1', data: undefined }];
454
-
455
- render(
456
- <TripCardsLayout
457
- element={mockElement}
458
- items={items}
459
- CardComponent={MockCard}
460
- itemsPerPage={2}
461
- />
462
- );
463
-
464
- const mainContainer = screen.getByTestId('trip-cards-container');
465
- expect(mainContainer).toBeInTheDocument();
466
- });
467
-
468
- it('renders title section', () => {
469
- const items = [{ id: '1', data: undefined }];
470
-
471
- render(
472
- <TripCardsLayout
473
- element={mockElement}
474
- items={items}
475
- CardComponent={MockCard}
476
- itemsPerPage={2}
477
- />
478
- );
479
-
480
- const titleSection = screen.getByTestId('title-section');
481
- expect(titleSection).toBeInTheDocument();
482
- });
483
-
484
- it('renders title bar with content', () => {
485
- const items = [{ id: '1', data: undefined }];
486
-
487
- render(
488
- <TripCardsLayout
489
- element={mockElement}
490
- items={items}
491
- CardComponent={MockCard}
492
- itemsPerPage={2}
493
- />
494
- );
495
-
496
- const titleBar = screen.getByTestId('title-bar');
497
- const titleContent = screen.getByTestId('title-content');
498
-
499
- expect(titleBar).toBeInTheDocument();
500
- expect(titleContent).toBeInTheDocument();
501
- });
502
- });
503
-
504
- describe('ItemsPerPage', () => {
505
- it('respects itemsPerPage prop', () => {
506
- const items = Array.from({ length: 6 }, (_, i) => ({
507
- id: `${i}`,
508
- data: undefined
509
- }));
510
-
511
- render(
512
- <TripCardsLayout
513
- element={mockElement}
514
- items={items}
515
- CardComponent={MockCard}
516
- itemsPerPage={3}
517
- />
518
- );
519
-
520
- const cards = screen.getAllByTestId('mock-card');
521
- expect(cards.length).toBe(6);
522
- });
523
-
524
- it('handles itemsPerPage of 1', () => {
525
- const items = [
526
- { id: '1', data: undefined },
527
- { id: '2', data: undefined }
528
- ];
529
-
530
- render(
531
- <TripCardsLayout
532
- element={mockElement}
533
- items={items}
534
- CardComponent={MockCard}
535
- itemsPerPage={1}
536
- />
537
- );
538
-
539
- const cards = screen.getAllByTestId('mock-card');
540
- expect(cards.length).toBe(2);
541
- });
542
- });
543
-
544
- describe('Edge Cases', () => {
545
- it('handles large number of items', () => {
546
- const items = Array.from({ length: 50 }, (_, i) => ({
547
- id: `${i}`,
548
- data: undefined
549
- }));
550
-
551
- render(
552
- <TripCardsLayout
553
- element={mockElement}
554
- items={items}
555
- CardComponent={MockCard}
556
- itemsPerPage={2}
557
- />
558
- );
559
-
560
- const cards = screen.getAllByTestId('mock-card');
561
- expect(cards.length).toBe(50);
562
- });
563
-
564
- it('handles empty title and description', () => {
565
- const emptyElement = {
566
- ...mockElement,
567
- title: '',
568
- description: ''
569
- };
570
-
571
- const items = [{ id: '1', data: undefined }];
572
-
573
- const { container } = render(
574
- <TripCardsLayout
575
- element={emptyElement}
576
- items={items}
577
- CardComponent={MockCard}
578
- itemsPerPage={2}
579
- />
580
- );
581
-
582
- const title = container.querySelector('h2');
583
- const description = container.querySelector('p');
584
-
585
- expect(title).toBeInTheDocument();
586
- expect(description).toBeInTheDocument();
587
- if (title && description) {
588
- expect(title.textContent).toBe('');
589
- expect(description.textContent).toBe('');
590
- }
591
- });
592
- });
593
-
594
- describe('Tracking', () => {
595
- it('calls tealiumTrackingHandler when title link is clicked', () => {
596
- const items = [{ id: '1', data: undefined }];
597
-
598
- render(
599
- <TripCardsLayout
600
- element={mockElement}
601
- items={items}
602
- CardComponent={MockCard}
603
- itemsPerPage={2}
604
- />
605
- );
606
-
607
- const titleLink = screen.getByTestId('trip-cards-title-link');
608
- fireEvent.click(titleLink);
609
-
610
- expect(tealiumTrackingHandler).toHaveBeenCalledWith(
611
- 'trip cards section title',
612
- 'navigation',
613
- 'click',
614
- 'Trip Cards',
615
- 'Test Cruises',
616
- {
617
- source_page: 'unknown'
618
- }
619
- );
620
- });
621
-
622
- it('calls tealiumTrackingHandler when icon link is clicked', () => {
623
- const items = [{ id: '1', data: undefined }];
624
-
625
- render(
626
- <TripCardsLayout
627
- element={mockElement}
628
- items={items}
629
- CardComponent={MockCard}
630
- itemsPerPage={2}
631
- />
632
- );
633
-
634
- const iconLink = screen.getByTestId('title-link');
635
- fireEvent.click(iconLink);
636
-
637
- expect(tealiumTrackingHandler).toHaveBeenCalledWith(
638
- 'trip cards section title',
639
- 'navigation',
640
- 'click',
641
- 'Trip Cards',
642
- 'Test Cruises',
643
- {
644
- source_page: 'unknown'
645
- }
646
- );
647
- });
648
-
649
- it('does not call tealiumTrackingHandler when title link is not clicked', () => {
650
- const elementWithoutLink = {
651
- ...mockElement,
652
- titleurl: undefined
653
- };
654
-
655
- const items = [{ id: '1', data: undefined }];
656
-
657
- render(
658
- <TripCardsLayout
659
- element={elementWithoutLink}
660
- items={items}
661
- CardComponent={MockCard}
662
- itemsPerPage={2}
663
- />
664
- );
665
-
666
- expect(tealiumTrackingHandler).not.toHaveBeenCalled();
667
- });
668
- });
669
- });