@capillarytech/creatives-library 9.2.1-alpha.sprint-cap-214249.42 → 9.2.1

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.
Files changed (51) hide show
  1. package/AppRoot.js +4 -7
  2. package/constants/unified.js +1 -0
  3. package/package.json +1 -1
  4. package/utils/beePluginLoader.js +106 -0
  5. package/utils/common.js +6 -0
  6. package/utils/createMobilePushPayload.js +51 -56
  7. package/utils/tests/beePluginLoader.test.js +199 -0
  8. package/utils/tests/createMobilePushPayload.test.js +10 -162
  9. package/v2Components/CapMpushCTA/index.js +57 -47
  10. package/v2Components/CapMpushCTA/index.scss +5 -43
  11. package/v2Components/CommonTestAndPreview/UnifiedPreview/MobilePushPreviewContent.js +8 -11
  12. package/v2Components/CommonTestAndPreview/UnifiedPreview/_unifiedPreview.scss +1 -13
  13. package/v2Components/CommonTestAndPreview/constants.js +0 -2
  14. package/v2Components/CommonTestAndPreview/index.js +10 -48
  15. package/v2Components/CommonTestAndPreview/tests/UnifiedPreview/MobilePushPreviewContent.test.js +5 -83
  16. package/v2Components/CommonTestAndPreview/tests/index.test.js +0 -86
  17. package/v2Components/TemplatePreview/_templatePreview.scss +2 -12
  18. package/v2Components/TemplatePreview/index.js +12 -14
  19. package/v2Components/TemplatePreview/tests/index.test.js +0 -69
  20. package/v2Containers/BeeEditor/index.js +49 -22
  21. package/v2Containers/BeeEditor/index.scss +12 -0
  22. package/v2Containers/BeeEditor/messages.js +8 -0
  23. package/v2Containers/BeeEditor/test/index.test.js +78 -0
  24. package/v2Containers/BeePopupEditor/index.js +22 -11
  25. package/v2Containers/CreativesContainer/SlideBoxContent.js +9 -5
  26. package/v2Containers/CreativesContainer/index.js +1 -2
  27. package/v2Containers/CreativesContainer/tests/SlideBoxContent.test.js +0 -43
  28. package/v2Containers/Email/index.js +2 -2
  29. package/v2Containers/EmailWrapper/hooks/useEmailWrapper.js +25 -23
  30. package/v2Containers/MobilePushNew/components/CtaButtons.js +47 -52
  31. package/v2Containers/MobilePushNew/components/MediaUploaders.js +222 -314
  32. package/v2Containers/MobilePushNew/components/PlatformContentFields.js +130 -161
  33. package/v2Containers/MobilePushNew/components/tests/CtaButtons.test.js +208 -30
  34. package/v2Containers/MobilePushNew/components/tests/MediaUploaders.test.js +123 -484
  35. package/v2Containers/MobilePushNew/components/tests/PlatformContentFields.test.js +46 -152
  36. package/v2Containers/MobilePushNew/constants.js +0 -12
  37. package/v2Containers/MobilePushNew/hooks/tests/usePlatformSync.test.js +1 -63
  38. package/v2Containers/MobilePushNew/hooks/tests/useUpload.test.js +0 -78
  39. package/v2Containers/MobilePushNew/hooks/usePlatformSync.js +1 -40
  40. package/v2Containers/MobilePushNew/hooks/useUpload.js +46 -42
  41. package/v2Containers/MobilePushNew/index.js +273 -503
  42. package/v2Containers/MobilePushNew/index.scss +4 -215
  43. package/v2Containers/MobilePushNew/messages.js +6 -106
  44. package/v2Containers/MobilePushNew/tests/index.test.js +1 -482
  45. package/v2Containers/MobilePushNew/tests/utils.test.js +0 -122
  46. package/v2Containers/MobilePushNew/utils.js +0 -107
  47. package/v2Containers/Templates/_templates.scss +2 -10
  48. package/v2Containers/Templates/index.js +81 -83
  49. package/v2Containers/Templates/tests/index.test.js +0 -68
  50. package/v2Components/CapMpushCTA/tests/index.test.js +0 -150
  51. package/v2Containers/MobilePushNew/components/TapLinkActions.js +0 -76
