@capillarytech/creatives-library 9.1.7 → 9.1.8-alpha.sprint-cap-214249.39
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/constants/unified.js +0 -1
- package/package.json +1 -1
- package/utils/common.js +0 -6
- package/utils/createMobilePushPayload.js +50 -33
- package/utils/tests/createMobilePushPayload.test.js +113 -8
- package/v2Components/CapMpushCTA/index.js +10 -9
- package/v2Components/CapMpushCTA/index.scss +29 -3
- package/v2Components/CapMpushCTA/tests/index.test.js +89 -0
- package/v2Components/CommonTestAndPreview/UnifiedPreview/MobilePushPreviewContent.js +20 -12
- package/v2Components/CommonTestAndPreview/UnifiedPreview/_unifiedPreview.scss +13 -1
- package/v2Components/CommonTestAndPreview/constants.js +2 -0
- package/v2Components/CommonTestAndPreview/index.js +48 -10
- package/v2Components/CommonTestAndPreview/tests/UnifiedPreview/MobilePushPreviewContent.test.js +81 -5
- package/v2Components/CommonTestAndPreview/tests/index.test.js +86 -0
- package/v2Components/TemplatePreview/_templatePreview.scss +12 -2
- package/v2Components/TemplatePreview/index.js +24 -16
- package/v2Components/TemplatePreview/tests/index.test.js +68 -0
- package/v2Containers/CreativesContainer/SlideBoxContent.js +4 -6
- package/v2Containers/CreativesContainer/index.js +2 -1
- package/v2Containers/CreativesContainer/tests/SlideBoxContent.test.js +43 -0
- package/v2Containers/MobilePushNew/components/CtaButtons.js +52 -47
- package/v2Containers/MobilePushNew/components/MediaUploaders.js +297 -216
- package/v2Containers/MobilePushNew/components/PlatformContentFields.js +158 -125
- package/v2Containers/MobilePushNew/components/TapLinkActions.js +76 -0
- package/v2Containers/MobilePushNew/components/tests/CtaButtons.test.js +30 -208
- package/v2Containers/MobilePushNew/components/tests/MediaUploaders.test.js +464 -108
- package/v2Containers/MobilePushNew/components/tests/PlatformContentFields.test.js +106 -35
- package/v2Containers/MobilePushNew/constants.js +5 -0
- package/v2Containers/MobilePushNew/hooks/tests/usePlatformSync.test.js +63 -1
- package/v2Containers/MobilePushNew/hooks/tests/useUpload.test.js +52 -0
- package/v2Containers/MobilePushNew/hooks/usePlatformSync.js +40 -1
- package/v2Containers/MobilePushNew/hooks/useUpload.js +29 -39
- package/v2Containers/MobilePushNew/index.js +487 -235
- package/v2Containers/MobilePushNew/index.scss +205 -4
- package/v2Containers/MobilePushNew/messages.js +106 -6
- package/v2Containers/MobilePushNew/tests/index.test.js +469 -1
- package/v2Containers/MobilePushNew/tests/utils.test.js +70 -0
- package/v2Containers/MobilePushNew/utils.js +56 -0
- package/v2Containers/Templates/_templates.scss +10 -2
- package/v2Containers/Templates/index.js +83 -81
- package/v2Containers/Templates/tests/index.test.js +68 -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
|
|
@@ -101,6 +101,15 @@ 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" },
|
|
104
113
|
deepLinkKeys: { id: "deepLinkKeys", defaultMessage: "Deep Link Keys" },
|
|
105
114
|
deepLinkKeysPlaceholder: { id: "deepLinkKeysPlaceholder", defaultMessage: "Enter {key}" },
|
|
106
115
|
deepLinkKeysRequired: { id: "deepLinkKeysRequired", defaultMessage: "Deep link keys are required" },
|
|
@@ -125,6 +134,7 @@ jest.mock("../../constants", () => ({
|
|
|
125
134
|
],
|
|
126
135
|
DEEP_LINK: "DEEP_LINK",
|
|
127
136
|
EXTERNAL_LINK: "EXTERNAL_LINK",
|
|
137
|
+
TAP_ACTION_APP: "APP",
|
|
128
138
|
}));
|
|
129
139
|
|
|
130
140
|
describe("PlatformContentFields", () => {
|
|
@@ -147,11 +157,11 @@ describe("PlatformContentFields", () => {
|
|
|
147
157
|
handleTitleChange: jest.fn(),
|
|
148
158
|
handleMessageChange: jest.fn(),
|
|
149
159
|
handleMediaTypeChange: jest.fn(),
|
|
150
|
-
|
|
151
|
-
handleLinkTypeChange: jest.fn(),
|
|
160
|
+
handleTapActionChange: jest.fn(),
|
|
152
161
|
handleDeepLinkChange: jest.fn(),
|
|
153
162
|
handleDeepLinkKeysChange: jest.fn(),
|
|
154
163
|
handleExternalLinkChange: jest.fn(),
|
|
164
|
+
handleTapLinkSavedChange: jest.fn(),
|
|
155
165
|
onTagSelect: jest.fn(),
|
|
156
166
|
handleOnTagsContextChange: jest.fn(),
|
|
157
167
|
},
|
|
@@ -309,30 +319,91 @@ describe("PlatformContentFields", () => {
|
|
|
309
319
|
});
|
|
310
320
|
});
|
|
311
321
|
|
|
312
|
-
describe("
|
|
313
|
-
|
|
314
|
-
|
|
315
|
-
|
|
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
|
+
});
|
|
316
337
|
|
|
317
|
-
|
|
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 } });
|
|
318
342
|
|
|
319
|
-
expect(defaultProps.handlers.
|
|
343
|
+
expect(defaultProps.handlers.handleTapActionChange).toHaveBeenCalledWith(EXTERNAL_LINK);
|
|
320
344
|
});
|
|
321
345
|
|
|
322
|
-
it("
|
|
346
|
+
it("shows the deep link select, without the App help text, for Deep link", () => {
|
|
323
347
|
const { container } = renderComponent({
|
|
324
|
-
content: { ...defaultProps.content, actionOnClick: true },
|
|
348
|
+
content: { ...defaultProps.content, actionOnClick: true, tapLinkSaved: false, linkType: DEEP_LINK },
|
|
325
349
|
});
|
|
326
350
|
|
|
327
|
-
expect(container
|
|
351
|
+
expect(getTapSelect(container)).toHaveValue(DEEP_LINK);
|
|
352
|
+
expect(container.querySelectorAll("select")).toHaveLength(3);
|
|
353
|
+
expect(container.textContent).not.toContain("Opens your app.");
|
|
328
354
|
});
|
|
329
355
|
|
|
330
|
-
it("
|
|
356
|
+
it("shows the URL input for External link", () => {
|
|
331
357
|
const { container } = renderComponent({
|
|
332
|
-
content: { ...defaultProps.content, actionOnClick: false },
|
|
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
|
+
});
|
|
376
|
+
|
|
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();
|
|
380
|
+
|
|
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");
|
|
385
|
+
});
|
|
386
|
+
|
|
387
|
+
it("saves an open link once it is filled", () => {
|
|
388
|
+
const { container } = renderComponent({
|
|
389
|
+
content: { ...defaultProps.content, actionOnClick: true, tapLinkSaved: false, linkType: EXTERNAL_LINK },
|
|
390
|
+
formatMessage: plainFormatMessage,
|
|
333
391
|
});
|
|
334
392
|
|
|
335
|
-
|
|
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);
|
|
397
|
+
});
|
|
398
|
+
|
|
399
|
+
it("keeps Save off while the link is empty", () => {
|
|
400
|
+
const { container } = renderComponent({
|
|
401
|
+
content: { ...defaultProps.content, actionOnClick: true, tapLinkSaved: false, linkType: DEEP_LINK },
|
|
402
|
+
linkProps: { ...defaultProps.linkProps, deepLinkValue: "" },
|
|
403
|
+
formatMessage: plainFormatMessage,
|
|
404
|
+
});
|
|
405
|
+
|
|
406
|
+
expect(container.querySelector(".mpush-tap-save-btn")).toBeDisabled();
|
|
336
407
|
});
|
|
337
408
|
});
|
|
338
409
|
|
|
@@ -353,7 +424,7 @@ describe("PlatformContentFields", () => {
|
|
|
353
424
|
describe("External Link Input", () => {
|
|
354
425
|
it("should call external link change handler", () => {
|
|
355
426
|
const { container } = renderComponent({
|
|
356
|
-
content: { ...defaultProps.content, actionOnClick: true, linkType: EXTERNAL_LINK },
|
|
427
|
+
content: { ...defaultProps.content, actionOnClick: true, tapLinkSaved: false, linkType: EXTERNAL_LINK },
|
|
357
428
|
});
|
|
358
429
|
|
|
359
430
|
const externalLinkInput = container.querySelector('input[value="https://example.com"]');
|
|
@@ -366,7 +437,7 @@ describe("PlatformContentFields", () => {
|
|
|
366
437
|
|
|
367
438
|
it("should display external link error when present", () => {
|
|
368
439
|
const { getByTestId } = renderComponent({
|
|
369
|
-
content: { ...defaultProps.content, actionOnClick: true, linkType: EXTERNAL_LINK },
|
|
440
|
+
content: { ...defaultProps.content, actionOnClick: true, tapLinkSaved: false, linkType: EXTERNAL_LINK },
|
|
370
441
|
errors: { ...defaultProps.errors, externalLink: "Invalid URL" },
|
|
371
442
|
});
|
|
372
443
|
|
|
@@ -380,7 +451,7 @@ describe("PlatformContentFields", () => {
|
|
|
380
451
|
content: { ...defaultProps.content, mediaType: "CAROUSEL" },
|
|
381
452
|
});
|
|
382
453
|
|
|
383
|
-
expect(container.textContent).not.toContain("
|
|
454
|
+
expect(container.textContent).not.toContain("Notification tap");
|
|
384
455
|
expect(container.textContent).not.toContain("CtaButtons");
|
|
385
456
|
});
|
|
386
457
|
|
|
@@ -389,7 +460,7 @@ describe("PlatformContentFields", () => {
|
|
|
389
460
|
content: { ...defaultProps.content, mediaType: "IMAGE" },
|
|
390
461
|
});
|
|
391
462
|
|
|
392
|
-
expect(container.textContent).toContain("
|
|
463
|
+
expect(container.textContent).toContain("Notification tap");
|
|
393
464
|
});
|
|
394
465
|
});
|
|
395
466
|
|
|
@@ -443,7 +514,7 @@ describe("PlatformContentFields", () => {
|
|
|
443
514
|
title: 'Test Title',
|
|
444
515
|
message: 'Test Message',
|
|
445
516
|
mediaType: 'IMAGE',
|
|
446
|
-
actionOnClick: true,
|
|
517
|
+
actionOnClick: true, tapLinkSaved: false,
|
|
447
518
|
linkType: 'DEEP_LINK',
|
|
448
519
|
};
|
|
449
520
|
|
|
@@ -481,7 +552,7 @@ describe("PlatformContentFields", () => {
|
|
|
481
552
|
title: 'Test Title',
|
|
482
553
|
message: 'Test Message',
|
|
483
554
|
mediaType: 'IMAGE',
|
|
484
|
-
actionOnClick: true,
|
|
555
|
+
actionOnClick: true, tapLinkSaved: false,
|
|
485
556
|
linkType: 'DEEP_LINK',
|
|
486
557
|
};
|
|
487
558
|
|
|
@@ -519,7 +590,7 @@ describe("PlatformContentFields", () => {
|
|
|
519
590
|
title: 'Test Title',
|
|
520
591
|
message: 'Test Message',
|
|
521
592
|
mediaType: 'IMAGE',
|
|
522
|
-
actionOnClick: true,
|
|
593
|
+
actionOnClick: true, tapLinkSaved: false,
|
|
523
594
|
linkType: 'DEEP_LINK',
|
|
524
595
|
};
|
|
525
596
|
|
|
@@ -556,7 +627,7 @@ describe("PlatformContentFields", () => {
|
|
|
556
627
|
title: 'Test Title',
|
|
557
628
|
message: 'Test Message',
|
|
558
629
|
mediaType: 'IMAGE',
|
|
559
|
-
actionOnClick: true,
|
|
630
|
+
actionOnClick: true, tapLinkSaved: false,
|
|
560
631
|
linkType: 'DEEP_LINK',
|
|
561
632
|
};
|
|
562
633
|
|
|
@@ -593,7 +664,7 @@ describe("PlatformContentFields", () => {
|
|
|
593
664
|
title: 'Test Title',
|
|
594
665
|
message: 'Test Message',
|
|
595
666
|
mediaType: 'IMAGE',
|
|
596
|
-
actionOnClick: true,
|
|
667
|
+
actionOnClick: true, tapLinkSaved: false,
|
|
597
668
|
linkType: 'DEEP_LINK',
|
|
598
669
|
};
|
|
599
670
|
|
|
@@ -630,7 +701,7 @@ describe("PlatformContentFields", () => {
|
|
|
630
701
|
title: 'Test Title',
|
|
631
702
|
message: 'Test Message',
|
|
632
703
|
mediaType: 'IMAGE',
|
|
633
|
-
actionOnClick: true,
|
|
704
|
+
actionOnClick: true, tapLinkSaved: false,
|
|
634
705
|
linkType: 'DEEP_LINK',
|
|
635
706
|
};
|
|
636
707
|
|
|
@@ -668,7 +739,7 @@ describe("PlatformContentFields", () => {
|
|
|
668
739
|
title: 'Test Title',
|
|
669
740
|
message: 'Test Message',
|
|
670
741
|
mediaType: 'IMAGE',
|
|
671
|
-
actionOnClick: true,
|
|
742
|
+
actionOnClick: true, tapLinkSaved: false,
|
|
672
743
|
linkType: 'DEEP_LINK',
|
|
673
744
|
};
|
|
674
745
|
|
|
@@ -708,7 +779,7 @@ describe("PlatformContentFields", () => {
|
|
|
708
779
|
title: 'Test Title',
|
|
709
780
|
message: 'Test Message',
|
|
710
781
|
mediaType: 'IMAGE',
|
|
711
|
-
actionOnClick: true,
|
|
782
|
+
actionOnClick: true, tapLinkSaved: false,
|
|
712
783
|
linkType: 'DEEP_LINK',
|
|
713
784
|
};
|
|
714
785
|
const mockErrors = {
|
|
@@ -738,7 +809,7 @@ describe("PlatformContentFields", () => {
|
|
|
738
809
|
describe('Deep link null/undefined handling', () => {
|
|
739
810
|
it('should handle null deepLink in options', () => {
|
|
740
811
|
const { container } = renderComponent({
|
|
741
|
-
content: { ...defaultProps.content, actionOnClick: true, linkType: DEEP_LINK },
|
|
812
|
+
content: { ...defaultProps.content, actionOnClick: true, tapLinkSaved: false, linkType: DEEP_LINK },
|
|
742
813
|
linkProps: {
|
|
743
814
|
deepLink: null, // This should trigger the fallback to empty array
|
|
744
815
|
deepLinkValue: '',
|
|
@@ -752,7 +823,7 @@ describe("PlatformContentFields", () => {
|
|
|
752
823
|
|
|
753
824
|
it('should handle undefined deepLink in options', () => {
|
|
754
825
|
const { container } = renderComponent({
|
|
755
|
-
content: { ...defaultProps.content, actionOnClick: true, linkType: DEEP_LINK },
|
|
826
|
+
content: { ...defaultProps.content, actionOnClick: true, tapLinkSaved: false, linkType: DEEP_LINK },
|
|
756
827
|
linkProps: {
|
|
757
828
|
deepLink: undefined, // This should trigger the fallback to empty array
|
|
758
829
|
deepLinkValue: '',
|
|
@@ -780,7 +851,7 @@ describe("PlatformContentFields", () => {
|
|
|
780
851
|
title: 'Test Title',
|
|
781
852
|
message: 'Test Message',
|
|
782
853
|
mediaType: 'IMAGE',
|
|
783
|
-
actionOnClick: true,
|
|
854
|
+
actionOnClick: true, tapLinkSaved: false,
|
|
784
855
|
linkType: 'DEEP_LINK',
|
|
785
856
|
};
|
|
786
857
|
|
|
@@ -819,7 +890,7 @@ describe("PlatformContentFields", () => {
|
|
|
819
890
|
title: 'Test Title',
|
|
820
891
|
message: 'Test Message',
|
|
821
892
|
mediaType: 'IMAGE',
|
|
822
|
-
actionOnClick: true,
|
|
893
|
+
actionOnClick: true, tapLinkSaved: false,
|
|
823
894
|
linkType: 'DEEP_LINK',
|
|
824
895
|
};
|
|
825
896
|
|
|
@@ -858,7 +929,7 @@ describe("PlatformContentFields", () => {
|
|
|
858
929
|
title: 'Test Title',
|
|
859
930
|
message: 'Test Message',
|
|
860
931
|
mediaType: 'IMAGE',
|
|
861
|
-
actionOnClick: true,
|
|
932
|
+
actionOnClick: true, tapLinkSaved: false,
|
|
862
933
|
linkType: 'DEEP_LINK',
|
|
863
934
|
};
|
|
864
935
|
|
|
@@ -897,7 +968,7 @@ describe("PlatformContentFields", () => {
|
|
|
897
968
|
title: 'Test Title',
|
|
898
969
|
message: 'Test Message',
|
|
899
970
|
mediaType: 'IMAGE',
|
|
900
|
-
actionOnClick: true,
|
|
971
|
+
actionOnClick: true, tapLinkSaved: false,
|
|
901
972
|
linkType: 'DEEP_LINK',
|
|
902
973
|
};
|
|
903
974
|
|
|
@@ -930,7 +1001,7 @@ describe("PlatformContentFields", () => {
|
|
|
930
1001
|
const { container } = renderComponent({
|
|
931
1002
|
content: {
|
|
932
1003
|
...defaultProps.content,
|
|
933
|
-
actionOnClick: true,
|
|
1004
|
+
actionOnClick: true, tapLinkSaved: false,
|
|
934
1005
|
linkType: EXTERNAL_LINK,
|
|
935
1006
|
},
|
|
936
1007
|
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,9 @@ 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
|
+
|
|
76
81
|
export const EXTERNAL_LINK_LOWERCASE = 'external link';
|
|
77
82
|
export const PRIMARY = 'PRIMARY';
|
|
78
83
|
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));
|
|
@@ -1121,6 +1121,19 @@ 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
|
+
|
|
1124
1137
|
it('should clear video data with sync enabled', () => {
|
|
1125
1138
|
const { result } = createHook({ sameContent: true });
|
|
1126
1139
|
|
|
@@ -1456,4 +1469,43 @@ describe('useUpload Hook', () => {
|
|
|
1456
1469
|
});
|
|
1457
1470
|
});
|
|
1458
1471
|
});
|
|
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
|
+
});
|
|
1459
1511
|
});
|
|
@@ -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,
|
|
4
|
+
ANDROID, DEEP_LINK, GIF, IMAGE, IOS, VIDEO, TAP_ACTION_APP,
|
|
5
5
|
} from '../constants';
|
|
6
6
|
import { NONE } from '../../Whatsapp/constants';
|
|
7
7
|
|
|
@@ -353,6 +353,44 @@ 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
|
+
|
|
356
394
|
return {
|
|
357
395
|
handleTitleChange,
|
|
358
396
|
handleMessageChange,
|
|
@@ -361,6 +399,7 @@ const usePlatformSync = ({
|
|
|
361
399
|
handleButtonChange,
|
|
362
400
|
handleActionOnClickChange,
|
|
363
401
|
handleLinkTypeChange,
|
|
402
|
+
handleTapActionChange,
|
|
364
403
|
};
|
|
365
404
|
};
|
|
366
405
|
|
|
@@ -148,8 +148,9 @@ 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
|
-
|
|
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) => {
|
|
153
154
|
if (mediaType === IMAGE) {
|
|
154
155
|
if (sameContent) {
|
|
155
156
|
// When sync is enabled, clear both platforms
|
|
@@ -158,11 +159,11 @@ const useUpload = (mobilePushActions, editData = {}, _uploadedAssetData0 = {}, _
|
|
|
158
159
|
iosImageSrc: "",
|
|
159
160
|
});
|
|
160
161
|
} else {
|
|
161
|
-
// When sync is disabled, only clear
|
|
162
|
-
const
|
|
162
|
+
// When sync is disabled, only clear that platform
|
|
163
|
+
const platformKey = platform === ANDROID ? 'androidImageSrc' : 'iosImageSrc';
|
|
163
164
|
setImageSrc((prevState) => ({
|
|
164
165
|
...prevState,
|
|
165
|
-
[
|
|
166
|
+
[platformKey]: "",
|
|
166
167
|
}));
|
|
167
168
|
}
|
|
168
169
|
} else if (mediaType === VIDEO || mediaType === GIF) {
|
|
@@ -196,9 +197,9 @@ const useUpload = (mobilePushActions, editData = {}, _uploadedAssetData0 = {}, _
|
|
|
196
197
|
mobilePushActions.clearAsset(0);
|
|
197
198
|
mobilePushActions.clearAsset(1);
|
|
198
199
|
} else {
|
|
199
|
-
// When sync is disabled, only clear
|
|
200
|
-
const platformIndex =
|
|
201
|
-
const isAndroid =
|
|
200
|
+
// When sync is disabled, only clear that platform
|
|
201
|
+
const platformIndex = platform === ANDROID ? 0 : 1;
|
|
202
|
+
const isAndroid = platform === ANDROID;
|
|
202
203
|
const videoProps = getVideoProperties(isAndroid);
|
|
203
204
|
|
|
204
205
|
setVideoState((prevState) => ({
|
|
@@ -293,17 +294,11 @@ const useUpload = (mobilePushActions, editData = {}, _uploadedAssetData0 = {}, _
|
|
|
293
294
|
}
|
|
294
295
|
}, [videoState?.androidVideoSrc, videoState?.iosVideoSrc, videoState?.androidVideoPreview, videoState?.iosVideoPreview, videoState?.androidVideoDuration, videoState?.iosVideoDuration, sameContent]);
|
|
295
296
|
|
|
296
|
-
//
|
|
297
|
+
// On tick, copy the active tab's image to both tabs, even when it has none
|
|
297
298
|
useEffect(() => {
|
|
298
299
|
if (sameContent) {
|
|
299
|
-
|
|
300
|
-
|
|
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)) {
|
|
300
|
+
const currentImageSrc = (activeTab === ANDROID ? imageSrc?.androidImageSrc : imageSrc?.iosImageSrc) || '';
|
|
301
|
+
if (imageSrc?.androidImageSrc !== currentImageSrc || imageSrc?.iosImageSrc !== currentImageSrc) {
|
|
307
302
|
setImageSrc({
|
|
308
303
|
androidImageSrc: currentImageSrc,
|
|
309
304
|
iosImageSrc: currentImageSrc,
|
|
@@ -314,31 +309,20 @@ const useUpload = (mobilePushActions, editData = {}, _uploadedAssetData0 = {}, _
|
|
|
314
309
|
// eslint-disable-next-line react-hooks/exhaustive-deps
|
|
315
310
|
}, [sameContent, activeTab]);
|
|
316
311
|
|
|
317
|
-
//
|
|
312
|
+
// On tick, copy the active tab's video to both tabs, even when it has none
|
|
318
313
|
useEffect(() => {
|
|
319
314
|
if (sameContent) {
|
|
320
|
-
|
|
321
|
-
|
|
322
|
-
|
|
323
|
-
|
|
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
|
-
}
|
|
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;
|
|
333
319
|
if (
|
|
334
|
-
|
|
335
|
-
|
|
336
|
-
|
|
337
|
-
|
|
338
|
-
|
|
339
|
-
|
|
340
|
-
|| videoState?.iosVideoDuration !== currentVideoDuration
|
|
341
|
-
)
|
|
320
|
+
videoState?.androidVideoSrc !== currentVideoSrc
|
|
321
|
+
|| videoState?.iosVideoSrc !== currentVideoSrc
|
|
322
|
+
|| videoState?.androidVideoPreview !== currentVideoPreview
|
|
323
|
+
|| videoState?.iosVideoPreview !== currentVideoPreview
|
|
324
|
+
|| videoState?.androidVideoDuration !== currentVideoDuration
|
|
325
|
+
|| videoState?.iosVideoDuration !== currentVideoDuration
|
|
342
326
|
) {
|
|
343
327
|
setVideoState({
|
|
344
328
|
androidVideoSrc: currentVideoSrc,
|
|
@@ -349,6 +333,12 @@ const useUpload = (mobilePushActions, editData = {}, _uploadedAssetData0 = {}, _
|
|
|
349
333
|
iosVideoDuration: currentVideoDuration,
|
|
350
334
|
});
|
|
351
335
|
}
|
|
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
|
+
}
|
|
352
342
|
}
|
|
353
343
|
// Only run when sameContent or activeTab changes
|
|
354
344
|
// eslint-disable-next-line react-hooks/exhaustive-deps
|