@capillarytech/creatives-library 9.1.7 → 9.1.8-alpha.sprint-cap-214249.38

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 (81) hide show
  1. package/constants/unified.js +0 -1
  2. package/index.js +0 -13
  3. package/package.json +1 -1
  4. package/services/getSchema.js +1 -4
  5. package/services/tests/getSchema.test.js +2 -2
  6. package/utils/common.js +0 -6
  7. package/utils/createMobilePushPayload.js +47 -33
  8. package/utils/tests/createMobilePushPayload.test.js +102 -8
  9. package/v2Components/CapMpushCTA/index.js +10 -9
  10. package/v2Components/CapMpushCTA/index.scss +29 -3
  11. package/v2Components/CapMpushCTA/tests/index.test.js +89 -0
  12. package/v2Components/CommonTestAndPreview/UnifiedPreview/MobilePushPreviewContent.js +26 -13
  13. package/v2Components/CommonTestAndPreview/UnifiedPreview/_unifiedPreview.scss +13 -1
  14. package/v2Components/CommonTestAndPreview/constants.js +2 -0
  15. package/v2Components/CommonTestAndPreview/index.js +49 -11
  16. package/v2Components/CommonTestAndPreview/tests/UnifiedPreview/MobilePushPreviewContent.test.js +79 -5
  17. package/v2Components/CommonTestAndPreview/tests/index.test.js +86 -0
  18. package/v2Components/FormBuilder/Functional/tests/mpush.crossFlowParity.test.js +1 -1
  19. package/v2Components/FormBuilder/Functional/tests/mpush.shellEvents.test.js +1 -1
  20. package/v2Components/FormBuilder/Functional/tests/mpush.singlePlatform.test.js +1 -1
  21. package/v2Components/FormBuilder/tests/mpush.characterization.test.js +2 -2
  22. package/v2Components/TemplatePreview/_templatePreview.scss +12 -2
  23. package/v2Components/TemplatePreview/index.js +30 -17
  24. package/v2Components/TemplatePreview/tests/index.test.js +61 -0
  25. package/v2Containers/Cap/index.js +0 -3
  26. package/v2Containers/CreativesContainer/SlideBoxContent.js +70 -151
  27. package/v2Containers/CreativesContainer/index.js +3 -6
  28. package/v2Containers/CreativesContainer/tests/SlideBoxContent.test.js +29 -0
  29. package/v2Containers/MobilePushNew/components/CtaButtons.js +52 -47
  30. package/v2Containers/MobilePushNew/components/MediaUploaders.js +207 -192
  31. package/v2Containers/MobilePushNew/components/PlatformContentFields.js +116 -121
  32. package/v2Containers/MobilePushNew/components/tests/CtaButtons.test.js +30 -208
  33. package/v2Containers/MobilePushNew/components/tests/MediaUploaders.test.js +316 -72
  34. package/v2Containers/MobilePushNew/components/tests/PlatformContentFields.test.js +45 -16
  35. package/v2Containers/MobilePushNew/constants.js +5 -0
  36. package/v2Containers/MobilePushNew/hooks/tests/usePlatformSync.test.js +63 -1
  37. package/v2Containers/MobilePushNew/hooks/tests/useUpload.test.js +52 -0
  38. package/v2Containers/MobilePushNew/hooks/usePlatformSync.js +38 -1
  39. package/v2Containers/MobilePushNew/hooks/useUpload.js +29 -39
  40. package/v2Containers/MobilePushNew/index.js +453 -188
  41. package/v2Containers/MobilePushNew/index.scss +188 -4
  42. package/v2Containers/MobilePushNew/messages.js +86 -6
  43. package/v2Containers/MobilePushNew/tests/index.test.js +450 -1
  44. package/v2Containers/MobilePushNew/tests/utils.test.js +25 -0
  45. package/v2Containers/MobilePushNew/utils.js +8 -0
  46. package/v2Containers/Templates/_templates.scss +10 -2
  47. package/v2Containers/Templates/index.js +84 -90
  48. package/v2Containers/Templates/tests/index.test.js +68 -0
  49. package/v2Components/FormBuilder/Functional/tests/manual.typingPerf.test.js +0 -135
  50. package/v2Components/FormBuilder/Functional/tests/mpush.ctaFlows.parity.test.js +0 -320
  51. package/v2Components/FormBuilder/Functional/tests/mpush.editContainer.parity.test.js +0 -148
  52. package/v2Components/FormBuilder/Functional/tests/mpush.libraryValidity.parity.test.js +0 -152
  53. package/v2Containers/MobilePush/Create/_mobilePushCreate.scss +0 -70
  54. package/v2Containers/MobilePush/Create/actions.js +0 -52
  55. package/v2Containers/MobilePush/Create/constants.js +0 -26
  56. package/v2Containers/MobilePush/Create/index.js +0 -2149
  57. package/v2Containers/MobilePush/Create/messages.js +0 -349
  58. package/v2Containers/MobilePush/Create/reducer.js +0 -72
  59. package/v2Containers/MobilePush/Create/sagas.js +0 -79
  60. package/v2Containers/MobilePush/Create/selectors.js +0 -29
  61. package/v2Containers/MobilePush/Create/test/contentValidity.test.js +0 -154
  62. package/v2Containers/MobilePush/Create/test/saga.test.js +0 -19
  63. package/v2Containers/MobilePush/Create/test/stayOpenOnSave.test.js +0 -80
  64. package/v2Containers/MobilePush/Edit/_mobilePushCreate.scss +0 -65
  65. package/v2Containers/MobilePush/Edit/actions.js +0 -94
  66. package/v2Containers/MobilePush/Edit/constants.js +0 -37
  67. package/v2Containers/MobilePush/Edit/index.js +0 -2407
  68. package/v2Containers/MobilePush/Edit/messages.js +0 -341
  69. package/v2Containers/MobilePush/Edit/reducer.js +0 -113
  70. package/v2Containers/MobilePush/Edit/sagas.js +0 -113
  71. package/v2Containers/MobilePush/Edit/selectors.js +0 -33
  72. package/v2Containers/MobilePush/Edit/test/contentValidity.test.js +0 -149
  73. package/v2Containers/MobilePush/Edit/test/saga.test.js +0 -255
  74. package/v2Containers/MobilePush/Edit/test/stayOpenOnSave.test.js +0 -60
  75. package/v2Containers/MobilePush/commonMethods.js +0 -333
  76. package/v2Containers/MobilePush/eventsMap.js +0 -130
  77. package/v2Containers/MobilePush/tests/commonMethods.test.js +0 -401
  78. package/v2Containers/MobilepushWrapper/_mobilepushWrapper.scss +0 -22
  79. package/v2Containers/MobilepushWrapper/index.js +0 -178
  80. package/v2Containers/MobilepushWrapper/messages.js +0 -29
  81. /package/{v2Containers/MobilePush/initialSchema.js → v2Components/FormBuilder/Functional/tests/fixtures/mpushInitialSchema.js} +0 -0
