@times-components/ts-components 1.146.2-784617dc4a33959b8795da1d7f425c9929322fae.24 → 1.146.2-e5795a0ef59e2adb61ba52aeb7332fda4405cb7a.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/opta/football/opta-match-stats/matchday-live/DesktopWidget.d.ts +10 -0
- package/dist/components/opta/football/opta-match-stats/matchday-live/DesktopWidget.js +69 -0
- package/dist/components/opta/football/opta-match-stats/matchday-live/MobileWidget.d.ts +12 -0
- package/dist/components/opta/football/opta-match-stats/matchday-live/MobileWidget.js +90 -0
- package/dist/components/opta/football/opta-match-stats/matchday-live/OptaMatchStatsMatchdayLive.d.ts +12 -0
- package/dist/components/opta/football/opta-match-stats/matchday-live/OptaMatchStatsMatchdayLive.js +10 -0
- package/dist/components/opta/football/opta-match-stats/matchday-live/OptaMatchStatsMatchdayLive.stories.js +24 -0
- package/dist/components/opta/football/opta-match-stats/matchday-live/__tests__/MobileWidget.test.js +57 -0
- package/dist/components/opta/football/opta-match-stats/matchday-live/__tests__/OptaMatchStatsMatchdayLive.test.d.ts +2 -0
- package/dist/components/opta/football/opta-match-stats/matchday-live/__tests__/OptaMatchStatsMatchdayLive.test.js +48 -0
- package/dist/components/opta/football/opta-match-stats/matchday-live/styles/MatchdayLiveController.d.ts +1 -0
- package/dist/components/opta/football/opta-match-stats/matchday-live/styles/MatchdayLiveController.js +19 -0
- package/dist/components/opta/football/opta-match-stats/matchday-live/styles/NavigationWrapper.d.ts +12 -0
- package/dist/components/opta/football/opta-match-stats/matchday-live/styles/NavigationWrapper.js +67 -0
- package/dist/components/opta/football/opta-match-stats/matchday-live/styles/WidgetContainer.d.ts +6 -0
- package/dist/components/opta/football/opta-match-stats/matchday-live/styles/WidgetContainer.js +736 -0
- package/dist/components/opta/football/opta-match-stats/matchday-live/styles/__tests__/NavigationWrapper.test.d.ts +1 -0
- package/dist/components/opta/football/opta-match-stats/matchday-live/styles/__tests__/NavigationWrapper.test.js +33 -0
- package/dist/components/opta/football/opta-match-stats/matchday-live/styles/__tests__/WidgetContainer.test.d.ts +1 -0
- package/dist/components/opta/football/opta-match-stats/matchday-live/styles/__tests__/WidgetContainer.test.js +36 -0
- package/dist/components/opta/football/opta-match-stats/shared/styles.js +8 -1
- 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 +19 -5
- 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/opta/football/opta-match-stats/commentary/__tests__/__snapshots__/OptaMatchStatsCommentary.test.tsx.snap +1 -1
- package/src/components/opta/football/opta-match-stats/matchday-live/DesktopWidget.tsx +108 -0
- package/src/components/opta/football/opta-match-stats/matchday-live/MobileWidget.tsx +158 -0
- package/src/components/opta/football/opta-match-stats/matchday-live/OptaMatchStatsMatchdayLive.stories.tsx +38 -0
- package/src/components/opta/football/opta-match-stats/matchday-live/OptaMatchStatsMatchdayLive.tsx +23 -0
- package/src/components/opta/football/opta-match-stats/matchday-live/__tests__/MobileWidget.test.tsx +69 -0
- package/src/components/opta/football/opta-match-stats/matchday-live/__tests__/OptaMatchStatsMatchdayLive.test.tsx +61 -0
- package/src/components/opta/football/opta-match-stats/matchday-live/__tests__/__snapshots__/OptaMatchStatsMatchdayLive.test.tsx.snap +61 -0
- package/src/components/opta/football/opta-match-stats/matchday-live/styles/MatchdayLiveController.tsx +19 -0
- package/src/components/opta/football/opta-match-stats/matchday-live/styles/NavigationWrapper.tsx +81 -0
- package/src/components/opta/football/opta-match-stats/matchday-live/styles/WidgetContainer.tsx +767 -0
- package/src/components/opta/football/opta-match-stats/matchday-live/styles/__tests__/NavigationWrapper.test.tsx +67 -0
- package/src/components/opta/football/opta-match-stats/matchday-live/styles/__tests__/WidgetContainer.test.tsx +64 -0
- package/src/components/opta/football/opta-match-stats/shared/styles.ts +8 -0
- 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 +18 -4
- package/src/components/opta/football/opta-match-stats/summary/__tests__/__snapshots__/OptaMatchStatsSummary.test.tsx.snap +1 -1
- package/src/index.ts +3 -1
- package/dist/components/travel-mini-cta/__tests__/index.test.js +0 -262
- package/dist/components/travel-mini-cta/index.d.ts +0 -10
- package/dist/components/travel-mini-cta/index.js +0 -93
- package/dist/components/travel-mini-cta/styles.d.ts +0 -42
- package/dist/components/travel-mini-cta/styles.js +0 -268
- package/dist/components/travel-mini-cta/travel-mini-cta.stories.js +0 -8
- package/dist/components/travel-mini-cta/types.d.ts +0 -10
- package/dist/components/travel-mini-cta/types.js +0 -2
- package/dist/utils/applyDarkMode.d.ts +0 -1
- package/dist/utils/applyDarkMode.js +0 -12
- package/dist/utils/getMediaQuery.d.ts +0 -11
- package/dist/utils/getMediaQuery.js +0 -19
- package/dist/utils/index.d.ts +0 -2
- package/dist/utils/index.js +0 -3
- package/src/components/travel-mini-cta/__tests__/__snapshots__/index.test.tsx.snap +0 -211
- package/src/components/travel-mini-cta/__tests__/index.test.tsx +0 -330
- package/src/components/travel-mini-cta/index.tsx +0 -190
- package/src/components/travel-mini-cta/styles.ts +0 -331
- package/src/components/travel-mini-cta/travel-mini-cta.stories.tsx +0 -23
- package/src/components/travel-mini-cta/types.ts +0 -10
- package/src/utils/applyDarkMode.ts +0 -12
- package/src/utils/getMediaQuery.ts +0 -25
- package/src/utils/index.ts +0 -2
- /package/dist/components/{travel-mini-cta/travel-mini-cta.stories.d.ts → opta/football/opta-match-stats/matchday-live/OptaMatchStatsMatchdayLive.stories.d.ts} +0 -0
- /package/dist/components/{travel-mini-cta/__tests__/index.test.d.ts → opta/football/opta-match-stats/matchday-live/__tests__/MobileWidget.test.d.ts} +0 -0
|
@@ -1,330 +0,0 @@
|
|
|
1
|
-
import React from 'react';
|
|
2
|
-
import '@testing-library/jest-dom';
|
|
3
|
-
import {
|
|
4
|
-
render,
|
|
5
|
-
screen,
|
|
6
|
-
act,
|
|
7
|
-
fireEvent,
|
|
8
|
-
waitFor
|
|
9
|
-
} from '@testing-library/react';
|
|
10
|
-
import { TravelMiniCTA } from '../index';
|
|
11
|
-
|
|
12
|
-
describe('TravelMiniCTA', () => {
|
|
13
|
-
const defaultProps = {
|
|
14
|
-
description:
|
|
15
|
-
'Begin your journey to Croatia with a holiday designed around you',
|
|
16
|
-
phoneLabel: 'Call us on',
|
|
17
|
-
phoneNumber: '08083049757',
|
|
18
|
-
workingHours: ['Mon - Fri: 9am - 6pm', 'Sat: 10am - 5pm'],
|
|
19
|
-
primaryButtonText: 'Chat with us',
|
|
20
|
-
secondaryButtonText: 'Enquire now',
|
|
21
|
-
secondaryButtonUrl: '/enquire'
|
|
22
|
-
};
|
|
23
|
-
|
|
24
|
-
let mockObserve: jest.Mock;
|
|
25
|
-
let mockDisconnect: jest.Mock;
|
|
26
|
-
let mutationCallback: MutationCallback;
|
|
27
|
-
|
|
28
|
-
beforeEach(() => {
|
|
29
|
-
jest.clearAllMocks();
|
|
30
|
-
jest.useFakeTimers();
|
|
31
|
-
|
|
32
|
-
// Mock MutationObserver
|
|
33
|
-
mockObserve = jest.fn();
|
|
34
|
-
mockDisconnect = jest.fn();
|
|
35
|
-
|
|
36
|
-
const MockMutationObserver: typeof MutationObserver = jest.fn(
|
|
37
|
-
(callback: MutationCallback) => {
|
|
38
|
-
mutationCallback = callback;
|
|
39
|
-
|
|
40
|
-
const observer: MutationObserver = {
|
|
41
|
-
observe: mockObserve,
|
|
42
|
-
disconnect: mockDisconnect,
|
|
43
|
-
takeRecords: jest.fn()
|
|
44
|
-
};
|
|
45
|
-
|
|
46
|
-
return observer;
|
|
47
|
-
}
|
|
48
|
-
);
|
|
49
|
-
|
|
50
|
-
global.MutationObserver = MockMutationObserver;
|
|
51
|
-
|
|
52
|
-
// Mock lpTag
|
|
53
|
-
(global as any).lpTag = {
|
|
54
|
-
newPage: jest.fn()
|
|
55
|
-
};
|
|
56
|
-
});
|
|
57
|
-
|
|
58
|
-
afterEach(() => {
|
|
59
|
-
jest.runOnlyPendingTimers();
|
|
60
|
-
jest.useRealTimers();
|
|
61
|
-
delete (global as any).lpTag;
|
|
62
|
-
});
|
|
63
|
-
|
|
64
|
-
it('should render with all props', () => {
|
|
65
|
-
const { container } = render(<TravelMiniCTA {...defaultProps} />);
|
|
66
|
-
expect(container).toMatchSnapshot();
|
|
67
|
-
});
|
|
68
|
-
|
|
69
|
-
it('should render the logo with "T" text', () => {
|
|
70
|
-
render(<TravelMiniCTA {...defaultProps} />);
|
|
71
|
-
expect(screen.getByText('T')).toBeInTheDocument();
|
|
72
|
-
});
|
|
73
|
-
|
|
74
|
-
it('should render the label "VISIT TIMES HOLIDAYS"', () => {
|
|
75
|
-
render(<TravelMiniCTA {...defaultProps} />);
|
|
76
|
-
const labels = screen.getAllByText('VISIT TIMES HOLIDAYS');
|
|
77
|
-
expect(labels.length).toBe(2); // Desktop and mobile labels
|
|
78
|
-
});
|
|
79
|
-
|
|
80
|
-
it('should render the description', () => {
|
|
81
|
-
render(<TravelMiniCTA {...defaultProps} />);
|
|
82
|
-
expect(screen.getByText(defaultProps.description)).toBeInTheDocument();
|
|
83
|
-
});
|
|
84
|
-
|
|
85
|
-
it('should render phone label and number', () => {
|
|
86
|
-
render(<TravelMiniCTA {...defaultProps} />);
|
|
87
|
-
expect(screen.getByText('Call us on')).toBeInTheDocument();
|
|
88
|
-
expect(screen.getByText('08083049757')).toBeInTheDocument();
|
|
89
|
-
});
|
|
90
|
-
|
|
91
|
-
it('should render phone number as a tel link', () => {
|
|
92
|
-
render(<TravelMiniCTA {...defaultProps} />);
|
|
93
|
-
const phoneLink = screen.getByText('Call us on').closest('a');
|
|
94
|
-
expect(phoneLink).toHaveAttribute('href', 'tel:08083049757');
|
|
95
|
-
});
|
|
96
|
-
|
|
97
|
-
it('should render working hours', () => {
|
|
98
|
-
render(<TravelMiniCTA {...defaultProps} />);
|
|
99
|
-
expect(screen.getByText('Mon - Fri: 9am - 6pm')).toBeInTheDocument();
|
|
100
|
-
expect(screen.getByText('Sat: 10am - 5pm')).toBeInTheDocument();
|
|
101
|
-
});
|
|
102
|
-
|
|
103
|
-
it('should render primary button with loading text initially', () => {
|
|
104
|
-
render(<TravelMiniCTA {...defaultProps} />);
|
|
105
|
-
expect(screen.getByText('Loading chat...')).toBeInTheDocument();
|
|
106
|
-
});
|
|
107
|
-
|
|
108
|
-
it('should render secondary button with correct text and URL', () => {
|
|
109
|
-
render(<TravelMiniCTA {...defaultProps} />);
|
|
110
|
-
const secondaryButton = screen.getByText('Enquire now');
|
|
111
|
-
expect(secondaryButton).toBeInTheDocument();
|
|
112
|
-
});
|
|
113
|
-
|
|
114
|
-
it('should render with minimal props', () => {
|
|
115
|
-
render(<TravelMiniCTA />);
|
|
116
|
-
expect(screen.getByTestId('travel-mini-cta')).toBeInTheDocument();
|
|
117
|
-
});
|
|
118
|
-
|
|
119
|
-
it('should render without working hours if not provided', () => {
|
|
120
|
-
const propsWithoutWorkingHours = {
|
|
121
|
-
...defaultProps,
|
|
122
|
-
workingHours: undefined
|
|
123
|
-
};
|
|
124
|
-
render(<TravelMiniCTA {...propsWithoutWorkingHours} />);
|
|
125
|
-
expect(screen.queryByText('Mon - Fri: 9am - 6pm')).not.toBeInTheDocument();
|
|
126
|
-
});
|
|
127
|
-
|
|
128
|
-
it('should render empty working hours array', () => {
|
|
129
|
-
const propsWithEmptyWorkingHours = {
|
|
130
|
-
...defaultProps,
|
|
131
|
-
workingHours: []
|
|
132
|
-
};
|
|
133
|
-
const { container } = render(
|
|
134
|
-
<TravelMiniCTA {...propsWithEmptyWorkingHours} />
|
|
135
|
-
);
|
|
136
|
-
expect(
|
|
137
|
-
container.querySelector('[data-testid="travel-mini-cta"]')
|
|
138
|
-
).toBeInTheDocument();
|
|
139
|
-
});
|
|
140
|
-
|
|
141
|
-
it('should render with custom description', () => {
|
|
142
|
-
const customDescription = 'Explore the world with our expert guidance';
|
|
143
|
-
render(<TravelMiniCTA {...defaultProps} description={customDescription} />);
|
|
144
|
-
expect(screen.getByText(customDescription)).toBeInTheDocument();
|
|
145
|
-
});
|
|
146
|
-
|
|
147
|
-
it('should render with custom phone details', () => {
|
|
148
|
-
const customProps = {
|
|
149
|
-
...defaultProps,
|
|
150
|
-
phoneLabel: 'Contact us at',
|
|
151
|
-
phoneNumber: '0123456789'
|
|
152
|
-
};
|
|
153
|
-
render(<TravelMiniCTA {...customProps} />);
|
|
154
|
-
expect(screen.getByText('Contact us at')).toBeInTheDocument();
|
|
155
|
-
expect(screen.getByText('0123456789')).toBeInTheDocument();
|
|
156
|
-
});
|
|
157
|
-
|
|
158
|
-
it('should have correct container test id', () => {
|
|
159
|
-
render(<TravelMiniCTA {...defaultProps} />);
|
|
160
|
-
expect(screen.getByTestId('travel-mini-cta')).toBeInTheDocument();
|
|
161
|
-
});
|
|
162
|
-
|
|
163
|
-
it('should render with isApp prop', () => {
|
|
164
|
-
const { container } = render(
|
|
165
|
-
<TravelMiniCTA {...defaultProps} isApp={true} />
|
|
166
|
-
);
|
|
167
|
-
expect(container).toMatchSnapshot();
|
|
168
|
-
});
|
|
169
|
-
|
|
170
|
-
it('should pass isApp prop to styled components', () => {
|
|
171
|
-
render(<TravelMiniCTA {...defaultProps} isApp={true} />);
|
|
172
|
-
const container = screen.getByTestId('travel-mini-cta');
|
|
173
|
-
expect(container).toBeInTheDocument();
|
|
174
|
-
});
|
|
175
|
-
|
|
176
|
-
describe('LivePerson Chat Integration', () => {
|
|
177
|
-
it('should render LivePerson container div with correct ID', () => {
|
|
178
|
-
render(<TravelMiniCTA {...defaultProps} />);
|
|
179
|
-
const chatDiv = document.getElementById('LP_DIV_TRAVEL_1239001');
|
|
180
|
-
expect(chatDiv).toBeInTheDocument();
|
|
181
|
-
});
|
|
182
|
-
|
|
183
|
-
it('should show loading text initially', () => {
|
|
184
|
-
render(<TravelMiniCTA {...defaultProps} />);
|
|
185
|
-
expect(screen.getByText('Loading chat...')).toBeInTheDocument();
|
|
186
|
-
});
|
|
187
|
-
|
|
188
|
-
it('should setup MutationObserver on mount', () => {
|
|
189
|
-
render(<TravelMiniCTA {...defaultProps} />);
|
|
190
|
-
expect(global.MutationObserver).toHaveBeenCalled();
|
|
191
|
-
expect(mockObserve).toHaveBeenCalledWith(expect.any(HTMLElement), {
|
|
192
|
-
childList: true,
|
|
193
|
-
subtree: true
|
|
194
|
-
});
|
|
195
|
-
});
|
|
196
|
-
|
|
197
|
-
it('should set chat ready when LivePerson element is detected', async () => {
|
|
198
|
-
render(<TravelMiniCTA {...defaultProps} />);
|
|
199
|
-
|
|
200
|
-
// Simulate LivePerson injecting the chat element
|
|
201
|
-
const chatDiv = document.getElementById('LP_DIV_TRAVEL_1239001');
|
|
202
|
-
const lpElement = document.createElement('div');
|
|
203
|
-
lpElement.setAttribute('data-lp-event', 'click');
|
|
204
|
-
lpElement.textContent = 'Chat';
|
|
205
|
-
chatDiv && chatDiv.appendChild(lpElement);
|
|
206
|
-
|
|
207
|
-
// Trigger the mutation observer callback
|
|
208
|
-
const observer: MutationObserver = {
|
|
209
|
-
observe: mockObserve,
|
|
210
|
-
disconnect: mockDisconnect,
|
|
211
|
-
takeRecords: jest.fn()
|
|
212
|
-
};
|
|
213
|
-
act(() => {
|
|
214
|
-
mutationCallback([], observer);
|
|
215
|
-
});
|
|
216
|
-
|
|
217
|
-
await waitFor(() => {
|
|
218
|
-
expect(screen.queryByText('Loading chat...')).not.toBeInTheDocument();
|
|
219
|
-
});
|
|
220
|
-
});
|
|
221
|
-
|
|
222
|
-
it('should clear timeout when chat loads successfully', async () => {
|
|
223
|
-
const clearTimeoutSpy = jest.spyOn(global, 'clearTimeout');
|
|
224
|
-
render(<TravelMiniCTA {...defaultProps} />);
|
|
225
|
-
|
|
226
|
-
const chatDiv = document.getElementById('LP_DIV_TRAVEL_1239001');
|
|
227
|
-
const lpElement = document.createElement('div');
|
|
228
|
-
lpElement.setAttribute('data-lp-event', 'click');
|
|
229
|
-
chatDiv && chatDiv.appendChild(lpElement);
|
|
230
|
-
|
|
231
|
-
const observer: MutationObserver = {
|
|
232
|
-
observe: mockObserve,
|
|
233
|
-
disconnect: mockDisconnect,
|
|
234
|
-
takeRecords: jest.fn()
|
|
235
|
-
};
|
|
236
|
-
act(() => {
|
|
237
|
-
mutationCallback([], observer);
|
|
238
|
-
});
|
|
239
|
-
|
|
240
|
-
await waitFor(() => {
|
|
241
|
-
expect(clearTimeoutSpy).toHaveBeenCalled();
|
|
242
|
-
});
|
|
243
|
-
|
|
244
|
-
// Timeout should not fire
|
|
245
|
-
act(() => {
|
|
246
|
-
jest.advanceTimersByTime(15000);
|
|
247
|
-
});
|
|
248
|
-
|
|
249
|
-
expect(screen.queryByText('Chat unavailable')).not.toBeInTheDocument();
|
|
250
|
-
clearTimeoutSpy.mockRestore();
|
|
251
|
-
});
|
|
252
|
-
|
|
253
|
-
it('should disconnect observer on unmount', () => {
|
|
254
|
-
const { unmount } = render(<TravelMiniCTA {...defaultProps} />);
|
|
255
|
-
unmount();
|
|
256
|
-
expect(mockDisconnect).toHaveBeenCalled();
|
|
257
|
-
});
|
|
258
|
-
|
|
259
|
-
it('should clear timeout on unmount', () => {
|
|
260
|
-
const clearTimeoutSpy = jest.spyOn(global, 'clearTimeout');
|
|
261
|
-
const { unmount } = render(<TravelMiniCTA {...defaultProps} />);
|
|
262
|
-
unmount();
|
|
263
|
-
expect(clearTimeoutSpy).toHaveBeenCalled();
|
|
264
|
-
clearTimeoutSpy.mockRestore();
|
|
265
|
-
});
|
|
266
|
-
|
|
267
|
-
it('should trigger LivePerson element click when primary button is clicked', async () => {
|
|
268
|
-
render(<TravelMiniCTA {...defaultProps} />);
|
|
269
|
-
|
|
270
|
-
// Simulate chat loaded
|
|
271
|
-
const chatDiv = document.getElementById('LP_DIV_TRAVEL_1239001');
|
|
272
|
-
const lpElement = document.createElement('button');
|
|
273
|
-
lpElement.setAttribute('data-lp-event', 'click');
|
|
274
|
-
|
|
275
|
-
// Mock click on the LivePerson element
|
|
276
|
-
const lpClickSpy = jest.fn();
|
|
277
|
-
lpElement.onclick = lpClickSpy;
|
|
278
|
-
|
|
279
|
-
chatDiv && chatDiv.appendChild(lpElement);
|
|
280
|
-
|
|
281
|
-
const observer: MutationObserver = {
|
|
282
|
-
observe: mockObserve,
|
|
283
|
-
disconnect: mockDisconnect,
|
|
284
|
-
takeRecords: jest.fn()
|
|
285
|
-
};
|
|
286
|
-
act(() => {
|
|
287
|
-
mutationCallback([], observer);
|
|
288
|
-
});
|
|
289
|
-
|
|
290
|
-
await waitFor(() => {
|
|
291
|
-
expect(screen.queryByText('Loading chat...')).not.toBeInTheDocument();
|
|
292
|
-
});
|
|
293
|
-
|
|
294
|
-
// Get and click the primary button
|
|
295
|
-
const parentElement = chatDiv ? chatDiv.parentElement : null;
|
|
296
|
-
if (parentElement instanceof HTMLButtonElement) {
|
|
297
|
-
fireEvent.click(parentElement);
|
|
298
|
-
expect(lpClickSpy).toHaveBeenCalled();
|
|
299
|
-
}
|
|
300
|
-
});
|
|
301
|
-
|
|
302
|
-
it('should handle button click without errors when chat is ready', async () => {
|
|
303
|
-
render(<TravelMiniCTA {...defaultProps} />);
|
|
304
|
-
|
|
305
|
-
const chatDiv = document.getElementById('LP_DIV_TRAVEL_1239001');
|
|
306
|
-
const lpElement = document.createElement('button');
|
|
307
|
-
lpElement.setAttribute('data-lp-event', 'click');
|
|
308
|
-
chatDiv && chatDiv.appendChild(lpElement);
|
|
309
|
-
|
|
310
|
-
const observer: MutationObserver = {
|
|
311
|
-
observe: mockObserve,
|
|
312
|
-
disconnect: mockDisconnect,
|
|
313
|
-
takeRecords: jest.fn()
|
|
314
|
-
};
|
|
315
|
-
act(() => {
|
|
316
|
-
mutationCallback([], observer);
|
|
317
|
-
});
|
|
318
|
-
|
|
319
|
-
await waitFor(() => {
|
|
320
|
-
expect(screen.queryByText('Loading chat...')).not.toBeInTheDocument();
|
|
321
|
-
});
|
|
322
|
-
|
|
323
|
-
// Click button should not throw error
|
|
324
|
-
const parentElement = chatDiv ? chatDiv.parentElement : null;
|
|
325
|
-
if (parentElement instanceof HTMLButtonElement) {
|
|
326
|
-
expect(() => fireEvent.click(parentElement)).not.toThrow();
|
|
327
|
-
}
|
|
328
|
-
});
|
|
329
|
-
});
|
|
330
|
-
});
|
|
@@ -1,190 +0,0 @@
|
|
|
1
|
-
import React, { useEffect, useState, useRef, MouseEvent, FC } from 'react';
|
|
2
|
-
import { TravelMiniCTAProps } from './types';
|
|
3
|
-
import {
|
|
4
|
-
Container,
|
|
5
|
-
ContentWrapper,
|
|
6
|
-
LeftSection,
|
|
7
|
-
LogoContainer,
|
|
8
|
-
LogoBox,
|
|
9
|
-
LogoText,
|
|
10
|
-
TextContainer,
|
|
11
|
-
Label,
|
|
12
|
-
MobileLabel,
|
|
13
|
-
Description,
|
|
14
|
-
RightSection,
|
|
15
|
-
ContactInfo,
|
|
16
|
-
PhoneLabel,
|
|
17
|
-
PhoneNumber,
|
|
18
|
-
WorkingHoursContainer,
|
|
19
|
-
WorkingHoursText,
|
|
20
|
-
ButtonsContainer,
|
|
21
|
-
PrimaryButton,
|
|
22
|
-
SecondaryButton
|
|
23
|
-
} from './styles';
|
|
24
|
-
|
|
25
|
-
// Extend Window interface for LivePerson
|
|
26
|
-
declare global {
|
|
27
|
-
interface Window {
|
|
28
|
-
lpTag?: {
|
|
29
|
-
[key: string]: any;
|
|
30
|
-
};
|
|
31
|
-
}
|
|
32
|
-
}
|
|
33
|
-
|
|
34
|
-
export const TravelMiniCTA: FC<TravelMiniCTAProps> = ({
|
|
35
|
-
description,
|
|
36
|
-
phoneLabel,
|
|
37
|
-
phoneNumber,
|
|
38
|
-
workingHours,
|
|
39
|
-
primaryButtonText,
|
|
40
|
-
secondaryButtonText,
|
|
41
|
-
secondaryButtonUrl,
|
|
42
|
-
isApp
|
|
43
|
-
}) => {
|
|
44
|
-
const [chatReady, setChatReady] = useState(false);
|
|
45
|
-
const [chatFailed, setChatFailed] = useState(false);
|
|
46
|
-
const [buttonText, setButtonText] = useState('Loading chat...');
|
|
47
|
-
const chatDivRef = useRef<HTMLDivElement>(null);
|
|
48
|
-
const timeoutRef = useRef<NodeJS.Timeout | null>(null);
|
|
49
|
-
const observerRef = useRef<MutationObserver | null>(null);
|
|
50
|
-
|
|
51
|
-
const handlePrimaryButtonClick = (
|
|
52
|
-
e: MouseEvent<HTMLButtonElement | HTMLAnchorElement>
|
|
53
|
-
) => {
|
|
54
|
-
e.preventDefault();
|
|
55
|
-
|
|
56
|
-
const chatDiv = chatDivRef.current;
|
|
57
|
-
if (chatDiv) {
|
|
58
|
-
const lpEventElement = chatDiv.querySelector(
|
|
59
|
-
'[data-lp-event]'
|
|
60
|
-
) as HTMLElement;
|
|
61
|
-
if (lpEventElement) {
|
|
62
|
-
lpEventElement.click();
|
|
63
|
-
}
|
|
64
|
-
}
|
|
65
|
-
};
|
|
66
|
-
|
|
67
|
-
useEffect(
|
|
68
|
-
() => {
|
|
69
|
-
if (typeof window === 'undefined') {
|
|
70
|
-
return;
|
|
71
|
-
}
|
|
72
|
-
|
|
73
|
-
const cleanup = () => {
|
|
74
|
-
if (timeoutRef.current) {
|
|
75
|
-
clearTimeout(timeoutRef.current);
|
|
76
|
-
timeoutRef.current = null;
|
|
77
|
-
}
|
|
78
|
-
if (observerRef.current) {
|
|
79
|
-
observerRef.current.disconnect();
|
|
80
|
-
observerRef.current = null;
|
|
81
|
-
}
|
|
82
|
-
};
|
|
83
|
-
|
|
84
|
-
const handleChatReady = () => {
|
|
85
|
-
cleanup();
|
|
86
|
-
setChatReady(true);
|
|
87
|
-
setChatFailed(false);
|
|
88
|
-
setButtonText(primaryButtonText || 'Chat with us');
|
|
89
|
-
};
|
|
90
|
-
|
|
91
|
-
const handleChatFailed = () => {
|
|
92
|
-
cleanup();
|
|
93
|
-
setChatReady(false);
|
|
94
|
-
setChatFailed(true);
|
|
95
|
-
setButtonText('Call us');
|
|
96
|
-
};
|
|
97
|
-
|
|
98
|
-
// Check if LivePerson is already loaded
|
|
99
|
-
if (window.lpTag && window.lpTag.loaded) {
|
|
100
|
-
handleChatReady();
|
|
101
|
-
return cleanup;
|
|
102
|
-
}
|
|
103
|
-
|
|
104
|
-
// Set up MutationObserver to detect when LivePerson loads
|
|
105
|
-
const chatDiv = chatDivRef.current;
|
|
106
|
-
if (!chatDiv) {
|
|
107
|
-
return cleanup;
|
|
108
|
-
}
|
|
109
|
-
|
|
110
|
-
observerRef.current = new MutationObserver(() => {
|
|
111
|
-
const lpEventElement = chatDiv.querySelector('[data-lp-event]');
|
|
112
|
-
if (lpEventElement) {
|
|
113
|
-
handleChatReady();
|
|
114
|
-
}
|
|
115
|
-
});
|
|
116
|
-
|
|
117
|
-
observerRef.current.observe(chatDiv, {
|
|
118
|
-
childList: true,
|
|
119
|
-
subtree: true
|
|
120
|
-
});
|
|
121
|
-
|
|
122
|
-
// Fallback: If LivePerson doesn't load in 15s, show "Call us"
|
|
123
|
-
timeoutRef.current = setTimeout(handleChatFailed, 15000);
|
|
124
|
-
|
|
125
|
-
return cleanup;
|
|
126
|
-
},
|
|
127
|
-
[primaryButtonText]
|
|
128
|
-
);
|
|
129
|
-
|
|
130
|
-
return (
|
|
131
|
-
<Container data-testid="travel-mini-cta" isApp={isApp}>
|
|
132
|
-
<ContentWrapper>
|
|
133
|
-
<LeftSection>
|
|
134
|
-
<LogoContainer>
|
|
135
|
-
<LogoBox isApp={isApp}>
|
|
136
|
-
<LogoText isApp={isApp}>T</LogoText>
|
|
137
|
-
</LogoBox>
|
|
138
|
-
<MobileLabel isApp={isApp}>TIMES HOLIDAYS</MobileLabel>
|
|
139
|
-
</LogoContainer>
|
|
140
|
-
<TextContainer>
|
|
141
|
-
<Label isApp={isApp}>TIMES HOLIDAYS</Label>
|
|
142
|
-
<Description isApp={isApp}>{description}</Description>
|
|
143
|
-
</TextContainer>
|
|
144
|
-
</LeftSection>
|
|
145
|
-
|
|
146
|
-
<RightSection>
|
|
147
|
-
<ContactInfo>
|
|
148
|
-
<PhoneLabel href={`tel:${phoneNumber}`} isApp={isApp}>
|
|
149
|
-
{phoneLabel}{' '}
|
|
150
|
-
<PhoneNumber isApp={isApp}>{phoneNumber}</PhoneNumber>
|
|
151
|
-
</PhoneLabel>
|
|
152
|
-
<WorkingHoursContainer>
|
|
153
|
-
{workingHours &&
|
|
154
|
-
workingHours.map((hours, index) => (
|
|
155
|
-
<WorkingHoursText key={index} isApp={isApp}>
|
|
156
|
-
{hours}
|
|
157
|
-
</WorkingHoursText>
|
|
158
|
-
))}
|
|
159
|
-
</WorkingHoursContainer>
|
|
160
|
-
</ContactInfo>
|
|
161
|
-
<ButtonsContainer>
|
|
162
|
-
{chatFailed ? (
|
|
163
|
-
<PrimaryButton as="a" href={`tel:${phoneNumber}`} isApp={isApp}>
|
|
164
|
-
{buttonText}
|
|
165
|
-
</PrimaryButton>
|
|
166
|
-
) : (
|
|
167
|
-
<PrimaryButton
|
|
168
|
-
as="button"
|
|
169
|
-
type="button"
|
|
170
|
-
onClick={handlePrimaryButtonClick}
|
|
171
|
-
isApp={isApp}
|
|
172
|
-
disabled={!chatReady}
|
|
173
|
-
>
|
|
174
|
-
{buttonText}
|
|
175
|
-
</PrimaryButton>
|
|
176
|
-
)}
|
|
177
|
-
<div
|
|
178
|
-
id="LP_DIV_TRAVEL_1239001"
|
|
179
|
-
ref={chatDivRef}
|
|
180
|
-
style={{ display: 'none' }}
|
|
181
|
-
/>
|
|
182
|
-
<SecondaryButton href={secondaryButtonUrl} isApp={isApp}>
|
|
183
|
-
{secondaryButtonText}
|
|
184
|
-
</SecondaryButton>
|
|
185
|
-
</ButtonsContainer>
|
|
186
|
-
</RightSection>
|
|
187
|
-
</ContentWrapper>
|
|
188
|
-
</Container>
|
|
189
|
-
);
|
|
190
|
-
};
|