@@ -1,103 +1,4 @@
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
- // Deep link params are kept as "key=value" entries, e.g. "testing_purpose=androidDeeplink"
14
- const toEntryArray = (entries) => {
15
- if (Array.isArray(entries)) return entries;
16
- return entries ? [entries] : [];
17
- };
18
-
19
- // Splits at the first "=". Old entries saved as just the key mean key=key
20
- export const splitDeepLinkParam = (entry) => {
21
- const text = String(entry ?? '');
22
- const index = text.indexOf('=');
23
- return index === -1 ? [text, text] : [text.slice(0, index), text.slice(index + 1)];
24
- };
25
-
26
- export const getDeepLinkParamValue = (entries, key) => {
27
- const match = toEntryArray(entries).find((entry) => splitDeepLinkParam(entry)[0] === key);
28
- return match === undefined ? '' : splitDeepLinkParam(match)[1];
29
- };
30
-
31
- // New entries after typing `value` for `key`, in configured-key order; empty values are dropped
32
- export const setDeepLinkParamValue = (entries, configuredKeys, key, value) => toEntryArray(configuredKeys)
33
- .map((configuredKey) => [configuredKey, configuredKey === key ? value : getDeepLinkParamValue(entries, configuredKey)])
34
- .filter(([, paramValue]) => paramValue !== '' && paramValue !== undefined && paramValue !== null)
35
- .map(([paramKey, paramValue]) => `${paramKey}=${paramValue}`);
36
-
37
- export const hasAllDeepLinkParams = (entries, configuredKeys) => toEntryArray(configuredKeys)
38
- .every((key) => getDeepLinkParamValue(entries, key).trim() !== '');
39
-
40
- // Every "key=value" in the URL's query, raw (not decoded) so tags like {{x}} round-trip
41
- export const extractDeepLinkParams = (url) => {
42
- if (typeof url !== 'string' || !url.includes('?')) return [];
43
- return url.slice(url.indexOf('?') + 1).split('&').filter((param) => param.indexOf('=') > 0);
44
- };
45
-
46
- // Adds the entries to the URL; a key already in the URL is replaced, not repeated
47
- export const appendDeepLinkParams = (url, entries) => {
48
- if (!url) return url;
49
- const pairs = toEntryArray(entries)
50
- .filter((entry) => typeof entry === 'string' && entry.length > 0)
51
- .map(splitDeepLinkParam)
52
- .filter(([key]) => key.length > 0);
53
- if (pairs.length === 0) return url;
54
- const keys = new Set(pairs.map(([key]) => key));
55
- const queryIndex = url.indexOf('?');
56
- const base = queryIndex === -1 ? url : url.slice(0, queryIndex);
57
- const kept = queryIndex === -1 ? [] : url.slice(queryIndex + 1).split('&')
58
- .filter((param) => param && !keys.has(splitDeepLinkParam(param)[0]));
59
- const params = [...kept, ...pairs.map(([key, value]) => `${key}=${value}`)];
60
- return `${base}?${params.join('&')}`;
61
- };
62
-
63
- export const CAROUSEL_CARD_ISSUE = {
64
- MEDIA: 'media',
65
- DEEP_LINK: 'deepLink',
66
- DEEP_LINK_KEYS: 'deepLinkKeys',
67
- EXTERNAL_LINK: 'externalLink',
68
- UNSAVED_LINK: 'unsavedLink',
69
- };
70
-
71
- /**
72
- * What a carousel card still needs before it can be saved. Link issues come first so the
73
- * card can show them while its media is still being added.
74
- * @param {Object} card - Editor carousel card
75
- * @param {Array} deepLinks - Deep link options ({ value, keys })
76
- * @returns {string|null} - A CAROUSEL_CARD_ISSUE value, or null when the card is complete
77
- */
78
- export const getCarouselCardIssue = (card, deepLinks) => {
79
- const buttons = card?.buttons || [];
80
- for (let i = 0; i < buttons.length; i += 1) {
81
- const button = buttons[i];
82
- if (button?.actionOnClick) {
83
- if (button.linkType === EXTERNAL_LINK) {
84
- if (!button.externalLinkValue?.trim()) return CAROUSEL_CARD_ISSUE.EXTERNAL_LINK;
85
- } else if (!button.deepLinkValue) {
86
- return CAROUSEL_CARD_ISSUE.DEEP_LINK;
87
- } else {
88
- const keysFromSelection = findSelectedDeepLink(deepLinks, button.deepLinkValue)?.keys;
89
- const hasKeys = Array.isArray(keysFromSelection) ? keysFromSelection.length > 0 : !!keysFromSelection;
90
- if (hasKeys && !hasAllDeepLinkParams(button.deepLinkKeys, keysFromSelection)) {
91
- return CAROUSEL_CARD_ISSUE.DEEP_LINK_KEYS;
92
- }
93
- }
94
- // Filled in but its Save not clicked yet (links loaded from a saved template have no flag)
95
- if (button.isSaved === false) return CAROUSEL_CARD_ISSUE.UNSAVED_LINK;
96
- }
97
- }
98
- const isMediaMissing = card?.mediaType === VIDEO.toLowerCase() ? !card?.videoSrc : !card?.imageUrl;
99
- return isMediaMissing ? CAROUSEL_CARD_ISSUE.MEDIA : null;
100
- };
101
2
 
