@times-components/ts-components 1.145.1-b32ea924749bafdf12e3e8515023538fa20e7808.3 → 1.145.1-cfea81c4084e6f91221ea00fec9fc730d5b933cb.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.
- package/dist/components/carousel-component/CarouselComponent.stories.js +146 -0
- package/dist/components/carousel-component/CarouselItem.d.ts +3 -0
- package/dist/components/carousel-component/CarouselItem.js +11 -0
- package/dist/components/carousel-component/DefaultNavigationArrow.d.ts +8 -0
- package/dist/components/carousel-component/DefaultNavigationArrow.js +6 -0
- package/dist/components/carousel-component/DefaultPageDot.d.ts +8 -0
- package/dist/components/carousel-component/DefaultPageDot.js +4 -0
- package/dist/components/carousel-component/__tests__/CarouselComponent.test.d.ts +1 -0
- package/dist/components/carousel-component/__tests__/CarouselComponent.test.js +163 -0
- package/dist/components/carousel-component/__tests__/CarouselItem.test.d.ts +1 -0
- package/dist/components/carousel-component/__tests__/CarouselItem.test.js +80 -0
- package/dist/components/carousel-component/__tests__/DefaultNavigationArrow.test.d.ts +1 -0
- package/dist/components/carousel-component/__tests__/DefaultNavigationArrow.test.js +62 -0
- package/dist/components/carousel-component/__tests__/DefaultPageDot.test.d.ts +1 -0
- package/dist/components/carousel-component/__tests__/DefaultPageDot.test.js +68 -0
- package/dist/components/carousel-component/hooks/__tests__/useCarousel.test.d.ts +1 -0
- package/dist/components/carousel-component/hooks/__tests__/useCarousel.test.js +314 -0
- package/dist/components/carousel-component/hooks/useCarousel.d.ts +2 -0
- package/dist/components/carousel-component/hooks/useCarousel.js +140 -0
- package/dist/components/carousel-component/index.d.ts +4 -0
- package/dist/components/carousel-component/index.js +20 -0
- package/dist/components/carousel-component/styles.d.ts +30 -0
- package/dist/components/carousel-component/styles.js +120 -0
- package/dist/components/carousel-component/types.d.ts +46 -0
- package/dist/components/carousel-component/types.js +2 -0
- package/dist/components/opta/cricket/scorecard/OptaCricketScorecard.js +2 -10
- package/dist/components/opta/cricket/scorecard/__tests__/OptaCricketScorecard.test.js +17 -94
- package/dist/components/opta/football/summary/OptaFootballSummary.js +2 -10
- package/dist/components/opta/football/summary/__tests__/OptaFootballSummary.test.js +18 -95
- package/dist/components/opta/rugby/summary/OptaRugbySummary.js +2 -10
- package/dist/components/opta/rugby/summary/__tests__/OptaRugbySummary.test.js +17 -94
- package/dist/components/trip-cards/SkeletonCard.d.ts +2 -0
- package/dist/components/trip-cards/SkeletonCard.js +21 -0
- package/dist/components/trip-cards/TripCard.d.ts +3 -0
- package/dist/components/trip-cards/TripCard.js +47 -0
- package/dist/components/trip-cards/TripCards.stories.d.ts +1 -0
- package/dist/components/trip-cards/TripCards.stories.js +40 -0
- package/dist/components/trip-cards/TripCardsLayout.d.ts +3 -0
- package/dist/components/trip-cards/TripCardsLayout.js +26 -0
- package/dist/components/trip-cards/__tests__/SkeletonCard.test.d.ts +1 -0
- package/dist/components/trip-cards/__tests__/SkeletonCard.test.js +139 -0
- package/dist/components/trip-cards/__tests__/TripCard.test.d.ts +1 -0
- package/dist/components/trip-cards/__tests__/TripCard.test.js +95 -0
- package/dist/components/trip-cards/__tests__/TripCardsLayout.test.d.ts +1 -0
- package/dist/components/trip-cards/__tests__/TripCardsLayout.test.js +277 -0
- package/dist/components/trip-cards/__tests__/assets.test.d.ts +1 -0
- package/dist/components/trip-cards/__tests__/assets.test.js +165 -0
- package/dist/components/trip-cards/__tests__/helpers.test.d.ts +1 -0
- package/dist/components/trip-cards/__tests__/helpers.test.js +135 -0
- package/dist/components/trip-cards/__tests__/index.test.d.ts +1 -0
- package/dist/components/trip-cards/__tests__/index.test.js +437 -0
- package/dist/components/trip-cards/__tests__/mockData.test.d.ts +1 -0
- package/dist/components/trip-cards/__tests__/mockData.test.js +57 -0
- package/dist/components/trip-cards/__tests__/skeletonStyles.test.d.ts +1 -0
- package/dist/components/trip-cards/__tests__/skeletonStyles.test.js +194 -0
- package/dist/components/trip-cards/assets/BoatIcon.d.ts +1 -0
- package/dist/components/trip-cards/assets/BoatIcon.js +4 -0
- package/dist/components/trip-cards/assets/CalendarIcon.d.ts +1 -0
- package/dist/components/trip-cards/assets/CalendarIcon.js +4 -0
- package/dist/components/trip-cards/assets/ChevronRightIcon.d.ts +1 -0
- package/dist/components/trip-cards/assets/ChevronRightIcon.js +4 -0
- package/dist/components/trip-cards/assets/LocationIcon.d.ts +1 -0
- package/dist/components/trip-cards/assets/LocationIcon.js +4 -0
- package/dist/components/trip-cards/assets/MoonIcon.d.ts +1 -0
- package/dist/components/trip-cards/assets/MoonIcon.js +4 -0
- package/dist/components/trip-cards/assets/index.d.ts +6 -0
- package/dist/components/trip-cards/assets/index.js +7 -0
- package/dist/components/trip-cards/helpers.d.ts +4 -0
- package/dist/components/trip-cards/helpers.js +74 -0
- package/dist/components/trip-cards/index.d.ts +4 -0
- package/dist/components/trip-cards/index.js +70 -0
- package/dist/components/trip-cards/mockData.d.ts +3 -0
- package/dist/components/trip-cards/mockData.js +323 -0
- package/dist/components/trip-cards/skeletonStyles.d.ts +9 -0
- package/dist/components/trip-cards/skeletonStyles.js +37 -0
- package/dist/components/trip-cards/styles.d.ts +39 -0
- package/dist/components/trip-cards/styles.js +387 -0
- package/dist/components/trip-cards/types.d.ts +87 -0
- package/dist/components/trip-cards/types.js +2 -0
- package/dist/index.d.ts +1 -0
- package/dist/index.js +2 -1
- package/package.json +3 -3
- package/rnw.js +1 -1
- package/src/components/carousel-component/CarouselComponent.stories.tsx +220 -0
- package/src/components/carousel-component/CarouselItem.tsx +20 -0
- package/src/components/carousel-component/DefaultNavigationArrow.tsx +37 -0
- package/src/components/carousel-component/DefaultPageDot.tsx +20 -0
- package/src/components/carousel-component/__tests__/CarouselComponent.test.tsx +259 -0
- package/src/components/carousel-component/__tests__/CarouselItem.test.tsx +140 -0
- package/src/components/carousel-component/__tests__/DefaultNavigationArrow.test.tsx +153 -0
- package/src/components/carousel-component/__tests__/DefaultPageDot.test.tsx +105 -0
- package/src/components/carousel-component/hooks/__tests__/useCarousel.test.ts +438 -0
- package/src/components/carousel-component/hooks/useCarousel.ts +187 -0
- package/src/components/carousel-component/index.tsx +88 -0
- package/src/components/carousel-component/styles.ts +140 -0
- package/src/components/carousel-component/types.ts +51 -0
- package/src/components/opta/cricket/scorecard/OptaCricketScorecard.tsx +0 -13
- package/src/components/opta/cricket/scorecard/__tests__/OptaCricketScorecard.test.tsx +16 -126
- package/src/components/opta/cricket/scorecard/__tests__/__snapshots__/OptaCricketScorecard.test.tsx.snap +6 -5
- package/src/components/opta/football/summary/OptaFootballSummary.tsx +0 -13
- package/src/components/opta/football/summary/__tests__/OptaFootballSummary.test.tsx +18 -127
- package/src/components/opta/football/summary/__tests__/__snapshots__/OptaFootballSummary.test.tsx.snap +6 -5
- package/src/components/opta/rugby/summary/OptaRugbySummary.tsx +0 -13
- package/src/components/opta/rugby/summary/__tests__/OptaRugbySummary.test.tsx +17 -127
- package/src/components/opta/rugby/summary/__tests__/__snapshots__/OptaRugbySummary.test.tsx.snap +6 -5
- package/src/components/trip-cards/SkeletonCard.tsx +54 -0
- package/src/components/trip-cards/TripCard.tsx +135 -0
- package/src/components/trip-cards/TripCards.stories.tsx +67 -0
- package/src/components/trip-cards/TripCardsLayout.tsx +75 -0
- package/src/components/trip-cards/__tests__/SkeletonCard.test.tsx +169 -0
- package/src/components/trip-cards/__tests__/TripCard.test.tsx +120 -0
- package/src/components/trip-cards/__tests__/TripCardsLayout.test.tsx +532 -0
- package/src/components/trip-cards/__tests__/assets.test.tsx +206 -0
- package/src/components/trip-cards/__tests__/helpers.test.ts +165 -0
- package/src/components/trip-cards/__tests__/index.test.tsx +499 -0
- package/src/components/trip-cards/__tests__/mockData.test.ts +67 -0
- package/src/components/trip-cards/__tests__/skeletonStyles.test.tsx +256 -0
- package/src/components/trip-cards/assets/BoatIcon.tsx +17 -0
- package/src/components/trip-cards/assets/CalendarIcon.tsx +17 -0
- package/src/components/trip-cards/assets/ChevronRightIcon.tsx +20 -0
- package/src/components/trip-cards/assets/LocationIcon.tsx +17 -0
- package/src/components/trip-cards/assets/MoonIcon.tsx +17 -0
- package/src/components/trip-cards/assets/index.ts +7 -0
- package/src/components/trip-cards/helpers.ts +99 -0
- package/src/components/trip-cards/index.tsx +104 -0
- package/src/components/trip-cards/mockData.ts +351 -0
- package/src/components/trip-cards/skeletonStyles.ts +46 -0
- package/src/components/trip-cards/styles.ts +426 -0
- package/src/components/trip-cards/types.ts +91 -0
- package/src/index.ts +2 -0
- package/dist/components/opta/utils/__tests__/emitEvent.test.js +0 -264
- package/dist/components/opta/utils/emitEvent.d.ts +0 -1
- package/dist/components/opta/utils/emitEvent.js +0 -9
- package/src/components/opta/utils/__tests__/emitEvent.test.tsx +0 -415
- package/src/components/opta/utils/emitEvent.ts +0 -11
- /package/dist/components/{opta/utils/__tests__/emitEvent.test.d.ts → carousel-component/CarouselComponent.stories.d.ts} +0 -0
|
@@ -0,0 +1,499 @@
|
|
|
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
|
+
});
|
|
@@ -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
|
+
});
|