@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.
Files changed (41) hide show
  1. package/constants/unified.js +0 -1
  2. package/package.json +1 -1
  3. package/utils/common.js +0 -6
  4. package/utils/createMobilePushPayload.js +50 -33
  5. package/utils/tests/createMobilePushPayload.test.js +113 -8
  6. package/v2Components/CapMpushCTA/index.js +10 -9
  7. package/v2Components/CapMpushCTA/index.scss +29 -3
  8. package/v2Components/CapMpushCTA/tests/index.test.js +89 -0
  9. package/v2Components/CommonTestAndPreview/UnifiedPreview/MobilePushPreviewContent.js +20 -12
  10. package/v2Components/CommonTestAndPreview/UnifiedPreview/_unifiedPreview.scss +13 -1
  11. package/v2Components/CommonTestAndPreview/constants.js +2 -0
  12. package/v2Components/CommonTestAndPreview/index.js +48 -10
  13. package/v2Components/CommonTestAndPreview/tests/UnifiedPreview/MobilePushPreviewContent.test.js +81 -5
  14. package/v2Components/CommonTestAndPreview/tests/index.test.js +86 -0
  15. package/v2Components/TemplatePreview/_templatePreview.scss +12 -2
  16. package/v2Components/TemplatePreview/index.js +24 -16
  17. package/v2Components/TemplatePreview/tests/index.test.js +68 -0
  18. package/v2Containers/CreativesContainer/SlideBoxContent.js +4 -6
  19. package/v2Containers/CreativesContainer/index.js +2 -1
  20. package/v2Containers/CreativesContainer/tests/SlideBoxContent.test.js +43 -0
  21. package/v2Containers/MobilePushNew/components/CtaButtons.js +52 -47
  22. package/v2Containers/MobilePushNew/components/MediaUploaders.js +297 -216
  23. package/v2Containers/MobilePushNew/components/PlatformContentFields.js +158 -125
  24. package/v2Containers/MobilePushNew/components/TapLinkActions.js +76 -0
  25. package/v2Containers/MobilePushNew/components/tests/CtaButtons.test.js +30 -208
  26. package/v2Containers/MobilePushNew/components/tests/MediaUploaders.test.js +464 -108
  27. package/v2Containers/MobilePushNew/components/tests/PlatformContentFields.test.js +106 -35
  28. package/v2Containers/MobilePushNew/constants.js +5 -0
  29. package/v2Containers/MobilePushNew/hooks/tests/usePlatformSync.test.js +63 -1
  30. package/v2Containers/MobilePushNew/hooks/tests/useUpload.test.js +52 -0
  31. package/v2Containers/MobilePushNew/hooks/usePlatformSync.js +40 -1
  32. package/v2Containers/MobilePushNew/hooks/useUpload.js +29 -39
  33. package/v2Containers/MobilePushNew/index.js +487 -235
  34. package/v2Containers/MobilePushNew/index.scss +205 -4
  35. package/v2Containers/MobilePushNew/messages.js +106 -6
  36. package/v2Containers/MobilePushNew/tests/index.test.js +469 -1
  37. package/v2Containers/MobilePushNew/tests/utils.test.js +70 -0
  38. package/v2Containers/MobilePushNew/utils.js +56 -0
  39. package/v2Containers/Templates/_templates.scss +10 -2
  40. package/v2Containers/Templates/index.js +83 -81
  41. package/v2Containers/Templates/tests/index.test.js +68 -0
@@ -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 } from '../MobilePushNew/constants';
167
+ import { AUTO_CAROUSEL, BIG_PICTURE, FILMSTRIP_CAROUSEL, MANUAL_CAROUSEL, VIDEO as MPUSH_VIDEO } 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,12 +1426,17 @@ 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
+ };
1429
1434
  // Extract Android content
1430
1435
  const androidPreview = {
1431
1436
  header: androidContent.title || '',
1432
1437
  bodyText: androidContent.message || '',
1433
1438
  bodyImage: expandableDetailsAndroid.image || '',
1434
- bodyVideo: expandableDetailsAndroid.media?.[0] || {},
1439
+ bodyVideo: toPreviewVideo(expandableDetailsAndroid.media),
1435
1440
  bodyGif: '',
1436
1441
  actions: expandableDetailsAndroid.ctas || [],
1437
1442
  carouselData: expandableDetailsAndroid.carouselData || [],
@@ -1442,7 +1447,7 @@ export class Templates extends React.Component { // eslint-disable-line react/pr
1442
1447
  header: iosContent.title || '',
1443
1448
  bodyText: iosContent.message || '',
1444
1449
  bodyImage: expandableDetailsIos.image || '',
1445
- bodyVideo: expandableDetailsIos.media?.[0] || {},
1450
+ bodyVideo: toPreviewVideo(expandableDetailsIos.media),
1446
1451
  bodyGif: '',
1447
1452
  actions: expandableDetailsIos.ctas || [],
1448
1453
  carouselData: expandableDetailsIos.carouselData || [],
@@ -2405,94 +2410,91 @@ export class Templates extends React.Component { // eslint-disable-line react/pr
2405
2410
  }
2406
2411
  break;
2407
2412
  }
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>
2427
- </div>
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>
2428
2429
  </div>
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>
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} />
2441
2442
  </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() && (
2443
+ </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">
2454
2463
  <CapImage
2455
- src={data?.imageUrl ? data?.imageUrl : data?.url ? data?.url : whatsappImageEmptyPreview}
2464
+ src={data?.videoPreviewImg ? data?.videoPreviewImg : data?.url ? data?.url : whatsappVideoEmptyPreview}
2456
2465
  className="whatsapp-image"
2457
2466
  />
2458
- )}
2459
- {data?.mediaType === VIDEO.toLowerCase() && (
2460
- <div className="video-preview">
2467
+ <div className="icon-position">
2461
2468
  <CapImage
2462
- src={data?.videoPreviewImg ? data?.videoPreviewImg : data?.url ? data?.url : whatsappVideoEmptyPreview}
2463
- className="whatsapp-image"
2469
+ className="video-icon"
2470
+ src={videoPlay}
2464
2471
  />
2465
- <div className="icon-position">
2466
- <CapImage
2467
- className="video-icon"
2468
- src={videoPlay}
2469
- />
2470
- </div>
2471
2472
  </div>
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
- )}
2473
+ </div>
2474
+ )}
2475
+ </div>
2476
+ </div>
2477
+ )
2478
+ })}
2491
2479
  </div>
2492
- );
2493
- templateData.isNewMobilePush = commonUtil.hasNewMobilePushFeatureEnabled();
2494
- }
2480
+ )}
2481
+ {ctas.length > 0 && (
2482
+ <div className="actions">
2483
+ {ctas.map((cta, index) => (
2484
+ <span
2485
+ className="action"
2486
+ key={`action-${index}`}
2487
+ >
2488
+ {cta?.actionText}
2489
+ </span>
2490
+ ))}
2491
+ </div>
2492
+ )}
2493
+ </div>
2494
+ );
2495
+ templateData.isNewMobilePush = true;
2495
2496
  break;
2497
+ }
2496
2498
  case INAPP: {
2497
2499
  // Pass the full template object to CapCustomCard so getInAppContent can extract the data
2498
2500
  // Similar to how MOBILE_PUSH passes the full template when new feature is enabled
@@ -498,4 +498,72 @@ 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
+ });
501
569
  });