@@ -55,7 +55,6 @@ import {
55
55
  } from "@capillarytech/cap-ui-library";
56
56
  import { makeSelectTemplates, makeSelectTemplatesResponse } from './selectors';
57
57
  import { makeSelectCreate as makeSelectCreateSms } from '../Sms/Create/selectors';
58
- import { makeSelectCreate as makeSelectCreateMobilePush } from '../MobilePush/Create/selectors';
59
58
  import { makeSelectMobilePushNew } from '../MobilePushNew/selectors';
60
59
  import { makeSelectEbill as makeSelectCreateEbill } from '../Ebill/selectors';
61
60
  import { makeSelectEmail as makeSelectCreateEmail } from '../Email/selectors';
@@ -66,7 +65,6 @@ import { makeSelectZalo } from '../Zalo/selectors';
66
65
  import { makeSelectInApp } from '../InApp/selectors';
67
66
  import * as actions from './actions';
68
67
  import * as smsActions from '../Sms/Create/actions';
69
- import * as mobilepushActions from '../MobilePush/Create/actions';
70
68
  import * as mobilePushNewActions from '../MobilePushNew/actions';
71
69
  import * as smsEditActions from '../Sms/Edit/actions';
72
70
  import * as ebillActions from '../Ebill/actions';
@@ -164,7 +162,7 @@ import { makeSelectRcs } from '../Rcs/selectors';
164
162
  import { getRcsStatusType } from '../Rcs/utils';
165
163
  import { makeSelectWebPush } from '../WebPush/selectors';
166
164
  import { v2MobilePushSagas } from '../MobilePushNew/sagas';
