@capillarytech/creatives-library 9.1.8-alpha.sprint-cap-214249.39 → 9.2.0

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 (87) hide show
  1. package/constants/unified.js +4 -0
  2. package/package.json +1 -1
  3. package/translations/en.json +1 -0
  4. package/translations/ja-JP.json +1 -0
  5. package/translations/zh.json +1 -0
  6. package/utils/common.js +6 -0
  7. package/utils/createMobilePushPayload.js +33 -50
  8. package/utils/tagValidations.js +35 -4
  9. package/utils/templateVarUtils.js +49 -0
  10. package/utils/tests/createMobilePushPayload.test.js +8 -113
  11. package/utils/tests/tagValidations.test.js +48 -0
  12. package/utils/tests/templateVarUtils.test.js +89 -0
  13. package/v2Components/CapMpushCTA/index.js +9 -10
  14. package/v2Components/CapMpushCTA/index.scss +3 -29
  15. package/v2Components/CapTagList/TagFallbackPanel.js +124 -0
  16. package/v2Components/CapTagList/constants.js +5 -0
  17. package/v2Components/CapTagList/index.js +46 -7
  18. package/v2Components/CapTagList/messages.js +44 -0
  19. package/v2Components/CapTagList/style.scss +113 -1
  20. package/v2Components/CapTagList/tests/TagFallback.test.js +222 -0
  21. package/v2Components/CapTagList/utils.js +17 -0
  22. package/v2Components/CommonTestAndPreview/UnifiedPreview/MobilePushPreviewContent.js +12 -20
  23. package/v2Components/CommonTestAndPreview/UnifiedPreview/_unifiedPreview.scss +1 -13
  24. package/v2Components/CommonTestAndPreview/constants.js +3 -2
  25. package/v2Components/CommonTestAndPreview/index.js +61 -61
  26. package/v2Components/CommonTestAndPreview/tests/UnifiedPreview/MobilePushPreviewContent.test.js +5 -81
  27. package/v2Components/CommonTestAndPreview/tests/index.test.js +0 -86
  28. package/v2Components/CommonTestAndPreview/tests/utils.test.js +102 -0
  29. package/v2Components/CommonTestAndPreview/utils.js +42 -3
  30. package/v2Components/FormBuilder/Classic.js +24 -14
  31. package/v2Components/FormBuilder/Functional/channels/mobilepush/config.js +1 -0
  32. package/v2Components/FormBuilder/Functional/channels/mobilepush/getEditorErrorDescriptor.js +1 -1
  33. package/v2Components/FormBuilder/Functional/channels/mobilepush/tests/validate.test.js +57 -0
  34. package/v2Components/FormBuilder/Functional/channels/mobilepush/validate.js +4 -4
  35. package/v2Components/FormBuilder/Functional/channels/sms/getEditorErrorDescriptor.js +3 -0
  36. package/v2Components/FormBuilder/Functional/channels/sms/tests/getEditorErrorDescriptor.test.js +5 -0
  37. package/v2Components/FormBuilder/Functional/channels/sms/tests/validate.test.js +6 -0
  38. package/v2Components/FormBuilder/Functional/channels/sms/validate.js +3 -1
  39. package/v2Components/FormBuilder/Functional/renderers/mpushRenderers.js +3 -0
  40. package/v2Components/FormBuilder/Functional/tests/mpushRenderers.test.js +22 -0
  41. package/v2Components/TemplatePreview/_templatePreview.scss +2 -12
  42. package/v2Components/TemplatePreview/index.js +16 -24
  43. package/v2Components/TemplatePreview/tests/index.test.js +0 -68
  44. package/v2Containers/Cap/messages.js +4 -0
  45. package/v2Containers/Cap/tests/__snapshots__/index.test.js.snap +1 -0
  46. package/v2Containers/CreativesContainer/SlideBoxContent.js +6 -4
  47. package/v2Containers/CreativesContainer/index.js +1 -2
  48. package/v2Containers/CreativesContainer/tests/SlideBoxContent.test.js +0 -43
  49. package/v2Containers/InApp/index.js +4 -1
  50. package/v2Containers/Line/Container/ImageCarousel/tests/__snapshots__/content.test.js.snap +3 -0
  51. package/v2Containers/Line/Container/ImageCarousel/tests/__snapshots__/index.test.js.snap +2 -0
  52. package/v2Containers/Line/Container/Text/index.js +3 -1
  53. package/v2Containers/Line/Container/Wrapper/tests/__snapshots__/index.test.js.snap +16 -0
  54. package/v2Containers/Line/Container/tests/__snapshots__/index.test.js.snap +18 -0
  55. package/v2Containers/MobilePushNew/components/CtaButtons.js +47 -52
  56. package/v2Containers/MobilePushNew/components/MediaUploaders.js +216 -297
  57. package/v2Containers/MobilePushNew/components/PlatformContentFields.js +125 -158
  58. package/v2Containers/MobilePushNew/components/tests/CtaButtons.test.js +208 -30
  59. package/v2Containers/MobilePushNew/components/tests/MediaUploaders.test.js +108 -464
  60. package/v2Containers/MobilePushNew/components/tests/PlatformContentFields.test.js +35 -106
  61. package/v2Containers/MobilePushNew/constants.js +0 -5
  62. package/v2Containers/MobilePushNew/hooks/tests/usePlatformSync.test.js +1 -63
  63. package/v2Containers/MobilePushNew/hooks/tests/useUpload.test.js +0 -52
  64. package/v2Containers/MobilePushNew/hooks/usePlatformSync.js +1 -40
  65. package/v2Containers/MobilePushNew/hooks/useUpload.js +39 -29
  66. package/v2Containers/MobilePushNew/index.js +239 -488
  67. package/v2Containers/MobilePushNew/index.scss +4 -205
  68. package/v2Containers/MobilePushNew/messages.js +6 -106
  69. package/v2Containers/MobilePushNew/tests/index.test.js +1 -469
  70. package/v2Containers/MobilePushNew/tests/utils.test.js +0 -70
  71. package/v2Containers/MobilePushNew/utils.js +0 -56
  72. package/v2Containers/Rcs/index.js +8 -1
  73. package/v2Containers/Rcs/tests/__snapshots__/index.test.js.snap +59 -0
  74. package/v2Containers/SmsTrai/Create/tests/__snapshots__/index.test.js.snap +4 -0
  75. package/v2Containers/SmsTrai/Edit/index.js +17 -7
  76. package/v2Containers/SmsTrai/Edit/tests/__snapshots__/index.test.js.snap +42 -0
  77. package/v2Containers/Templates/_templates.scss +2 -10
  78. package/v2Containers/Templates/index.js +81 -83
  79. package/v2Containers/Templates/tests/index.test.js +0 -68
  80. package/v2Containers/Viber/index.js +3 -1
  81. package/v2Containers/WebPush/Create/utils/validation.js +6 -0
  82. package/v2Containers/WebPush/Create/utils/validation.test.js +50 -0
  83. package/v2Containers/Whatsapp/index.js +9 -5
  84. package/v2Containers/Whatsapp/tests/__snapshots__/index.test.js.snap +2 -2
  85. package/v2Containers/Zalo/index.js +4 -1
  86. package/v2Components/CapMpushCTA/tests/index.test.js +0 -89
  87. package/v2Containers/MobilePushNew/components/TapLinkActions.js +0 -76
