@capillarytech/creatives-library 9.2.2 → 9.2.3
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/constants/unified.js +0 -1
- package/package.json +1 -1
- package/utils/common.js +0 -6
- package/utils/createMobilePushPayload.js +50 -56
- package/utils/tests/createMobilePushPayload.test.js +177 -168
- package/v2Components/CapMpushCTA/index.js +47 -57
- package/v2Components/CapMpushCTA/index.scss +43 -5
- package/v2Components/CapMpushCTA/tests/index.test.js +150 -0
- package/v2Components/CommonTestAndPreview/UnifiedPreview/MobilePushPreviewContent.js +11 -8
- package/v2Components/CommonTestAndPreview/UnifiedPreview/_unifiedPreview.scss +13 -1
- package/v2Components/CommonTestAndPreview/constants.js +2 -0
- package/v2Components/CommonTestAndPreview/index.js +51 -12
- package/v2Components/CommonTestAndPreview/tests/UnifiedPreview/MobilePushPreviewContent.test.js +83 -5
- package/v2Components/CommonTestAndPreview/tests/index.test.js +100 -0
- package/v2Components/MobilePushPreviewV2/_mobilePushPreviewV2.scss +7 -0
- package/v2Components/MobilePushPreviewV2/index.js +22 -9
- package/v2Components/MobilePushPreviewV2/tests/index.test.js +55 -0
- package/v2Components/TemplatePreview/_mobilePushPhone.scss +72 -0
- package/v2Components/TemplatePreview/_templatePreview.scss +18 -2
- package/v2Components/TemplatePreview/index.js +20 -18
- package/v2Components/TemplatePreview/tests/index.test.js +69 -0
- package/v2Containers/CommunicationFlow/steps/ChannelSelectionStep/Tests/extractContentForPreview.test.js +45 -0
- package/v2Containers/CommunicationFlow/steps/ChannelSelectionStep/extractContentForPreview.js +12 -2
- package/v2Containers/CreativesContainer/SlideBoxContent.js +4 -6
- package/v2Containers/CreativesContainer/index.js +2 -1
- package/v2Containers/CreativesContainer/tests/SlideBoxContent.test.js +43 -0
- package/v2Containers/MobilePushNew/components/CtaButtons.js +52 -47
- package/v2Containers/MobilePushNew/components/MediaUploaders.js +105 -345
- package/v2Containers/MobilePushNew/components/PlatformContentFields.js +127 -105
- package/v2Containers/MobilePushNew/components/TapLinkActions.js +76 -0
- package/v2Containers/MobilePushNew/components/tests/CtaButtons.test.js +30 -208
- package/v2Containers/MobilePushNew/components/tests/MediaUploaders.test.js +305 -1482
- package/v2Containers/MobilePushNew/components/tests/PlatformContentFields.test.js +165 -59
- package/v2Containers/MobilePushNew/constants.js +12 -0
- package/v2Containers/MobilePushNew/hooks/tests/usePlatformSync.test.js +63 -1
- package/v2Containers/MobilePushNew/hooks/tests/useUpload.test.js +78 -0
- package/v2Containers/MobilePushNew/hooks/usePlatformSync.js +40 -1
- package/v2Containers/MobilePushNew/hooks/useUpload.js +42 -46
- package/v2Containers/MobilePushNew/index.js +498 -289
- package/v2Containers/MobilePushNew/index.scss +151 -4
- package/v2Containers/MobilePushNew/messages.js +106 -6
- package/v2Containers/MobilePushNew/tests/index.test.js +483 -1
- package/v2Containers/MobilePushNew/tests/utils.test.js +110 -0
- package/v2Containers/MobilePushNew/utils.js +83 -0
- package/v2Containers/Templates/_templates.scss +10 -2
- package/v2Containers/Templates/index.js +86 -81
- package/v2Containers/Templates/tests/index.test.js +81 -0
|
@@ -6,7 +6,8 @@ import { configureStore } from '@capillarytech/vulcan-react-sdk/utils';
|
|
|
6
6
|
import history from '../../../utils/history';
|
|
7
7
|
import { initialReducer } from '../../../initialReducer';
|
|
8
8
|
import { MobilePushNew } from '..';
|
|
9
|
-
import { render, screen, fireEvent } from '../../../utils/test-utils';
|
|
9
|
+
import { render, screen, fireEvent, waitFor } from '../../../utils/test-utils';
|
|
10
|
+
import * as commonUtils from '../../../utils/commonUtils';
|
|
10
11
|
|
|
11
12
|
jest.mock('../../TagList/index.js', () => ({
|
|
12
13
|
__esModule: true,
|
|
@@ -17,6 +18,23 @@ jest.mock('../../TagList/index.js', () => ({
|
|
|
17
18
|
),
|
|
18
19
|
}));
|
|
19
20
|
|
|
21
|
+
jest.mock('../../../v2Components/TestAndPreviewSlidebox', () => ({
|
|
22
|
+
__esModule: true,
|
|
23
|
+
default: ({
|
|
24
|
+
show, onClose, content, formData,
|
|
25
|
+
}) => (
|
|
26
|
+
<button
|
|
27
|
+
type="button"
|
|
28
|
+
data-testid="test-preview-slidebox"
|
|
29
|
+
data-show={String(!!show)}
|
|
30
|
+
data-android-actions={JSON.stringify(content?.androidContent?.actions || [])}
|
|
31
|
+
data-ios-actions={JSON.stringify(content?.iosContent?.actions || [])}
|
|
32
|
+
data-form-data={JSON.stringify(formData || [])}
|
|
33
|
+
onClick={onClose}
|
|
34
|
+
/>
|
|
35
|
+
),
|
|
36
|
+
}));
|
|
37
|
+
|
|
20
38
|
let store;
|
|
21
39
|
beforeAll(() => {
|
|
22
40
|
store = configureStore({}, initialReducer, history);
|
|
@@ -116,6 +134,41 @@ describe('MobilePushNew', () => {
|
|
|
116
134
|
|
|
117
135
|
await screen.findByPlaceholderText('Enter title');
|
|
118
136
|
});
|
|
137
|
+
|
|
138
|
+
it('renders the Android and iOS tab labels when both platforms are supported', async () => {
|
|
139
|
+
renderComponent({
|
|
140
|
+
accountData: { configs: { android: '1', ios: '1' } },
|
|
141
|
+
templateData: {},
|
|
142
|
+
location: {},
|
|
143
|
+
injectedTags: {},
|
|
144
|
+
getDefaultTags: jest.fn(),
|
|
145
|
+
globalActions,
|
|
146
|
+
});
|
|
147
|
+
|
|
148
|
+
expect((await screen.findAllByText('iOS')).length).toBeGreaterThan(0);
|
|
149
|
+
expect(screen.getAllByText('Android').length).toBeGreaterThan(0);
|
|
150
|
+
});
|
|
151
|
+
|
|
152
|
+
it('runs liquid validation from the sticky Save row in library mode', async () => {
|
|
153
|
+
const validateSpy = jest.spyOn(commonUtils, 'validateMobilePushContent').mockImplementation(() => {});
|
|
154
|
+
renderComponent({
|
|
155
|
+
accountData,
|
|
156
|
+
templateData: {},
|
|
157
|
+
location: {},
|
|
158
|
+
injectedTags: {},
|
|
159
|
+
getDefaultTags: jest.fn(),
|
|
160
|
+
globalActions,
|
|
161
|
+
});
|
|
162
|
+
|
|
163
|
+
fireEvent.change(await screen.findByPlaceholderText('Enter title'), { target: { value: 'Hello' } });
|
|
164
|
+
fireEvent.change(await screen.findByPlaceholderText('Enter message'), { target: { value: 'World' } });
|
|
165
|
+
const saveButton = screen.getByRole('button', { name: 'Save Template' });
|
|
166
|
+
expect(saveButton.closest('.mpush-save-section')).not.toBeNull();
|
|
167
|
+
|
|
168
|
+
fireEvent.click(saveButton);
|
|
169
|
+
expect(validateSpy).toHaveBeenCalledTimes(1);
|
|
170
|
+
validateSpy.mockRestore();
|
|
171
|
+
});
|
|
119
172
|
});
|
|
120
173
|
|
|
121
174
|
describe('MobilePushNew — full mode keeps the slidebox open after saving', () => {
|
|
@@ -177,4 +230,433 @@ describe('MobilePushNew — full mode keeps the slidebox open after saving', ()
|
|
|
177
230
|
expect(props.mobilePushActions.editTemplate.mock.calls[0][0]._id).toBe('mp-1');
|
|
178
231
|
expect(props.handleClose).not.toHaveBeenCalled();
|
|
179
232
|
});
|
|
233
|
+
|
|
234
|
+
it('saves directly from the sticky Save row in full mode', async () => {
|
|
235
|
+
const props = buildProps();
|
|
236
|
+
render(<ComponentWithStore {...props} />);
|
|
237
|
+
|
|
238
|
+
fireEvent.change(await screen.findByPlaceholderText('Enter creative name'), { target: { value: 'Promo push' } });
|
|
239
|
+
fireEvent.change(await screen.findByPlaceholderText('Enter title'), { target: { value: 'Hello' } });
|
|
240
|
+
fireEvent.change(await screen.findByPlaceholderText('Enter message'), { target: { value: 'World' } });
|
|
241
|
+
|
|
242
|
+
fireEvent.click(screen.getByRole('button', { name: 'Save Template' }));
|
|
243
|
+
expect(props.mobilePushActions.createTemplate).toHaveBeenCalledTimes(1);
|
|
244
|
+
});
|
|
245
|
+
|
|
246
|
+
describe('both platforms supported, only Android filled', () => {
|
|
247
|
+
const bothPlatformsAccount = {
|
|
248
|
+
configs: { android: '1', ios: '1' }, accountId: 'acc-1', licenseCode: 'lic-1', sourceType: 'FCM',
|
|
249
|
+
};
|
|
250
|
+
|
|
251
|
+
// Fills Android (and optionally an iOS title), then saves from the footer
|
|
252
|
+
const fillAndroidAndFooterSave = async (props, iosTitle = '') => {
|
|
253
|
+
const { rerender } = render(<ComponentWithStore {...props} />);
|
|
254
|
+
fireEvent.change(await screen.findByPlaceholderText('Enter creative name'), { target: { value: 'Promo push' } });
|
|
255
|
+
fireEvent.change((await screen.findAllByPlaceholderText('Enter title'))[0], { target: { value: 'Hello' } });
|
|
256
|
+
fireEvent.change(screen.getAllByPlaceholderText('Enter message')[0], { target: { value: 'World' } });
|
|
257
|
+
if (iosTitle) {
|
|
258
|
+
fireEvent.click(screen.getAllByText('iOS')[0]);
|
|
259
|
+
const titleInputs = await screen.findAllByPlaceholderText('Enter title');
|
|
260
|
+
fireEvent.change(titleInputs[titleInputs.length - 1], { target: { value: iosTitle } });
|
|
261
|
+
fireEvent.click(screen.getAllByText('Android')[0]);
|
|
262
|
+
}
|
|
263
|
+
expect(screen.getByRole('button', { name: 'Save Template' })).toBeDisabled();
|
|
264
|
+
rerender(<ComponentWithStore {...props} isGetFormData />);
|
|
265
|
+
};
|
|
266
|
+
|
|
267
|
+
it('does not save with iOS empty: opens the iOS tab with inline errors, no dialog', async () => {
|
|
268
|
+
const props = buildProps({ accountData: bothPlatformsAccount });
|
|
269
|
+
await fillAndroidAndFooterSave(props);
|
|
270
|
+
|
|
271
|
+
expect((await screen.findAllByText('Template message cannot be empty')).length).toBe(2);
|
|
272
|
+
expect(screen.getByRole('tab', { selected: true })).toHaveTextContent('iOS');
|
|
273
|
+
expect(screen.queryByRole('dialog')).toBeNull();
|
|
274
|
+
expect(props.mobilePushActions.createTemplate).not.toHaveBeenCalled();
|
|
275
|
+
});
|
|
276
|
+
|
|
277
|
+
it('does not save with iOS half filled: inline error on the iOS message', async () => {
|
|
278
|
+
const props = buildProps({ accountData: bothPlatformsAccount });
|
|
279
|
+
await fillAndroidAndFooterSave(props, 'Only a title');
|
|
280
|
+
|
|
281
|
+
expect((await screen.findAllByText('Template message cannot be empty')).length).toBe(1);
|
|
282
|
+
expect(screen.queryByRole('dialog')).toBeNull();
|
|
283
|
+
expect(props.mobilePushActions.createTemplate).not.toHaveBeenCalled();
|
|
284
|
+
});
|
|
285
|
+
});
|
|
286
|
+
|
|
287
|
+
describe('Notification tap', () => {
|
|
288
|
+
const fillAndChooseTap = async (props, tapLabel) => {
|
|
289
|
+
render(<ComponentWithStore {...props} />);
|
|
290
|
+
fireEvent.change(await screen.findByPlaceholderText('Enter creative name'), { target: { value: 'Promo push' } });
|
|
291
|
+
fireEvent.change(await screen.findByPlaceholderText('Enter title'), { target: { value: 'Hello' } });
|
|
292
|
+
fireEvent.change(screen.getByPlaceholderText('Enter message'), { target: { value: 'World' } });
|
|
293
|
+
|
|
294
|
+
expect(screen.getByText('Opens your app. Choose a link to send people to a specific page instead.')).toBeInTheDocument();
|
|
295
|
+
// antd Select opens on mouseDown, not click
|
|
296
|
+
fireEvent.mouseDown(screen.getByText('App (default)'));
|
|
297
|
+
const options = await screen.findAllByText(tapLabel);
|
|
298
|
+
fireEvent.click(options[options.length - 1]);
|
|
299
|
+
};
|
|
300
|
+
|
|
301
|
+
it('an open External link blocks the template Save until its own Save is clicked', async () => {
|
|
302
|
+
const props = buildProps();
|
|
303
|
+
await fillAndChooseTap(props, 'External link');
|
|
304
|
+
const urlInput = await screen.findByPlaceholderText('Enter URL');
|
|
305
|
+
|
|
306
|
+
expect(screen.getByRole('button', { name: 'Save Template' })).toBeDisabled();
|
|
307
|
+
expect(screen.getByRole('button', { name: 'Save' })).toBeDisabled();
|
|
308
|
+
|
|
309
|
+
fireEvent.change(urlInput, { target: { value: 'https://example.com' } });
|
|
310
|
+
fireEvent.click(screen.getByRole('button', { name: 'Save' }));
|
|
311
|
+
|
|
312
|
+
expect(await screen.findByText('https://example.com')).toBeInTheDocument();
|
|
313
|
+
expect(screen.queryByPlaceholderText('Enter URL')).toBeNull();
|
|
314
|
+
expect(screen.getByRole('button', { name: 'Save Template' })).not.toBeDisabled();
|
|
315
|
+
});
|
|
316
|
+
|
|
317
|
+
it('passes the notification tap to Test & Preview as its CTA fields', async () => {
|
|
318
|
+
const props = buildProps();
|
|
319
|
+
await fillAndChooseTap(props, 'External link');
|
|
320
|
+
fireEvent.change(await screen.findByPlaceholderText('Enter URL'), { target: { value: 'https://example.com' } });
|
|
321
|
+
|
|
322
|
+
const [androidFormData] = JSON.parse(screen.getByTestId('test-preview-slidebox').dataset.formData);
|
|
323
|
+
expect(androidFormData).toEqual(expect.objectContaining({
|
|
324
|
+
'cta-deeplink': 'External Link',
|
|
325
|
+
'cta-deeplink-select': '',
|
|
326
|
+
'cta-deeplink-text': 'https://example.com',
|
|
327
|
+
}));
|
|
328
|
+
});
|
|
329
|
+
|
|
330
|
+
it('an open Deep link with none picked keeps both Saves off', async () => {
|
|
331
|
+
const props = buildProps();
|
|
332
|
+
await fillAndChooseTap(props, 'Deep link');
|
|
333
|
+
|
|
334
|
+
expect(screen.getByRole('button', { name: 'Save Template' })).toBeDisabled();
|
|
335
|
+
expect(screen.getByRole('button', { name: 'Save' })).toBeDisabled();
|
|
336
|
+
expect(props.mobilePushActions.createTemplate).not.toHaveBeenCalled();
|
|
337
|
+
});
|
|
338
|
+
});
|
|
339
|
+
|
|
340
|
+
describe('Same content for both platforms', () => {
|
|
341
|
+
const bothPlatformsAccount = {
|
|
342
|
+
configs: { android: '1', ios: '1' }, accountId: 'acc-1', licenseCode: 'lic-1', sourceType: 'FCM',
|
|
343
|
+
};
|
|
344
|
+
const fillTab = async (tabLabel, title, message) => {
|
|
345
|
+
fireEvent.click(screen.getAllByText(tabLabel)[0]);
|
|
346
|
+
const titleInputs = await screen.findAllByPlaceholderText('Enter title');
|
|
347
|
+
const messageInputs = screen.getAllByPlaceholderText('Enter message');
|
|
348
|
+
const index = tabLabel === 'Android' ? 0 : titleInputs.length - 1;
|
|
349
|
+
fireEvent.change(titleInputs[index], { target: { value: title } });
|
|
350
|
+
fireEvent.change(messageInputs[index], { target: { value: message } });
|
|
351
|
+
};
|
|
352
|
+
const sameContentBox = () => screen.getByRole('checkbox', { name: 'Same content for both platforms' });
|
|
353
|
+
const iosTitleValue = async () => {
|
|
354
|
+
fireEvent.click(screen.getAllByText('iOS')[0]);
|
|
355
|
+
const titleInputs = await screen.findAllByPlaceholderText('Enter title');
|
|
356
|
+
return titleInputs[titleInputs.length - 1].value;
|
|
357
|
+
};
|
|
358
|
+
|
|
359
|
+
it('ticks straight away when the other tab is empty', async () => {
|
|
360
|
+
render(<ComponentWithStore {...buildProps({ accountData: bothPlatformsAccount })} />);
|
|
361
|
+
await screen.findByPlaceholderText('Enter creative name');
|
|
362
|
+
await fillTab('Android', 'Android title', 'Android message');
|
|
363
|
+
|
|
364
|
+
fireEvent.click(sameContentBox());
|
|
365
|
+
expect(screen.queryByText('Replace iOS content?')).toBeNull();
|
|
366
|
+
expect(sameContentBox()).toBeChecked();
|
|
367
|
+
expect(await iosTitleValue()).toBe('Android title');
|
|
368
|
+
});
|
|
369
|
+
|
|
370
|
+
it('asks before replacing different content; Cancel keeps both, Replace copies', async () => {
|
|
371
|
+
render(<ComponentWithStore {...buildProps({ accountData: bothPlatformsAccount })} />);
|
|
372
|
+
await screen.findByPlaceholderText('Enter creative name');
|
|
373
|
+
await fillTab('iOS', 'iOS title', 'iOS message');
|
|
374
|
+
await fillTab('Android', 'Android title', 'Android message');
|
|
375
|
+
|
|
376
|
+
fireEvent.click(sameContentBox());
|
|
377
|
+
expect(await screen.findByText('Replace iOS content?')).toBeInTheDocument();
|
|
378
|
+
fireEvent.click(screen.getByRole('button', { name: 'Cancel' }));
|
|
379
|
+
expect(sameContentBox()).not.toBeChecked();
|
|
380
|
+
|
|
381
|
+
fireEvent.click(screen.getAllByText('Android')[0]);
|
|
382
|
+
fireEvent.click(sameContentBox());
|
|
383
|
+
fireEvent.click(await screen.findByRole('button', { name: 'Replace' }));
|
|
384
|
+
expect(sameContentBox()).toBeChecked();
|
|
385
|
+
expect(await iosTitleValue()).toBe('Android title');
|
|
386
|
+
});
|
|
387
|
+
});
|
|
388
|
+
|
|
389
|
+
describe('Platforms dropdown', () => {
|
|
390
|
+
const bothPlatformsAccount = {
|
|
391
|
+
configs: { android: '1', ios: '1' }, accountId: 'acc-1', licenseCode: 'lic-1', sourceType: 'FCM',
|
|
392
|
+
};
|
|
393
|
+
|
|
394
|
+
// Opens the dropdown from its shown value and picks an option
|
|
395
|
+
const choosePlatform = async (currentLabel, nextLabel) => {
|
|
396
|
+
fireEvent.mouseDown(screen.getAllByText(currentLabel)[0]);
|
|
397
|
+
const options = await screen.findAllByText(nextLabel);
|
|
398
|
+
fireEvent.click(options[options.length - 1]);
|
|
399
|
+
};
|
|
400
|
+
|
|
401
|
+
const fillVisibleForm = async (title, message) => {
|
|
402
|
+
const titleInputs = await screen.findAllByPlaceholderText('Enter title');
|
|
403
|
+
const messageInputs = screen.getAllByPlaceholderText('Enter message');
|
|
404
|
+
fireEvent.change(titleInputs[titleInputs.length - 1], { target: { value: title } });
|
|
405
|
+
fireEvent.change(messageInputs[messageInputs.length - 1], { target: { value: message } });
|
|
406
|
+
};
|
|
407
|
+
|
|
408
|
+
const createdPayload = (props) => props.mobilePushActions.createTemplate.mock.calls[0][0];
|
|
409
|
+
|
|
410
|
+
it('Android and iOS with both tabs filled saves both platforms without the alert', async () => {
|
|
411
|
+
const props = buildProps({ accountData: bothPlatformsAccount });
|
|
412
|
+
render(<ComponentWithStore {...props} />);
|
|
413
|
+
fireEvent.change(await screen.findByPlaceholderText('Enter creative name'), { target: { value: 'Promo push' } });
|
|
414
|
+
|
|
415
|
+
expect(screen.getByText('Same content for both platforms')).toBeInTheDocument();
|
|
416
|
+
await fillVisibleForm('Android title', 'Android message');
|
|
417
|
+
fireEvent.click(screen.getAllByText('iOS')[0]);
|
|
418
|
+
await fillVisibleForm('iOS title', 'iOS message');
|
|
419
|
+
fireEvent.click(screen.getByRole('button', { name: 'Save Template' }));
|
|
420
|
+
|
|
421
|
+
expect(screen.queryByRole('dialog')).toBeNull();
|
|
422
|
+
expect(props.mobilePushActions.createTemplate).toHaveBeenCalledTimes(1);
|
|
423
|
+
const { versions } = createdPayload(props);
|
|
424
|
+
expect(versions.base.ANDROID).toEqual(expect.objectContaining({ title: 'Android title', message: 'Android message' }));
|
|
425
|
+
expect(versions.base.IOS).toEqual(expect.objectContaining({ title: 'iOS title', message: 'iOS message' }));
|
|
426
|
+
});
|
|
427
|
+
|
|
428
|
+
it('Android only hides the tabs and checkbox and saves only the ANDROID key', async () => {
|
|
429
|
+
const props = buildProps({ accountData: bothPlatformsAccount });
|
|
430
|
+
render(<ComponentWithStore {...props} />);
|
|
431
|
+
fireEvent.change(await screen.findByPlaceholderText('Enter creative name'), { target: { value: 'Promo push' } });
|
|
432
|
+
|
|
433
|
+
await choosePlatform('Android and iOS', 'Android only');
|
|
434
|
+
expect(screen.queryByText('Same content for both platforms')).toBeNull();
|
|
435
|
+
expect(screen.getAllByPlaceholderText('Enter title')).toHaveLength(1);
|
|
436
|
+
|
|
437
|
+
await fillVisibleForm('Android title', 'Android message');
|
|
438
|
+
fireEvent.click(screen.getByRole('button', { name: 'Save Template' }));
|
|
439
|
+
|
|
440
|
+
expect(screen.queryByRole('dialog')).toBeNull();
|
|
441
|
+
const { versions, definition } = createdPayload(props);
|
|
442
|
+
expect(Object.keys(versions.base)).toEqual(['ANDROID']);
|
|
443
|
+
expect(definition.sameContent).toBe(false);
|
|
444
|
+
});
|
|
445
|
+
|
|
446
|
+
it('iOS only saves only the IOS key', async () => {
|
|
447
|
+
const props = buildProps({ accountData: bothPlatformsAccount });
|
|
448
|
+
render(<ComponentWithStore {...props} />);
|
|
449
|
+
fireEvent.change(await screen.findByPlaceholderText('Enter creative name'), { target: { value: 'Promo push' } });
|
|
450
|
+
|
|
451
|
+
await choosePlatform('Android and iOS', 'iOS only');
|
|
452
|
+
expect(screen.queryByText('Same content for both platforms')).toBeNull();
|
|
453
|
+
await fillVisibleForm('iOS title', 'iOS message');
|
|
454
|
+
fireEvent.click(screen.getByRole('button', { name: 'Save Template' }));
|
|
455
|
+
|
|
456
|
+
const { versions } = createdPayload(props);
|
|
457
|
+
expect(Object.keys(versions.base)).toEqual(['IOS']);
|
|
458
|
+
expect(versions.base.IOS).toEqual(expect.objectContaining({ title: 'iOS title', message: 'iOS message' }));
|
|
459
|
+
});
|
|
460
|
+
|
|
461
|
+
it('a single platform with empty fields shows inline errors, not the alert', async () => {
|
|
462
|
+
const props = buildProps({ accountData: bothPlatformsAccount });
|
|
463
|
+
const { rerender } = render(<ComponentWithStore {...props} />);
|
|
464
|
+
fireEvent.change(await screen.findByPlaceholderText('Enter creative name'), { target: { value: 'Promo push' } });
|
|
465
|
+
|
|
466
|
+
await choosePlatform('Android and iOS', 'Android only');
|
|
467
|
+
rerender(<ComponentWithStore {...props} isGetFormData />); // footer Save
|
|
468
|
+
|
|
469
|
+
expect((await screen.findAllByText('Template message cannot be empty')).length).toBe(2);
|
|
470
|
+
expect(screen.queryByRole('dialog')).toBeNull();
|
|
471
|
+
expect(props.mobilePushActions.createTemplate).not.toHaveBeenCalled();
|
|
472
|
+
});
|
|
473
|
+
|
|
474
|
+
it('confirms before dropping the other platform\'s content; Cancel keeps Android and iOS', async () => {
|
|
475
|
+
const props = buildProps({ accountData: bothPlatformsAccount });
|
|
476
|
+
render(<ComponentWithStore {...props} />);
|
|
477
|
+
await screen.findByPlaceholderText('Enter creative name');
|
|
478
|
+
fireEvent.click(screen.getAllByText('iOS')[0]);
|
|
479
|
+
await fillVisibleForm('iOS title', 'iOS message');
|
|
480
|
+
|
|
481
|
+
await choosePlatform('Android and iOS', 'Android only');
|
|
482
|
+
expect(await screen.findByText('Remove iOS content?')).toBeInTheDocument();
|
|
483
|
+
fireEvent.click(screen.getByRole('button', { name: 'Cancel' }));
|
|
484
|
+
expect(screen.getByText('Same content for both platforms')).toBeInTheDocument();
|
|
485
|
+
|
|
486
|
+
await choosePlatform('Android and iOS', 'Android only');
|
|
487
|
+
fireEvent.click(await screen.findByRole('button', { name: 'Remove content' }));
|
|
488
|
+
expect(screen.queryByText('Same content for both platforms')).toBeNull();
|
|
489
|
+
|
|
490
|
+
// Back to both: the iOS tab is empty
|
|
491
|
+
await choosePlatform('Android only', 'Android and iOS');
|
|
492
|
+
fireEvent.click(screen.getAllByText('iOS')[0]);
|
|
493
|
+
const titleInputs = await screen.findAllByPlaceholderText('Enter title');
|
|
494
|
+
expect(titleInputs[titleInputs.length - 1]).toHaveValue('');
|
|
495
|
+
});
|
|
496
|
+
|
|
497
|
+
it('opens a template saved with only Android as Android only', async () => {
|
|
498
|
+
renderComponent({
|
|
499
|
+
accountData: { configs: { android: '1', ios: '1' } },
|
|
500
|
+
templateData: {
|
|
501
|
+
name: 'Saved Android push',
|
|
502
|
+
versions: { base: { ANDROID: { title: 'A title', message: 'A msg', expandableDetails: { style: 'BIG_TEXT' } } } },
|
|
503
|
+
},
|
|
504
|
+
location: {},
|
|
505
|
+
injectedTags: {},
|
|
506
|
+
getDefaultTags: jest.fn(),
|
|
507
|
+
globalActions,
|
|
508
|
+
mobilePushActions: { setTemplateDetails: jest.fn(), getTemplateDetails: jest.fn(), clearData: jest.fn() },
|
|
509
|
+
});
|
|
510
|
+
|
|
511
|
+
expect(await screen.findByText('Android only')).toBeInTheDocument();
|
|
512
|
+
expect(screen.queryByText('Same content for both platforms')).toBeNull();
|
|
513
|
+
await waitFor(() => expect(screen.getByPlaceholderText('Enter title')).toHaveValue('A title'));
|
|
514
|
+
});
|
|
515
|
+
});
|
|
516
|
+
|
|
517
|
+
describe('Test & Preview from the edit footer', () => {
|
|
518
|
+
const baseProps = {
|
|
519
|
+
accountData,
|
|
520
|
+
templateData: {},
|
|
521
|
+
location: {},
|
|
522
|
+
injectedTags: {},
|
|
523
|
+
getDefaultTags: jest.fn(),
|
|
524
|
+
globalActions,
|
|
525
|
+
};
|
|
526
|
+
|
|
527
|
+
it('opens the slidebox when the parent sets showTestAndPreviewSlidebox', async () => {
|
|
528
|
+
renderComponent({ ...baseProps, showTestAndPreviewSlidebox: true });
|
|
529
|
+
expect(await screen.findByTestId('test-preview-slidebox')).toHaveAttribute('data-show', 'true');
|
|
530
|
+
});
|
|
531
|
+
|
|
532
|
+
it('stays closed by default and tells the parent on close', async () => {
|
|
533
|
+
const handleCloseTestAndPreview = jest.fn();
|
|
534
|
+
renderComponent({ ...baseProps, handleCloseTestAndPreview });
|
|
535
|
+
const slidebox = await screen.findByTestId('test-preview-slidebox');
|
|
536
|
+
|
|
537
|
+
expect(slidebox).toHaveAttribute('data-show', 'false');
|
|
538
|
+
fireEvent.click(slidebox);
|
|
539
|
+
expect(handleCloseTestAndPreview).toHaveBeenCalledTimes(1);
|
|
540
|
+
});
|
|
541
|
+
});
|
|
542
|
+
|
|
543
|
+
describe('saved template buttons in the preview', () => {
|
|
544
|
+
const cta = (actionText) => ({ actionText, type: 'EXTERNAL_URL', actionLink: 'https://x.com' });
|
|
545
|
+
const savedTemplate = {
|
|
546
|
+
name: 'Saved push',
|
|
547
|
+
versions: {
|
|
548
|
+
base: {
|
|
549
|
+
ANDROID: { title: 'A title', message: 'A msg', expandableDetails: { style: 'BIG_TEXT', ctas: [cta('AndPrim')] } },
|
|
550
|
+
IOS: { title: 'I title', message: 'I msg', expandableDetails: { style: 'BIG_TEXT', ctas: [cta('IOSPrim')] } },
|
|
551
|
+
},
|
|
552
|
+
},
|
|
553
|
+
};
|
|
554
|
+
|
|
555
|
+
const renderSaved = () => renderComponent({
|
|
556
|
+
accountData: { configs: { android: '1', ios: '1' } },
|
|
557
|
+
templateData: savedTemplate,
|
|
558
|
+
location: {},
|
|
559
|
+
injectedTags: {},
|
|
560
|
+
getDefaultTags: jest.fn(),
|
|
561
|
+
globalActions,
|
|
562
|
+
mobilePushActions: { setTemplateDetails: jest.fn(), getTemplateDetails: jest.fn(), clearData: jest.fn() },
|
|
563
|
+
});
|
|
564
|
+
|
|
565
|
+
it('passes saved buttons in the test payload formData', async () => {
|
|
566
|
+
renderSaved();
|
|
567
|
+
const slidebox = await screen.findByTestId('test-preview-slidebox');
|
|
568
|
+
|
|
569
|
+
await waitFor(() => {
|
|
570
|
+
const [android, ios] = JSON.parse(slidebox.getAttribute('data-form-data'));
|
|
571
|
+
expect(android).toEqual(expect.objectContaining({
|
|
572
|
+
'secondary-cta-0-label': 'AndPrim',
|
|
573
|
+
'cta-deeplink-secondary-cta-0': 'External Link',
|
|
574
|
+
'cta-deeplink-secondary-cta-0-text': 'https://x.com',
|
|
575
|
+
}));
|
|
576
|
+
expect(ios).toEqual(expect.objectContaining({
|
|
577
|
+
'secondary-cta-1-label': 'IOSPrim',
|
|
578
|
+
'cta-deeplink-secondary-cta-1': 'External Link',
|
|
579
|
+
'cta-deeplink-secondary-cta-1-text': 'https://x.com',
|
|
580
|
+
}));
|
|
581
|
+
});
|
|
582
|
+
});
|
|
583
|
+
|
|
584
|
+
it('fills iOS buttons without opening the iOS tab', async () => {
|
|
585
|
+
renderSaved();
|
|
586
|
+
const slidebox = await screen.findByTestId('test-preview-slidebox');
|
|
587
|
+
|
|
588
|
+
await waitFor(() => {
|
|
589
|
+
expect(slidebox).toHaveAttribute('data-android-actions', JSON.stringify([{ label: 'AndPrim' }]));
|
|
590
|
+
expect(slidebox).toHaveAttribute('data-ios-actions', JSON.stringify([{ label: 'IOSPrim' }]));
|
|
591
|
+
});
|
|
592
|
+
});
|
|
593
|
+
|
|
594
|
+
it('passes each platform\'s own saved video in the test payload formData', async () => {
|
|
595
|
+
const videoTemplate = {
|
|
596
|
+
name: 'Saved video push',
|
|
597
|
+
versions: {
|
|
598
|
+
base: {
|
|
599
|
+
ANDROID: {
|
|
600
|
+
title: 'A title',
|
|
601
|
+
message: 'A msg',
|
|
602
|
+
type: 'VIDEO',
|
|
603
|
+
expandableDetails: { style: 'VIDEO', media: [{ url: 'https://s3/a.mp4', text: '', type: 'VIDEO' }] },
|
|
604
|
+
},
|
|
605
|
+
IOS: { title: 'I title', message: 'I msg', expandableDetails: { style: 'BIG_TEXT' } },
|
|
606
|
+
},
|
|
607
|
+
},
|
|
608
|
+
};
|
|
609
|
+
renderComponent({
|
|
610
|
+
accountData: { configs: { android: '1', ios: '1' } },
|
|
611
|
+
templateData: videoTemplate,
|
|
612
|
+
location: {},
|
|
613
|
+
injectedTags: {},
|
|
614
|
+
getDefaultTags: jest.fn(),
|
|
615
|
+
globalActions,
|
|
616
|
+
mobilePushActions: { setTemplateDetails: jest.fn(), getTemplateDetails: jest.fn(), clearData: jest.fn() },
|
|
617
|
+
});
|
|
618
|
+
const slidebox = await screen.findByTestId('test-preview-slidebox');
|
|
619
|
+
|
|
620
|
+
await waitFor(() => {
|
|
621
|
+
const [android, ios] = JSON.parse(slidebox.getAttribute('data-form-data'));
|
|
622
|
+
expect(android.video).toBe('https://s3/a.mp4');
|
|
623
|
+
expect(ios.video).toBe('');
|
|
624
|
+
});
|
|
625
|
+
});
|
|
626
|
+
|
|
627
|
+
it('passes saved carousel cards in the test payload formData', async () => {
|
|
628
|
+
const card = {
|
|
629
|
+
mediaType: 'video', imageUrl: '', videoSrc: 'https://s3/c.mp4', buttons: [],
|
|
630
|
+
};
|
|
631
|
+
renderComponent({
|
|
632
|
+
accountData: { configs: { android: '1', ios: '1' } },
|
|
633
|
+
templateData: {
|
|
634
|
+
name: 'Saved carousel push',
|
|
635
|
+
versions: {
|
|
636
|
+
base: {
|
|
637
|
+
ANDROID: {
|
|
638
|
+
title: 'A title',
|
|
639
|
+
message: 'A msg',
|
|
640
|
+
type: 'CAROUSEL',
|
|
641
|
+
expandableDetails: { style: 'MANUAL_CAROUSEL', carouselData: [card] },
|
|
642
|
+
},
|
|
643
|
+
IOS: { title: 'I title', message: 'I msg', expandableDetails: { style: 'BIG_TEXT' } },
|
|
644
|
+
},
|
|
645
|
+
},
|
|
646
|
+
},
|
|
647
|
+
location: {},
|
|
648
|
+
injectedTags: {},
|
|
649
|
+
getDefaultTags: jest.fn(),
|
|
650
|
+
globalActions,
|
|
651
|
+
mobilePushActions: { setTemplateDetails: jest.fn(), getTemplateDetails: jest.fn(), clearData: jest.fn() },
|
|
652
|
+
});
|
|
653
|
+
const slidebox = await screen.findByTestId('test-preview-slidebox');
|
|
654
|
+
|
|
655
|
+
await waitFor(() => {
|
|
656
|
+
const [android, ios] = JSON.parse(slidebox.getAttribute('data-form-data'));
|
|
657
|
+
expect(android.carouselData).toEqual([expect.objectContaining({ mediaType: 'video', videoSrc: 'https://s3/c.mp4' })]);
|
|
658
|
+
expect(ios.carouselData).toEqual([]);
|
|
659
|
+
});
|
|
660
|
+
});
|
|
661
|
+
});
|
|
180
662
|
});
|
|
@@ -5,6 +5,16 @@ import {
|
|
|
5
5
|
isDeepLink,
|
|
6
6
|
isPlatformFieldsMissing,
|
|
7
7
|
computeIsContentEmpty,
|
|
8
|
+
getContent,
|
|
9
|
+
findSelectedDeepLink,
|
|
10
|
+
getCarouselCardIssue,
|
|
11
|
+
CAROUSEL_CARD_ISSUE,
|
|
12
|
+
splitDeepLinkParam,
|
|
13
|
+
getDeepLinkParamValue,
|
|
14
|
+
setDeepLinkParamValue,
|
|
15
|
+
hasAllDeepLinkParams,
|
|
16
|
+
extractDeepLinkParams,
|
|
17
|
+
appendDeepLinkParams,
|
|
8
18
|
} from "../utils";
|
|
9
19
|
import { isUrl } from "../../Line/Container/Wrapper/utils";
|
|
10
20
|
|
|
@@ -510,3 +520,103 @@ describe("utils.js", () => {
|
|
|
510
520
|
});
|
|
511
521
|
});
|
|
512
522
|
});
|
|
523
|
+
|
|
524
|
+
describe("getContent", () => {
|
|
525
|
+
it("returns three spaces when there is no content", () => {
|
|
526
|
+
expect(getContent(null)).toBe(" ");
|
|
527
|
+
expect(getContent({ versions: { base: {} } })).toBe(" ");
|
|
528
|
+
});
|
|
529
|
+
|
|
530
|
+
it("joins Android and iOS title and message", () => {
|
|
531
|
+
const payload = {
|
|
532
|
+
versions: {
|
|
533
|
+
base: {
|
|
534
|
+
ANDROID: { title: "A title", message: "A msg" },
|
|
535
|
+
IOS: { title: "I title", message: "I msg" },
|
|
536
|
+
},
|
|
537
|
+
},
|
|
538
|
+
};
|
|
539
|
+
expect(getContent(payload)).toBe("A title A msg I title I msg");
|
|
540
|
+
});
|
|
541
|
+
|
|
542
|
+
it("leaves an empty slot for a missing platform", () => {
|
|
543
|
+
const payload = { versions: { base: { ANDROID: { title: "A", message: "B" } } } };
|
|
544
|
+
expect(getContent(payload)).toBe("A B ");
|
|
545
|
+
});
|
|
546
|
+
});
|
|
547
|
+
|
|
548
|
+
describe("findSelectedDeepLink", () => {
|
|
549
|
+
const links = [{ value: "app://offer", keys: ["offerId"] }];
|
|
550
|
+
|
|
551
|
+
it("matches exactly, then without query params", () => {
|
|
552
|
+
expect(findSelectedDeepLink(links, "app://offer")).toBe(links[0]);
|
|
553
|
+
expect(findSelectedDeepLink(links, "app://offer?offerId=offerId")).toBe(links[0]);
|
|
554
|
+
expect(findSelectedDeepLink(links, "app://other")).toBeUndefined();
|
|
555
|
+
expect(findSelectedDeepLink(undefined, "app://offer")).toBeUndefined();
|
|
556
|
+
});
|
|
557
|
+
});
|
|
558
|
+
|
|
559
|
+
describe("getCarouselCardIssue", () => {
|
|
560
|
+
it("is complete once the card has its media", () => {
|
|
561
|
+
expect(getCarouselCardIssue({ mediaType: "image", imageUrl: "a.jpg" })).toBeNull();
|
|
562
|
+
expect(getCarouselCardIssue({ mediaType: "video", videoSrc: "a.mp4" })).toBeNull();
|
|
563
|
+
});
|
|
564
|
+
|
|
565
|
+
it("flags missing media", () => {
|
|
566
|
+
expect(getCarouselCardIssue({ mediaType: "image", imageUrl: "" })).toBe(CAROUSEL_CARD_ISSUE.MEDIA);
|
|
567
|
+
expect(getCarouselCardIssue({ mediaType: "video", videoSrc: "" })).toBe(CAROUSEL_CARD_ISSUE.MEDIA);
|
|
568
|
+
});
|
|
569
|
+
|
|
570
|
+
it("ignores card links (the notification tap is for the whole notification)", () => {
|
|
571
|
+
const card = {
|
|
572
|
+
mediaType: "image",
|
|
573
|
+
imageUrl: "a.jpg",
|
|
574
|
+
buttons: [{ actionOnClick: true, linkType: "DEEP_LINK", deepLinkValue: "", isSaved: false }],
|
|
575
|
+
};
|
|
576
|
+
expect(getCarouselCardIssue(card)).toBeNull();
|
|
577
|
+
});
|
|
578
|
+
});
|
|
579
|
+
|
|
580
|
+
describe("deep link params", () => {
|
|
581
|
+
it("splits at the first = and reads an old key-only entry as key=key", () => {
|
|
582
|
+
expect(splitDeepLinkParam("testing_purpose=androidDeeplink")).toEqual(["testing_purpose", "androidDeeplink"]);
|
|
583
|
+
expect(splitDeepLinkParam("url=a=b")).toEqual(["url", "a=b"]);
|
|
584
|
+
expect(splitDeepLinkParam("offerId")).toEqual(["offerId", "offerId"]);
|
|
585
|
+
});
|
|
586
|
+
|
|
587
|
+
it("reads the value typed for a key", () => {
|
|
588
|
+
expect(getDeepLinkParamValue(["a=1", "b=2"], "b")).toBe("2");
|
|
589
|
+
expect(getDeepLinkParamValue(["a=1"], "b")).toBe("");
|
|
590
|
+
expect(getDeepLinkParamValue(undefined, "a")).toBe("");
|
|
591
|
+
});
|
|
592
|
+
|
|
593
|
+
it("stores the typed value against its configured key, in key order", () => {
|
|
594
|
+
expect(setDeepLinkParamValue([], ["testing_purpose"], "testing_purpose", "androidDeeplink"))
|
|
595
|
+
.toEqual(["testing_purpose=androidDeeplink"]);
|
|
596
|
+
expect(setDeepLinkParamValue(["b=2"], ["a", "b"], "a", "1")).toEqual(["a=1", "b=2"]);
|
|
597
|
+
expect(setDeepLinkParamValue(["a=1", "b=2"], ["a", "b"], "a", "")).toEqual(["b=2"]);
|
|
598
|
+
});
|
|
599
|
+
|
|
600
|
+
it("needs a value for every configured key", () => {
|
|
601
|
+
expect(hasAllDeepLinkParams(["a=1", "b=2"], ["a", "b"])).toBe(true);
|
|
602
|
+
expect(hasAllDeepLinkParams(["a=1"], ["a", "b"])).toBe(false);
|
|
603
|
+
expect(hasAllDeepLinkParams(["a= "], ["a"])).toBe(false);
|
|
604
|
+
expect(hasAllDeepLinkParams([], [])).toBe(true);
|
|
605
|
+
});
|
|
606
|
+
|
|
607
|
+
it("extracts every key=value from a saved URL without decoding it", () => {
|
|
608
|
+
expect(extractDeepLinkParams("app://home?id={{user_id}}&src=push")).toEqual(["id={{user_id}}", "src=push"]);
|
|
609
|
+
expect(extractDeepLinkParams("app://home")).toEqual([]);
|
|
610
|
+
expect(extractDeepLinkParams(undefined)).toEqual([]);
|
|
611
|
+
});
|
|
612
|
+
|
|
613
|
+
it("appends params and replaces a key already in the URL", () => {
|
|
614
|
+
expect(appendDeepLinkParams("https://www.youtube.com/", ["testing_purpose=androidDeeplink"]))
|
|
615
|
+
.toBe("https://www.youtube.com/?testing_purpose=androidDeeplink");
|
|
616
|
+
expect(appendDeepLinkParams("app://home?src=push&id=5", ["id=7"])).toBe("app://home?src=push&id=7");
|
|
617
|
+
expect(appendDeepLinkParams("app://home?id=5", ["id=5"])).toBe("app://home?id=5");
|
|
618
|
+
expect(appendDeepLinkParams("app://home", ["offerId"])).toBe("app://home?offerId=offerId");
|
|
619
|
+
expect(appendDeepLinkParams("app://home", [])).toBe("app://home");
|
|
620
|
+
expect(appendDeepLinkParams("", ["a=1"])).toBe("");
|
|
621
|
+
});
|
|
622
|
+
});
|