167
- import { AUTO_CAROUSEL, BIG_PICTURE, FILMSTRIP_CAROUSEL, MANUAL_CAROUSEL } from '../MobilePushNew/constants';
165
+ import { AUTO_CAROUSEL, BIG_PICTURE, FILMSTRIP_CAROUSEL, MANUAL_CAROUSEL, VIDEO as MPUSH_VIDEO } from '../MobilePushNew/constants';
168
166
  import CapPageSpinner from '../../v2Components/CapPageSpinner';
169
167
  import webPushSagas from '../WebPush/sagas';
170
168
  import { DLT_LEGACY_VAR_REGEX } from '../SmsTrai/Edit/dltVarTypes';
@@ -791,14 +789,11 @@ export class Templates extends React.Component { // eslint-disable-line react/pr
791
789
  if ((this.state.channel || '').toLowerCase() !== "sms") {
792
790
  CapNotification.error({key: 'somethingWrong', message});
793
791
  }
794
- const { smsActions, mobilepushActions, ebillActions, lineActions, viberActions, facebookActions, whatsappActions, inAppActions, rcsActions, webpushActions } = this.props;
792
+ const { smsActions, ebillActions, lineActions, viberActions, facebookActions, whatsappActions, inAppActions, rcsActions, webpushActions } = this.props;
795
793
  switch (selectedChannel) {
796
794
  case SMS_LOWERCASE:
797
795
  smsActions.clearCreateResponse();
798
796
  break;
799
- case MOBILE_PUSH_LOWERCASE:
800
- mobilepushActions.clearCreateResponse();
801
- break;
802
797
  case EBILL_LOWERCASE:
803
798
  ebillActions.clearCreateResponse();
804
799
  break;
@@ -1426,12 +1421,17 @@ export class Templates extends React.Component { // eslint-disable-line react/pr
1426
1421
 
1427
1422
  const expandableDetailsAndroid = androidContent.expandableDetails || {};
1428
1423
  const expandableDetailsIos = iosContent.expandableDetails || {};
1424
+ // Saved media[0] is { url, type, videoPreviewUrl }; the preview reads { videoSrc, videoPreview }
1425
+ const toPreviewVideo = (media) => {
1426
+ const { type, url, videoPreviewUrl } = media?.[0] || {};
1427
+ return type === MPUSH_VIDEO && url ? { videoSrc: url, videoPreview: videoPreviewUrl || '' } : {};
1428
+ };
1429
1429
  // Extract Android content
1430
1430
  const androidPreview = {
1431
1431
  header: androidContent.title || '',
1432
1432
  bodyText: androidContent.message || '',
1433
1433
  bodyImage: expandableDetailsAndroid.image || '',
1434
- bodyVideo: expandableDetailsAndroid.media?.[0] || {},
1434
+ bodyVideo: toPreviewVideo(expandableDetailsAndroid.media),
1435
1435
  bodyGif: '',
1436
1436
  actions: expandableDetailsAndroid.ctas || [],
1437
1437
  carouselData: expandableDetailsAndroid.carouselData || [],
@@ -1442,7 +1442,7 @@ export class Templates extends React.Component { // eslint-disable-line react/pr
1442
1442
  header: iosContent.title || '',
1443
1443
  bodyText: iosContent.message || '',
1444
1444
  bodyImage: expandableDetailsIos.image || '',
1445
- bodyVideo: expandableDetailsIos.media?.[0] || {},
1445
+ bodyVideo: toPreviewVideo(expandableDetailsIos.media),
1446
1446
  bodyGif: '',
1447
1447
  actions: expandableDetailsIos.ctas || [],
1448
1448
  carouselData: expandableDetailsIos.carouselData || [],
@@ -2405,94 +2405,91 @@ export class Templates extends React.Component { // eslint-disable-line react/pr
2405
2405
  }
2406
2406
  break;
2407
2407
  }
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>
2408
+ case MOBILE_PUSH: {
2409
+ const mpushData = get(template, 'versions.base', template);
2410
+ const androidData = get(mpushData, 'ANDROID') || get(mpushData, 'androidContent');
2411
+ const iosData = get(mpushData, 'IOS') || get(mpushData, 'iosContent');
2412
+ let mpushListingData = androidData;
2413
+ if (isEmpty(androidData) || !androidData?.title) {
2414
+ mpushListingData = iosData;
2415
+ };
2416
+ const { title, message, expandableDetails: { style = '', image, carouselData = [], ctas = [], media = [] } = {} } = mpushListingData || {};
2417
+ const {url = ''} = media?.[0] || {};
2418
+ templateData.content = (
2419
+ <div className='mobilepush-container'>
2420
+ <div className="app-header">
2421
+ <div className="app-header-left">
2422
+ <span className="app-icon">{""}</span>
2423
+ <CapLabel type="label4">{title}</CapLabel>
2428
2424
  </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>
2425
+ </div>
2426
+ <CapLabel className="mobilepush-message" type="label1">{message}</CapLabel>
2427
+ {style === BIG_PICTURE && (
2428
+ <CapImage src={image} className="mobilepush-image mobilepush-image-padding" />
2429
+ )}
2430
+ {style === VIDEO && (
2431
+ <div className="video-preview">
2432
+ <video aria-label="Template video preview" controls={false} tabIndex="0">
2433
+ <source src={url} type="video/mp4" />
2434
+ </video>
2435
+ <div className="icon-position">
2436
+ <CapImage className="video-icon" src={videoPlay} />
2441
2437
  </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() && (
2438
+ </div>
2439
+ )}
2440
+ {[MANUAL_CAROUSEL, AUTO_CAROUSEL, FILMSTRIP_CAROUSEL].includes(style) && (
2441
+ <div className="scroll-container">
2442
+ {carouselData?.map((data, index) => {
2443
+ return (
2444
+ <div
2445
+ key={`carousel-${index + 1}`}
2446
+ className="whatsapp-carousel-container"
2447
+ role="group"
2448
+ >
2449
+ <div className="whatsapp-carousel-card">
2450
+ {data?.mediaType === IMAGE.toLowerCase() && (
2451
+ <CapImage
2452
+ src={data?.imageUrl ? data?.imageUrl : data?.url ? data?.url : whatsappImageEmptyPreview}
2453
+ className="whatsapp-image"
2454
+ />
2455
+ )}
2456
+ {data?.mediaType === VIDEO.toLowerCase() && (
2457
+ <div className="video-preview">
2454
2458
  <CapImage
2455
- src={data?.imageUrl ? data?.imageUrl : data?.url ? data?.url : whatsappImageEmptyPreview}
2459
+ src={data?.videoPreviewImg ? data?.videoPreviewImg : data?.url ? data?.url : whatsappVideoEmptyPreview}
2456
2460
  className="whatsapp-image"
2457
2461
  />
2458
- )}
2459
- {data?.mediaType === VIDEO.toLowerCase() && (
2460
- <div className="video-preview">
2462
+ <div className="icon-position">
2461
2463
  <CapImage
2462
- src={data?.videoPreviewImg ? data?.videoPreviewImg : data?.url ? data?.url : whatsappVideoEmptyPreview}
2463
- className="whatsapp-image"
2464
+ className="video-icon"
2465
+ src={videoPlay}
2464
2466
  />
2465
- <div className="icon-position">
2466
- <CapImage
2467
- className="video-icon"
2468
- src={videoPlay}
2469
- />
2470
- </div>
2471
2467
  </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
- )}
2468
+ </div>
2469
+ )}
2470
+ </div>
2471
+ </div>
2472
+ )
2473
+ })}
2491
2474
  </div>
2492
- );
2493
- templateData.isNewMobilePush = commonUtil.hasNewMobilePushFeatureEnabled();
2494
- }
2475
+ )}
2476
+ {ctas.length > 0 && (
2477
+ <div className="actions">
2478
+ {ctas.map((cta, index) => (
2479
+ <span
2480
+ className="action"
2481
+ key={`action-${index}`}
2482
+ >
2483
+ {cta?.actionText}
2484
+ </span>
2485
+ ))}
2486
+ </div>
2487
+ )}
2488
+ </div>
2489
+ );
2490
+ templateData.isNewMobilePush = true;
2495
2491
  break;
2492
+ }
2496
2493
  case INAPP: {
2497
2494
  // Pass the full template object to CapCustomCard so getInAppContent can extract the data
2498
2495
  // Similar to how MOBILE_PUSH passes the full template when new feature is enabled
@@ -5356,7 +5353,6 @@ export class Templates extends React.Component { // eslint-disable-line react/pr
5356
5353
  Templates.propTypes = {
5357
5354
  actions: PropTypes.object.isRequired,
5358
5355
  smsActions: PropTypes.object,
5359
- mobilepushActions: PropTypes.object,
5360
5356
  mobilePushNewActions: PropTypes.object,
5361
5357
  smsEditActions: PropTypes.object,
5362
5358
  ebillActions: PropTypes.object,
@@ -5400,7 +5396,6 @@ const mapStateToProps = createStructuredSelector({
5400
5396
  Templates: makeSelectTemplates(),
5401
5397
  TemplatesList: makeSelectTemplatesResponse(),
5402
5398
  Create: makeSelectCreateSms(),
5403
- CreateMobilePush: makeSelectCreateMobilePush(),
5404
5399
  MobilePushNew: makeSelectMobilePushNew(),
5405
5400
  CreateEbill: makeSelectCreateEbill(),
5406
5401
  Edit: makeSelectEdit(),
@@ -5418,7 +5413,6 @@ function mapDispatchToProps(dispatch) {
5418
5413
  return {
5419
5414
  actions: bindActionCreators(actions, dispatch),
5420
5415
  smsActions: bindActionCreators(smsActions, dispatch),
5421
- mobilepushActions: bindActionCreators(mobilepushActions, dispatch),
5422
5416
  mobilePushNewActions: bindActionCreators(mobilePushNewActions, dispatch),
5423
5417
  inAppActions: bindActionCreators(inAppActions, dispatch),
5424
5418
  smsEditActions: bindActionCreators(smsEditActions, dispatch),
@@ -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
  });
@@ -1,135 +0,0 @@
1
- /**
2
- * MANUAL perf probe (skipped by default): per-keystroke JS cost, Classic vs
3
- * Functional, over the real embedded Create container. jsdom has no paint, so
4
- * this measures the render+effects side of typing lag as an A/B comparison.
5
- * Run: RUN_PERF=1 TZ=UTC npx jest --config internals/testing/jest.unit.config.js manual.typingPerf
6
- */
7
- import React from 'react';
8
- import '@testing-library/jest-dom';
9
- import _ from 'lodash';
10
- import { Router } from 'react-router-dom';
11
- import { render, act, fireEvent } from '../../../../utils/test-utils';
12
- import history from '../../../../utils/history';
13
- import { response as mpushSchemaResponse } from '../../../../v2Containers/MobilePush/initialSchema';
14
- import { Create } from '../../../../v2Containers/MobilePush/Create';
15
-
16
- jest.mock('redux-auth-wrapper/history4/redirect', () => ({
17
- connectedRouterRedirect: jest.fn(() => (Component) => Component),
18
- }));
19
- jest.mock('../../../../services/api', () => ({
20
- ...jest.requireActual('../../../../services/api'),
21
- getUnsubscribeUrl: () => Promise.resolve({ response: { response: '' } }),
22
- }));
23
-
24
- let mockMpushFlag = false;
25
- jest.mock('../../../../utils/common', () => ({
26
- ...jest.requireActual('../../../../utils/common'),
27
- hasNewFormBuilderEnabledForMpush: () => mockMpushFlag,
28
- }));
29
-
30
- const fullDefinition = () => _.cloneDeep(mpushSchemaResponse.metaEntities[0].definition);
31
- const intl = { formatMessage: (d) => (d && (d.defaultMessage || d.id)) || '', locale: 'en' };
32
- const DEEPLINKS = JSON.stringify([{ name: 'Home Page', link: 'app://home', keys: ['user_id'] }]);
33
- const selectedAccount = {
34
- id: 'acc-1', name: 'Acc', sourceTypeName: 'SOME_SDK', sourceAccountIdentifier: 'lic-1',
35
- configs: { android: '1', ios: '1', deeplink: DEEPLINKS },
36
- };
37
-
38
- const buildProps = () => ({
39
- intl,
40
- params: { mode: 'text' },
41
- route: { name: 'create' },
42
- location: { pathname: '/mobilepush/create/text', query: { module: 'default', type: 'embedded' } },
43
- router: { push: jest.fn() },
44
- isFullMode: false,
45
- isGetFormData: false,
46
- isLoadingMetaEntities: false,
47
- metaEntities: {},
48
- Create: { createTemplateInProgress: false },
49
- Edit: {},
50
- Templates: { selectedWeChatAccount: selectedAccount },
51
- actions: new Proxy({}, { get: (t, n) => { if (!t[n]) t[n] = jest.fn(); return t[n]; } }), // eslint-disable-line no-param-reassign
52
- globalActions: { fetchSchemaForEntity: jest.fn(), addMessageToQueue: jest.fn(), setInjectedTags: jest.fn() },
53
- getFormLibraryData: jest.fn(),
54
- onValidationFail: jest.fn(),
55
- showLiquidErrorInFooter: jest.fn(),
56
- onPersonalizationTokensChange: jest.fn(),
57
- onContentValidityChange: jest.fn(),
58
- getLiquidTags: jest.fn(),
59
- injectedTags: {},
60
- });
61
-
62
- const setNativeValue = (el, value) => {
63
- Object.getOwnPropertyDescriptor(Object.getPrototypeOf(el), 'value').set.call(el, value);
64
- };
65
-
66
- const measureFlow = (flag, { withCta = false, longContent = 0 } = {}) => {
67
- mockMpushFlag = flag;
68
- const props = buildProps();
69
- const ui = (p) => (
70
- <Router history={history}>
71
- <Create {...p} />
72
- </Router>
73
- );
74
- const utils = render(ui(props));
75
- const meta = { layouts: [{ definition: fullDefinition() }], tags: { standard: [] } };
76
- act(() => { utils.rerender(ui({ ...props, metaEntities: meta })); });
77
-
78
- if (withCta) {
79
- const pane = document.querySelectorAll('.ant-tabs-tabpane')[0] || document;
80
- const label = Array.from(pane.querySelectorAll('label')).find((l) => /action link/i.test(l.textContent || ''));
81
- const cb = (label && label.querySelector('input[type="checkbox"]')) || pane.querySelector('input[type="checkbox"]');
82
- act(() => { fireEvent.click(cb); });
83
- }
84
-
85
- const editor = document.getElementById('message-editor');
86
- let text = 'The quick brown fox jumped over the lazy dog and kept typing more content ';
87
- if (longContent) {
88
- // long-message scenario incl. personalization tags — catches superlinear
89
- // per-keystroke validation/render costs that short content hides.
90
- text = 'Hello {{first_name}}, your offer {{offer_id}} is waiting. '.repeat(Math.ceil(longContent / 58));
91
- }
92
- // warm-up keystrokes (JIT/styles)
93
- for (let i = 0; i < 5; i++) {
94
- text += 'w';
95
- setNativeValue(editor, text);
96
- act(() => { fireEvent.change(editor, { target: { value: text } }); });
97
- }
98
- const N = 30;
99
- const t0 = performance.now();
100
- for (let i = 0; i < N; i++) {
101
- text += String.fromCharCode(97 + (i % 26));
102
- setNativeValue(editor, text);
103
- act(() => { fireEvent.change(editor, { target: { value: text } }); });
104
- }
105
- const perKey = (performance.now() - t0) / N;
106
- utils.unmount();
107
- mockMpushFlag = false;
108
- return perKey;
109
- };
110
-
111
- const describePerf = process.env.RUN_PERF ? describe : describe.skip;
112
- describePerf('MANUAL typing perf (RUN_PERF=1 to enable)', () => {
113
- it('per-keystroke JS cost, Classic vs Functional', () => {
114
- const classicPlain = measureFlow(false);
115
- const functionalPlain = measureFlow(true);
116
- const classicCta = measureFlow(false, { withCta: true });
117
- const functionalCta = measureFlow(true, { withCta: true });
118
- const classicLong5k = measureFlow(false, { longContent: 5000 });
119
- const functionalLong5k = measureFlow(true, { longContent: 5000 });
120
- const classicLong20k = measureFlow(false, { longContent: 20000 });
121
- const functionalLong20k = measureFlow(true, { longContent: 20000 });
122
- // eslint-disable-next-line no-console
123
- console.log(JSON.stringify({
124
- classicPlain: `${classicPlain.toFixed(1)} ms/key`,
125
- functionalPlain: `${functionalPlain.toFixed(1)} ms/key`,
126
- classicWithCta: `${classicCta.toFixed(1)} ms/key`,
127
- functionalWithCta: `${functionalCta.toFixed(1)} ms/key`,
128
- classicLong5k: `${classicLong5k.toFixed(1)} ms/key`,
129
- functionalLong5k: `${functionalLong5k.toFixed(1)} ms/key`,
130
- classicLong20k: `${classicLong20k.toFixed(1)} ms/key`,
131
- functionalLong20k: `${functionalLong20k.toFixed(1)} ms/key`,
132
- }, null, 1));
133
- expect(true).toBe(true);
134
- });
135
- });