@@ -8,8 +8,8 @@ import {
8
8
  } from "../../constants";
9
9
 
10
10
  // Simple mock components
11
- jest.mock("@capillarytech/cap-ui-library/CapRow", () => ({ children, className }) => <div className={className}>{children}</div>);
12
- jest.mock("@capillarytech/cap-ui-library/CapColumn", () => ({ children, className, onClick }) => <div className={className} onClick={onClick}>{children}</div>);
11
+ jest.mock("@capillarytech/cap-ui-library/CapRow", () => ({ children }) => <div>{children}</div>);
12
+ jest.mock("@capillarytech/cap-ui-library/CapColumn", () => ({ children }) => <div>{children}</div>);
13
13
  jest.mock("@capillarytech/cap-ui-library/CapInput", () => {
14
14
  const MockCapInput = ({
15
15
  value, onChange, errorMessage, error, ...props
@@ -101,15 +101,6 @@ jest.mock("../../messages", () => ({
101
101
  deepLink: { id: "deepLink", defaultMessage: "Deep Link" },
102
102
  externalLink: { id: "externalLink", defaultMessage: "External Link" },
103
103
  enterExternalLink: { id: "enterExternalLink", defaultMessage: "Enter external link" },
104
- notificationTap: { id: "notificationTap", defaultMessage: "Notification tap" },
105
- notificationTapDescription: { id: "notificationTapDescription", defaultMessage: "What happens when someone taps the notification itself." },
106
- whenTappedOpen: { id: "whenTappedOpen", defaultMessage: "When tapped, open" },
107
- tapActionApp: { id: "tapActionApp", defaultMessage: "App (default)" },
108
- tapActionAppHelp: { id: "tapActionAppHelp", defaultMessage: "Opens your app. Choose a link to send people to a specific page instead." },
109
- tapActionDeepLink: { id: "tapActionDeepLink", defaultMessage: "Deep link" },
110
- tapActionExternalLink: { id: "tapActionExternalLink", defaultMessage: "External link" },
111
- url: { id: "url", defaultMessage: "URL" },
112
- enterUrl: { id: "enterUrl", defaultMessage: "Enter URL" },
113
104
  deepLinkKeys: { id: "deepLinkKeys", defaultMessage: "Deep Link Keys" },
114
105
  deepLinkKeysPlaceholder: { id: "deepLinkKeysPlaceholder", defaultMessage: "Enter {key}" },
115
106
  deepLinkKeysRequired: { id: "deepLinkKeysRequired", defaultMessage: "Deep link keys are required" },
@@ -134,7 +125,6 @@ jest.mock("../../constants", () => ({
134
125
  ],
135
126
  DEEP_LINK: "DEEP_LINK",
136
127
  EXTERNAL_LINK: "EXTERNAL_LINK",
137
- TAP_ACTION_APP: "APP",
138
128
  }));
139
129
 
140
130
  describe("PlatformContentFields", () => {
@@ -157,11 +147,11 @@ describe("PlatformContentFields", () => {
157
147
  handleTitleChange: jest.fn(),
158
148
  handleMessageChange: jest.fn(),
159
149
  handleMediaTypeChange: jest.fn(),
160
- handleTapActionChange: jest.fn(),
150
+ handleActionOnClickChange: jest.fn(),
151
+ handleLinkTypeChange: jest.fn(),
161
152
  handleDeepLinkChange: jest.fn(),
162
153
  handleDeepLinkKeysChange: jest.fn(),
163
154
  handleExternalLinkChange: jest.fn(),
164
- handleTapLinkSavedChange: jest.fn(),
165
155
  onTagSelect: jest.fn(),
166
156
  handleOnTagsContextChange: jest.fn(),
167
157
  },
@@ -319,91 +309,30 @@ describe("PlatformContentFields", () => {
319
309
  });
320
310
  });
321
311
 
322
- describe("Notification tap", () => {
323
- // Second select: the first one is Media type
324
- const getTapSelect = (container) => container.querySelectorAll("select")[1];
325
-
326
- it("shows App (default) with its help text when there is no tap action", () => {
327
- const { container } = renderComponent({
328
- content: { ...defaultProps.content, actionOnClick: false },
329
- });
330
-
331
- expect(container.textContent).toContain("Notification tap");
332
- expect(container.textContent).toContain("When tapped, open");
333
- expect(getTapSelect(container)).toHaveValue("APP");
334
- expect(container.textContent).toContain("Opens your app. Choose a link to send people to a specific page instead.");
335
- expect(container.textContent).not.toContain("Buttons and Links");
336
- });
337
-
338
- it("calls the tap action handler with the chosen option", () => {
339
- const { container } = renderComponent();
340
-
341
- fireEvent.change(getTapSelect(container), { target: { value: EXTERNAL_LINK } });
342
-
343
- expect(defaultProps.handlers.handleTapActionChange).toHaveBeenCalledWith(EXTERNAL_LINK);
344
- });
345
-
346
- it("shows the deep link select, without the App help text, for Deep link", () => {
347
- const { container } = renderComponent({
348
- content: { ...defaultProps.content, actionOnClick: true, tapLinkSaved: false, linkType: DEEP_LINK },
349
- });
350
-
351
- expect(getTapSelect(container)).toHaveValue(DEEP_LINK);
352
- expect(container.querySelectorAll("select")).toHaveLength(3);
353
- expect(container.textContent).not.toContain("Opens your app.");
354
- });
355
-
356
- it("shows the URL input for External link", () => {
357
- const { container } = renderComponent({
358
- content: { ...defaultProps.content, actionOnClick: true, tapLinkSaved: false, linkType: EXTERNAL_LINK },
359
- // plain fn: resetMocks wipes jest.fn implementations
360
- formatMessage: (msg) => msg?.defaultMessage ?? "",
361
- });
362
-
363
- expect(getTapSelect(container)).toHaveValue(EXTERNAL_LINK);
364
- expect(container.textContent).toContain("URL");
365
- expect(container.querySelector("#mobile-push-external-link-input")).toHaveAttribute("placeholder", "Enter URL");
366
- });
367
-
368
- // plain fn: resetMocks wipes jest.fn implementations
369
- const plainFormatMessage = (msg) => msg?.defaultMessage ?? "";
370
-
371
- it("shows a saved link as one row; edit reopens it, delete sets App", () => {
372
- const { container } = renderComponent({
373
- content: { ...defaultProps.content, actionOnClick: true, linkType: EXTERNAL_LINK },
374
- formatMessage: plainFormatMessage,
375
- });
312
+ describe("Action on Click", () => {
313
+ it("should call action on click change handler", () => {
314
+ const { getByTestId } = renderComponent();
315
+ const checkbox = getByTestId("action-checkbox");
376
316
 
377
- expect(container.querySelector(".mpush-saved-tap-link")).toBeInTheDocument();
378
- expect(container.textContent).toContain("https://example.com");
379
- expect(container.querySelector("#mobile-push-external-link-input")).toBeNull();
317
+ fireEvent.click(checkbox);
380
318
 
381
- fireEvent.click(container.querySelector(".mpush-saved-tap-link-edit-icon"));
382
- expect(defaultProps.handlers.handleTapLinkSavedChange).toHaveBeenCalledWith(false);
383
- fireEvent.click(container.querySelector(".mpush-saved-tap-link-delete-icon"));
384
- expect(defaultProps.handlers.handleTapActionChange).toHaveBeenCalledWith("APP");
319
+ expect(defaultProps.handlers.handleActionOnClickChange).toHaveBeenCalled();
385
320
  });
386
321
 
387
- it("saves an open link once it is filled", () => {
322
+ it("should show action controls when actionOnClick is true", () => {
388
323
  const { container } = renderComponent({
389
- content: { ...defaultProps.content, actionOnClick: true, tapLinkSaved: false, linkType: EXTERNAL_LINK },
390
- formatMessage: plainFormatMessage,
324
+ content: { ...defaultProps.content, actionOnClick: true },
391
325
  });
392
326
 
393
- const saveButton = container.querySelector(".mpush-tap-save-btn");
394
- expect(saveButton).not.toBeDisabled();
395
- fireEvent.click(saveButton);
396
- expect(defaultProps.handlers.handleTapLinkSavedChange).toHaveBeenCalledWith(true);
327
+ expect(container.textContent).toContain("Link Type");
397
328
  });
398
329
 
399
- it("keeps Save off while the link is empty", () => {
330
+ it("should hide action controls when actionOnClick is false", () => {
400
331
  const { container } = renderComponent({
401
- content: { ...defaultProps.content, actionOnClick: true, tapLinkSaved: false, linkType: DEEP_LINK },
402
- linkProps: { ...defaultProps.linkProps, deepLinkValue: "" },
403
- formatMessage: plainFormatMessage,
332
+ content: { ...defaultProps.content, actionOnClick: false },
404
333
  });
405
334
 
406
- expect(container.querySelector(".mpush-tap-save-btn")).toBeDisabled();
335
+ expect(container.textContent).not.toContain("Link Type");
407
336
  });
408
337
  });
409
338
 
@@ -424,7 +353,7 @@ describe("PlatformContentFields", () => {
424
353
  describe("External Link Input", () => {
425
354
  it("should call external link change handler", () => {
426
355
  const { container } = renderComponent({
427
- content: { ...defaultProps.content, actionOnClick: true, tapLinkSaved: false, linkType: EXTERNAL_LINK },
356
+ content: { ...defaultProps.content, actionOnClick: true, linkType: EXTERNAL_LINK },
428
357
  });
429
358
 
430
359
  const externalLinkInput = container.querySelector('input[value="https://example.com"]');
@@ -437,7 +366,7 @@ describe("PlatformContentFields", () => {
437
366
 
438
367
  it("should display external link error when present", () => {
439
368
  const { getByTestId } = renderComponent({
440
- content: { ...defaultProps.content, actionOnClick: true, tapLinkSaved: false, linkType: EXTERNAL_LINK },
369
+ content: { ...defaultProps.content, actionOnClick: true, linkType: EXTERNAL_LINK },
441
370
  errors: { ...defaultProps.errors, externalLink: "Invalid URL" },
442
371
  });
443
372
 
@@ -451,7 +380,7 @@ describe("PlatformContentFields", () => {
451
380
  content: { ...defaultProps.content, mediaType: "CAROUSEL" },
452
381
  });
453
382
 
454
- expect(container.textContent).not.toContain("Notification tap");
383
+ expect(container.textContent).not.toContain("Buttons and Links");
455
384
  expect(container.textContent).not.toContain("CtaButtons");
456
385
  });
457
386
 
@@ -460,7 +389,7 @@ describe("PlatformContentFields", () => {
460
389
  content: { ...defaultProps.content, mediaType: "IMAGE" },
461
390
  });
462
391
 
463
- expect(container.textContent).toContain("Notification tap");
392
+ expect(container.textContent).toContain("Buttons and Links");
464
393
  });
465
394
  });
466
395
 
@@ -514,7 +443,7 @@ describe("PlatformContentFields", () => {
514
443
  title: 'Test Title',
515
444
  message: 'Test Message',
516
445
  mediaType: 'IMAGE',
517
- actionOnClick: true, tapLinkSaved: false,
446
+ actionOnClick: true,
518
447
  linkType: 'DEEP_LINK',
519
448
  };
520
449
 
@@ -552,7 +481,7 @@ describe("PlatformContentFields", () => {
552
481
  title: 'Test Title',
553
482
  message: 'Test Message',
554
483
  mediaType: 'IMAGE',
555
- actionOnClick: true, tapLinkSaved: false,
484
+ actionOnClick: true,
556
485
  linkType: 'DEEP_LINK',
557
486
  };
558
487
 
@@ -590,7 +519,7 @@ describe("PlatformContentFields", () => {
590
519
  title: 'Test Title',
591
520
  message: 'Test Message',
592
521
  mediaType: 'IMAGE',
593
- actionOnClick: true, tapLinkSaved: false,
522
+ actionOnClick: true,
594
523
  linkType: 'DEEP_LINK',
595
524
  };
596
525
 
@@ -627,7 +556,7 @@ describe("PlatformContentFields", () => {
627
556
  title: 'Test Title',
628
557
  message: 'Test Message',
629
558
  mediaType: 'IMAGE',
630
- actionOnClick: true, tapLinkSaved: false,
559
+ actionOnClick: true,
631
560
  linkType: 'DEEP_LINK',
632
561
  };
633
562
 
@@ -664,7 +593,7 @@ describe("PlatformContentFields", () => {
664
593
  title: 'Test Title',
665
594
  message: 'Test Message',
666
595
  mediaType: 'IMAGE',
667
- actionOnClick: true, tapLinkSaved: false,
596
+ actionOnClick: true,
668
597
  linkType: 'DEEP_LINK',
669
598
  };
670
599
 
@@ -701,7 +630,7 @@ describe("PlatformContentFields", () => {
701
630
  title: 'Test Title',
702
631
  message: 'Test Message',
703
632
  mediaType: 'IMAGE',
704
- actionOnClick: true, tapLinkSaved: false,
633
+ actionOnClick: true,
705
634
  linkType: 'DEEP_LINK',
706
635
  };
707
636
 
@@ -739,7 +668,7 @@ describe("PlatformContentFields", () => {
739
668
  title: 'Test Title',
740
669
  message: 'Test Message',
741
670
  mediaType: 'IMAGE',
742
- actionOnClick: true, tapLinkSaved: false,
671
+ actionOnClick: true,
743
672
  linkType: 'DEEP_LINK',
744
673
  };
745
674
 
@@ -779,7 +708,7 @@ describe("PlatformContentFields", () => {
779
708
  title: 'Test Title',
780
709
  message: 'Test Message',
781
710
  mediaType: 'IMAGE',
782
- actionOnClick: true, tapLinkSaved: false,
711
+ actionOnClick: true,
783
712
  linkType: 'DEEP_LINK',
784
713
  };
785
714
  const mockErrors = {
@@ -809,7 +738,7 @@ describe("PlatformContentFields", () => {
809
738
  describe('Deep link null/undefined handling', () => {
810
739
  it('should handle null deepLink in options', () => {
811
740
  const { container } = renderComponent({
812
- content: { ...defaultProps.content, actionOnClick: true, tapLinkSaved: false, linkType: DEEP_LINK },
741
+ content: { ...defaultProps.content, actionOnClick: true, linkType: DEEP_LINK },
813
742
  linkProps: {
814
743
  deepLink: null, // This should trigger the fallback to empty array
815
744
  deepLinkValue: '',
@@ -823,7 +752,7 @@ describe("PlatformContentFields", () => {
823
752
 
824
753
  it('should handle undefined deepLink in options', () => {
825
754
  const { container } = renderComponent({
826
- content: { ...defaultProps.content, actionOnClick: true, tapLinkSaved: false, linkType: DEEP_LINK },
755
+ content: { ...defaultProps.content, actionOnClick: true, linkType: DEEP_LINK },
827
756
  linkProps: {
828
757
  deepLink: undefined, // This should trigger the fallback to empty array
829
758
  deepLinkValue: '',
@@ -851,7 +780,7 @@ describe("PlatformContentFields", () => {
851
780
  title: 'Test Title',
852
781
  message: 'Test Message',
853
782
  mediaType: 'IMAGE',
854
- actionOnClick: true, tapLinkSaved: false,
783
+ actionOnClick: true,
855
784
  linkType: 'DEEP_LINK',
856
785
  };
857
786
 
@@ -890,7 +819,7 @@ describe("PlatformContentFields", () => {
890
819
  title: 'Test Title',
891
820
  message: 'Test Message',
892
821
  mediaType: 'IMAGE',
893
- actionOnClick: true, tapLinkSaved: false,
822
+ actionOnClick: true,
894
823
  linkType: 'DEEP_LINK',
895
824
  };
896
825
 
@@ -929,7 +858,7 @@ describe("PlatformContentFields", () => {
929
858
  title: 'Test Title',
930
859
  message: 'Test Message',
931
860
  mediaType: 'IMAGE',
932
- actionOnClick: true, tapLinkSaved: false,
861
+ actionOnClick: true,
933
862
  linkType: 'DEEP_LINK',
934
863
  };
935
864
 
@@ -968,7 +897,7 @@ describe("PlatformContentFields", () => {
968
897
  title: 'Test Title',
969
898
  message: 'Test Message',
970
899
  mediaType: 'IMAGE',
971
- actionOnClick: true, tapLinkSaved: false,
900
+ actionOnClick: true,
972
901
  linkType: 'DEEP_LINK',
973
902
  };
974
903
 
@@ -1001,7 +930,7 @@ describe("PlatformContentFields", () => {
1001
930
  const { container } = renderComponent({
1002
931
  content: {
1003
932
  ...defaultProps.content,
1004
- actionOnClick: true, tapLinkSaved: false,
933
+ actionOnClick: true,
1005
934
  linkType: EXTERNAL_LINK,
1006
935
  },
1007
936
  linkProps: {
@@ -50,8 +50,6 @@ export const MEDIA_TYPES_OPTIONS = [
50
50
  export const MOBILE_PUSH_CHANNEL = "MOBILEPUSH";
51
51
  export const ANDROID = "ANDROID";
52
52
  export const IOS = "IOS";
53
- // Platforms dropdown value for Android and iOS together
54
- export const BOTH_PLATFORMS = "BOTH";
55
53
  export const ALLOWED_IMAGE_EXTENSIONS_REGEX = /\.(jpe?g|png)$/i;
56
54
  export const MPUSH_IMG_SIZE = 2000000; // 2MB
57
55
  export const MPUSH_VIDEO_SIZE = 209715200; // 200MB (200 * 1024 * 1024)
@@ -75,9 +73,6 @@ export const LINK_TYPE_OPTIONS = [
75
73
  { label: 'External Link', value: EXTERNAL_LINK },
76
74
  ];
77
75
 
78
- // "When tapped, open" dropdown value for opening the app (no link); the other values are DEEP_LINK / EXTERNAL_LINK
79
- export const TAP_ACTION_APP = 'APP';
80
-
81
76
  export const EXTERNAL_LINK_LOWERCASE = 'external link';
82
77
  export const PRIMARY = 'PRIMARY';
83
78
  export const SECONDARY = 'SECONDARY';
@@ -1,7 +1,7 @@
1
1
  import { renderHook, act } from '@testing-library/react';
2
2
  import usePlatformSync from '../usePlatformSync';
3
3
  import {
4
- ANDROID, GIF, IMAGE, IOS, VIDEO, DEEP_LINK, EXTERNAL_LINK, TAP_ACTION_APP,
4
+ ANDROID, GIF, IMAGE, IOS, VIDEO,
5
5
  } from '../../constants';
6
6
  import { NONE } from '../../../Whatsapp/constants';
7
7
 
@@ -979,68 +979,6 @@ describe('usePlatformSync Hook', () => {
979
979
  });
980
980
  });
981
981
 
982
- describe('handleTapActionChange', () => {
983
- it('turns the tap action on with External link in one update', () => {
984
- const { result } = renderHook(() => usePlatformSync(defaultProps));
985
-
986
- act(() => {
987
- result.current.handleTapActionChange(ANDROID, EXTERNAL_LINK);
988
- });
989
-
990
- expect(mockSetAndroidContent).toHaveBeenCalledTimes(1);
991
- expect(mockSetAndroidContent).toHaveBeenCalledWith(expect.objectContaining({
992
- actionOnClick: true,
993
- linkType: EXTERNAL_LINK,
994
- deepLinkValue: '',
995
- externalLinkValue: '',
996
- }));
997
- expect(mockSetIosContent).not.toHaveBeenCalled();
998
- });
999
-
1000
- it('turns the tap action off and resets the link for App', () => {
1001
- const props = {
1002
- ...defaultProps,
1003
- iosContent: {
1004
- ...defaultIosContent, actionOnClick: true, linkType: EXTERNAL_LINK, externalLinkValue: 'https://x.com',
1005
- },
1006
- };
1007
- const { result } = renderHook(() => usePlatformSync(props));
1008
-
1009
- act(() => {
1010
- result.current.handleTapActionChange(IOS, TAP_ACTION_APP);
1011
- });
1012
-
1013
- expect(mockSetIosContent).toHaveBeenCalledWith(expect.objectContaining({
1014
- actionOnClick: false,
1015
- linkType: DEEP_LINK,
1016
- externalLinkValue: '',
1017
- }));
1018
- });
1019
-
1020
- it('does nothing when the same option is chosen again', () => {
1021
- const { result } = renderHook(() => usePlatformSync(defaultProps));
1022
-
1023
- act(() => {
1024
- result.current.handleTapActionChange(ANDROID, TAP_ACTION_APP);
1025
- });
1026
-
1027
- expect(mockSetAndroidContent).not.toHaveBeenCalled();
1028
- });
1029
-
1030
- it('syncs to the other platform when sync is enabled', () => {
1031
- const { result } = renderHook(() => usePlatformSync({ ...defaultProps, sameContent: true }));
1032
-
1033
- act(() => {
1034
- result.current.handleTapActionChange(ANDROID, DEEP_LINK);
1035
- });
1036
-
1037
- expect(mockSetIosContent).toHaveBeenCalledWith(expect.objectContaining({
1038
- actionOnClick: true,
1039
- linkType: DEEP_LINK,
1040
- }));
1041
- });
1042
- });
1043
-
1044
982
  describe('handleLinkTypeChange', () => {
1045
983
  it('should update Android linkType when sync is disabled', () => {
1046
984
  const { result } = renderHook(() => usePlatformSync(defaultProps));
@@ -1121,19 +1121,6 @@ describe('useUpload Hook', () => {
1121
1121
  });
1122
1122
  });
1123
1123
 
1124
- it('clears the platform it is given, not the visible tab', () => {
1125
- const { result } = createHook({ sameContent: false, activeTab: ANDROID });
1126
- act(() => {
1127
- result.current.setImageSrc({ androidImageSrc: 'a.jpg', iosImageSrc: 'b.jpg' });
1128
- });
1129
-
1130
- act(() => {
1131
- result.current.clearImageDataByMediaType(IMAGE, IOS);
1132
- });
1133
-
1134
- expect(result.current.imageSrc).toEqual({ androidImageSrc: 'a.jpg', iosImageSrc: '' });
1135
- });
1136
-
1137
1124
  it('should clear video data with sync enabled', () => {
1138
1125
  const { result } = createHook({ sameContent: true });
1139
1126
 
@@ -1469,43 +1456,4 @@ describe('useUpload Hook', () => {
1469
1456
  });
1470
1457
  });
1471
1458
  });
1472
-
1473
- describe('Ticking same content', () => {
1474
- // Android has image A, iOS has video V; then tick on the given tab
1475
- const renderAndTick = (activeTab) => {
1476
- const hook = renderHook(({ sameContent }) => useUpload(
1477
- mockMobilePushActions, {}, {}, {}, false, sameContent,
1478
- mockSetAndroidContent, mockSetIosContent, activeTab, androidContent, iosContent, mockFormatMessage,
1479
- ), { initialProps: { sameContent: false } });
1480
- act(() => {
1481
- hook.result.current.setImageSrc({ androidImageSrc: 'A.jpg', iosImageSrc: '' });
1482
- hook.result.current.setUpdateMpushVideoSrc(1, { videoSrc: 'V.mp4', previewUrl: 'V.jpg', videoDuration: 5 });
1483
- });
1484
- hook.rerender({ sameContent: true });
1485
- return hook.result;
1486
- };
1487
-
1488
- it('wipes the iOS video when ticked on Android, which has none', () => {
1489
- const result = renderAndTick(ANDROID);
1490
- expect(result.current.videoState).toEqual({
1491
- androidVideoSrc: '',
1492
- iosVideoSrc: '',
1493
- androidVideoPreview: '',
1494
- iosVideoPreview: '',
1495
- androidVideoDuration: 0,
1496
- iosVideoDuration: 0,
1497
- });
1498
- expect(result.current.iosAssetList).toEqual([]);
1499
- expect(result.current.imageSrc).toEqual({ androidImageSrc: 'A.jpg', iosImageSrc: 'A.jpg' });
1500
- expect(androidContent.videoSrc).toBe('');
1501
- expect(iosContent.videoSrc).toBe('');
1502
- });
1503
-
1504
- it('wipes the Android image when ticked on iOS, which has none', () => {
1505
- const result = renderAndTick(IOS);
1506
- expect(result.current.imageSrc).toEqual({ androidImageSrc: '', iosImageSrc: '' });
1507
- expect(result.current.videoState.androidVideoSrc).toBe('V.mp4');
1508
- expect(result.current.androidAssetList).toMatchObject({ videoSrc: 'V.mp4' });
1509
- });
1510
- });
1511
1459
  });
@@ -1,7 +1,7 @@
1
1
  // eslint-disable-next-line jsx-a11y/href-no-hash
2
2
  import { useCallback, useEffect, useRef } from 'react';
3
3
  import {
4
- ANDROID, DEEP_LINK, GIF, IMAGE, IOS, VIDEO, TAP_ACTION_APP,
4
+ ANDROID, DEEP_LINK, GIF, IMAGE, IOS, VIDEO,
5
5
  } from '../constants';
6
6
  import { NONE } from '../../Whatsapp/constants';
7
7
 
@@ -353,44 +353,6 @@ const usePlatformSync = ({
353
353
  }
354
354
  }, [androidContent, iosContent, setAndroidContent, setIosContent, sameContent, deepSyncContent]);
355
355
 
356
- // "When tapped, open" dropdown: TAP_ACTION_APP turns the tap action off, DEEP_LINK / EXTERNAL_LINK
357
- // turn it on with that link type. One update, so actionOnClick and linkType can't overwrite each other.
358
- const handleTapActionChange = useCallback((platform, value) => {
359
- const {
360
- setContent,
361
- otherSetContent,
362
- otherContent,
363
- currentContent,
364
- targetPlatform,
365
- } = getPlatformContent(platform, {
366
- androidContent,
367
- iosContent,
368
- setAndroidContent,
369
- setIosContent,
370
- });
371
-
372
- const isApp = value === TAP_ACTION_APP;
373
- const currentValue = currentContent?.actionOnClick ? (currentContent?.linkType || DEEP_LINK) : TAP_ACTION_APP;
374
- if (value === currentValue) return;
375
-
376
- const newContent = {
377
- ...currentContent,
378
- actionOnClick: !isApp,
379
- linkType: isApp ? DEEP_LINK : value,
380
- deepLinkValue: "",
381
- deepLinkKeysValue: [],
382
- externalLinkValue: "",
383
- // A new link stays open until its Save is clicked
384
- tapLinkSaved: isApp ? undefined : false,
385
- };
386
- setContent(newContent);
387
-
388
- if (sameContent) {
389
- const synced = deepSyncContent(newContent, otherContent, targetPlatform);
390
- otherSetContent(synced);
391
- }
392
- }, [androidContent, iosContent, setAndroidContent, setIosContent, sameContent, deepSyncContent]);
393
-
394
356
  return {
395
357
  handleTitleChange,
396
358
  handleMessageChange,
@@ -399,7 +361,6 @@ const usePlatformSync = ({
399
361
  handleButtonChange,
400
362
  handleActionOnClickChange,
401
363
  handleLinkTypeChange,
402
- handleTapActionChange,
403
364
  };
404
365
  };
405
366
 
@@ -148,9 +148,8 @@ const useUpload = (mobilePushActions, editData = {}, _uploadedAssetData0 = {}, _
148
148
  mobilePushActions.uploadAsset(file, assetType, fileParams, activeTab === ANDROID ? 0 : 1, mobilePushParams);
149
149
  }, [mobilePushActions, validateImageFile, validateVideoFile, validateGifFile, activeTab]);
150
150
 
151
- // Clear media data when switching media types.
152
- // platform: the tab whose media changed (defaults to the visible tab).
153
- const clearImageDataByMediaType = useCallback((mediaType, platform = activeTab) => {
151
+ // Clear media data when switching media types
152
+ const clearImageDataByMediaType = useCallback((mediaType) => {
154
153
  if (mediaType === IMAGE) {
155
154
  if (sameContent) {
156
155
  // When sync is enabled, clear both platforms
@@ -159,11 +158,11 @@ const useUpload = (mobilePushActions, editData = {}, _uploadedAssetData0 = {}, _
159
158
  iosImageSrc: "",
160
159
  });
161
160
  } else {
162
- // When sync is disabled, only clear that platform
163
- const platformKey = platform === ANDROID ? 'androidImageSrc' : 'iosImageSrc';
161
+ // When sync is disabled, only clear the current platform
162
+ const platform = activeTab === ANDROID ? 'androidImageSrc' : 'iosImageSrc';
164
163
  setImageSrc((prevState) => ({
165
164
  ...prevState,
166
- [platformKey]: "",
165
+ [platform]: "",
167
166
  }));
168
167
  }
169
168
  } else if (mediaType === VIDEO || mediaType === GIF) {
@@ -197,9 +196,9 @@ const useUpload = (mobilePushActions, editData = {}, _uploadedAssetData0 = {}, _
197
196
  mobilePushActions.clearAsset(0);
198
197
  mobilePushActions.clearAsset(1);
199
198
  } else {
200
- // When sync is disabled, only clear that platform
201
- const platformIndex = platform === ANDROID ? 0 : 1;
202
- const isAndroid = platform === ANDROID;
199
+ // When sync is disabled, only clear the current platform
200
+ const platformIndex = activeTab === ANDROID ? 0 : 1;
201
+ const isAndroid = activeTab === ANDROID;
203
202
  const videoProps = getVideoProperties(isAndroid);
204
203
 
205
204
  setVideoState((prevState) => ({
@@ -294,11 +293,17 @@ const useUpload = (mobilePushActions, editData = {}, _uploadedAssetData0 = {}, _
294
293
  }
295
294
  }, [videoState?.androidVideoSrc, videoState?.iosVideoSrc, videoState?.androidVideoPreview, videoState?.iosVideoPreview, videoState?.androidVideoDuration, videoState?.iosVideoDuration, sameContent]);
296
295
 
297
- // On tick, copy the active tab's image to both tabs, even when it has none
296
+ // Sync imageSrc state for both platforms when sameContent is toggled ON
298
297
  useEffect(() => {
299
298
  if (sameContent) {
300
- const currentImageSrc = (activeTab === ANDROID ? imageSrc?.androidImageSrc : imageSrc?.iosImageSrc) || '';
301
- if (imageSrc?.androidImageSrc !== currentImageSrc || imageSrc?.iosImageSrc !== currentImageSrc) {
299
+ // Determine which image to use (prefer activeTab, fallback to either)
300
+ let currentImageSrc = '';
301
+ if (activeTab === ANDROID) {
302
+ currentImageSrc = imageSrc?.androidImageSrc || imageSrc?.iosImageSrc;
303
+ } else {
304
+ currentImageSrc = imageSrc?.iosImageSrc || imageSrc?.androidImageSrc;
305
+ }
306
+ if (currentImageSrc && (imageSrc?.androidImageSrc !== currentImageSrc || imageSrc?.iosImageSrc !== currentImageSrc)) {
302
307
  setImageSrc({
303
308
  androidImageSrc: currentImageSrc,
304
309
  iosImageSrc: currentImageSrc,
@@ -309,20 +314,31 @@ const useUpload = (mobilePushActions, editData = {}, _uploadedAssetData0 = {}, _
309
314
  // eslint-disable-next-line react-hooks/exhaustive-deps
310
315
  }, [sameContent, activeTab]);
311
316
 
312
- // On tick, copy the active tab's video to both tabs, even when it has none
317
+ // Sync videoState for both platforms when sameContent is toggled ON
313
318
  useEffect(() => {
314
319
  if (sameContent) {
315
- const isAndroid = activeTab === ANDROID;
316
- const currentVideoSrc = (isAndroid ? videoState?.androidVideoSrc : videoState?.iosVideoSrc) || '';
317
- const currentVideoPreview = (isAndroid ? videoState?.androidVideoPreview : videoState?.iosVideoPreview) || '';
318
- const currentVideoDuration = (isAndroid ? videoState?.androidVideoDuration : videoState?.iosVideoDuration) || 0;
320
+ // Determine which video to use (prefer activeTab, fallback to either)
321
+ let currentVideoSrc = '';
322
+ let currentVideoPreview = '';
323
+ let currentVideoDuration = 0;
324
+ if (activeTab === ANDROID) {
325
+ currentVideoSrc = videoState?.androidVideoSrc || videoState?.iosVideoSrc;
326
+ currentVideoPreview = videoState?.androidVideoPreview || videoState?.iosVideoPreview;
327
+ currentVideoDuration = videoState?.androidVideoDuration || videoState?.iosVideoDuration;
328
+ } else {
329
+ currentVideoSrc = videoState?.iosVideoSrc || videoState?.androidVideoSrc;
330
+ currentVideoPreview = videoState?.iosVideoPreview || videoState?.androidVideoPreview;
331
+ currentVideoDuration = videoState?.iosVideoDuration || videoState?.androidVideoDuration;
332
+ }
319
333
  if (
320
- videoState?.androidVideoSrc !== currentVideoSrc
321
- || videoState?.iosVideoSrc !== currentVideoSrc
322
- || videoState?.androidVideoPreview !== currentVideoPreview
323
- || videoState?.iosVideoPreview !== currentVideoPreview
324
- || videoState?.androidVideoDuration !== currentVideoDuration
325
- || videoState?.iosVideoDuration !== currentVideoDuration
334
+ currentVideoSrc && (
335
+ videoState?.androidVideoSrc !== currentVideoSrc
336
+ || videoState?.iosVideoSrc !== currentVideoSrc
337
+ || videoState?.androidVideoPreview !== currentVideoPreview
338
+ || videoState?.iosVideoPreview !== currentVideoPreview
339
+ || videoState?.androidVideoDuration !== currentVideoDuration
340
+ || videoState?.iosVideoDuration !== currentVideoDuration
341
+ )
326
342
  ) {
327
343
  setVideoState({
328
344
  androidVideoSrc: currentVideoSrc,
@@ -333,12 +349,6 @@ const useUpload = (mobilePushActions, editData = {}, _uploadedAssetData0 = {}, _
333
349
  iosVideoDuration: currentVideoDuration,
334
350
  });
335
351
  }
336
- // The upload box also reads the uploaded-file list
337
- const sourceAssetList = isAndroid ? androidAssetList : iosAssetList;
338
- const targetAssetList = isAndroid ? iosAssetList : androidAssetList;
339
- if (JSON.stringify(sourceAssetList) !== JSON.stringify(targetAssetList)) {
340
- (isAndroid ? updateIosAssetList : updateAndroidAssetList)(sourceAssetList);
341
- }
342
352
  }
343
353
  // Only run when sameContent or activeTab changes
344
354
  // eslint-disable-next-line react-hooks/exhaustive-deps