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

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 (47) 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 -56
  5. package/utils/tests/createMobilePushPayload.test.js +177 -168
  6. package/v2Components/CapMpushCTA/index.js +47 -57
  7. package/v2Components/CapMpushCTA/index.scss +43 -5
  8. package/v2Components/CapMpushCTA/tests/index.test.js +150 -0
  9. package/v2Components/CommonTestAndPreview/UnifiedPreview/MobilePushPreviewContent.js +11 -8
  10. package/v2Components/CommonTestAndPreview/UnifiedPreview/_unifiedPreview.scss +13 -1
  11. package/v2Components/CommonTestAndPreview/constants.js +2 -0
  12. package/v2Components/CommonTestAndPreview/index.js +51 -12
  13. package/v2Components/CommonTestAndPreview/tests/UnifiedPreview/MobilePushPreviewContent.test.js +83 -5
  14. package/v2Components/CommonTestAndPreview/tests/index.test.js +100 -0
  15. package/v2Components/MobilePushPreviewV2/_mobilePushPreviewV2.scss +7 -0
  16. package/v2Components/MobilePushPreviewV2/index.js +22 -9
  17. package/v2Components/MobilePushPreviewV2/tests/index.test.js +55 -0
  18. package/v2Components/TemplatePreview/_mobilePushPhone.scss +72 -0
  19. package/v2Components/TemplatePreview/_templatePreview.scss +18 -2
  20. package/v2Components/TemplatePreview/index.js +20 -18
  21. package/v2Components/TemplatePreview/tests/index.test.js +69 -0
  22. package/v2Containers/CommunicationFlow/steps/ChannelSelectionStep/Tests/extractContentForPreview.test.js +45 -0
  23. package/v2Containers/CommunicationFlow/steps/ChannelSelectionStep/extractContentForPreview.js +12 -2
  24. package/v2Containers/CreativesContainer/SlideBoxContent.js +4 -6
  25. package/v2Containers/CreativesContainer/index.js +2 -1
  26. package/v2Containers/CreativesContainer/tests/SlideBoxContent.test.js +43 -0
  27. package/v2Containers/MobilePushNew/components/CtaButtons.js +52 -47
  28. package/v2Containers/MobilePushNew/components/MediaUploaders.js +105 -345
  29. package/v2Containers/MobilePushNew/components/PlatformContentFields.js +127 -105
  30. package/v2Containers/MobilePushNew/components/TapLinkActions.js +76 -0
  31. package/v2Containers/MobilePushNew/components/tests/CtaButtons.test.js +30 -208
  32. package/v2Containers/MobilePushNew/components/tests/MediaUploaders.test.js +305 -1482
  33. package/v2Containers/MobilePushNew/components/tests/PlatformContentFields.test.js +165 -59
  34. package/v2Containers/MobilePushNew/constants.js +12 -0
  35. package/v2Containers/MobilePushNew/hooks/tests/usePlatformSync.test.js +63 -1
  36. package/v2Containers/MobilePushNew/hooks/tests/useUpload.test.js +78 -0
  37. package/v2Containers/MobilePushNew/hooks/usePlatformSync.js +40 -1
  38. package/v2Containers/MobilePushNew/hooks/useUpload.js +42 -46
  39. package/v2Containers/MobilePushNew/index.js +498 -289
  40. package/v2Containers/MobilePushNew/index.scss +151 -4
  41. package/v2Containers/MobilePushNew/messages.js +106 -6
  42. package/v2Containers/MobilePushNew/tests/index.test.js +483 -1
  43. package/v2Containers/MobilePushNew/tests/utils.test.js +110 -0
  44. package/v2Containers/MobilePushNew/utils.js +83 -0
  45. package/v2Containers/Templates/_templates.scss +10 -2
  46. package/v2Containers/Templates/index.js +86 -81
  47. package/v2Containers/Templates/tests/index.test.js +81 -0