102
3
  /**
103
4
  * Validate deep link format - supports custom schemes, HTTP/HTTPS, and relative paths
@@ -218,11 +119,3 @@ export const computeIsContentEmpty = ({
218
119
  const isIosMissing = isPlatformFieldsMissing(isIosSupported, iosContent);
219
120
  return (!isAndroidSupported || isAndroidMissing) && (!isIosSupported || isIosMissing);
220
121
  };
221
-
222
- // Android and iOS title + message joined, for the create GA event
223
- export const getContent = (obj) => {
224
- const base = obj?.versions?.base || {};
225
- const android = base.ANDROID || {};
226
- const ios = base.IOS || {};
227
- return `${android.title || ''} ${android.message || ''} ${ios.title || ''} ${ios.message || ''}`;
228
- };
@@ -495,23 +495,15 @@
495
495
  padding: $CAP_SPACE_08;
496
496
  text-align: center;
497
497
  display: flex;
498
+ flex-direction: column;
498
499
  align-items: center;
499
500
  justify-content: center;
500
501
  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;
508
503
  font-size: $FONT_SIZE_S;
509
504
  font-weight: 600;
510
- color: $FONT_COLOR_01;
505
+ color: #1970DA;
511
506
  height: 1.25rem;
512
- & + .action {
513
- border-left: 1px solid $CAP_G07;
514
- }
515
507
  }
516
508
  }
517
509
  }
@@ -164,7 +164,7 @@ import { makeSelectRcs } from '../Rcs/selectors';
164
164
  import { getRcsStatusType } from '../Rcs/utils';
165
165
  import { makeSelectWebPush } from '../WebPush/selectors';
166
166
  import { v2MobilePushSagas } from '../MobilePushNew/sagas';
167
- import { AUTO_CAROUSEL, BIG_PICTURE, FILMSTRIP_CAROUSEL, MANUAL_CAROUSEL, VIDEO as MPUSH_VIDEO } from '../MobilePushNew/constants';
167
+ import { AUTO_CAROUSEL, BIG_PICTURE, FILMSTRIP_CAROUSEL, MANUAL_CAROUSEL } from '../MobilePushNew/constants';
168
168
  import CapPageSpinner from '../../v2Components/CapPageSpinner';
169
169
  import webPushSagas from '../WebPush/sagas';
170
170
  import { DLT_LEGACY_VAR_REGEX } from '../SmsTrai/Edit/dltVarTypes';
@@ -1426,17 +1426,12 @@ export class Templates extends React.Component { // eslint-disable-line react/pr
1426
1426
 
1427
1427
  const expandableDetailsAndroid = androidContent.expandableDetails || {};
1428
1428
  const expandableDetailsIos = iosContent.expandableDetails || {};
1429
- // Saved media[0] is { url, type, videoPreviewUrl }; the preview reads { videoSrc, videoPreview }
1430
- const toPreviewVideo = (media) => {
1431
- const { type, url, videoPreviewUrl } = media?.[0] || {};
1432
- return type === MPUSH_VIDEO && url ? { videoSrc: url, videoPreview: videoPreviewUrl || '' } : {};
1433
- };
1434
1429
  // Extract Android content
1435
1430
  const androidPreview = {
1436
1431
  header: androidContent.title || '',
1437
1432
  bodyText: androidContent.message || '',
1438
1433
  bodyImage: expandableDetailsAndroid.image || '',
1439
- bodyVideo: toPreviewVideo(expandableDetailsAndroid.media),
1434
+ bodyVideo: expandableDetailsAndroid.media?.[0] || {},
1440
1435
  bodyGif: '',
1441
1436
  actions: expandableDetailsAndroid.ctas || [],
1442
1437
  carouselData: expandableDetailsAndroid.carouselData || [],
@@ -1447,7 +1442,7 @@ export class Templates extends React.Component { // eslint-disable-line react/pr
1447
1442
  header: iosContent.title || '',
1448
1443
  bodyText: iosContent.message || '',
1449
1444
  bodyImage: expandableDetailsIos.image || '',
1450
- bodyVideo: toPreviewVideo(expandableDetailsIos.media),
1445
+ bodyVideo: expandableDetailsIos.media?.[0] || {},
1451
1446
  bodyGif: '',
1452
1447
  actions: expandableDetailsIos.ctas || [],
1453
1448
  carouselData: expandableDetailsIos.carouselData || [],
@@ -2410,91 +2405,94 @@ export class Templates extends React.Component { // eslint-disable-line react/pr
2410
2405
  }
2411
2406
  break;
2412
2407
  }
2413
- case MOBILE_PUSH: {
2414
- const mpushData = get(template, 'versions.base', template);
2415
- const androidData = get(mpushData, 'ANDROID') || get(mpushData, 'androidContent');
2416
- const iosData = get(mpushData, 'IOS') || get(mpushData, 'iosContent');
2417
- let mpushListingData = androidData;
2418
- if (isEmpty(androidData) || !androidData?.title) {
2419
- mpushListingData = iosData;
2420
- };
2421
- const { title, message, expandableDetails: { style = '', image, carouselData = [], ctas = [], media = [] } = {} } = mpushListingData || {};
2422
- const {url = ''} = media?.[0] || {};
2423
- templateData.content = (
2424
- <div className='mobilepush-container'>
2425
- <div className="app-header">
2426
- <div className="app-header-left">
2427
- <span className="app-icon">{""}</span>
2428
- <CapLabel type="label4">{title}</CapLabel>
2429
- </div>
2430
- </div>
2431
- <CapLabel className="mobilepush-message" type="label1">{message}</CapLabel>
2432
- {style === BIG_PICTURE && (
2433
- <CapImage src={image} className="mobilepush-image mobilepush-image-padding" />
2434
- )}
2435
- {style === VIDEO && (
2436
- <div className="video-preview">
2437
- <video aria-label="Template video preview" controls={false} tabIndex="0">
2438
- <source src={url} type="video/mp4" />
2439
- </video>
2440
- <div className="icon-position">
2441
- <CapImage className="video-icon" src={videoPlay} />
2408
+ case MOBILE_PUSH:
2409
+ if (!commonUtil.hasNewMobilePushFeatureEnabled()) {
2410
+ templateData.content = template;
2411
+ } else {
2412
+ const mpushData = get(template, 'versions.base', template);
2413
+ const androidData = get(mpushData, 'ANDROID') || get(mpushData, 'androidContent');
2414
+ const iosData = get(mpushData, 'IOS') || get(mpushData, 'iosContent');
2415
+ let mpushListingData = androidData;
2416
+ if (isEmpty(androidData) || !androidData?.title) {
2417
+ mpushListingData = iosData;
2418
+ };
2419
+ const { title, message, expandableDetails: { style = '', image, carouselData = [], ctas = [], media = [] } = {} } = mpushListingData || {};
2420
+ const {url = ''} = media?.[0] || {};
2421
+ templateData.content = (
2422
+ <div className='mobilepush-container'>
2423
+ <div className="app-header">
2424
+ <div className="app-header-left">
2425
+ <span className="app-icon">{""}</span>
2426
+ <CapLabel type="label4">{title}</CapLabel>
2442
2427
  </div>
2443
2428
  </div>
2444
- )}
2445
- {[MANUAL_CAROUSEL, AUTO_CAROUSEL, FILMSTRIP_CAROUSEL].includes(style) && (
2446
- <div className="scroll-container">
2447
- {carouselData?.map((data, index) => {
2448
- return (
2449
- <div
2450
- key={`carousel-${index + 1}`}
2451
- className="whatsapp-carousel-container"
2452
- role="group"
2453
- >
2454
- <div className="whatsapp-carousel-card">
2455
- {data?.mediaType === IMAGE.toLowerCase() && (
2456
- <CapImage
2457
- src={data?.imageUrl ? data?.imageUrl : data?.url ? data?.url : whatsappImageEmptyPreview}
2458
- className="whatsapp-image"
2459
- />
2460
- )}
2461
- {data?.mediaType === VIDEO.toLowerCase() && (
2462
- <div className="video-preview">
2429
+ <CapLabel className="mobilepush-message" type="label1">{message}</CapLabel>
2430
+ {style === BIG_PICTURE && (
2431
+ <CapImage src={image} className="mobilepush-image mobilepush-image-padding" />
2432
+ )}
2433
+ {style === VIDEO && (
2434
+ <div className="video-preview">
2435
+ <video aria-label="Template video preview" controls={false} tabIndex="0">
2436
+ <source src={url} type="video/mp4" />
2437
+ </video>
2438
+ <div className="icon-position">
2439
+ <CapImage className="video-icon" src={videoPlay} />
2440
+ </div>
2441
+ </div>
2442
+ )}
2443
+ {[MANUAL_CAROUSEL, AUTO_CAROUSEL, FILMSTRIP_CAROUSEL].includes(style) && (
2444
+ <div className="scroll-container">
2445
+ {carouselData?.map((data, index) => {
2446
+ return (
2447
+ <div
2448
+ key={`carousel-${index + 1}`}
2449
+ className="whatsapp-carousel-container"
2450
+ role="group"
2451
+ >
2452
+ <div className="whatsapp-carousel-card">
2453
+ {data?.mediaType === IMAGE.toLowerCase() && (
2463
2454
  <CapImage
2464
- src={data?.videoPreviewImg ? data?.videoPreviewImg : data?.url ? data?.url : whatsappVideoEmptyPreview}
2455
+ src={data?.imageUrl ? data?.imageUrl : data?.url ? data?.url : whatsappImageEmptyPreview}
2465
2456
  className="whatsapp-image"
2466
2457
  />
2467
- <div className="icon-position">
2458
+ )}
2459
+ {data?.mediaType === VIDEO.toLowerCase() && (
2460
+ <div className="video-preview">
2468
2461
  <CapImage
2469
- className="video-icon"
2470
- src={videoPlay}
2462
+ src={data?.videoPreviewImg ? data?.videoPreviewImg : data?.url ? data?.url : whatsappVideoEmptyPreview}
2463
+ className="whatsapp-image"
2471
2464
  />
2465
+ <div className="icon-position">
2466
+ <CapImage
2467
+ className="video-icon"
2468
+ src={videoPlay}
2469
+ />
2470
+ </div>
2472
2471
  </div>
2473
- </div>
2474
- )}
2475
- </div>
2476
- </div>
2477
- )
2478
- })}
2472
+ )}
2473
+ </div>
2474
+ </div>
2475
+ )
2476
+ })}
2477
+ </div>
2478
+ )}
2479
+ {ctas.length > 0 && (
2480
+ <div className="actions">
2481
+ {ctas.map((cta) => (
2482
+ <span
2483
+ className="action"
2484
+ key={`action-${cta?.actionText}`}
2485
+ >
2486
+ {cta?.actionText && cta?.actionText.toUpperCase()}
2487
+ </span>
2488
+ ))}
2489
+ </div>
2490
+ )}
2479
2491
  </div>
2480
- )}
2481
- {ctas.length > 0 && (
2482
- <CapRow type="flex" align="middle" justify="center" className="actions">
2483
- {ctas.map((cta, index) => (
2484
- <CapLabel.CapLabelInline
2485
- className="action"
2486
- key={`action-${index}`}
2487
- >
2488
- {cta?.actionText}
2489
- </CapLabel.CapLabelInline>
2490
- ))}
2491
- </CapRow>
2492
- )}
2493
- </div>
2494
- );
2495
- templateData.isNewMobilePush = true;
2492
+ );
2493
+ templateData.isNewMobilePush = commonUtil.hasNewMobilePushFeatureEnabled();
2494
+ }
2496
2495
  break;
2497
- }
2498
2496
  case INAPP: {
2499
2497
  // Pass the full template object to CapCustomCard so getInAppContent can extract the data
2500
2498
  // Similar to how MOBILE_PUSH passes the full template when new feature is enabled
@@ -498,72 +498,4 @@ describe('Test Templates container', () => {
498
498
  expect(renderedComponent.instance().getCreativesParams()).not.toHaveProperty('openTestAndPreview');
499
499
  });
500
500
  });
501
-
502
- describe('Mobile push grid tile buttons', () => {
503
- it('renders button labels as typed with index keys, so duplicate labels do not clash', () => {
504
- RenderFunctionFor('whatsapp', true);
505
-
506
- const cardDataList = renderedComponent.instance().getTemplateDataForGrid({
507
- templates: [{
508
- _id: 'mpush_1',
509
- name: 'Push Template',
510
- versions: {
511
- base: {
512
- ANDROID: {
513
- title: 'Title',
514
- message: 'Body',
515
- expandableDetails: { ctas: [{ actionText: 'Shop' }, { actionText: 'Shop' }] },
516
- },
517
- },
518
- },
519
- }],
520
- handlers: { handlePreviewClick: jest.fn(), handleEditClick: jest.fn() },
521
- filterContent: null,
522
- channel: 'mobilepush',
523
- isLoading: false,
524
- isInitialLoading: false,
525
- loadingTip: '',
526
- previewTemplateId: null,
527
- });
528
-
529
- const buttons = findByClassName(cardDataList, 'mobilepush-container').props.children
530
- .find((child) => child?.props?.className === 'actions').props.children;
531
- expect(buttons.map((button) => button.key)).toEqual(['action-0', 'action-1']);
532
- expect(buttons.map((button) => button.props.children)).toEqual(['Shop', 'Shop']);
533
- });
534
- });
535
-
536
- describe('Mobile push Test & Preview content from the list', () => {
537
- it('maps each saved video to the { videoSrc, videoPreview } shape the preview reads', () => {
538
- RenderFunctionFor('whatsapp', true);
539
-
540
- const result = renderedComponent.instance().extractTemplateContentForPreview({
541
- versions: {
542
- base: {
543
- ANDROID: {
544
- title: 'A',
545
- expandableDetails: { media: [{ url: 'https://a.mp4', type: 'VIDEO', videoPreviewUrl: 'https://a.jpg' }] },
546
- },
547
- IOS: {
548
- title: 'I',
549
- expandableDetails: { media: [{ url: 'https://i.mp4', type: 'VIDEO' }] },
550
- },
551
- },
552
- },
553
- }, 'MOBILEPUSH');
554
-
555
- expect(result.androidContent.bodyVideo).toEqual({ videoSrc: 'https://a.mp4', videoPreview: 'https://a.jpg' });
556
- expect(result.iosContent.bodyVideo).toEqual({ videoSrc: 'https://i.mp4', videoPreview: '' });
557
- });
558
-
559
- it('gives no video for a text template', () => {
560
- RenderFunctionFor('whatsapp', true);
561
-
562
- const result = renderedComponent.instance().extractTemplateContentForPreview({
563
- versions: { base: { ANDROID: { title: 'A', expandableDetails: { style: 'BIG_TEXT' } } } },
564
- }, 'MOBILEPUSH');
565
-
566
- expect(result.androidContent.bodyVideo).toEqual({});
567
- });
568
- });
569
501
  });
@@ -1,150 +0,0 @@
1
- import React from 'react';
2
- import { shallow } from 'enzyme';
3
- import CapIcon from '@capillarytech/cap-ui-library/CapIcon';
4
- import { CapMpushCTA } from '../index';
5
- import CapTagListWithInput from '../../CapTagListWithInput';
6
- import { DEEP_LINK, EXTERNAL_URL } from '../constants';
7
- import { PRIMARY } from '../../../v2Containers/MobilePushNew/constants';
8
-
9
- jest.mock('../../../v2Containers/TagList', () => () => null);
10
- jest.mock('../../CapTagListWithInput', () => () => null);
11
-
12
- const intl = { formatMessage: (msg) => msg?.defaultMessage || '' };
13
-
14
- const renderCta = (cta, extraProps = {}) => shallow(
15
- <CapMpushCTA
16
- intl={intl}
17
- ctaData={[{ index: 0, text: 'Shop', ...cta }]}
18
- buttonType={PRIMARY}
19
- updateHandler={jest.fn()}
20
- deleteHandler={jest.fn()}
21
- deepLink={[{ value: 'app://home', label: 'Home' }]}
22
- location={{ query: {} }}
23
- {...extraProps}
24
- />,
25
- );
26
-
27
- describe('CapMpushCTA', () => {
28
- describe('saved button card', () => {
29
- it('uses the mask-free "open-in-new" icon, not "launch"', () => {
30
- const wrapper = renderCta({ urlType: EXTERNAL_URL, url: 'https://google.com', isSaved: true });
31
- const iconTypes = wrapper.find(CapIcon).map((icon) => icon.prop('type'));
32
-
33
- expect(iconTypes).toContain('open-in-new');
34
- expect(iconTypes).not.toContain('launch');
35
- });
36
-
37
- it('shows the external URL in the link column with the URL as tooltip', () => {
38
- const wrapper = renderCta({ urlType: EXTERNAL_URL, url: 'https://google.com', isSaved: true });
39
- const link = wrapper.find('.mpush-saved-cta-link');
40
-
41
- expect(link.prop('children')).toBe('https://google.com');
42
- expect(link.prop('title')).toBe('https://google.com');
43
- expect(wrapper.find('.cta-type-label').prop('children')).toBe('External link');
44
- });
45
-
46
- it('shows the selected deep link label in the link column', () => {
47
- const wrapper = renderCta({ urlType: DEEP_LINK, url: 'app://home', isSaved: true });
48
-
49
- expect(wrapper.find('.mpush-saved-cta-link').prop('children')).toBe('Home');
50
- expect(wrapper.find('.cta-type-label').prop('children')).toBe('Deep link');
51
- });
52
-
53
- it('lays out the card rows horizontally with vertically centred items', () => {
54
- const wrapper = renderCta({ urlType: EXTERNAL_URL, url: 'https://google.com', isSaved: true });
55
-
56
- expect(wrapper.find('.mpush-cta-row').props()).toEqual(expect.objectContaining({ type: 'flex', align: 'middle' }));
57
- expect(wrapper.find('.cta-action-grp').props()).toEqual(expect.objectContaining({ type: 'flex', align: 'middle' }));
58
- });
59
-
60
- it('reopens the button for editing and deletes it from the card icons', () => {
61
- const updateHandler = jest.fn();
62
- const deleteHandler = jest.fn();
63
- const wrapper = renderCta(
64
- { urlType: EXTERNAL_URL, url: 'https://google.com', isSaved: true },
65
- { updateHandler, deleteHandler },
66
- );
67
-
68
- wrapper.find('.mpush-saved-cta-edit-icon').simulate('click');
69
- expect(updateHandler).toHaveBeenCalledWith(expect.objectContaining({ isSaved: false }), 0);
70
-
71
- wrapper.find('.cta-del-icon').simulate('click');
72
- expect(deleteHandler).toHaveBeenCalledWith(0);
73
- });
74
- });
75
-
76
- it('keeps the "External link" heading on one line in the edit form', () => {
77
- const wrapper = renderCta({ urlType: EXTERNAL_URL, url: '', isSaved: false });
78
-
79
- expect(wrapper.find(CapTagListWithInput).prop('headingStyle')).toEqual(
80
- expect.objectContaining({ whiteSpace: 'nowrap' }),
81
- );
82
- });
83
-
84
- it('wraps the External link field so its label row lines up with "Type of link"', () => {
85
- const wrapper = renderCta({ urlType: EXTERNAL_URL, url: '', isSaved: false });
86
-
87
- expect(wrapper.find('.mpush-cta-external-link-field').find(CapTagListWithInput).exists()).toBe(true);
88
- });
89
-
90
- describe('deep link keys', () => {
91
- const offerLink = [{ value: 'app://offer', label: 'Offer', keys: ['offerId', 'src'] }];
92
-
93
- it('shows one input per configured key with its saved value', () => {
94
- const wrapper = renderCta(
95
- { urlType: DEEP_LINK, url: 'app://offer', isSaved: false, deepLinkKeys: ['offerId=5'] },
96
- { deepLink: offerLink },
97
- );
98
-
99
- expect(wrapper.find({ id: 'mpush-deep-link-keys' }).prop('value')).toBe('5');
100
- expect(wrapper.find({ id: 'mpush-deep-link-keys-1' }).prop('value')).toBe('');
101
- });
102
-
103
- it('stores the configured key with the typed value', () => {
104
- const updateHandler = jest.fn();
105
- const wrapper = renderCta(
106
- { urlType: DEEP_LINK, url: 'app://offer', isSaved: false, deepLinkKeys: ['offerId=5'] },
107
- { deepLink: offerLink, updateHandler },
108
- );
109
-
110
- wrapper.find({ id: 'mpush-deep-link-keys-1' }).simulate('change', { target: { value: 'push' } });
111
- expect(updateHandler).toHaveBeenCalledWith(
112
- expect.objectContaining({ deepLinkKeys: ['offerId=5', 'src=push'] }),
113
- 0,
114
- );
115
- });
116
-
117
- it('shows a deep link copied in from the other tab after the form is open', () => {
118
- const wrapper = renderCta(
119
- { urlType: DEEP_LINK, url: '', isSaved: false },
120
- { deepLink: offerLink },
121
- );
122
- expect(wrapper.find({ id: 'mpush-deep-link-type' }).prop('value')).toBe('');
123
-
124
- wrapper.setProps({
125
- ctaData: [{
126
- index: 0, text: 'Shop', urlType: DEEP_LINK, url: 'app://offer', isSaved: false, deepLinkKeys: ['offerId=5'],
127
- }],
128
- });
129
-
130
- expect(wrapper.find({ id: 'mpush-deep-link-type' }).prop('value')).toBe('app://offer');
131
- expect(wrapper.find({ id: 'mpush-deep-link-keys' }).prop('value')).toBe('5');
132
- });
133
- });
134
-
135
- it('clears the url and sets the new type in one update on type change', () => {
136
- const updateHandler = jest.fn();
137
- const wrapper = renderCta(
138
- { urlType: DEEP_LINK, url: 'app://home', isSaved: false },
139
- { updateHandler },
140
- );
141
-
142
- wrapper.find({ id: 'mpush-cta-type' }).simulate('change', EXTERNAL_URL);
143
-
144
- expect(updateHandler).toHaveBeenCalledTimes(1);
145
- expect(updateHandler).toHaveBeenCalledWith(
146
- expect.objectContaining({ url: '', urlType: EXTERNAL_URL }),
147
- 0,
148
- );
149
- });
150
- });
@@ -1,76 +0,0 @@
1
- import React from "react";
2
- import PropTypes from "prop-types";
3
- import CapRow from "@capillarytech/cap-ui-library/CapRow";
4
- import CapColumn from "@capillarytech/cap-ui-library/CapColumn";
5
- import CapButton from "@capillarytech/cap-ui-library/CapButton";
6
- import CapIcon from "@capillarytech/cap-ui-library/CapIcon";
7
- import CapTag from "@capillarytech/cap-ui-library/CapTag";
8
- import CapTooltip from "@capillarytech/cap-ui-library/CapTooltip";
9
- import globalMessages from "../../Cap/messages";
10
- import messages from "../messages";
11
- import { DEEP_LINK } from "../constants";
12
- // Saved-row styles (.cap-mpush-saved-cta, .cta-type-label, ...) shared with the buttons
13
- import "../../../v2Components/CapMpushCTA/index.scss";
14
-
15
- // Save / Delete under an open tap link, as in the button form
16
- export const TapLinkSaveDelete = ({
17
- isSaveDisabled, onSave, onDelete, formatMessage,
18
- }) => (
19
- <CapRow type="flex" align="middle" className="mpush-tap-save-delete-btn">
20
- <CapTooltip title={isSaveDisabled ? formatMessage(messages.tapLinkSaveDisabled) : ""}>
21
- <CapRow className="button-disabled-tooltip-wrapper">
22
- <CapButton onClick={onSave} disabled={isSaveDisabled} className="mpush-tap-save-btn">
23
- {formatMessage(globalMessages.save)}
24
- </CapButton>
25
- </CapRow>
26
- </CapTooltip>
27
- <CapButton onClick={onDelete} type="secondary" className="mpush-tap-delete-btn">
28
- {formatMessage(globalMessages.delete)}
29
- </CapButton>
30
- </CapRow>
31
- );
32
-
33
- TapLinkSaveDelete.propTypes = {
34
- isSaveDisabled: PropTypes.bool.isRequired,
35
- onSave: PropTypes.func.isRequired,
36
- onDelete: PropTypes.func.isRequired,
37
- formatMessage: PropTypes.func.isRequired,
38
- };
39
-
40
- // Collapsed row for a saved tap link, as for a saved button
41
- export const SavedTapLink = ({
42
- linkType, linkText, onEdit, onDelete, formatMessage,
43
- }) => (
44
- <CapRow type="flex" align="middle" className="cap-mpush-saved-cta mpush-saved-tap-link">
45
- <CapColumn>
46
- <CapTag className="cta-type-label">
47
- {formatMessage(linkType === DEEP_LINK ? messages.tapActionDeepLink : messages.tapActionExternalLink)}
48
- </CapTag>
49
- </CapColumn>
50
- <CapColumn className="mpush-saved-cta-link" title={linkText}>
51
- {linkText}
52
- </CapColumn>
53
- <CapColumn>
54
- <CapRow type="flex" align="middle" className="cta-action-grp">
55
- <CapColumn className="mpush-saved-tap-link-edit-icon" onClick={onEdit}>
56
- <CapIcon size="s" type="edit" className="cta-action" />
57
- </CapColumn>
58
- <CapColumn className="cta-del-icon mpush-saved-tap-link-delete-icon" onClick={onDelete}>
59
- <CapIcon size="s" type="delete" className="cta-action" />
60
- </CapColumn>
61
- </CapRow>
62
- </CapColumn>
63
- </CapRow>
64
- );
65
-
66
- SavedTapLink.propTypes = {
67
- linkType: PropTypes.string.isRequired,
68
- linkText: PropTypes.string,
69
- onEdit: PropTypes.func.isRequired,
70
- onDelete: PropTypes.func.isRequired,
71
- formatMessage: PropTypes.func.isRequired,
72
- };
73
-
74
- SavedTapLink.defaultProps = {
75
- linkText: "",
76
- };