@times-components/ts-components 1.145.1-82bc6796129e892c1eb22c6257c5e3809c159767.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.js +163 -0
- package/dist/components/carousel-component/__tests__/CarouselItem.test.js +80 -0
- package/dist/components/carousel-component/__tests__/DefaultNavigationArrow.test.js +62 -0
- package/dist/components/{opta/football/opta-match-stats/matchday-live/__tests__/OptaMatchStatsMatchdayLive.test.d.ts → carousel-component/__tests__/DefaultPageDot.test.d.ts} +0 -1
- 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/football/opta-match-stats/shared/styles.js +1 -8
- package/dist/components/opta/football/opta-match-stats/summary/OptaMatchStatsSummary.js +2 -2
- package/dist/components/opta/football/opta-match-stats/summary/OptaMatchStatsSummary.stories.js +1 -1
- package/dist/components/opta/football/opta-match-stats/summary/WidgetContainer.js +4 -13
- 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 -1
- package/dist/index.js +2 -2
- 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/football/opta-match-stats/commentary/__tests__/__snapshots__/OptaMatchStatsCommentary.test.tsx.snap +1 -1
- package/src/components/opta/football/opta-match-stats/shared/styles.ts +0 -8
- package/src/components/opta/football/opta-match-stats/stats-graphs/__tests__/__snapshots__/OptaMatchStatsGraphs.test.tsx.snap +1 -1
- package/src/components/opta/football/opta-match-stats/summary/OptaMatchStatsSummary.stories.tsx +1 -1
- package/src/components/opta/football/opta-match-stats/summary/OptaMatchStatsSummary.tsx +1 -1
- package/src/components/opta/football/opta-match-stats/summary/WidgetContainer.tsx +3 -12
- package/src/components/opta/football/opta-match-stats/summary/__tests__/__snapshots__/OptaMatchStatsSummary.test.tsx.snap +1 -1
- 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 -3
- package/dist/components/opta/football/opta-match-stats/matchday-live/DesktopWidget.d.ts +0 -10
- package/dist/components/opta/football/opta-match-stats/matchday-live/DesktopWidget.js +0 -69
- package/dist/components/opta/football/opta-match-stats/matchday-live/MobileWidget.d.ts +0 -12
- package/dist/components/opta/football/opta-match-stats/matchday-live/MobileWidget.js +0 -90
- package/dist/components/opta/football/opta-match-stats/matchday-live/OptaMatchStatsMatchdayLive.d.ts +0 -12
- package/dist/components/opta/football/opta-match-stats/matchday-live/OptaMatchStatsMatchdayLive.js +0 -10
- package/dist/components/opta/football/opta-match-stats/matchday-live/OptaMatchStatsMatchdayLive.stories.js +0 -24
- package/dist/components/opta/football/opta-match-stats/matchday-live/__tests__/MobileWidget.test.js +0 -57
- package/dist/components/opta/football/opta-match-stats/matchday-live/__tests__/OptaMatchStatsMatchdayLive.test.js +0 -48
- package/dist/components/opta/football/opta-match-stats/matchday-live/styles/MatchdayLiveController.d.ts +0 -1
- package/dist/components/opta/football/opta-match-stats/matchday-live/styles/MatchdayLiveController.js +0 -19
- package/dist/components/opta/football/opta-match-stats/matchday-live/styles/NavigationWrapper.d.ts +0 -12
- package/dist/components/opta/football/opta-match-stats/matchday-live/styles/NavigationWrapper.js +0 -67
- package/dist/components/opta/football/opta-match-stats/matchday-live/styles/WidgetContainer.d.ts +0 -6
- package/dist/components/opta/football/opta-match-stats/matchday-live/styles/WidgetContainer.js +0 -730
- package/dist/components/opta/football/opta-match-stats/matchday-live/styles/__tests__/NavigationWrapper.test.js +0 -33
- package/dist/components/opta/football/opta-match-stats/matchday-live/styles/__tests__/WidgetContainer.test.js +0 -36
- package/src/components/opta/football/opta-match-stats/matchday-live/DesktopWidget.tsx +0 -108
- package/src/components/opta/football/opta-match-stats/matchday-live/MobileWidget.tsx +0 -158
- package/src/components/opta/football/opta-match-stats/matchday-live/OptaMatchStatsMatchdayLive.stories.tsx +0 -38
- package/src/components/opta/football/opta-match-stats/matchday-live/OptaMatchStatsMatchdayLive.tsx +0 -23
- package/src/components/opta/football/opta-match-stats/matchday-live/__tests__/MobileWidget.test.tsx +0 -69
- package/src/components/opta/football/opta-match-stats/matchday-live/__tests__/OptaMatchStatsMatchdayLive.test.tsx +0 -61
- package/src/components/opta/football/opta-match-stats/matchday-live/__tests__/__snapshots__/OptaMatchStatsMatchdayLive.test.tsx.snap +0 -61
- package/src/components/opta/football/opta-match-stats/matchday-live/styles/MatchdayLiveController.tsx +0 -19
- package/src/components/opta/football/opta-match-stats/matchday-live/styles/NavigationWrapper.tsx +0 -81
- package/src/components/opta/football/opta-match-stats/matchday-live/styles/WidgetContainer.tsx +0 -761
- package/src/components/opta/football/opta-match-stats/matchday-live/styles/__tests__/NavigationWrapper.test.tsx +0 -67
- package/src/components/opta/football/opta-match-stats/matchday-live/styles/__tests__/WidgetContainer.test.tsx +0 -64
- /package/dist/components/{opta/football/opta-match-stats/matchday-live/OptaMatchStatsMatchdayLive.stories.d.ts → carousel-component/CarouselComponent.stories.d.ts} +0 -0
- /package/dist/components/{opta/football/opta-match-stats/matchday-live/__tests__/MobileWidget.test.d.ts → carousel-component/__tests__/CarouselComponent.test.d.ts} +0 -0
- /package/dist/components/{opta/football/opta-match-stats/matchday-live/styles/__tests__/NavigationWrapper.test.d.ts → carousel-component/__tests__/CarouselItem.test.d.ts} +0 -0
- /package/dist/components/{opta/football/opta-match-stats/matchday-live/styles/__tests__/WidgetContainer.test.d.ts → carousel-component/__tests__/DefaultNavigationArrow.test.d.ts} +0 -0
|
@@ -0,0 +1,206 @@
|
|
|
1
|
+
import React from 'react';
|
|
2
|
+
import { render } from '@testing-library/react';
|
|
3
|
+
import '@testing-library/jest-dom';
|
|
4
|
+
import {
|
|
5
|
+
BoatIcon,
|
|
6
|
+
CalendarIcon,
|
|
7
|
+
ChevronRightIcon,
|
|
8
|
+
LocationIcon,
|
|
9
|
+
MoonIcon
|
|
10
|
+
} from '../assets';
|
|
11
|
+
|
|
12
|
+
describe('Trip Cards Assets', () => {
|
|
13
|
+
describe('BoatIcon', () => {
|
|
14
|
+
it('renders correctly', () => {
|
|
15
|
+
const { container } = render(<BoatIcon />);
|
|
16
|
+
const svg = container.querySelector('svg');
|
|
17
|
+
expect(svg).toBeInTheDocument();
|
|
18
|
+
});
|
|
19
|
+
|
|
20
|
+
it('has correct viewBox', () => {
|
|
21
|
+
const { container } = render(<BoatIcon />);
|
|
22
|
+
const svg = container.querySelector('svg');
|
|
23
|
+
expect(svg).toHaveAttribute('viewBox');
|
|
24
|
+
});
|
|
25
|
+
|
|
26
|
+
it('accepts custom props', () => {
|
|
27
|
+
const { container } = render(<BoatIcon className="custom-class" />);
|
|
28
|
+
const svg = container.querySelector('svg');
|
|
29
|
+
expect(svg).toHaveClass('custom-class');
|
|
30
|
+
});
|
|
31
|
+
|
|
32
|
+
it('has fill attribute', () => {
|
|
33
|
+
const { container } = render(<BoatIcon />);
|
|
34
|
+
const svg = container.querySelector('svg');
|
|
35
|
+
expect(svg).toHaveAttribute('fill');
|
|
36
|
+
});
|
|
37
|
+
});
|
|
38
|
+
|
|
39
|
+
describe('CalendarIcon', () => {
|
|
40
|
+
it('renders correctly', () => {
|
|
41
|
+
const { container } = render(<CalendarIcon />);
|
|
42
|
+
const svg = container.querySelector('svg');
|
|
43
|
+
expect(svg).toBeInTheDocument();
|
|
44
|
+
});
|
|
45
|
+
|
|
46
|
+
it('has correct viewBox', () => {
|
|
47
|
+
const { container } = render(<CalendarIcon />);
|
|
48
|
+
const svg = container.querySelector('svg');
|
|
49
|
+
expect(svg).toHaveAttribute('viewBox');
|
|
50
|
+
});
|
|
51
|
+
|
|
52
|
+
it('accepts custom props', () => {
|
|
53
|
+
const { container } = render(<CalendarIcon data-testid="calendar" />);
|
|
54
|
+
const svg = container.querySelector('svg');
|
|
55
|
+
expect(svg).toHaveAttribute('data-testid', 'calendar');
|
|
56
|
+
});
|
|
57
|
+
|
|
58
|
+
it('renders path elements', () => {
|
|
59
|
+
const { container } = render(<CalendarIcon />);
|
|
60
|
+
const paths = container.querySelectorAll('path');
|
|
61
|
+
expect(paths.length).toBeGreaterThan(0);
|
|
62
|
+
});
|
|
63
|
+
});
|
|
64
|
+
|
|
65
|
+
describe('ChevronRightIcon', () => {
|
|
66
|
+
it('renders correctly', () => {
|
|
67
|
+
const { container } = render(<ChevronRightIcon />);
|
|
68
|
+
const svg = container.querySelector('svg');
|
|
69
|
+
expect(svg).toBeInTheDocument();
|
|
70
|
+
});
|
|
71
|
+
|
|
72
|
+
it('has correct dimensions', () => {
|
|
73
|
+
const { container } = render(<ChevronRightIcon />);
|
|
74
|
+
const svg = container.querySelector('svg');
|
|
75
|
+
expect(svg).toHaveAttribute('width', '16');
|
|
76
|
+
expect(svg).toHaveAttribute('height', '16');
|
|
77
|
+
});
|
|
78
|
+
|
|
79
|
+
it('has correct viewBox', () => {
|
|
80
|
+
const { container } = render(<ChevronRightIcon />);
|
|
81
|
+
const svg = container.querySelector('svg');
|
|
82
|
+
expect(svg).toHaveAttribute('viewBox', '0 0 16 16');
|
|
83
|
+
});
|
|
84
|
+
|
|
85
|
+
it('renders with currentColor stroke', () => {
|
|
86
|
+
const { container } = render(<ChevronRightIcon />);
|
|
87
|
+
const path = container.querySelector('path');
|
|
88
|
+
expect(path).toHaveAttribute('stroke', 'currentColor');
|
|
89
|
+
});
|
|
90
|
+
|
|
91
|
+
it('accepts custom props', () => {
|
|
92
|
+
const { container } = render(
|
|
93
|
+
<ChevronRightIcon style={{ color: 'red' }} />
|
|
94
|
+
);
|
|
95
|
+
const svg = container.querySelector('svg');
|
|
96
|
+
expect(svg).toHaveStyle({ color: 'red' });
|
|
97
|
+
});
|
|
98
|
+
});
|
|
99
|
+
|
|
100
|
+
describe('LocationIcon', () => {
|
|
101
|
+
it('renders correctly', () => {
|
|
102
|
+
const { container } = render(<LocationIcon />);
|
|
103
|
+
const svg = container.querySelector('svg');
|
|
104
|
+
expect(svg).toBeInTheDocument();
|
|
105
|
+
});
|
|
106
|
+
|
|
107
|
+
it('has correct viewBox', () => {
|
|
108
|
+
const { container } = render(<LocationIcon />);
|
|
109
|
+
const svg = container.querySelector('svg');
|
|
110
|
+
expect(svg).toHaveAttribute('viewBox');
|
|
111
|
+
});
|
|
112
|
+
|
|
113
|
+
it('accepts custom props', () => {
|
|
114
|
+
const { container } = render(<LocationIcon aria-label="location" />);
|
|
115
|
+
const svg = container.querySelector('svg');
|
|
116
|
+
expect(svg).toHaveAttribute('aria-label', 'location');
|
|
117
|
+
});
|
|
118
|
+
|
|
119
|
+
it('renders path elements', () => {
|
|
120
|
+
const { container } = render(<LocationIcon />);
|
|
121
|
+
const path = container.querySelector('path');
|
|
122
|
+
expect(path).toBeInTheDocument();
|
|
123
|
+
});
|
|
124
|
+
});
|
|
125
|
+
|
|
126
|
+
describe('MoonIcon', () => {
|
|
127
|
+
it('renders correctly', () => {
|
|
128
|
+
const { container } = render(<MoonIcon />);
|
|
129
|
+
const svg = container.querySelector('svg');
|
|
130
|
+
expect(svg).toBeInTheDocument();
|
|
131
|
+
});
|
|
132
|
+
|
|
133
|
+
it('has correct viewBox', () => {
|
|
134
|
+
const { container } = render(<MoonIcon />);
|
|
135
|
+
const svg = container.querySelector('svg');
|
|
136
|
+
expect(svg).toHaveAttribute('viewBox');
|
|
137
|
+
});
|
|
138
|
+
|
|
139
|
+
it('has correct dimensions', () => {
|
|
140
|
+
const { container } = render(<MoonIcon />);
|
|
141
|
+
const svg = container.querySelector('svg');
|
|
142
|
+
expect(svg).toHaveAttribute('width');
|
|
143
|
+
expect(svg).toHaveAttribute('height');
|
|
144
|
+
});
|
|
145
|
+
|
|
146
|
+
it('accepts custom props', () => {
|
|
147
|
+
const { container } = render(<MoonIcon id="moon-icon" />);
|
|
148
|
+
const svg = container.querySelector('svg');
|
|
149
|
+
expect(svg).toHaveAttribute('id', 'moon-icon');
|
|
150
|
+
});
|
|
151
|
+
|
|
152
|
+
it('renders path with fill color', () => {
|
|
153
|
+
const { container } = render(<MoonIcon />);
|
|
154
|
+
const path = container.querySelector('path');
|
|
155
|
+
expect(path).toHaveAttribute('fill');
|
|
156
|
+
});
|
|
157
|
+
});
|
|
158
|
+
|
|
159
|
+
describe('Icons Integration', () => {
|
|
160
|
+
it('all icons render without errors', () => {
|
|
161
|
+
const { container } = render(
|
|
162
|
+
<div>
|
|
163
|
+
<BoatIcon />
|
|
164
|
+
<CalendarIcon />
|
|
165
|
+
<ChevronRightIcon />
|
|
166
|
+
<LocationIcon />
|
|
167
|
+
<MoonIcon />
|
|
168
|
+
</div>
|
|
169
|
+
);
|
|
170
|
+
|
|
171
|
+
const svgs = container.querySelectorAll('svg');
|
|
172
|
+
expect(svgs.length).toBe(5);
|
|
173
|
+
});
|
|
174
|
+
|
|
175
|
+
it('icons can be styled with className', () => {
|
|
176
|
+
const { container } = render(
|
|
177
|
+
<div>
|
|
178
|
+
<BoatIcon className="icon-style" />
|
|
179
|
+
<CalendarIcon className="icon-style" />
|
|
180
|
+
<LocationIcon className="icon-style" />
|
|
181
|
+
</div>
|
|
182
|
+
);
|
|
183
|
+
|
|
184
|
+
const svgs = container.querySelectorAll('.icon-style');
|
|
185
|
+
expect(svgs.length).toBe(3);
|
|
186
|
+
});
|
|
187
|
+
|
|
188
|
+
it('icons maintain SVG structure', () => {
|
|
189
|
+
const icons = [
|
|
190
|
+
<BoatIcon key="boat" />,
|
|
191
|
+
<CalendarIcon key="calendar" />,
|
|
192
|
+
<ChevronRightIcon key="chevron" />,
|
|
193
|
+
<LocationIcon key="location" />,
|
|
194
|
+
<MoonIcon key="moon" />
|
|
195
|
+
];
|
|
196
|
+
|
|
197
|
+
icons.forEach(icon => {
|
|
198
|
+
const { container } = render(icon);
|
|
199
|
+
const svg = container.querySelector('svg');
|
|
200
|
+
if (svg) {
|
|
201
|
+
expect(svg.tagName).toBe('svg');
|
|
202
|
+
}
|
|
203
|
+
});
|
|
204
|
+
});
|
|
205
|
+
});
|
|
206
|
+
});
|
|
@@ -0,0 +1,165 @@
|
|
|
1
|
+
import { transformApiResult } from '../helpers';
|
|
2
|
+
import { ApiCruiseResult } from '../types';
|
|
3
|
+
|
|
4
|
+
const mockApiResult: ApiCruiseResult = {
|
|
5
|
+
post_id: 34246,
|
|
6
|
+
cruise_id: 2074350,
|
|
7
|
+
cruise_title: 'Mediterranean from Barcelona',
|
|
8
|
+
cruise_line: {
|
|
9
|
+
name: 'MSC Cruises',
|
|
10
|
+
link: 'https://example.com/cruise-lines/msc-cruises/',
|
|
11
|
+
logo: 'https://example.com/msc-logo.png'
|
|
12
|
+
},
|
|
13
|
+
ship: {
|
|
14
|
+
name: 'MSC Seaside',
|
|
15
|
+
link: 'https://example.com/ships/msc-seaside/',
|
|
16
|
+
image: 'https://example.com/ship-image.jpg'
|
|
17
|
+
},
|
|
18
|
+
departs: '2025-10-21',
|
|
19
|
+
ends: '2025-10-28',
|
|
20
|
+
date_label: 'Oct 21 - Oct 28, 2025',
|
|
21
|
+
destination: ['Mediterranean'],
|
|
22
|
+
duration: 7,
|
|
23
|
+
itinerary: ['Barcelona', 'Naples', 'Rome', 'Marseille'],
|
|
24
|
+
prices: {
|
|
25
|
+
cheapest_price: 2000,
|
|
26
|
+
inside: 'Enquire now',
|
|
27
|
+
outside: 'Enquire now',
|
|
28
|
+
balcony: '2000',
|
|
29
|
+
suite: 'Enquire now'
|
|
30
|
+
},
|
|
31
|
+
was_prices: {
|
|
32
|
+
cheapest_price: 2500,
|
|
33
|
+
inside: 0,
|
|
34
|
+
outside: 0,
|
|
35
|
+
balcony: 2500,
|
|
36
|
+
suite: 0
|
|
37
|
+
},
|
|
38
|
+
link: 'https://example.com/cruises/mediterranean-from-barcelona',
|
|
39
|
+
campaigns: ['Special Offer'],
|
|
40
|
+
extras: {
|
|
41
|
+
date: 'Oct 2025 - Oct 2025',
|
|
42
|
+
duration: 'Seven Days',
|
|
43
|
+
destination: 'Mediterranean',
|
|
44
|
+
info: 'Seven nights onboard a four-star ship'
|
|
45
|
+
}
|
|
46
|
+
};
|
|
47
|
+
|
|
48
|
+
describe('transformApiResult', () => {
|
|
49
|
+
it('transforms API result to TripCardApiData format', () => {
|
|
50
|
+
const result = transformApiResult(mockApiResult);
|
|
51
|
+
|
|
52
|
+
expect(result).toEqual({
|
|
53
|
+
cruise_id: '2074350',
|
|
54
|
+
image: 'https://example.com/ship-image.jpg',
|
|
55
|
+
offer_label: 'Special Offer',
|
|
56
|
+
headline: 'Mediterranean from Barcelona',
|
|
57
|
+
date: 'Oct 2025 - Oct 2025',
|
|
58
|
+
duration: 'Seven Days',
|
|
59
|
+
route: 'Barcelona → Marseille',
|
|
60
|
+
ship: 'MSC Seaside',
|
|
61
|
+
original_price: '£2500',
|
|
62
|
+
price: '£2000',
|
|
63
|
+
logo: 'https://example.com/msc-logo.png',
|
|
64
|
+
logo_url: 'https://example.com/cruise-lines/msc-cruises/',
|
|
65
|
+
cta_url: 'https://example.com/cruises/mediterranean-from-barcelona',
|
|
66
|
+
cta_text: 'View Itinerary'
|
|
67
|
+
});
|
|
68
|
+
});
|
|
69
|
+
|
|
70
|
+
it('formats price as "Enquire now" when price is 0', () => {
|
|
71
|
+
const resultWithZeroPrice = {
|
|
72
|
+
...mockApiResult,
|
|
73
|
+
prices: { ...mockApiResult.prices, cheapest_price: 0 }
|
|
74
|
+
};
|
|
75
|
+
|
|
76
|
+
const result = transformApiResult(resultWithZeroPrice);
|
|
77
|
+
|
|
78
|
+
expect(result.price).toBe('Enquire now');
|
|
79
|
+
});
|
|
80
|
+
|
|
81
|
+
it('formats price as "Enquire now" when price is "Enquire now"', () => {
|
|
82
|
+
const resultWithEnquire = {
|
|
83
|
+
...mockApiResult,
|
|
84
|
+
prices: { ...mockApiResult.prices, cheapest_price: 'Enquire now' }
|
|
85
|
+
};
|
|
86
|
+
|
|
87
|
+
const result = transformApiResult(resultWithEnquire);
|
|
88
|
+
|
|
89
|
+
expect(result.price).toBe('Enquire now');
|
|
90
|
+
});
|
|
91
|
+
|
|
92
|
+
it('formats numeric price with £ symbol', () => {
|
|
93
|
+
const result = transformApiResult(mockApiResult);
|
|
94
|
+
|
|
95
|
+
expect(result.price).toBe('£2000');
|
|
96
|
+
});
|
|
97
|
+
|
|
98
|
+
it('returns undefined original_price when was_price is 0', () => {
|
|
99
|
+
const resultWithZeroWasPrice = {
|
|
100
|
+
...mockApiResult,
|
|
101
|
+
was_prices: { ...mockApiResult.was_prices, cheapest_price: 0 }
|
|
102
|
+
};
|
|
103
|
+
|
|
104
|
+
const result = transformApiResult(resultWithZeroWasPrice);
|
|
105
|
+
|
|
106
|
+
expect(result.original_price).toBeUndefined();
|
|
107
|
+
});
|
|
108
|
+
|
|
109
|
+
it('returns undefined original_price when was_price is "Enquire now"', () => {
|
|
110
|
+
const resultWithEnquireWasPrice = {
|
|
111
|
+
...mockApiResult,
|
|
112
|
+
was_prices: { ...mockApiResult.was_prices, cheapest_price: 'Enquire now' }
|
|
113
|
+
};
|
|
114
|
+
|
|
115
|
+
const result = transformApiResult(resultWithEnquireWasPrice);
|
|
116
|
+
|
|
117
|
+
expect(result.original_price).toBeUndefined();
|
|
118
|
+
});
|
|
119
|
+
|
|
120
|
+
it('formats route with start and end for long itineraries', () => {
|
|
121
|
+
const result = transformApiResult(mockApiResult);
|
|
122
|
+
|
|
123
|
+
expect(result.route).toBe('Barcelona → Marseille');
|
|
124
|
+
});
|
|
125
|
+
|
|
126
|
+
it('formats route with all stops for short itineraries', () => {
|
|
127
|
+
const resultWithShortItinerary = {
|
|
128
|
+
...mockApiResult,
|
|
129
|
+
itinerary: ['Barcelona', 'Rome']
|
|
130
|
+
};
|
|
131
|
+
|
|
132
|
+
const result = transformApiResult(resultWithShortItinerary);
|
|
133
|
+
|
|
134
|
+
expect(result.route).toBe('Barcelona → Rome');
|
|
135
|
+
});
|
|
136
|
+
|
|
137
|
+
it('returns undefined offer_label when no campaigns', () => {
|
|
138
|
+
const resultWithNoCampaigns = {
|
|
139
|
+
...mockApiResult,
|
|
140
|
+
campaigns: []
|
|
141
|
+
};
|
|
142
|
+
|
|
143
|
+
const result = transformApiResult(resultWithNoCampaigns);
|
|
144
|
+
|
|
145
|
+
expect(result.offer_label).toBeUndefined();
|
|
146
|
+
});
|
|
147
|
+
|
|
148
|
+
it('uses data from extras object', () => {
|
|
149
|
+
const result = transformApiResult(mockApiResult);
|
|
150
|
+
|
|
151
|
+
expect(result.date).toBe('Oct 2025 - Oct 2025');
|
|
152
|
+
expect(result.duration).toBe('Seven Days');
|
|
153
|
+
});
|
|
154
|
+
|
|
155
|
+
it('handles string prices correctly', () => {
|
|
156
|
+
const resultWithStringPrice = {
|
|
157
|
+
...mockApiResult,
|
|
158
|
+
prices: { ...mockApiResult.prices, cheapest_price: '£1500pp' }
|
|
159
|
+
};
|
|
160
|
+
|
|
161
|
+
const result = transformApiResult(resultWithStringPrice);
|
|
162
|
+
|
|
163
|
+
expect(result.price).toBe('£1500pp');
|
|
164
|
+
});
|
|
165
|
+
});
|