@@ -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 }) => <div>{children}</div>);
12
- jest.mock("@capillarytech/cap-ui-library/CapColumn", () => ({ children }) => <div>{children}</div>);
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>);
13
13
  jest.mock("@capillarytech/cap-ui-library/CapInput", () => {
14
14
  const MockCapInput = ({
15
15
  value, onChange, errorMessage, error, ...props
@@ -39,17 +39,15 @@ jest.mock("@capillarytech/cap-ui-library/CapInput", () => {
39
39
  jest.mock("@capillarytech/cap-ui-library/CapHeading", () => ({ children }) => <div>{children}</div>);
40
40
  jest.mock("@capillarytech/cap-ui-library/CapError", () => ({ children }) => <div data-testid="cap-error">{children}</div>);
41
41
  jest.mock("@capillarytech/cap-ui-library/CapDivider", () => () => <div data-testid="divider" />);
42
- jest.mock("@capillarytech/cap-ui-library/CapSelect", () => ({
43
- CapCustomSelect: ({ value, onChange, options }) => (
44
- <select value={value} onChange={(e) => onChange && onChange(e.target.value)}>
45
- {options?.map((option) => (
46
- <option key={option.value} value={option.value}>
47
- {option.label}
48
- </option>
49
- ))}
50
- </select>
51
- ),
52
- }));
42
+ jest.mock("@capillarytech/cap-ui-library/CapSelect", () => ({ value, onChange, options }) => (
43
+ <select value={value} onChange={(e) => onChange && onChange(e.target.value)}>
44
+ {options?.map((option) => (
45
+ <option key={option.value} value={option.value}>
46
+ {option.label}
47
+ </option>
48
+ ))}
49
+ </select>
50
+ ));
53
51
  jest.mock("@capillarytech/cap-ui-library/CapCheckbox", () => ({ checked, onChange, children }) => (
54
52
  <div>
55
53
  <input type="checkbox" checked={checked} onChange={onChange} data-testid="action-checkbox" />
@@ -101,8 +99,18 @@ jest.mock("../../messages", () => ({
101
99
  deepLink: { id: "deepLink", defaultMessage: "Deep Link" },
102
100
  externalLink: { id: "externalLink", defaultMessage: "External Link" },
103
101
  enterExternalLink: { id: "enterExternalLink", defaultMessage: "Enter external link" },
102
+ notificationTap: { id: "notificationTap", defaultMessage: "Notification tap" },
103
+ notificationTapDescription: { id: "notificationTapDescription", defaultMessage: "What happens when someone taps the notification itself." },
104
+ whenTappedOpen: { id: "whenTappedOpen", defaultMessage: "When tapped, open" },
105
+ tapActionApp: { id: "tapActionApp", defaultMessage: "App (default)" },
106
+ tapActionAppHelp: { id: "tapActionAppHelp", defaultMessage: "Opens your app. Choose a link to send people to a specific page instead." },
107
+ tapActionDeepLink: { id: "tapActionDeepLink", defaultMessage: "Deep link" },
108
+ tapActionExternalLink: { id: "tapActionExternalLink", defaultMessage: "External link" },
109
+ url: { id: "url", defaultMessage: "URL" },
110
+ enterUrl: { id: "enterUrl", defaultMessage: "Enter URL" },
104
111
  deepLinkKeys: { id: "deepLinkKeys", defaultMessage: "Deep Link Keys" },
105
112
  deepLinkKeysPlaceholder: { id: "deepLinkKeysPlaceholder", defaultMessage: "Enter {key}" },
113
+ tapLinkSaveDisabled: { id: "tapLinkSaveDisabled", defaultMessage: "Please complete the above fields to enable Save" },
106
114
  deepLinkKeysRequired: { id: "deepLinkKeysRequired", defaultMessage: "Deep link keys are required" },
107
115
  addLabels: { id: "addLabels", defaultMessage: "Add labels" },
108
116
  personalizationTagsErrorMessage: { id: "personalizationTagsErrorMessage", defaultMessage: "Personalization tags are not supported for anonymous customers, please remove the tags." },
@@ -125,6 +133,12 @@ jest.mock("../../constants", () => ({
125
133
  ],
126
134
  DEEP_LINK: "DEEP_LINK",
127
135
  EXTERNAL_LINK: "EXTERNAL_LINK",
136
+ TAP_ACTION_APP: "APP",
137
+ TAP_ACTION_OPTIONS: [
138
+ { labelKey: "tapActionApp", value: "APP" },
139
+ { labelKey: "tapActionDeepLink", value: "DEEP_LINK" },
140
+ { labelKey: "tapActionExternalLink", value: "EXTERNAL_LINK" },
141
+ ],
128
142
  }));
129
143
 
130
144
  describe("PlatformContentFields", () => {
@@ -147,11 +161,11 @@ describe("PlatformContentFields", () => {
147
161
  handleTitleChange: jest.fn(),
148
162
  handleMessageChange: jest.fn(),
149
163
  handleMediaTypeChange: jest.fn(),
150
- handleActionOnClickChange: jest.fn(),
151
- handleLinkTypeChange: jest.fn(),
164
+ handleTapActionChange: jest.fn(),
152
165
  handleDeepLinkChange: jest.fn(),
153
166
  handleDeepLinkKeysChange: jest.fn(),
154
167
  handleExternalLinkChange: jest.fn(),
168
+ handleTapLinkSavedChange: jest.fn(),
155
169
  onTagSelect: jest.fn(),
156
170
  handleOnTagsContextChange: jest.fn(),
157
171
  },
@@ -309,30 +323,91 @@ describe("PlatformContentFields", () => {
309
323
  });
310
324
  });
311
325
 
312
- describe("Action on Click", () => {
313
- it("should call action on click change handler", () => {
314
- const { getByTestId } = renderComponent();
315
- const checkbox = getByTestId("action-checkbox");
326
+ describe("Notification tap", () => {
327
+ // Second select: the first one is Media type
328
+ const getTapSelect = (container) => container.querySelectorAll("select")[1];
329
+
330
+ it("shows App (default) with its help text when there is no tap action", () => {
331
+ const { container } = renderComponent({
332
+ content: { ...defaultProps.content, actionOnClick: false },
333
+ });
334
+
335
+ expect(container.textContent).toContain("Notification tap");
336
+ expect(container.textContent).toContain("When tapped, open");
337
+ expect(getTapSelect(container)).toHaveValue("APP");
338
+ expect(container.textContent).toContain("Opens your app. Choose a link to send people to a specific page instead.");
339
+ expect(container.textContent).not.toContain("Buttons and Links");
340
+ });
341
+
342
+ it("calls the tap action handler with the chosen option", () => {
343
+ const { container } = renderComponent();
316
344
 
317
- fireEvent.click(checkbox);
345
+ fireEvent.change(getTapSelect(container), { target: { value: EXTERNAL_LINK } });
318
346
 
319
- expect(defaultProps.handlers.handleActionOnClickChange).toHaveBeenCalled();
347
+ expect(defaultProps.handlers.handleTapActionChange).toHaveBeenCalledWith(EXTERNAL_LINK);
320
348
  });
321
349
 
322
- it("should show action controls when actionOnClick is true", () => {
350
+ it("shows the deep link select, without the App help text, for Deep link", () => {
323
351
  const { container } = renderComponent({
324
- content: { ...defaultProps.content, actionOnClick: true },
352
+ content: { ...defaultProps.content, actionOnClick: true, tapLinkSaved: false, linkType: DEEP_LINK },
325
353
  });
326
354
 
327
- expect(container.textContent).toContain("Link Type");
355
+ expect(getTapSelect(container)).toHaveValue(DEEP_LINK);
356
+ expect(container.querySelectorAll("select")).toHaveLength(3);
357
+ expect(container.textContent).not.toContain("Opens your app.");
328
358
  });
329
359
 
330
- it("should hide action controls when actionOnClick is false", () => {
360
+ it("shows the URL input for External link", () => {
331
361
  const { container } = renderComponent({
332
- content: { ...defaultProps.content, actionOnClick: false },
362
+ content: { ...defaultProps.content, actionOnClick: true, tapLinkSaved: false, linkType: EXTERNAL_LINK },
363
+ // plain fn: resetMocks wipes jest.fn implementations
364
+ formatMessage: (msg) => msg?.defaultMessage ?? "",
365
+ });
366
+
367
+ expect(getTapSelect(container)).toHaveValue(EXTERNAL_LINK);
368
+ expect(container.textContent).toContain("URL");
369
+ expect(container.querySelector("#mobile-push-external-link-input")).toHaveAttribute("placeholder", "Enter URL");
370
+ });
371
+
372
+ // plain fn: resetMocks wipes jest.fn implementations
373
+ const plainFormatMessage = (msg) => msg?.defaultMessage ?? "";
374
+
375
+ it("shows a saved link as one row; edit reopens it, delete sets App", () => {
376
+ const { container } = renderComponent({
377
+ content: { ...defaultProps.content, actionOnClick: true, linkType: EXTERNAL_LINK },
378
+ formatMessage: plainFormatMessage,
379
+ });
380
+
381
+ expect(container.querySelector(".mpush-saved-tap-link")).toBeInTheDocument();
382
+ expect(container.textContent).toContain("https://example.com");
383
+ expect(container.querySelector("#mobile-push-external-link-input")).toBeNull();
384
+
385
+ fireEvent.click(container.querySelector(".mpush-saved-tap-link-edit-icon"));
386
+ expect(defaultProps.handlers.handleTapLinkSavedChange).toHaveBeenCalledWith(false);
387
+ fireEvent.click(container.querySelector(".mpush-saved-tap-link-delete-icon"));
388
+ expect(defaultProps.handlers.handleTapActionChange).toHaveBeenCalledWith("APP");
389
+ });
390
+
391
+ it("saves an open link once it is filled", () => {
392
+ const { container } = renderComponent({
393
+ content: { ...defaultProps.content, actionOnClick: true, tapLinkSaved: false, linkType: EXTERNAL_LINK },
394
+ formatMessage: plainFormatMessage,
395
+ });
396
+
397
+ const saveButton = container.querySelector(".mpush-tap-save-btn");
398
+ expect(saveButton).not.toBeDisabled();
399
+ fireEvent.click(saveButton);
400
+ expect(defaultProps.handlers.handleTapLinkSavedChange).toHaveBeenCalledWith(true);
401
+ });
402
+
403
+ it("keeps Save off while the link is empty", () => {
404
+ const { container } = renderComponent({
405
+ content: { ...defaultProps.content, actionOnClick: true, tapLinkSaved: false, linkType: DEEP_LINK },
406
+ linkProps: { ...defaultProps.linkProps, deepLinkValue: "" },
407
+ formatMessage: plainFormatMessage,
333
408
  });
334
409
 
335
- expect(container.textContent).not.toContain("Link Type");
410
+ expect(container.querySelector(".mpush-tap-save-btn")).toBeDisabled();
336
411
  });
337
412
  });
338
413
 
@@ -353,7 +428,7 @@ describe("PlatformContentFields", () => {
353
428
  describe("External Link Input", () => {
354
429
  it("should call external link change handler", () => {
355
430
  const { container } = renderComponent({
356
- content: { ...defaultProps.content, actionOnClick: true, linkType: EXTERNAL_LINK },
431
+ content: { ...defaultProps.content, actionOnClick: true, tapLinkSaved: false, linkType: EXTERNAL_LINK },
357
432
  });
358
433
 
359
434
  const externalLinkInput = container.querySelector('input[value="https://example.com"]');
@@ -366,7 +441,7 @@ describe("PlatformContentFields", () => {
366
441
 
367
442
  it("should display external link error when present", () => {
368
443
  const { getByTestId } = renderComponent({
369
- content: { ...defaultProps.content, actionOnClick: true, linkType: EXTERNAL_LINK },
444
+ content: { ...defaultProps.content, actionOnClick: true, tapLinkSaved: false, linkType: EXTERNAL_LINK },
370
445
  errors: { ...defaultProps.errors, externalLink: "Invalid URL" },
371
446
  });
372
447
 
@@ -375,21 +450,23 @@ describe("PlatformContentFields", () => {
375
450
  });
376
451
 
377
452
  describe("Carousel Media Type", () => {
378
- it("should hide action controls when mediaType is CAROUSEL", () => {
453
+ it("shows Notification tap but hides Buttons when mediaType is CAROUSEL", () => {
379
454
  const { container } = renderComponent({
380
455
  content: { ...defaultProps.content, mediaType: "CAROUSEL" },
381
456
  });
382
457
 
383
- expect(container.textContent).not.toContain("Buttons and Links");
458
+ // Notification tap is for the whole notification, carousel included
459
+ expect(container.textContent).toContain("Notification tap");
384
460
  expect(container.textContent).not.toContain("CtaButtons");
385
461
  });
386
462
 
387
- it("should show action controls when mediaType is not CAROUSEL", () => {
463
+ it("shows Notification tap and Buttons when mediaType is not CAROUSEL", () => {
388
464
  const { container } = renderComponent({
389
465
  content: { ...defaultProps.content, mediaType: "IMAGE" },
390
466
  });
391
467
 
392
- expect(container.textContent).toContain("Buttons and Links");
468
+ expect(container.textContent).toContain("Notification tap");
469
+ expect(container.textContent).toContain("CtaButtons");
393
470
  });
394
471
  });
395
472
 
@@ -436,14 +513,14 @@ describe("PlatformContentFields", () => {
436
513
  const mockLinkProps = {
437
514
  deepLink: mockDeepLink,
438
515
  deepLinkValue: 'test-deep-link',
439
- deepLinkKeysValue: ['key1', 'key2'],
516
+ deepLinkKeysValue: ['key1=value1', 'key2=value2'],
440
517
  externalLinkValue: '',
441
518
  };
442
519
  const mockContent = {
443
520
  title: 'Test Title',
444
521
  message: 'Test Message',
445
522
  mediaType: 'IMAGE',
446
- actionOnClick: true,
523
+ actionOnClick: true, tapLinkSaved: false,
447
524
  linkType: 'DEEP_LINK',
448
525
  };
449
526
 
@@ -462,9 +539,11 @@ describe("PlatformContentFields", () => {
462
539
  />
463
540
  );
464
541
 
465
- // Check that deep link keys are displayed correctly
466
- expect(getByText('key1, key2')).toBeInTheDocument();
467
- expect(getByDisplayValue('key1, key2')).toBeInTheDocument();
542
+ // One input per configured key, showing the value typed for it
543
+ expect(getByText('key1')).toBeInTheDocument();
544
+ expect(getByText('key2')).toBeInTheDocument();
545
+ expect(getByDisplayValue('value1')).toBeInTheDocument();
546
+ expect(getByDisplayValue('value2')).toBeInTheDocument();
468
547
  });
469
548
 
470
549
  it('should handle deep link keys with single key from selection', () => {
@@ -481,7 +560,7 @@ describe("PlatformContentFields", () => {
481
560
  title: 'Test Title',
482
561
  message: 'Test Message',
483
562
  mediaType: 'IMAGE',
484
- actionOnClick: true,
563
+ actionOnClick: true, tapLinkSaved: false,
485
564
  linkType: 'DEEP_LINK',
486
565
  };
487
566
 
@@ -519,7 +598,7 @@ describe("PlatformContentFields", () => {
519
598
  title: 'Test Title',
520
599
  message: 'Test Message',
521
600
  mediaType: 'IMAGE',
522
- actionOnClick: true,
601
+ actionOnClick: true, tapLinkSaved: false,
523
602
  linkType: 'DEEP_LINK',
524
603
  };
525
604
 
@@ -556,7 +635,7 @@ describe("PlatformContentFields", () => {
556
635
  title: 'Test Title',
557
636
  message: 'Test Message',
558
637
  mediaType: 'IMAGE',
559
- actionOnClick: true,
638
+ actionOnClick: true, tapLinkSaved: false,
560
639
  linkType: 'DEEP_LINK',
561
640
  };
562
641
 
@@ -586,14 +665,14 @@ describe("PlatformContentFields", () => {
586
665
  const mockLinkProps = {
587
666
  deepLink: mockDeepLink,
588
667
  deepLinkValue: 'test-deep-link',
589
- deepLinkKeysValue: 'string-key-value',
668
+ deepLinkKeysValue: 'single-key=string-key-value',
590
669
  externalLinkValue: '',
591
670
  };
592
671
  const mockContent = {
593
672
  title: 'Test Title',
594
673
  message: 'Test Message',
595
674
  mediaType: 'IMAGE',
596
- actionOnClick: true,
675
+ actionOnClick: true, tapLinkSaved: false,
597
676
  linkType: 'DEEP_LINK',
598
677
  };
599
678
 
@@ -630,7 +709,7 @@ describe("PlatformContentFields", () => {
630
709
  title: 'Test Title',
631
710
  message: 'Test Message',
632
711
  mediaType: 'IMAGE',
633
- actionOnClick: true,
712
+ actionOnClick: true, tapLinkSaved: false,
634
713
  linkType: 'DEEP_LINK',
635
714
  };
636
715
 
@@ -668,7 +747,7 @@ describe("PlatformContentFields", () => {
668
747
  title: 'Test Title',
669
748
  message: 'Test Message',
670
749
  mediaType: 'IMAGE',
671
- actionOnClick: true,
750
+ actionOnClick: true, tapLinkSaved: false,
672
751
  linkType: 'DEEP_LINK',
673
752
  };
674
753
 
@@ -687,11 +766,9 @@ describe("PlatformContentFields", () => {
687
766
  />
688
767
  );
689
768
 
690
- // Verify that formatMessage was called with the fallback placeholder
691
- expect(defaultProps.formatMessage).toHaveBeenCalledWith(
692
- expect.any(Object),
693
- { key: 'key1, key2' }
694
- );
769
+ // Each input asks for its own key
770
+ expect(defaultProps.formatMessage).toHaveBeenCalledWith(expect.any(Object), { key: 'key1' });
771
+ expect(defaultProps.formatMessage).toHaveBeenCalledWith(expect.any(Object), { key: 'key2' });
695
772
  });
696
773
 
697
774
  it('should handle deep link keys error display', () => {
@@ -708,7 +785,7 @@ describe("PlatformContentFields", () => {
708
785
  title: 'Test Title',
709
786
  message: 'Test Message',
710
787
  mediaType: 'IMAGE',
711
- actionOnClick: true,
788
+ actionOnClick: true, tapLinkSaved: false,
712
789
  linkType: 'DEEP_LINK',
713
790
  };
714
791
  const mockErrors = {
@@ -734,11 +811,39 @@ describe("PlatformContentFields", () => {
734
811
  expect(getByText('Deep link keys error message')).toBeInTheDocument();
735
812
  });
736
813
 
814
+ it('sends the configured key with the typed value', () => {
815
+ const handleDeepLinkKeysChange = jest.fn();
816
+ const { getByPlaceholderText } = render(
817
+ <PlatformContentFields
818
+ deviceType="ANDROID"
819
+ content={{
820
+ title: 'Test Title', message: 'Test Message', mediaType: 'IMAGE', actionOnClick: true, tapLinkSaved: false, linkType: 'DEEP_LINK',
821
+ }}
822
+ errors={{}}
823
+ handlers={{ ...defaultProps.handlers, handleDeepLinkKeysChange }}
824
+ tagListProps={defaultProps.tagListProps}
825
+ mediaUploaderProps={defaultProps.mediaUploaderProps}
826
+ ctaButtonProps={defaultProps.ctaButtonProps}
827
+ linkProps={{
828
+ deepLink: [{ value: 'https://www.youtube.com/', keys: ['testing_purpose'] }],
829
+ deepLinkValue: 'https://www.youtube.com/',
830
+ deepLinkKeysValue: [],
831
+ externalLinkValue: '',
832
+ }}
833
+ sameContent={false}
834
+ formatMessage={(msg, values) => (values?.key ? `Please input ${values.key} here` : msg.defaultMessage)}
835
+ />
836
+ );
837
+
838
+ fireEvent.change(getByPlaceholderText('Please input testing_purpose here'), { target: { value: 'androidDeeplink' } });
839
+ expect(handleDeepLinkKeysChange).toHaveBeenCalledWith(['testing_purpose=androidDeeplink']);
840
+ });
841
+
737
842
  // Test cases for uncovered lines
738
843
  describe('Deep link null/undefined handling', () => {
739
844
  it('should handle null deepLink in options', () => {
740
845
  const { container } = renderComponent({
741
- content: { ...defaultProps.content, actionOnClick: true, linkType: DEEP_LINK },
846
+ content: { ...defaultProps.content, actionOnClick: true, tapLinkSaved: false, linkType: DEEP_LINK },
742
847
  linkProps: {
743
848
  deepLink: null, // This should trigger the fallback to empty array
744
849
  deepLinkValue: '',
@@ -752,7 +857,7 @@ describe("PlatformContentFields", () => {
752
857
 
753
858
  it('should handle undefined deepLink in options', () => {
754
859
  const { container } = renderComponent({
755
- content: { ...defaultProps.content, actionOnClick: true, linkType: DEEP_LINK },
860
+ content: { ...defaultProps.content, actionOnClick: true, tapLinkSaved: false, linkType: DEEP_LINK },
756
861
  linkProps: {
757
862
  deepLink: undefined, // This should trigger the fallback to empty array
758
863
  deepLinkValue: '',
@@ -780,7 +885,7 @@ describe("PlatformContentFields", () => {
780
885
  title: 'Test Title',
781
886
  message: 'Test Message',
782
887
  mediaType: 'IMAGE',
783
- actionOnClick: true,
888
+ actionOnClick: true, tapLinkSaved: false,
784
889
  linkType: 'DEEP_LINK',
785
890
  };
786
891
 
@@ -819,7 +924,7 @@ describe("PlatformContentFields", () => {
819
924
  title: 'Test Title',
820
925
  message: 'Test Message',
821
926
  mediaType: 'IMAGE',
822
- actionOnClick: true,
927
+ actionOnClick: true, tapLinkSaved: false,
823
928
  linkType: 'DEEP_LINK',
824
929
  };
825
930
 
@@ -858,7 +963,7 @@ describe("PlatformContentFields", () => {
858
963
  title: 'Test Title',
859
964
  message: 'Test Message',
860
965
  mediaType: 'IMAGE',
861
- actionOnClick: true,
966
+ actionOnClick: true, tapLinkSaved: false,
862
967
  linkType: 'DEEP_LINK',
863
968
  };
864
969
 
@@ -880,7 +985,8 @@ describe("PlatformContentFields", () => {
880
985
  );
881
986
 
882
987
  // Should find the base deep link and display keys
883
- expect(getByText('category, filter')).toBeInTheDocument();
988
+ expect(getByText('category')).toBeInTheDocument();
989
+ expect(getByText('filter')).toBeInTheDocument();
884
990
  });
885
991
 
886
992
  it('should handle empty query parameters in deep link value', () => {
@@ -897,7 +1003,7 @@ describe("PlatformContentFields", () => {
897
1003
  title: 'Test Title',
898
1004
  message: 'Test Message',
899
1005
  mediaType: 'IMAGE',
900
- actionOnClick: true,
1006
+ actionOnClick: true, tapLinkSaved: false,
901
1007
  linkType: 'DEEP_LINK',
902
1008
  };
903
1009
 
@@ -930,7 +1036,7 @@ describe("PlatformContentFields", () => {
930
1036
  const { container } = renderComponent({
931
1037
  content: {
932
1038
  ...defaultProps.content,
933
- actionOnClick: true,
1039
+ actionOnClick: true, tapLinkSaved: false,
934
1040
  linkType: EXTERNAL_LINK,
935
1041
  },
936
1042
  linkProps: {
@@ -50,6 +50,8 @@ 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";
53
55
  export const ALLOWED_IMAGE_EXTENSIONS_REGEX = /\.(jpe?g|png)$/i;
54
56
  export const MPUSH_IMG_SIZE = 2000000; // 2MB
55
57
  export const MPUSH_VIDEO_SIZE = 209715200; // 200MB (200 * 1024 * 1024)
@@ -73,6 +75,16 @@ export const LINK_TYPE_OPTIONS = [
73
75
  { label: 'External Link', value: EXTERNAL_LINK },
74
76
  ];
75
77
 
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
+ // "When tapped, open" options; labelKey is the messages.js key
82
+ export const TAP_ACTION_OPTIONS = [
83
+ { labelKey: 'tapActionApp', value: TAP_ACTION_APP },
84
+ { labelKey: 'tapActionDeepLink', value: DEEP_LINK },
85
+ { labelKey: 'tapActionExternalLink', value: EXTERNAL_LINK },
86
+ ];
87
+
76
88
  export const EXTERNAL_LINK_LOWERCASE = 'external link';
77
89
  export const PRIMARY = 'PRIMARY';
78
90
  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,
4
+ ANDROID, GIF, IMAGE, IOS, VIDEO, DEEP_LINK, EXTERNAL_LINK, TAP_ACTION_APP,
5
5
  } from '../../constants';
6
6
  import { NONE } from '../../../Whatsapp/constants';
7
7
 
@@ -979,6 +979,68 @@ 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
+
982
1044
  describe('handleLinkTypeChange', () => {
983
1045
  it('should update Android linkType when sync is disabled', () => {
984
1046
  const { result } = renderHook(() => usePlatformSync(defaultProps));
@@ -602,6 +602,32 @@ describe('useUpload Hook', () => {
602
602
  });
603
603
  });
604
604
 
605
+ it('should clear only the iOS image when re-upload handlers kept from the ticked render run after untick', () => {
606
+ const { result, rerender } = renderHook(
607
+ ({ sameContent }) => useUpload(
608
+ mockMobilePushActions, {}, {}, {}, false, sameContent,
609
+ mockSetAndroidContent, mockSetIosContent, IOS, androidContent, iosContent, mockFormatMessage,
610
+ ),
611
+ { initialProps: { sameContent: true } },
612
+ );
613
+ // Handlers as the uploader keeps them from its first render
614
+ const { setUpdateMpushImageSrc, updateOnMpushImageReUpload } = result.current;
615
+
616
+ act(() => {
617
+ setUpdateMpushImageSrc('img.png', 1);
618
+ });
619
+ rerender({ sameContent: false });
620
+ act(() => {
621
+ setUpdateMpushImageSrc('', 1);
622
+ updateOnMpushImageReUpload();
623
+ });
624
+
625
+ expect(result.current.imageSrc).toEqual({
626
+ androidImageSrc: 'img.png',
627
+ iosImageSrc: '',
628
+ });
629
+ });
630
+
605
631
  it('should handle image source update with sync enabled', () => {
606
632
  const { result } = createHook({ sameContent: true });
607
633
 
@@ -1121,6 +1147,19 @@ describe('useUpload Hook', () => {
1121
1147
  });
1122
1148
  });
1123
1149
 
1150
+ it('clears the platform it is given, not the visible tab', () => {
1151
+ const { result } = createHook({ sameContent: false, activeTab: ANDROID });
1152
+ act(() => {
1153
+ result.current.setImageSrc({ androidImageSrc: 'a.jpg', iosImageSrc: 'b.jpg' });
1154
+ });
1155
+
1156
+ act(() => {
1157
+ result.current.clearImageDataByMediaType(IMAGE, IOS);
1158
+ });
1159
+
1160
+ expect(result.current.imageSrc).toEqual({ androidImageSrc: 'a.jpg', iosImageSrc: '' });
1161
+ });
1162
+
1124
1163
  it('should clear video data with sync enabled', () => {
1125
1164
  const { result } = createHook({ sameContent: true });
1126
1165
 
@@ -1456,4 +1495,43 @@ describe('useUpload Hook', () => {
1456
1495
  });
1457
1496
  });
1458
1497
  });
1498
+
1499
+ describe('Ticking same content', () => {
1500
+ // Android has image A, iOS has video V; then tick on the given tab
1501
+ const renderAndTick = (activeTab) => {
1502
+ const hook = renderHook(({ sameContent }) => useUpload(
1503
+ mockMobilePushActions, {}, {}, {}, false, sameContent,
1504
+ mockSetAndroidContent, mockSetIosContent, activeTab, androidContent, iosContent, mockFormatMessage,
1505
+ ), { initialProps: { sameContent: false } });
1506
+ act(() => {
1507
+ hook.result.current.setImageSrc({ androidImageSrc: 'A.jpg', iosImageSrc: '' });
1508
+ hook.result.current.setUpdateMpushVideoSrc(1, { videoSrc: 'V.mp4', previewUrl: 'V.jpg', videoDuration: 5 });
1509
+ });
1510
+ hook.rerender({ sameContent: true });
1511
+ return hook.result;
1512
+ };
1513
+
1514
+ it('wipes the iOS video when ticked on Android, which has none', () => {
1515
+ const result = renderAndTick(ANDROID);
1516
+ expect(result.current.videoState).toEqual({
1517
+ androidVideoSrc: '',
1518
+ iosVideoSrc: '',
1519
+ androidVideoPreview: '',
1520
+ iosVideoPreview: '',
1521
+ androidVideoDuration: 0,
1522
+ iosVideoDuration: 0,
1523
+ });
1524
+ expect(result.current.iosAssetList).toEqual([]);
1525
+ expect(result.current.imageSrc).toEqual({ androidImageSrc: 'A.jpg', iosImageSrc: 'A.jpg' });
1526
+ expect(androidContent.videoSrc).toBe('');
1527
+ expect(iosContent.videoSrc).toBe('');
1528
+ });
1529
+
1530
+ it('wipes the Android image when ticked on iOS, which has none', () => {
1531
+ const result = renderAndTick(IOS);
1532
+ expect(result.current.imageSrc).toEqual({ androidImageSrc: '', iosImageSrc: '' });
1533
+ expect(result.current.videoState.androidVideoSrc).toBe('V.mp4');
1534
+ expect(result.current.androidAssetList).toMatchObject({ videoSrc: 'V.mp4' });
1535
+ });
1536
+ });
1459
1537
  });