@capillarytech/creatives-library 9.1.7 → 9.1.8-alpha.sprint-cap-214249.39
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 -33
- package/utils/tests/createMobilePushPayload.test.js +113 -8
- package/v2Components/CapMpushCTA/index.js +10 -9
- package/v2Components/CapMpushCTA/index.scss +29 -3
- package/v2Components/CapMpushCTA/tests/index.test.js +89 -0
- package/v2Components/CommonTestAndPreview/UnifiedPreview/MobilePushPreviewContent.js +20 -12
- package/v2Components/CommonTestAndPreview/UnifiedPreview/_unifiedPreview.scss +13 -1
- package/v2Components/CommonTestAndPreview/constants.js +2 -0
- package/v2Components/CommonTestAndPreview/index.js +48 -10
- package/v2Components/CommonTestAndPreview/tests/UnifiedPreview/MobilePushPreviewContent.test.js +81 -5
- package/v2Components/CommonTestAndPreview/tests/index.test.js +86 -0
- package/v2Components/TemplatePreview/_templatePreview.scss +12 -2
- package/v2Components/TemplatePreview/index.js +24 -16
- package/v2Components/TemplatePreview/tests/index.test.js +68 -0
- 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 +297 -216
- package/v2Containers/MobilePushNew/components/PlatformContentFields.js +158 -125
- 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 +464 -108
- package/v2Containers/MobilePushNew/components/tests/PlatformContentFields.test.js +106 -35
- package/v2Containers/MobilePushNew/constants.js +5 -0
- package/v2Containers/MobilePushNew/hooks/tests/usePlatformSync.test.js +63 -1
- package/v2Containers/MobilePushNew/hooks/tests/useUpload.test.js +52 -0
- package/v2Containers/MobilePushNew/hooks/usePlatformSync.js +40 -1
- package/v2Containers/MobilePushNew/hooks/useUpload.js +29 -39
- package/v2Containers/MobilePushNew/index.js +487 -235
- package/v2Containers/MobilePushNew/index.scss +205 -4
- package/v2Containers/MobilePushNew/messages.js +106 -6
- package/v2Containers/MobilePushNew/tests/index.test.js +469 -1
- package/v2Containers/MobilePushNew/tests/utils.test.js +70 -0
- package/v2Containers/MobilePushNew/utils.js +56 -0
- package/v2Containers/Templates/_templates.scss +10 -2
- package/v2Containers/Templates/index.js +83 -81
- package/v2Containers/Templates/tests/index.test.js +68 -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,419 @@ 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
|
+
fireEvent.click(screen.getByText('App (default)'));
|
|
296
|
+
const options = await screen.findAllByText(tapLabel);
|
|
297
|
+
fireEvent.click(options[options.length - 1]);
|
|
298
|
+
};
|
|
299
|
+
|
|
300
|
+
it('an open External link blocks the template Save until its own Save is clicked', async () => {
|
|
301
|
+
const props = buildProps();
|
|
302
|
+
await fillAndChooseTap(props, 'External link');
|
|
303
|
+
const urlInput = await screen.findByPlaceholderText('Enter URL');
|
|
304
|
+
|
|
305
|
+
expect(screen.getByRole('button', { name: 'Save Template' })).toBeDisabled();
|
|
306
|
+
expect(screen.getByRole('button', { name: 'Save' })).toBeDisabled();
|
|
307
|
+
|
|
308
|
+
fireEvent.change(urlInput, { target: { value: 'https://example.com' } });
|
|
309
|
+
fireEvent.click(screen.getByRole('button', { name: 'Save' }));
|
|
310
|
+
|
|
311
|
+
expect(await screen.findByText('https://example.com')).toBeInTheDocument();
|
|
312
|
+
expect(screen.queryByPlaceholderText('Enter URL')).toBeNull();
|
|
313
|
+
expect(screen.getByRole('button', { name: 'Save Template' })).not.toBeDisabled();
|
|
314
|
+
});
|
|
315
|
+
|
|
316
|
+
it('an open Deep link with none picked keeps both Saves off', async () => {
|
|
317
|
+
const props = buildProps();
|
|
318
|
+
await fillAndChooseTap(props, 'Deep link');
|
|
319
|
+
|
|
320
|
+
expect(screen.getByRole('button', { name: 'Save Template' })).toBeDisabled();
|
|
321
|
+
expect(screen.getByRole('button', { name: 'Save' })).toBeDisabled();
|
|
322
|
+
expect(props.mobilePushActions.createTemplate).not.toHaveBeenCalled();
|
|
323
|
+
});
|
|
324
|
+
});
|
|
325
|
+
|
|
326
|
+
describe('Same content for both platforms', () => {
|
|
327
|
+
const bothPlatformsAccount = {
|
|
328
|
+
configs: { android: '1', ios: '1' }, accountId: 'acc-1', licenseCode: 'lic-1', sourceType: 'FCM',
|
|
329
|
+
};
|
|
330
|
+
const fillTab = async (tabLabel, title, message) => {
|
|
331
|
+
fireEvent.click(screen.getAllByText(tabLabel)[0]);
|
|
332
|
+
const titleInputs = await screen.findAllByPlaceholderText('Enter title');
|
|
333
|
+
const messageInputs = screen.getAllByPlaceholderText('Enter message');
|
|
334
|
+
const index = tabLabel === 'Android' ? 0 : titleInputs.length - 1;
|
|
335
|
+
fireEvent.change(titleInputs[index], { target: { value: title } });
|
|
336
|
+
fireEvent.change(messageInputs[index], { target: { value: message } });
|
|
337
|
+
};
|
|
338
|
+
const sameContentBox = () => screen.getByRole('checkbox', { name: 'Same content for both platforms' });
|
|
339
|
+
const iosTitleValue = async () => {
|
|
340
|
+
fireEvent.click(screen.getAllByText('iOS')[0]);
|
|
341
|
+
const titleInputs = await screen.findAllByPlaceholderText('Enter title');
|
|
342
|
+
return titleInputs[titleInputs.length - 1].value;
|
|
343
|
+
};
|
|
344
|
+
|
|
345
|
+
it('ticks straight away when the other tab is empty', async () => {
|
|
346
|
+
render(<ComponentWithStore {...buildProps({ accountData: bothPlatformsAccount })} />);
|
|
347
|
+
await screen.findByPlaceholderText('Enter creative name');
|
|
348
|
+
await fillTab('Android', 'Android title', 'Android message');
|
|
349
|
+
|
|
350
|
+
fireEvent.click(sameContentBox());
|
|
351
|
+
expect(screen.queryByText('Replace iOS content?')).toBeNull();
|
|
352
|
+
expect(sameContentBox()).toBeChecked();
|
|
353
|
+
expect(await iosTitleValue()).toBe('Android title');
|
|
354
|
+
});
|
|
355
|
+
|
|
356
|
+
it('asks before replacing different content; Cancel keeps both, Replace copies', async () => {
|
|
357
|
+
render(<ComponentWithStore {...buildProps({ accountData: bothPlatformsAccount })} />);
|
|
358
|
+
await screen.findByPlaceholderText('Enter creative name');
|
|
359
|
+
await fillTab('iOS', 'iOS title', 'iOS message');
|
|
360
|
+
await fillTab('Android', 'Android title', 'Android message');
|
|
361
|
+
|
|
362
|
+
fireEvent.click(sameContentBox());
|
|
363
|
+
expect(await screen.findByText('Replace iOS content?')).toBeInTheDocument();
|
|
364
|
+
fireEvent.click(screen.getByRole('button', { name: 'Cancel' }));
|
|
365
|
+
expect(sameContentBox()).not.toBeChecked();
|
|
366
|
+
|
|
367
|
+
fireEvent.click(screen.getAllByText('Android')[0]);
|
|
368
|
+
fireEvent.click(sameContentBox());
|
|
369
|
+
fireEvent.click(await screen.findByRole('button', { name: 'Replace' }));
|
|
370
|
+
expect(sameContentBox()).toBeChecked();
|
|
371
|
+
expect(await iosTitleValue()).toBe('Android title');
|
|
372
|
+
});
|
|
373
|
+
});
|
|
374
|
+
|
|
375
|
+
describe('Platforms dropdown', () => {
|
|
376
|
+
const bothPlatformsAccount = {
|
|
377
|
+
configs: { android: '1', ios: '1' }, accountId: 'acc-1', licenseCode: 'lic-1', sourceType: 'FCM',
|
|
378
|
+
};
|
|
379
|
+
|
|
380
|
+
// Opens the dropdown from its shown value and picks an option
|
|
381
|
+
const choosePlatform = async (currentLabel, nextLabel) => {
|
|
382
|
+
fireEvent.click(screen.getAllByText(currentLabel)[0]);
|
|
383
|
+
const options = await screen.findAllByText(nextLabel);
|
|
384
|
+
fireEvent.click(options[options.length - 1]);
|
|
385
|
+
};
|
|
386
|
+
|
|
387
|
+
const fillVisibleForm = async (title, message) => {
|
|
388
|
+
const titleInputs = await screen.findAllByPlaceholderText('Enter title');
|
|
389
|
+
const messageInputs = screen.getAllByPlaceholderText('Enter message');
|
|
390
|
+
fireEvent.change(titleInputs[titleInputs.length - 1], { target: { value: title } });
|
|
391
|
+
fireEvent.change(messageInputs[messageInputs.length - 1], { target: { value: message } });
|
|
392
|
+
};
|
|
393
|
+
|
|
394
|
+
const createdPayload = (props) => props.mobilePushActions.createTemplate.mock.calls[0][0];
|
|
395
|
+
|
|
396
|
+
it('Android and iOS with both tabs filled saves both platforms without the alert', async () => {
|
|
397
|
+
const props = buildProps({ accountData: bothPlatformsAccount });
|
|
398
|
+
render(<ComponentWithStore {...props} />);
|
|
399
|
+
fireEvent.change(await screen.findByPlaceholderText('Enter creative name'), { target: { value: 'Promo push' } });
|
|
400
|
+
|
|
401
|
+
expect(screen.getByText('Same content for both platforms')).toBeInTheDocument();
|
|
402
|
+
await fillVisibleForm('Android title', 'Android message');
|
|
403
|
+
fireEvent.click(screen.getAllByText('iOS')[0]);
|
|
404
|
+
await fillVisibleForm('iOS title', 'iOS message');
|
|
405
|
+
fireEvent.click(screen.getByRole('button', { name: 'Save Template' }));
|
|
406
|
+
|
|
407
|
+
expect(screen.queryByRole('dialog')).toBeNull();
|
|
408
|
+
expect(props.mobilePushActions.createTemplate).toHaveBeenCalledTimes(1);
|
|
409
|
+
const { versions } = createdPayload(props);
|
|
410
|
+
expect(versions.base.ANDROID).toEqual(expect.objectContaining({ title: 'Android title', message: 'Android message' }));
|
|
411
|
+
expect(versions.base.IOS).toEqual(expect.objectContaining({ title: 'iOS title', message: 'iOS message' }));
|
|
412
|
+
});
|
|
413
|
+
|
|
414
|
+
it('Android only hides the tabs and checkbox and saves only the ANDROID key', async () => {
|
|
415
|
+
const props = buildProps({ accountData: bothPlatformsAccount });
|
|
416
|
+
render(<ComponentWithStore {...props} />);
|
|
417
|
+
fireEvent.change(await screen.findByPlaceholderText('Enter creative name'), { target: { value: 'Promo push' } });
|
|
418
|
+
|
|
419
|
+
await choosePlatform('Android and iOS', 'Android only');
|
|
420
|
+
expect(screen.queryByText('Same content for both platforms')).toBeNull();
|
|
421
|
+
expect(screen.getAllByPlaceholderText('Enter title')).toHaveLength(1);
|
|
422
|
+
|
|
423
|
+
await fillVisibleForm('Android title', 'Android message');
|
|
424
|
+
fireEvent.click(screen.getByRole('button', { name: 'Save Template' }));
|
|
425
|
+
|
|
426
|
+
expect(screen.queryByRole('dialog')).toBeNull();
|
|
427
|
+
const { versions, definition } = createdPayload(props);
|
|
428
|
+
expect(Object.keys(versions.base)).toEqual(['ANDROID']);
|
|
429
|
+
expect(definition.sameContent).toBe(false);
|
|
430
|
+
});
|
|
431
|
+
|
|
432
|
+
it('iOS only saves only the IOS key', async () => {
|
|
433
|
+
const props = buildProps({ accountData: bothPlatformsAccount });
|
|
434
|
+
render(<ComponentWithStore {...props} />);
|
|
435
|
+
fireEvent.change(await screen.findByPlaceholderText('Enter creative name'), { target: { value: 'Promo push' } });
|
|
436
|
+
|
|
437
|
+
await choosePlatform('Android and iOS', 'iOS only');
|
|
438
|
+
expect(screen.queryByText('Same content for both platforms')).toBeNull();
|
|
439
|
+
await fillVisibleForm('iOS title', 'iOS message');
|
|
440
|
+
fireEvent.click(screen.getByRole('button', { name: 'Save Template' }));
|
|
441
|
+
|
|
442
|
+
const { versions } = createdPayload(props);
|
|
443
|
+
expect(Object.keys(versions.base)).toEqual(['IOS']);
|
|
444
|
+
expect(versions.base.IOS).toEqual(expect.objectContaining({ title: 'iOS title', message: 'iOS message' }));
|
|
445
|
+
});
|
|
446
|
+
|
|
447
|
+
it('a single platform with empty fields shows inline errors, not the alert', async () => {
|
|
448
|
+
const props = buildProps({ accountData: bothPlatformsAccount });
|
|
449
|
+
const { rerender } = render(<ComponentWithStore {...props} />);
|
|
450
|
+
fireEvent.change(await screen.findByPlaceholderText('Enter creative name'), { target: { value: 'Promo push' } });
|
|
451
|
+
|
|
452
|
+
await choosePlatform('Android and iOS', 'Android only');
|
|
453
|
+
rerender(<ComponentWithStore {...props} isGetFormData />); // footer Save
|
|
454
|
+
|
|
455
|
+
expect((await screen.findAllByText('Template message cannot be empty')).length).toBe(2);
|
|
456
|
+
expect(screen.queryByRole('dialog')).toBeNull();
|
|
457
|
+
expect(props.mobilePushActions.createTemplate).not.toHaveBeenCalled();
|
|
458
|
+
});
|
|
459
|
+
|
|
460
|
+
it('confirms before dropping the other platform\'s content; Cancel keeps Android and iOS', async () => {
|
|
461
|
+
const props = buildProps({ accountData: bothPlatformsAccount });
|
|
462
|
+
render(<ComponentWithStore {...props} />);
|
|
463
|
+
await screen.findByPlaceholderText('Enter creative name');
|
|
464
|
+
fireEvent.click(screen.getAllByText('iOS')[0]);
|
|
465
|
+
await fillVisibleForm('iOS title', 'iOS message');
|
|
466
|
+
|
|
467
|
+
await choosePlatform('Android and iOS', 'Android only');
|
|
468
|
+
expect(await screen.findByText('Remove iOS content?')).toBeInTheDocument();
|
|
469
|
+
fireEvent.click(screen.getByRole('button', { name: 'Cancel' }));
|
|
470
|
+
expect(screen.getByText('Same content for both platforms')).toBeInTheDocument();
|
|
471
|
+
|
|
472
|
+
await choosePlatform('Android and iOS', 'Android only');
|
|
473
|
+
fireEvent.click(await screen.findByRole('button', { name: 'Remove content' }));
|
|
474
|
+
expect(screen.queryByText('Same content for both platforms')).toBeNull();
|
|
475
|
+
|
|
476
|
+
// Back to both: the iOS tab is empty
|
|
477
|
+
await choosePlatform('Android only', 'Android and iOS');
|
|
478
|
+
fireEvent.click(screen.getAllByText('iOS')[0]);
|
|
479
|
+
const titleInputs = await screen.findAllByPlaceholderText('Enter title');
|
|
480
|
+
expect(titleInputs[titleInputs.length - 1]).toHaveValue('');
|
|
481
|
+
});
|
|
482
|
+
|
|
483
|
+
it('opens a template saved with only Android as Android only', async () => {
|
|
484
|
+
renderComponent({
|
|
485
|
+
accountData: { configs: { android: '1', ios: '1' } },
|
|
486
|
+
templateData: {
|
|
487
|
+
name: 'Saved Android push',
|
|
488
|
+
versions: { base: { ANDROID: { title: 'A title', message: 'A msg', expandableDetails: { style: 'BIG_TEXT' } } } },
|
|
489
|
+
},
|
|
490
|
+
location: {},
|
|
491
|
+
injectedTags: {},
|
|
492
|
+
getDefaultTags: jest.fn(),
|
|
493
|
+
globalActions,
|
|
494
|
+
mobilePushActions: { setTemplateDetails: jest.fn(), getTemplateDetails: jest.fn(), clearData: jest.fn() },
|
|
495
|
+
});
|
|
496
|
+
|
|
497
|
+
expect(await screen.findByText('Android only')).toBeInTheDocument();
|
|
498
|
+
expect(screen.queryByText('Same content for both platforms')).toBeNull();
|
|
499
|
+
await waitFor(() => expect(screen.getByPlaceholderText('Enter title')).toHaveValue('A title'));
|
|
500
|
+
});
|
|
501
|
+
});
|
|
502
|
+
|
|
503
|
+
describe('Test & Preview from the edit footer', () => {
|
|
504
|
+
const baseProps = {
|
|
505
|
+
accountData,
|
|
506
|
+
templateData: {},
|
|
507
|
+
location: {},
|
|
508
|
+
injectedTags: {},
|
|
509
|
+
getDefaultTags: jest.fn(),
|
|
510
|
+
globalActions,
|
|
511
|
+
};
|
|
512
|
+
|
|
513
|
+
it('opens the slidebox when the parent sets showTestAndPreviewSlidebox', async () => {
|
|
514
|
+
renderComponent({ ...baseProps, showTestAndPreviewSlidebox: true });
|
|
515
|
+
expect(await screen.findByTestId('test-preview-slidebox')).toHaveAttribute('data-show', 'true');
|
|
516
|
+
});
|
|
517
|
+
|
|
518
|
+
it('stays closed by default and tells the parent on close', async () => {
|
|
519
|
+
const handleCloseTestAndPreview = jest.fn();
|
|
520
|
+
renderComponent({ ...baseProps, handleCloseTestAndPreview });
|
|
521
|
+
const slidebox = await screen.findByTestId('test-preview-slidebox');
|
|
522
|
+
|
|
523
|
+
expect(slidebox).toHaveAttribute('data-show', 'false');
|
|
524
|
+
fireEvent.click(slidebox);
|
|
525
|
+
expect(handleCloseTestAndPreview).toHaveBeenCalledTimes(1);
|
|
526
|
+
});
|
|
527
|
+
});
|
|
528
|
+
|
|
529
|
+
describe('saved template buttons in the preview', () => {
|
|
530
|
+
const cta = (actionText) => ({ actionText, type: 'EXTERNAL_URL', actionLink: 'https://x.com' });
|
|
531
|
+
const savedTemplate = {
|
|
532
|
+
name: 'Saved push',
|
|
533
|
+
versions: {
|
|
534
|
+
base: {
|
|
535
|
+
ANDROID: { title: 'A title', message: 'A msg', expandableDetails: { style: 'BIG_TEXT', ctas: [cta('AndPrim')] } },
|
|
536
|
+
IOS: { title: 'I title', message: 'I msg', expandableDetails: { style: 'BIG_TEXT', ctas: [cta('IOSPrim')] } },
|
|
537
|
+
},
|
|
538
|
+
},
|
|
539
|
+
};
|
|
540
|
+
|
|
541
|
+
const renderSaved = () => renderComponent({
|
|
542
|
+
accountData: { configs: { android: '1', ios: '1' } },
|
|
543
|
+
templateData: savedTemplate,
|
|
544
|
+
location: {},
|
|
545
|
+
injectedTags: {},
|
|
546
|
+
getDefaultTags: jest.fn(),
|
|
547
|
+
globalActions,
|
|
548
|
+
mobilePushActions: { setTemplateDetails: jest.fn(), getTemplateDetails: jest.fn(), clearData: jest.fn() },
|
|
549
|
+
});
|
|
550
|
+
|
|
551
|
+
it('passes saved buttons in the test payload formData', async () => {
|
|
552
|
+
renderSaved();
|
|
553
|
+
const slidebox = await screen.findByTestId('test-preview-slidebox');
|
|
554
|
+
|
|
555
|
+
await waitFor(() => {
|
|
556
|
+
const [android, ios] = JSON.parse(slidebox.getAttribute('data-form-data'));
|
|
557
|
+
expect(android).toEqual(expect.objectContaining({
|
|
558
|
+
'secondary-cta-0-label': 'AndPrim',
|
|
559
|
+
'cta-deeplink-secondary-cta-0': 'External Link',
|
|
560
|
+
'cta-deeplink-secondary-cta-0-text': 'https://x.com',
|
|
561
|
+
}));
|
|
562
|
+
expect(ios).toEqual(expect.objectContaining({
|
|
563
|
+
'secondary-cta-1-label': 'IOSPrim',
|
|
564
|
+
'cta-deeplink-secondary-cta-1': 'External Link',
|
|
565
|
+
'cta-deeplink-secondary-cta-1-text': 'https://x.com',
|
|
566
|
+
}));
|
|
567
|
+
});
|
|
568
|
+
});
|
|
569
|
+
|
|
570
|
+
it('fills iOS buttons without opening the iOS tab', async () => {
|
|
571
|
+
renderSaved();
|
|
572
|
+
const slidebox = await screen.findByTestId('test-preview-slidebox');
|
|
573
|
+
|
|
574
|
+
await waitFor(() => {
|
|
575
|
+
expect(slidebox).toHaveAttribute('data-android-actions', JSON.stringify([{ label: 'AndPrim' }]));
|
|
576
|
+
expect(slidebox).toHaveAttribute('data-ios-actions', JSON.stringify([{ label: 'IOSPrim' }]));
|
|
577
|
+
});
|
|
578
|
+
});
|
|
579
|
+
|
|
580
|
+
it('passes each platform\'s own saved video in the test payload formData', async () => {
|
|
581
|
+
const videoTemplate = {
|
|
582
|
+
name: 'Saved video push',
|
|
583
|
+
versions: {
|
|
584
|
+
base: {
|
|
585
|
+
ANDROID: {
|
|
586
|
+
title: 'A title',
|
|
587
|
+
message: 'A msg',
|
|
588
|
+
type: 'VIDEO',
|
|
589
|
+
expandableDetails: { style: 'VIDEO', media: [{ url: 'https://s3/a.mp4', text: '', type: 'VIDEO' }] },
|
|
590
|
+
},
|
|
591
|
+
IOS: { title: 'I title', message: 'I msg', expandableDetails: { style: 'BIG_TEXT' } },
|
|
592
|
+
},
|
|
593
|
+
},
|
|
594
|
+
};
|
|
595
|
+
renderComponent({
|
|
596
|
+
accountData: { configs: { android: '1', ios: '1' } },
|
|
597
|
+
templateData: videoTemplate,
|
|
598
|
+
location: {},
|
|
599
|
+
injectedTags: {},
|
|
600
|
+
getDefaultTags: jest.fn(),
|
|
601
|
+
globalActions,
|
|
602
|
+
mobilePushActions: { setTemplateDetails: jest.fn(), getTemplateDetails: jest.fn(), clearData: jest.fn() },
|
|
603
|
+
});
|
|
604
|
+
const slidebox = await screen.findByTestId('test-preview-slidebox');
|
|
605
|
+
|
|
606
|
+
await waitFor(() => {
|
|
607
|
+
const [android, ios] = JSON.parse(slidebox.getAttribute('data-form-data'));
|
|
608
|
+
expect(android.video).toBe('https://s3/a.mp4');
|
|
609
|
+
expect(ios.video).toBe('');
|
|
610
|
+
});
|
|
611
|
+
});
|
|
612
|
+
|
|
613
|
+
it('passes saved carousel cards in the test payload formData', async () => {
|
|
614
|
+
const card = {
|
|
615
|
+
mediaType: 'video', imageUrl: '', videoSrc: 'https://s3/c.mp4', buttons: [],
|
|
616
|
+
};
|
|
617
|
+
renderComponent({
|
|
618
|
+
accountData: { configs: { android: '1', ios: '1' } },
|
|
619
|
+
templateData: {
|
|
620
|
+
name: 'Saved carousel push',
|
|
621
|
+
versions: {
|
|
622
|
+
base: {
|
|
623
|
+
ANDROID: {
|
|
624
|
+
title: 'A title',
|
|
625
|
+
message: 'A msg',
|
|
626
|
+
type: 'CAROUSEL',
|
|
627
|
+
expandableDetails: { style: 'MANUAL_CAROUSEL', carouselData: [card] },
|
|
628
|
+
},
|
|
629
|
+
IOS: { title: 'I title', message: 'I msg', expandableDetails: { style: 'BIG_TEXT' } },
|
|
630
|
+
},
|
|
631
|
+
},
|
|
632
|
+
},
|
|
633
|
+
location: {},
|
|
634
|
+
injectedTags: {},
|
|
635
|
+
getDefaultTags: jest.fn(),
|
|
636
|
+
globalActions,
|
|
637
|
+
mobilePushActions: { setTemplateDetails: jest.fn(), getTemplateDetails: jest.fn(), clearData: jest.fn() },
|
|
638
|
+
});
|
|
639
|
+
const slidebox = await screen.findByTestId('test-preview-slidebox');
|
|
640
|
+
|
|
641
|
+
await waitFor(() => {
|
|
642
|
+
const [android, ios] = JSON.parse(slidebox.getAttribute('data-form-data'));
|
|
643
|
+
expect(android.carouselData).toEqual([expect.objectContaining({ mediaType: 'video', videoSrc: 'https://s3/c.mp4' })]);
|
|
644
|
+
expect(ios.carouselData).toEqual([]);
|
|
645
|
+
});
|
|
646
|
+
});
|
|
647
|
+
});
|
|
180
648
|
});
|
|
@@ -5,6 +5,10 @@ import {
|
|
|
5
5
|
isDeepLink,
|
|
6
6
|
isPlatformFieldsMissing,
|
|
7
7
|
computeIsContentEmpty,
|
|
8
|
+
getContent,
|
|
9
|
+
findSelectedDeepLink,
|
|
10
|
+
getCarouselCardIssue,
|
|
11
|
+
CAROUSEL_CARD_ISSUE,
|
|
8
12
|
} from "../utils";
|
|
9
13
|
import { isUrl } from "../../Line/Container/Wrapper/utils";
|
|
10
14
|
|
|
@@ -510,3 +514,69 @@ describe("utils.js", () => {
|
|
|
510
514
|
});
|
|
511
515
|
});
|
|
512
516
|
});
|
|
517
|
+
|
|
518
|
+
describe("getContent", () => {
|
|
519
|
+
it("returns three spaces when there is no content", () => {
|
|
520
|
+
expect(getContent(null)).toBe(" ");
|
|
521
|
+
expect(getContent({ versions: { base: {} } })).toBe(" ");
|
|
522
|
+
});
|
|
523
|
+
|
|
524
|
+
it("joins Android and iOS title and message", () => {
|
|
525
|
+
const payload = {
|
|
526
|
+
versions: {
|
|
527
|
+
base: {
|
|
528
|
+
ANDROID: { title: "A title", message: "A msg" },
|
|
529
|
+
IOS: { title: "I title", message: "I msg" },
|
|
530
|
+
},
|
|
531
|
+
},
|
|
532
|
+
};
|
|
533
|
+
expect(getContent(payload)).toBe("A title A msg I title I msg");
|
|
534
|
+
});
|
|
535
|
+
|
|
536
|
+
it("leaves an empty slot for a missing platform", () => {
|
|
537
|
+
const payload = { versions: { base: { ANDROID: { title: "A", message: "B" } } } };
|
|
538
|
+
expect(getContent(payload)).toBe("A B ");
|
|
539
|
+
});
|
|
540
|
+
});
|
|
541
|
+
|
|
542
|
+
describe("findSelectedDeepLink", () => {
|
|
543
|
+
const links = [{ value: "app://offer", keys: ["offerId"] }];
|
|
544
|
+
|
|
545
|
+
it("matches exactly, then without query params", () => {
|
|
546
|
+
expect(findSelectedDeepLink(links, "app://offer")).toBe(links[0]);
|
|
547
|
+
expect(findSelectedDeepLink(links, "app://offer?offerId=offerId")).toBe(links[0]);
|
|
548
|
+
expect(findSelectedDeepLink(links, "app://other")).toBeUndefined();
|
|
549
|
+
expect(findSelectedDeepLink(undefined, "app://offer")).toBeUndefined();
|
|
550
|
+
});
|
|
551
|
+
});
|
|
552
|
+
|
|
553
|
+
describe("getCarouselCardIssue", () => {
|
|
554
|
+
const links = [{ value: "app://offer", keys: ["offerId"] }, { value: "app://home" }];
|
|
555
|
+
const card = (button = {}, media = { mediaType: "image", imageUrl: "a.jpg" }) => ({
|
|
556
|
+
...media,
|
|
557
|
+
buttons: [{
|
|
558
|
+
actionOnClick: true, linkType: "DEEP_LINK", deepLinkValue: "", deepLinkKeys: [], externalLinkValue: "", ...button,
|
|
559
|
+
}],
|
|
560
|
+
});
|
|
561
|
+
|
|
562
|
+
it("is complete with media and App as the tap action", () => {
|
|
563
|
+
expect(getCarouselCardIssue(card({ actionOnClick: false }), links)).toBeNull();
|
|
564
|
+
});
|
|
565
|
+
|
|
566
|
+
it("flags missing media", () => {
|
|
567
|
+
expect(getCarouselCardIssue(card({ actionOnClick: false }, { mediaType: "image", imageUrl: "" }), links)).toBe(CAROUSEL_CARD_ISSUE.MEDIA);
|
|
568
|
+
expect(getCarouselCardIssue(card({ actionOnClick: false }, { mediaType: "video", videoSrc: "" }), links)).toBe(CAROUSEL_CARD_ISSUE.MEDIA);
|
|
569
|
+
});
|
|
570
|
+
|
|
571
|
+
it("flags an empty deep link or URL before missing media", () => {
|
|
572
|
+
const noMedia = { mediaType: "image", imageUrl: "" };
|
|
573
|
+
expect(getCarouselCardIssue(card({}, noMedia), links)).toBe(CAROUSEL_CARD_ISSUE.DEEP_LINK);
|
|
574
|
+
expect(getCarouselCardIssue(card({ linkType: "EXTERNAL_LINK", externalLinkValue: " " }), links)).toBe(CAROUSEL_CARD_ISSUE.EXTERNAL_LINK);
|
|
575
|
+
});
|
|
576
|
+
|
|
577
|
+
it("needs keys only when the chosen deep link has them", () => {
|
|
578
|
+
expect(getCarouselCardIssue(card({ deepLinkValue: "app://offer" }), links)).toBe(CAROUSEL_CARD_ISSUE.DEEP_LINK_KEYS);
|
|
579
|
+
expect(getCarouselCardIssue(card({ deepLinkValue: "app://offer", deepLinkKeys: ["offerId"] }), links)).toBeNull();
|
|
580
|
+
expect(getCarouselCardIssue(card({ deepLinkValue: "app://home" }), links)).toBeNull();
|
|
581
|
+
});
|
|
582
|
+
});
|
|
@@ -1,4 +1,52 @@
|
|
|
1
1
|
import { isUrl } from "../Line/Container/Wrapper/utils";
|
|
2
|
+
import { EXTERNAL_LINK, VIDEO } from "./constants";
|
|
3
|
+
|
|
4
|
+
// Deep link option for a saved value; falls back to matching without query params
|
|
5
|
+
export const findSelectedDeepLink = (links, value) => {
|
|
6
|
+
if (!links || !value) return undefined;
|
|
7
|
+
const exactMatch = links.find((link) => link?.value === value);
|
|
8
|
+
if (exactMatch || !value.includes('?')) return exactMatch;
|
|
9
|
+
const baseDeepLinkValue = value.split('?')[0];
|
|
10
|
+
return links.find((link) => link?.value === baseDeepLinkValue);
|
|
11
|
+
};
|
|
12
|
+
|
|
13
|
+
export const CAROUSEL_CARD_ISSUE = {
|
|
14
|
+
MEDIA: 'media',
|
|
15
|
+
DEEP_LINK: 'deepLink',
|
|
16
|
+
DEEP_LINK_KEYS: 'deepLinkKeys',
|
|
17
|
+
EXTERNAL_LINK: 'externalLink',
|
|
18
|
+
UNSAVED_LINK: 'unsavedLink',
|
|
19
|
+
};
|
|
20
|
+
|
|
21
|
+
/**
|
|
22
|
+
* What a carousel card still needs before it can be saved. Link issues come first so the
|
|
23
|
+
* card can show them while its media is still being added.
|
|
24
|
+
* @param {Object} card - Editor carousel card
|
|
25
|
+
* @param {Array} deepLinks - Deep link options ({ value, keys })
|
|
26
|
+
* @returns {string|null} - A CAROUSEL_CARD_ISSUE value, or null when the card is complete
|
|
27
|
+
*/
|
|
28
|
+
export const getCarouselCardIssue = (card, deepLinks) => {
|
|
29
|
+
const buttons = card?.buttons || [];
|
|
30
|
+
for (let i = 0; i < buttons.length; i += 1) {
|
|
31
|
+
const button = buttons[i];
|
|
32
|
+
if (button?.actionOnClick) {
|
|
33
|
+
if (button.linkType === EXTERNAL_LINK) {
|
|
34
|
+
if (!button.externalLinkValue?.trim()) return CAROUSEL_CARD_ISSUE.EXTERNAL_LINK;
|
|
35
|
+
} else if (!button.deepLinkValue) {
|
|
36
|
+
return CAROUSEL_CARD_ISSUE.DEEP_LINK;
|
|
37
|
+
} else {
|
|
38
|
+
const keysFromSelection = findSelectedDeepLink(deepLinks, button.deepLinkValue)?.keys;
|
|
39
|
+
const hasKeys = Array.isArray(keysFromSelection) ? keysFromSelection.length > 0 : !!keysFromSelection;
|
|
40
|
+
const hasSavedKeys = Array.isArray(button.deepLinkKeys) && button.deepLinkKeys.length > 0;
|
|
41
|
+
if (hasKeys && !hasSavedKeys) return CAROUSEL_CARD_ISSUE.DEEP_LINK_KEYS;
|
|
42
|
+
}
|
|
43
|
+
// Filled in but its Save not clicked yet (links loaded from a saved template have no flag)
|
|
44
|
+
if (button.isSaved === false) return CAROUSEL_CARD_ISSUE.UNSAVED_LINK;
|
|
45
|
+
}
|
|
46
|
+
}
|
|
47
|
+
const isMediaMissing = card?.mediaType === VIDEO.toLowerCase() ? !card?.videoSrc : !card?.imageUrl;
|
|
48
|
+
return isMediaMissing ? CAROUSEL_CARD_ISSUE.MEDIA : null;
|
|
49
|
+
};
|
|
2
50
|
|
|
3
51
|
/**
|
|
4
52
|
* Validate deep link format - supports custom schemes, HTTP/HTTPS, and relative paths
|
|
@@ -119,3 +167,11 @@ export const computeIsContentEmpty = ({
|
|
|
119
167
|
const isIosMissing = isPlatformFieldsMissing(isIosSupported, iosContent);
|
|
120
168
|
return (!isAndroidSupported || isAndroidMissing) && (!isIosSupported || isIosMissing);
|
|
121
169
|
};
|
|
170
|
+
|
|
171
|
+
// Android and iOS title + message joined, for the create GA event
|
|
172
|
+
export const getContent = (obj) => {
|
|
173
|
+
const base = obj?.versions?.base || {};
|
|
174
|
+
const android = base.ANDROID || {};
|
|
175
|
+
const ios = base.IOS || {};
|
|
176
|
+
return `${android.title || ''} ${android.message || ''} ${ios.title || ''} ${ios.message || ''}`;
|
|
177
|
+
};
|
|
@@ -495,15 +495,23 @@
|
|
|
495
495
|
padding: $CAP_SPACE_08;
|
|
496
496
|
text-align: center;
|
|
497
497
|
display: flex;
|
|
498
|
-
flex-direction: column;
|
|
499
498
|
align-items: center;
|
|
500
499
|
justify-content: center;
|
|
501
500
|
gap: $CAP_SPACE_08;
|
|
501
|
+
// Same as the editor previews: one button centred, two as halves split by a divider
|
|
502
502
|
.action{
|
|
503
|
+
flex: 1 1 0;
|
|
504
|
+
min-width: 0;
|
|
505
|
+
white-space: nowrap;
|
|
506
|
+
overflow: hidden;
|
|
507
|
+
text-overflow: ellipsis;
|
|
503
508
|
font-size: $FONT_SIZE_S;
|
|
504
509
|
font-weight: 600;
|
|
505
|
-
color:
|
|
510
|
+
color: $FONT_COLOR_01;
|
|
506
511
|
height: 1.25rem;
|
|
512
|
+
& + .action {
|
|
513
|
+
border-left: 1px solid $CAP_G07;
|
|
514
|
+
}
|
|
507
515
|
}
|
|
508
516
|
}
|
|
509
517
|
}
|