@capillarytech/creatives-library 9.2.2-alpha.sprint-cap-214249.44 → 9.2.2
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 +1 -3
- package/package.json +1 -1
- package/translations/en.json +0 -1
- package/translations/ja-JP.json +0 -1
- package/translations/zh.json +0 -1
- package/utils/common.js +6 -0
- package/utils/createMobilePushPayload.js +56 -50
- package/utils/tagValidations.js +4 -35
- package/utils/tests/createMobilePushPayload.test.js +168 -177
- package/utils/tests/tagValidations.test.js +0 -48
- package/v2Components/CapMpushCTA/index.js +57 -47
- package/v2Components/CapMpushCTA/index.scss +5 -43
- package/v2Components/CapTagList/index.js +7 -46
- package/v2Components/CapTagList/messages.js +0 -44
- package/v2Components/CapTagList/style.scss +1 -113
- package/v2Components/CommonTestAndPreview/UnifiedPreview/MobilePushPreviewContent.js +8 -11
- package/v2Components/CommonTestAndPreview/UnifiedPreview/_unifiedPreview.scss +1 -13
- package/v2Components/CommonTestAndPreview/constants.js +0 -2
- package/v2Components/CommonTestAndPreview/index.js +12 -51
- package/v2Components/CommonTestAndPreview/tests/UnifiedPreview/MobilePushPreviewContent.test.js +5 -83
- package/v2Components/CommonTestAndPreview/tests/index.test.js +0 -100
- package/v2Components/FormBuilder/Classic.js +14 -24
- package/v2Components/FormBuilder/Functional/channels/mobilepush/config.js +0 -1
- package/v2Components/FormBuilder/Functional/channels/mobilepush/getEditorErrorDescriptor.js +1 -1
- package/v2Components/FormBuilder/Functional/channels/mobilepush/tests/validate.test.js +0 -57
- package/v2Components/FormBuilder/Functional/channels/mobilepush/validate.js +4 -4
- package/v2Components/FormBuilder/Functional/channels/sms/getEditorErrorDescriptor.js +0 -3
- package/v2Components/FormBuilder/Functional/channels/sms/tests/getEditorErrorDescriptor.test.js +0 -5
- package/v2Components/FormBuilder/Functional/channels/sms/tests/validate.test.js +0 -6
- package/v2Components/FormBuilder/Functional/channels/sms/validate.js +1 -3
- package/v2Components/FormBuilder/Functional/renderers/mpushRenderers.js +0 -3
- package/v2Components/FormBuilder/Functional/tests/mpushRenderers.test.js +0 -22
- package/v2Components/MobilePushPreviewV2/index.js +9 -22
- package/v2Components/TemplatePreview/_templatePreview.scss +2 -18
- package/v2Components/TemplatePreview/index.js +18 -20
- package/v2Components/TemplatePreview/tests/index.test.js +0 -69
- package/v2Containers/Cap/messages.js +0 -4
- package/v2Containers/Cap/tests/__snapshots__/index.test.js.snap +0 -1
- package/v2Containers/CommunicationFlow/steps/ChannelSelectionStep/extractContentForPreview.js +2 -12
- package/v2Containers/CreativesContainer/SlideBoxContent.js +6 -4
- package/v2Containers/CreativesContainer/index.js +1 -2
- package/v2Containers/CreativesContainer/tests/SlideBoxContent.test.js +0 -43
- package/v2Containers/InApp/index.js +1 -4
- package/v2Containers/Line/Container/ImageCarousel/tests/__snapshots__/content.test.js.snap +0 -3
- package/v2Containers/Line/Container/ImageCarousel/tests/__snapshots__/index.test.js.snap +0 -2
- package/v2Containers/Line/Container/Text/index.js +1 -3
- package/v2Containers/Line/Container/Wrapper/tests/__snapshots__/index.test.js.snap +0 -16
- package/v2Containers/Line/Container/tests/__snapshots__/index.test.js.snap +0 -18
- package/v2Containers/MobilePushNew/components/CtaButtons.js +47 -52
- package/v2Containers/MobilePushNew/components/MediaUploaders.js +345 -105
- package/v2Containers/MobilePushNew/components/PlatformContentFields.js +105 -127
- package/v2Containers/MobilePushNew/components/tests/CtaButtons.test.js +208 -30
- package/v2Containers/MobilePushNew/components/tests/MediaUploaders.test.js +1484 -307
- package/v2Containers/MobilePushNew/components/tests/PlatformContentFields.test.js +59 -165
- package/v2Containers/MobilePushNew/constants.js +0 -12
- package/v2Containers/MobilePushNew/hooks/tests/usePlatformSync.test.js +1 -63
- package/v2Containers/MobilePushNew/hooks/tests/useUpload.test.js +0 -78
- package/v2Containers/MobilePushNew/hooks/usePlatformSync.js +1 -40
- package/v2Containers/MobilePushNew/hooks/useUpload.js +46 -42
- package/v2Containers/MobilePushNew/index.js +290 -502
- package/v2Containers/MobilePushNew/index.scss +4 -151
- package/v2Containers/MobilePushNew/messages.js +6 -106
- package/v2Containers/MobilePushNew/tests/index.test.js +1 -483
- package/v2Containers/MobilePushNew/tests/utils.test.js +0 -110
- package/v2Containers/MobilePushNew/utils.js +0 -83
- package/v2Containers/Rcs/index.js +1 -8
- package/v2Containers/Rcs/tests/__snapshots__/index.test.js.snap +0 -59
- package/v2Containers/SmsTrai/Create/tests/__snapshots__/index.test.js.snap +0 -4
- package/v2Containers/SmsTrai/Edit/index.js +5 -13
- package/v2Containers/SmsTrai/Edit/tests/__snapshots__/index.test.js.snap +0 -15
- package/v2Containers/Templates/_templates.scss +2 -10
- package/v2Containers/Templates/index.js +81 -86
- package/v2Containers/Templates/tests/index.test.js +0 -81
- package/v2Containers/Viber/index.js +1 -3
- package/v2Containers/WebPush/Create/utils/validation.js +0 -6
- package/v2Containers/WebPush/Create/utils/validation.test.js +0 -50
- package/v2Containers/Whatsapp/index.js +5 -9
- package/v2Containers/Whatsapp/tests/__snapshots__/index.test.js.snap +2 -2
- package/v2Containers/Zalo/index.js +1 -4
- package/v2Components/CapMpushCTA/tests/index.test.js +0 -150
- package/v2Components/CapTagList/TagFallbackPanel.js +0 -124
- package/v2Components/CapTagList/constants.js +0 -5
- package/v2Components/CapTagList/tests/TagFallback.test.js +0 -222
- package/v2Components/CapTagList/utils.js +0 -17
- package/v2Components/MobilePushPreviewV2/_mobilePushPreviewV2.scss +0 -7
- package/v2Components/MobilePushPreviewV2/tests/index.test.js +0 -55
- package/v2Components/TemplatePreview/_mobilePushPhone.scss +0 -72
- package/v2Containers/CommunicationFlow/steps/ChannelSelectionStep/Tests/extractContentForPreview.test.js +0 -45
- package/v2Containers/MobilePushNew/components/TapLinkActions.js +0 -76
|
@@ -7,7 +7,7 @@ import { configureStore } from '@capillarytech/vulcan-react-sdk/utils';
|
|
|
7
7
|
import { initialReducer } from '../../../../initialReducer';
|
|
8
8
|
import history from '../../../../utils/history';
|
|
9
9
|
import MediaUploaders from '../MediaUploaders';
|
|
10
|
-
import { ANDROID, IOS
|
|
10
|
+
import { ANDROID, IOS } from '../../constants';
|
|
11
11
|
import { act } from 'react';
|
|
12
12
|
import messages from '../../messages';
|
|
13
13
|
|
|
@@ -97,18 +97,20 @@ jest.mock('@capillarytech/cap-ui-library/CapRadioGroup', () =>
|
|
|
97
97
|
}
|
|
98
98
|
);
|
|
99
99
|
|
|
100
|
-
jest.mock('@capillarytech/cap-ui-library/CapSelect', () =>
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
<
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
{option.
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
100
|
+
jest.mock('@capillarytech/cap-ui-library/CapSelect', () => ({
|
|
101
|
+
CapCustomSelect: function MockCapCustomSelect({ options, value, onChange, placeholder, ...props }) {
|
|
102
|
+
return (
|
|
103
|
+
<select {...props} value={value} onChange={(e) => onChange(e.target.value)}>
|
|
104
|
+
<option value="">{placeholder}</option>
|
|
105
|
+
{options?.map((option, index) => (
|
|
106
|
+
<option key={index} value={option.value}>
|
|
107
|
+
{option.label}
|
|
108
|
+
</option>
|
|
109
|
+
))}
|
|
110
|
+
</select>
|
|
111
|
+
);
|
|
112
|
+
}
|
|
113
|
+
}));
|
|
112
114
|
|
|
113
115
|
jest.mock('@capillarytech/cap-ui-library/CapRow', () =>
|
|
114
116
|
function MockCapRow({ children, ...props }) {
|
|
@@ -200,27 +202,11 @@ jest.mock('../../../../v2Components/CapVideoUpload', () =>
|
|
|
200
202
|
<div data-testid="cap-video-upload">
|
|
201
203
|
<button
|
|
202
204
|
type="button"
|
|
203
|
-
|
|
204
|
-
onClick={() => props.onVideoUploadUpdateAssestList(0, { videoSrc: 'mock-video-url', previewUrl: 'mock-preview-url' })}
|
|
205
|
+
onClick={() => props.onVideoUploadUpdateAssestList('mock-video-url')}
|
|
205
206
|
data-testid="video-upload-button"
|
|
206
207
|
>
|
|
207
208
|
Upload Video
|
|
208
209
|
</button>
|
|
209
|
-
<button
|
|
210
|
-
type="button"
|
|
211
|
-
// Real Re upload clears the video, then opens the file picker
|
|
212
|
-
onClick={() => props.onVideoUploadUpdateAssestList(0, { videoSrc: '', previewUrl: '' })}
|
|
213
|
-
data-testid="video-reupload-button"
|
|
214
|
-
>
|
|
215
|
-
Re upload Video
|
|
216
|
-
</button>
|
|
217
|
-
<button
|
|
218
|
-
type="button"
|
|
219
|
-
onClick={() => props.uploadAsset({ name: 'test.mp4' }, 'video', {}, props.index)}
|
|
220
|
-
data-testid="video-file-upload-button"
|
|
221
|
-
>
|
|
222
|
-
Pick Video File
|
|
223
|
-
</button>
|
|
224
210
|
</div>
|
|
225
211
|
);
|
|
226
212
|
}
|
|
@@ -339,21 +325,24 @@ jest.mock('@capillarytech/cap-ui-library/CapInput', () => ({
|
|
|
339
325
|
},
|
|
340
326
|
}));
|
|
341
327
|
|
|
342
|
-
|
|
343
|
-
|
|
344
|
-
|
|
345
|
-
|
|
346
|
-
|
|
347
|
-
|
|
348
|
-
|
|
349
|
-
|
|
350
|
-
|
|
351
|
-
|
|
352
|
-
|
|
353
|
-
|
|
354
|
-
|
|
355
|
-
|
|
356
|
-
|
|
328
|
+
// Mock the CapSelect.CapCustomSelect component
|
|
329
|
+
jest.mock('@capillarytech/cap-ui-library/CapSelect', () => ({
|
|
330
|
+
CapCustomSelect: function MockCapCustomSelect({ value, onChange, options }) {
|
|
331
|
+
return (
|
|
332
|
+
<select
|
|
333
|
+
data-testid="cap-custom-select"
|
|
334
|
+
value={value}
|
|
335
|
+
onChange={(e) => onChange && onChange(e.target.value)}
|
|
336
|
+
>
|
|
337
|
+
{options?.map((option) => (
|
|
338
|
+
<option key={option.value} value={option.value}>
|
|
339
|
+
{option.label || option.value}
|
|
340
|
+
</option>
|
|
341
|
+
))}
|
|
342
|
+
</select>
|
|
343
|
+
);
|
|
344
|
+
},
|
|
345
|
+
}));
|
|
357
346
|
|
|
358
347
|
jest.mock('@capillarytech/cap-ui-library/CapRow', () =>
|
|
359
348
|
function MockCapRow({ children, className, style }) {
|
|
@@ -362,8 +351,8 @@ jest.mock('@capillarytech/cap-ui-library/CapRow', () =>
|
|
|
362
351
|
);
|
|
363
352
|
|
|
364
353
|
jest.mock('@capillarytech/cap-ui-library/CapColumn', () =>
|
|
365
|
-
function MockCapColumn({ children, className, span
|
|
366
|
-
return <div className={className} data-span={span}
|
|
354
|
+
function MockCapColumn({ children, className, span }) {
|
|
355
|
+
return <div className={className} data-span={span}>{children}</div>;
|
|
367
356
|
}
|
|
368
357
|
);
|
|
369
358
|
|
|
@@ -403,7 +392,6 @@ jest.mock('../../constants', () => ({
|
|
|
403
392
|
|
|
404
393
|
// Mock the utils
|
|
405
394
|
jest.mock('../../utils', () => ({
|
|
406
|
-
...jest.requireActual('../../utils'),
|
|
407
395
|
validateExternalLink: jest.fn(),
|
|
408
396
|
validateDeepLink: jest.fn(),
|
|
409
397
|
}));
|
|
@@ -500,62 +488,6 @@ jest.mock('../../messages', () => ({
|
|
|
500
488
|
id: 'creatives.containersV2.MobilePushNew.actionOnClickBody',
|
|
501
489
|
defaultMessage: 'Action on click of notification body',
|
|
502
490
|
},
|
|
503
|
-
tapLinkSaveDisabled: {
|
|
504
|
-
id: 'creatives.containersV2.MobilePushNew.tapLinkSaveDisabled',
|
|
505
|
-
defaultMessage: 'Please complete the above fields to enable Save',
|
|
506
|
-
},
|
|
507
|
-
cardTap: {
|
|
508
|
-
id: 'creatives.containersV2.MobilePushNew.cardTap',
|
|
509
|
-
defaultMessage: 'Card tap',
|
|
510
|
-
},
|
|
511
|
-
deepLinkRequired: {
|
|
512
|
-
id: 'creatives.containersV2.MobilePushNew.deepLinkRequired',
|
|
513
|
-
defaultMessage: 'Select a deep link',
|
|
514
|
-
},
|
|
515
|
-
urlNotValid: {
|
|
516
|
-
id: 'creatives.containersV2.MobilePushNew.urlNotValid',
|
|
517
|
-
defaultMessage: 'URL is not valid',
|
|
518
|
-
},
|
|
519
|
-
completeCardToAdd: {
|
|
520
|
-
id: 'creatives.containersV2.MobilePushNew.completeCardToAdd',
|
|
521
|
-
defaultMessage: 'Please set-up the first card before creating the next ones',
|
|
522
|
-
},
|
|
523
|
-
carouselMaxCardTooltip: {
|
|
524
|
-
id: 'creatives.containersV2.MobilePushNew.carouselMaxCardTooltip',
|
|
525
|
-
defaultMessage: 'Mobile push carousel cannot contain more than {max} content cards.',
|
|
526
|
-
},
|
|
527
|
-
cardTapDescription: {
|
|
528
|
-
id: 'creatives.containersV2.MobilePushNew.cardTapDescription',
|
|
529
|
-
defaultMessage: 'What happens when someone taps this card.',
|
|
530
|
-
},
|
|
531
|
-
cardTapAppHelp: {
|
|
532
|
-
id: 'creatives.containersV2.MobilePushNew.cardTapAppHelp',
|
|
533
|
-
defaultMessage: 'Opens your app. Choose a link to send people to a specific page from this card instead.',
|
|
534
|
-
},
|
|
535
|
-
whenTappedOpen: {
|
|
536
|
-
id: 'creatives.containersV2.MobilePushNew.whenTappedOpen',
|
|
537
|
-
defaultMessage: 'When tapped, open',
|
|
538
|
-
},
|
|
539
|
-
tapActionApp: {
|
|
540
|
-
id: 'creatives.containersV2.MobilePushNew.tapActionApp',
|
|
541
|
-
defaultMessage: 'App (default)',
|
|
542
|
-
},
|
|
543
|
-
tapActionDeepLink: {
|
|
544
|
-
id: 'creatives.containersV2.MobilePushNew.tapActionDeepLink',
|
|
545
|
-
defaultMessage: 'Deep link',
|
|
546
|
-
},
|
|
547
|
-
tapActionExternalLink: {
|
|
548
|
-
id: 'creatives.containersV2.MobilePushNew.tapActionExternalLink',
|
|
549
|
-
defaultMessage: 'External link',
|
|
550
|
-
},
|
|
551
|
-
url: {
|
|
552
|
-
id: 'creatives.containersV2.MobilePushNew.url',
|
|
553
|
-
defaultMessage: 'URL',
|
|
554
|
-
},
|
|
555
|
-
enterUrl: {
|
|
556
|
-
id: 'creatives.containersV2.MobilePushNew.enterUrl',
|
|
557
|
-
defaultMessage: 'Enter URL',
|
|
558
|
-
},
|
|
559
491
|
},
|
|
560
492
|
}));
|
|
561
493
|
|
|
@@ -687,7 +619,7 @@ describe('MediaUploaders', () => {
|
|
|
687
619
|
});
|
|
688
620
|
|
|
689
621
|
fireEvent.click(screen.getByTestId('video-upload-button'));
|
|
690
|
-
expect(setUpdateMpushVideoSrc).toHaveBeenCalledWith(
|
|
622
|
+
expect(setUpdateMpushVideoSrc).toHaveBeenCalledWith('mock-video-url');
|
|
691
623
|
});
|
|
692
624
|
});
|
|
693
625
|
|
|
@@ -705,7 +637,7 @@ describe('MediaUploaders', () => {
|
|
|
705
637
|
});
|
|
706
638
|
|
|
707
639
|
fireEvent.click(screen.getByTestId('video-upload-button'));
|
|
708
|
-
expect(setUpdateMpushVideoSrc).toHaveBeenCalledWith(
|
|
640
|
+
expect(setUpdateMpushVideoSrc).toHaveBeenCalledWith('mock-video-url');
|
|
709
641
|
});
|
|
710
642
|
});
|
|
711
643
|
|
|
@@ -720,7 +652,7 @@ describe('MediaUploaders', () => {
|
|
|
720
652
|
mediaType: 'image',
|
|
721
653
|
imageUrl: 'test.jpg',
|
|
722
654
|
buttons: [{
|
|
723
|
-
actionOnClick: true,
|
|
655
|
+
actionOnClick: true,
|
|
724
656
|
linkType: 'EXTERNAL_LINK',
|
|
725
657
|
deepLinkValue: '',
|
|
726
658
|
deepLinkKeys: [],
|
|
@@ -742,9 +674,9 @@ describe('MediaUploaders', () => {
|
|
|
742
674
|
const carouselCard = screen.getByText('Card 1');
|
|
743
675
|
expect(carouselCard).toBeInTheDocument();
|
|
744
676
|
|
|
745
|
-
//
|
|
746
|
-
|
|
747
|
-
expect(
|
|
677
|
+
// Check if the buttons and links section is rendered
|
|
678
|
+
const buttonsAndLinks = screen.getByText('Buttons and links');
|
|
679
|
+
expect(buttonsAndLinks).toBeInTheDocument();
|
|
748
680
|
});
|
|
749
681
|
|
|
750
682
|
it('should initialize carousel data when empty', () => {
|
|
@@ -796,6 +728,59 @@ describe('MediaUploaders', () => {
|
|
|
796
728
|
expect(onCarouselDataChange).toHaveBeenCalledWith(ANDROID, []);
|
|
797
729
|
});
|
|
798
730
|
|
|
731
|
+
it('should handle external link change in carousel actions', () => {
|
|
732
|
+
const mockOnCarouselDataChange = jest.fn();
|
|
733
|
+
|
|
734
|
+
const { container } = renderComponent({
|
|
735
|
+
mediaType: 'CAROUSEL',
|
|
736
|
+
carouselData: [
|
|
737
|
+
{
|
|
738
|
+
mediaType: 'image',
|
|
739
|
+
imageUrl: 'test.jpg',
|
|
740
|
+
buttons: [{
|
|
741
|
+
actionOnClick: true,
|
|
742
|
+
linkType: 'EXTERNAL_LINK',
|
|
743
|
+
deepLinkValue: '',
|
|
744
|
+
deepLinkKeys: [],
|
|
745
|
+
externalLinkValue: 'https://example.com',
|
|
746
|
+
}],
|
|
747
|
+
}
|
|
748
|
+
],
|
|
749
|
+
onCarouselDataChange: mockOnCarouselDataChange,
|
|
750
|
+
carouselActiveTabIndex: 0,
|
|
751
|
+
activeTab: 'ANDROID',
|
|
752
|
+
formatMessage: mockFormatMessage,
|
|
753
|
+
});
|
|
754
|
+
|
|
755
|
+
// First check if the checkbox is checked
|
|
756
|
+
const actionOnClickCheckbox = screen.getByTestId('cap-checkbox');
|
|
757
|
+
expect(actionOnClickCheckbox).toBeChecked();
|
|
758
|
+
|
|
759
|
+
// First select the external link type
|
|
760
|
+
const linkTypeSelect = screen.getAllByTestId('cap-custom-select')[0];
|
|
761
|
+
fireEvent.change(linkTypeSelect, { target: { value: 'EXTERNAL_LINK' } });
|
|
762
|
+
|
|
763
|
+
// Wait for the external link input to be rendered
|
|
764
|
+
const externalLinkInput = screen.getByTestId('cap-input-mobile-push-external-link-input-ANDROID-0');
|
|
765
|
+
expect(externalLinkInput).toBeInTheDocument();
|
|
766
|
+
expect(externalLinkInput.value).toBe('https://example.com');
|
|
767
|
+
|
|
768
|
+
// Change external link value
|
|
769
|
+
fireEvent.change(externalLinkInput, { target: { value: 'https://newexample.com' } });
|
|
770
|
+
|
|
771
|
+
expect(mockOnCarouselDataChange).toHaveBeenCalledWith(
|
|
772
|
+
'ANDROID',
|
|
773
|
+
expect.arrayContaining([
|
|
774
|
+
expect.objectContaining({
|
|
775
|
+
buttons: expect.arrayContaining([
|
|
776
|
+
expect.objectContaining({
|
|
777
|
+
externalLinkValue: 'https://newexample.com',
|
|
778
|
+
}),
|
|
779
|
+
]),
|
|
780
|
+
}),
|
|
781
|
+
])
|
|
782
|
+
);
|
|
783
|
+
});
|
|
799
784
|
});
|
|
800
785
|
|
|
801
786
|
describe('Platform switching', () => {
|
|
@@ -846,7 +831,7 @@ describe('MediaUploaders', () => {
|
|
|
846
831
|
</Provider>
|
|
847
832
|
);
|
|
848
833
|
|
|
849
|
-
expect(clearImageDataByMediaType).toHaveBeenCalledWith('IMAGE'
|
|
834
|
+
expect(clearImageDataByMediaType).toHaveBeenCalledWith('IMAGE');
|
|
850
835
|
});
|
|
851
836
|
|
|
852
837
|
it('should clear image data when switching from CAROUSEL to IMAGE', () => {
|
|
@@ -868,36 +853,7 @@ describe('MediaUploaders', () => {
|
|
|
868
853
|
</Provider>
|
|
869
854
|
);
|
|
870
855
|
|
|
871
|
-
expect(clearImageDataByMediaType).toHaveBeenCalledWith('IMAGE'
|
|
872
|
-
});
|
|
873
|
-
|
|
874
|
-
// A tab switch gives the hidden pane a new clearImageDataByMediaType; that alone must not clear anything
|
|
875
|
-
it('does not clear when only the callbacks change (tab switch), and clears its own platform on a real change', () => {
|
|
876
|
-
const firstClear = jest.fn();
|
|
877
|
-
const onCarouselDataChange = jest.fn();
|
|
878
|
-
const renderPane = (mediaType, clearImageDataByMediaType) => (
|
|
879
|
-
<Provider store={mockStore}>
|
|
880
|
-
<IntlProvider messages={messages} locale="en">
|
|
881
|
-
<MediaUploaders
|
|
882
|
-
{...defaultProps}
|
|
883
|
-
activeTab={IOS}
|
|
884
|
-
mediaType={mediaType}
|
|
885
|
-
clearImageDataByMediaType={clearImageDataByMediaType}
|
|
886
|
-
onCarouselDataChange={onCarouselDataChange}
|
|
887
|
-
/>
|
|
888
|
-
</IntlProvider>
|
|
889
|
-
</Provider>
|
|
890
|
-
);
|
|
891
|
-
const { rerender } = render(renderPane('VIDEO', firstClear));
|
|
892
|
-
|
|
893
|
-
const clearAfterTabSwitch = jest.fn();
|
|
894
|
-
rerender(renderPane('VIDEO', clearAfterTabSwitch));
|
|
895
|
-
expect(firstClear).not.toHaveBeenCalled();
|
|
896
|
-
expect(clearAfterTabSwitch).not.toHaveBeenCalled();
|
|
897
|
-
expect(onCarouselDataChange).not.toHaveBeenCalled();
|
|
898
|
-
|
|
899
|
-
rerender(renderPane('NONE', clearAfterTabSwitch));
|
|
900
|
-
expect(clearAfterTabSwitch).toHaveBeenCalledWith('IMAGE', IOS);
|
|
856
|
+
expect(clearImageDataByMediaType).toHaveBeenCalledWith('IMAGE');
|
|
901
857
|
});
|
|
902
858
|
});
|
|
903
859
|
|
|
@@ -1021,44 +977,6 @@ describe('MediaUploaders', () => {
|
|
|
1021
977
|
});
|
|
1022
978
|
|
|
1023
979
|
describe('Carousel card management', () => {
|
|
1024
|
-
const doneCard = (mediaType, media) => ({
|
|
1025
|
-
mediaType,
|
|
1026
|
-
imageUrl: mediaType === 'image' ? media : '',
|
|
1027
|
-
videoSrc: mediaType === 'video' ? media : '',
|
|
1028
|
-
buttons: [{ actionOnClick: false, linkType: 'DEEP_LINK', deepLinkValue: '', externalLinkValue: '' }],
|
|
1029
|
-
});
|
|
1030
|
-
|
|
1031
|
-
it('opens the new card after adding it', () => {
|
|
1032
|
-
const onCarouselDataChange = jest.fn();
|
|
1033
|
-
const setCarouselActiveTabIndex = jest.fn();
|
|
1034
|
-
renderComponent({
|
|
1035
|
-
mediaType: 'CAROUSEL',
|
|
1036
|
-
carouselData: [doneCard('image', 'a.jpg'), doneCard('image', 'b.jpg')],
|
|
1037
|
-
onCarouselDataChange,
|
|
1038
|
-
setCarouselActiveTabIndex,
|
|
1039
|
-
});
|
|
1040
|
-
setCarouselActiveTabIndex.mockClear();
|
|
1041
|
-
|
|
1042
|
-
fireEvent.click(document.querySelector('.add-carousel-content-button'));
|
|
1043
|
-
|
|
1044
|
-
expect(onCarouselDataChange).toHaveBeenCalledWith(ANDROID, expect.any(Array));
|
|
1045
|
-
expect(onCarouselDataChange.mock.calls.pop()[1]).toHaveLength(3);
|
|
1046
|
-
expect(setCarouselActiveTabIndex).toHaveBeenCalledWith(2);
|
|
1047
|
-
});
|
|
1048
|
-
|
|
1049
|
-
it.each([
|
|
1050
|
-
['an image card has no image', [doneCard('image', 'a.jpg'), doneCard('image', '')]],
|
|
1051
|
-
['a video card has no video', [doneCard('video', 'a.mp4'), doneCard('video', '')]],
|
|
1052
|
-
])('disables add while %s', (_label, carouselData) => {
|
|
1053
|
-
renderComponent({ mediaType: 'CAROUSEL', carouselData });
|
|
1054
|
-
expect(document.querySelector('.add-carousel-content-button')).toBeDisabled();
|
|
1055
|
-
});
|
|
1056
|
-
|
|
1057
|
-
it('enables add once every video card has its video', () => {
|
|
1058
|
-
renderComponent({ mediaType: 'CAROUSEL', carouselData: [doneCard('video', 'a.mp4'), doneCard('video', 'b.mp4')] });
|
|
1059
|
-
expect(document.querySelector('.add-carousel-content-button')).not.toBeDisabled();
|
|
1060
|
-
});
|
|
1061
|
-
|
|
1062
980
|
it('should add new carousel card when add button is clicked', () => {
|
|
1063
981
|
const onCarouselDataChange = jest.fn();
|
|
1064
982
|
renderComponent({
|
|
@@ -1066,7 +984,7 @@ describe('MediaUploaders', () => {
|
|
|
1066
984
|
carouselData: [
|
|
1067
985
|
{
|
|
1068
986
|
mediaType: 'image',
|
|
1069
|
-
imageUrl: '
|
|
987
|
+
imageUrl: '',
|
|
1070
988
|
buttons: [{
|
|
1071
989
|
actionOnClick: false,
|
|
1072
990
|
linkType: 'DEEP_LINK',
|
|
@@ -1214,6 +1132,147 @@ describe('MediaUploaders', () => {
|
|
|
1214
1132
|
});
|
|
1215
1133
|
|
|
1216
1134
|
describe('Carousel action link handlers', () => {
|
|
1135
|
+
it('should handle carousel action on click change', () => {
|
|
1136
|
+
const onCarouselDataChange = jest.fn();
|
|
1137
|
+
renderComponent({
|
|
1138
|
+
mediaType: 'CAROUSEL',
|
|
1139
|
+
carouselData: [
|
|
1140
|
+
{
|
|
1141
|
+
mediaType: 'image',
|
|
1142
|
+
imageUrl: '',
|
|
1143
|
+
buttons: [{
|
|
1144
|
+
actionOnClick: false,
|
|
1145
|
+
linkType: 'DEEP_LINK',
|
|
1146
|
+
deepLinkValue: '',
|
|
1147
|
+
externalLinkValue: '',
|
|
1148
|
+
}],
|
|
1149
|
+
}
|
|
1150
|
+
],
|
|
1151
|
+
onCarouselDataChange,
|
|
1152
|
+
});
|
|
1153
|
+
|
|
1154
|
+
// Find checkbox by class name since it renders with cap-checkbox-v2
|
|
1155
|
+
const checkbox = document.querySelector('.cap-checkbox-v2 input[type="checkbox"]');
|
|
1156
|
+
if (checkbox) {
|
|
1157
|
+
fireEvent.click(checkbox);
|
|
1158
|
+
expect(onCarouselDataChange).toHaveBeenCalledWith(
|
|
1159
|
+
ANDROID,
|
|
1160
|
+
expect.arrayContaining([
|
|
1161
|
+
expect.objectContaining({
|
|
1162
|
+
buttons: expect.arrayContaining([
|
|
1163
|
+
expect.objectContaining({
|
|
1164
|
+
actionOnClick: true,
|
|
1165
|
+
})
|
|
1166
|
+
])
|
|
1167
|
+
})
|
|
1168
|
+
])
|
|
1169
|
+
);
|
|
1170
|
+
} else {
|
|
1171
|
+
// If checkbox not found, just verify component renders
|
|
1172
|
+
expect(screen.getByTestId('cap-image-upload')).toBeInTheDocument();
|
|
1173
|
+
}
|
|
1174
|
+
});
|
|
1175
|
+
|
|
1176
|
+
it('should handle carousel link type change', () => {
|
|
1177
|
+
const onCarouselDataChange = jest.fn();
|
|
1178
|
+
const updateCarouselLinkError = jest.fn();
|
|
1179
|
+
renderComponent({
|
|
1180
|
+
mediaType: 'CAROUSEL',
|
|
1181
|
+
carouselData: [
|
|
1182
|
+
{
|
|
1183
|
+
mediaType: 'image',
|
|
1184
|
+
imageUrl: '',
|
|
1185
|
+
buttons: [{
|
|
1186
|
+
actionOnClick: true, // Enable action links
|
|
1187
|
+
linkType: 'DEEP_LINK',
|
|
1188
|
+
deepLinkValue: '',
|
|
1189
|
+
externalLinkValue: '',
|
|
1190
|
+
}],
|
|
1191
|
+
}
|
|
1192
|
+
],
|
|
1193
|
+
onCarouselDataChange,
|
|
1194
|
+
updateCarouselLinkError,
|
|
1195
|
+
});
|
|
1196
|
+
|
|
1197
|
+
// Should show action checkbox and description when carousel is rendered
|
|
1198
|
+
const checkbox = document.querySelector('.cap-checkbox-v2');
|
|
1199
|
+
if (checkbox) {
|
|
1200
|
+
expect(checkbox).toBeInTheDocument();
|
|
1201
|
+
|
|
1202
|
+
// The checkbox should be checked since actionOnClick is true
|
|
1203
|
+
const checkboxInput = checkbox.querySelector('input[type="checkbox"]');
|
|
1204
|
+
expect(checkboxInput.checked).toBe(true);
|
|
1205
|
+
} else {
|
|
1206
|
+
// If checkbox not found, just verify component renders
|
|
1207
|
+
expect(screen.getByTestId('cap-image-upload')).toBeInTheDocument();
|
|
1208
|
+
}
|
|
1209
|
+
});
|
|
1210
|
+
|
|
1211
|
+
it('should validate deep link when value changes', () => {
|
|
1212
|
+
const onCarouselDataChange = jest.fn();
|
|
1213
|
+
const updateCarouselLinkError = jest.fn();
|
|
1214
|
+
renderComponent({
|
|
1215
|
+
mediaType: 'CAROUSEL',
|
|
1216
|
+
carouselData: [
|
|
1217
|
+
{
|
|
1218
|
+
mediaType: 'image',
|
|
1219
|
+
imageUrl: '',
|
|
1220
|
+
buttons: [{
|
|
1221
|
+
actionOnClick: true,
|
|
1222
|
+
linkType: 'DEEP_LINK',
|
|
1223
|
+
deepLinkValue: '',
|
|
1224
|
+
externalLinkValue: '',
|
|
1225
|
+
}],
|
|
1226
|
+
}
|
|
1227
|
+
],
|
|
1228
|
+
onCarouselDataChange,
|
|
1229
|
+
updateCarouselLinkError,
|
|
1230
|
+
linkProps: {
|
|
1231
|
+
deepLink: [
|
|
1232
|
+
{ value: 'test-deep-link', label: 'Test Deep Link' }
|
|
1233
|
+
]
|
|
1234
|
+
}
|
|
1235
|
+
});
|
|
1236
|
+
|
|
1237
|
+
// Should render carousel component with action checkbox
|
|
1238
|
+
const checkbox = document.querySelector('.cap-checkbox-v2');
|
|
1239
|
+
if (checkbox) {
|
|
1240
|
+
expect(checkbox).toBeInTheDocument();
|
|
1241
|
+
} else {
|
|
1242
|
+
// If checkbox not found, just verify component renders
|
|
1243
|
+
expect(screen.getByTestId('cap-image-upload')).toBeInTheDocument();
|
|
1244
|
+
}
|
|
1245
|
+
|
|
1246
|
+
// Verify deep link props are available and component renders correctly
|
|
1247
|
+
expect(screen.getByTestId('cap-image-upload')).toBeInTheDocument();
|
|
1248
|
+
});
|
|
1249
|
+
|
|
1250
|
+
it('should validate external link when value changes', () => {
|
|
1251
|
+
const onCarouselDataChange = jest.fn();
|
|
1252
|
+
const updateCarouselLinkError = jest.fn();
|
|
1253
|
+
renderComponent({
|
|
1254
|
+
mediaType: 'CAROUSEL',
|
|
1255
|
+
carouselData: [
|
|
1256
|
+
{
|
|
1257
|
+
mediaType: 'image',
|
|
1258
|
+
imageUrl: '',
|
|
1259
|
+
buttons: [{
|
|
1260
|
+
actionOnClick: true,
|
|
1261
|
+
linkType: 'EXTERNAL_LINK',
|
|
1262
|
+
deepLinkValue: '',
|
|
1263
|
+
externalLinkValue: '',
|
|
1264
|
+
}],
|
|
1265
|
+
}
|
|
1266
|
+
],
|
|
1267
|
+
onCarouselDataChange,
|
|
1268
|
+
updateCarouselLinkError,
|
|
1269
|
+
});
|
|
1270
|
+
|
|
1271
|
+
// Should render external link input when EXTERNAL_LINK is selected
|
|
1272
|
+
// Note: This would require the component to be modified to show external link input
|
|
1273
|
+
// For now, we're testing that the component renders without errors
|
|
1274
|
+
expect(screen.getByTestId('cap-image-upload')).toBeInTheDocument();
|
|
1275
|
+
});
|
|
1217
1276
|
|
|
1218
1277
|
it('should handle carousel image change', () => {
|
|
1219
1278
|
const onCarouselDataChange = jest.fn();
|
|
@@ -1261,6 +1320,61 @@ describe('MediaUploaders', () => {
|
|
|
1261
1320
|
});
|
|
1262
1321
|
});
|
|
1263
1322
|
|
|
1323
|
+
describe('Carousel error handling', () => {
|
|
1324
|
+
it('should display carousel deep link error when present', () => {
|
|
1325
|
+
renderComponent({
|
|
1326
|
+
mediaType: 'CAROUSEL',
|
|
1327
|
+
carouselData: [
|
|
1328
|
+
{
|
|
1329
|
+
mediaType: 'image',
|
|
1330
|
+
imageUrl: '',
|
|
1331
|
+
buttons: [{
|
|
1332
|
+
actionOnClick: true,
|
|
1333
|
+
linkType: 'DEEP_LINK',
|
|
1334
|
+
deepLinkValue: 'invalid-deep-link',
|
|
1335
|
+
externalLinkValue: '',
|
|
1336
|
+
}],
|
|
1337
|
+
}
|
|
1338
|
+
],
|
|
1339
|
+
carouselLinkErrors: {
|
|
1340
|
+
'0-deepLink': 'Invalid deep link format'
|
|
1341
|
+
},
|
|
1342
|
+
linkProps: {
|
|
1343
|
+
deepLink: [
|
|
1344
|
+
{ value: 'valid-deep-link', label: 'Valid Deep Link' }
|
|
1345
|
+
]
|
|
1346
|
+
}
|
|
1347
|
+
});
|
|
1348
|
+
|
|
1349
|
+
// Component should render without crashing when errors are present
|
|
1350
|
+
expect(screen.getByTestId('cap-image-upload')).toBeInTheDocument();
|
|
1351
|
+
});
|
|
1352
|
+
|
|
1353
|
+
it('should display carousel external link error when present', () => {
|
|
1354
|
+
renderComponent({
|
|
1355
|
+
mediaType: 'CAROUSEL',
|
|
1356
|
+
carouselData: [
|
|
1357
|
+
{
|
|
1358
|
+
mediaType: 'image',
|
|
1359
|
+
imageUrl: '',
|
|
1360
|
+
buttons: [{
|
|
1361
|
+
actionOnClick: true,
|
|
1362
|
+
linkType: 'EXTERNAL_LINK',
|
|
1363
|
+
deepLinkValue: '',
|
|
1364
|
+
externalLinkValue: 'invalid-url',
|
|
1365
|
+
}],
|
|
1366
|
+
}
|
|
1367
|
+
],
|
|
1368
|
+
carouselLinkErrors: {
|
|
1369
|
+
'0-externalLink': 'Invalid external link format'
|
|
1370
|
+
}
|
|
1371
|
+
});
|
|
1372
|
+
|
|
1373
|
+
// Component should render without crashing when errors are present
|
|
1374
|
+
expect(screen.getByTestId('cap-image-upload')).toBeInTheDocument();
|
|
1375
|
+
});
|
|
1376
|
+
});
|
|
1377
|
+
|
|
1264
1378
|
describe('Carousel maximum cards limit', () => {
|
|
1265
1379
|
it('should disable add button when maximum carousel cards reached', () => {
|
|
1266
1380
|
const carouselData = Array(10).fill().map((_, index) => ({
|
|
@@ -1361,9 +1475,8 @@ describe('MediaUploaders', () => {
|
|
|
1361
1475
|
onCarouselDataChange,
|
|
1362
1476
|
});
|
|
1363
1477
|
|
|
1364
|
-
//
|
|
1365
|
-
expect(screen.getByTestId('cap-
|
|
1366
|
-
expect(screen.queryByTestId('cap-image-upload')).toBeNull();
|
|
1478
|
+
// Should render carousel component
|
|
1479
|
+
expect(screen.getByTestId('cap-image-upload')).toBeInTheDocument();
|
|
1367
1480
|
});
|
|
1368
1481
|
|
|
1369
1482
|
it('should handle carousel video upload when video component is used', () => {
|
|
@@ -1410,8 +1523,7 @@ describe('MediaUploaders', () => {
|
|
|
1410
1523
|
</Provider>
|
|
1411
1524
|
);
|
|
1412
1525
|
|
|
1413
|
-
expect(screen.getByTestId('cap-
|
|
1414
|
-
expect(screen.queryByTestId('cap-image-upload')).toBeNull();
|
|
1526
|
+
expect(screen.getByTestId('cap-image-upload')).toBeInTheDocument();
|
|
1415
1527
|
});
|
|
1416
1528
|
});
|
|
1417
1529
|
|
|
@@ -1545,12 +1657,105 @@ describe('MediaUploaders', () => {
|
|
|
1545
1657
|
});
|
|
1546
1658
|
});
|
|
1547
1659
|
|
|
1548
|
-
describe('Carousel
|
|
1549
|
-
it('should clear
|
|
1550
|
-
const
|
|
1551
|
-
|
|
1552
|
-
|
|
1553
|
-
|
|
1660
|
+
describe('Carousel link validation', () => {
|
|
1661
|
+
it('should clear errors when link type changes', () => {
|
|
1662
|
+
const updateCarouselLinkError = jest.fn();
|
|
1663
|
+
renderComponent({
|
|
1664
|
+
mediaType: 'CAROUSEL',
|
|
1665
|
+
carouselData: [
|
|
1666
|
+
{
|
|
1667
|
+
mediaType: 'image',
|
|
1668
|
+
imageUrl: '',
|
|
1669
|
+
buttons: [{
|
|
1670
|
+
actionOnClick: true,
|
|
1671
|
+
linkType: 'DEEP_LINK',
|
|
1672
|
+
deepLinkValue: 'test',
|
|
1673
|
+
externalLinkValue: '',
|
|
1674
|
+
}],
|
|
1675
|
+
}
|
|
1676
|
+
],
|
|
1677
|
+
updateCarouselLinkError,
|
|
1678
|
+
carouselLinkErrors: {
|
|
1679
|
+
'0-deepLink': 'Previous error'
|
|
1680
|
+
}
|
|
1681
|
+
});
|
|
1682
|
+
|
|
1683
|
+
// Should render carousel component
|
|
1684
|
+
expect(screen.getByTestId('cap-image-upload')).toBeInTheDocument();
|
|
1685
|
+
});
|
|
1686
|
+
|
|
1687
|
+
it('should validate external link on change', () => {
|
|
1688
|
+
const updateCarouselLinkError = jest.fn();
|
|
1689
|
+
const onCarouselDataChange = jest.fn();
|
|
1690
|
+
|
|
1691
|
+
// Mock the validation function
|
|
1692
|
+
const { validateExternalLink } = require('../../utils');
|
|
1693
|
+
validateExternalLink.mockReturnValue('Invalid URL');
|
|
1694
|
+
|
|
1695
|
+
renderComponent({
|
|
1696
|
+
mediaType: 'CAROUSEL',
|
|
1697
|
+
carouselData: [
|
|
1698
|
+
{
|
|
1699
|
+
mediaType: 'image',
|
|
1700
|
+
imageUrl: '',
|
|
1701
|
+
buttons: [{
|
|
1702
|
+
actionOnClick: true,
|
|
1703
|
+
linkType: 'EXTERNAL_LINK',
|
|
1704
|
+
deepLinkValue: '',
|
|
1705
|
+
externalLinkValue: 'invalid-url',
|
|
1706
|
+
}],
|
|
1707
|
+
}
|
|
1708
|
+
],
|
|
1709
|
+
updateCarouselLinkError,
|
|
1710
|
+
onCarouselDataChange,
|
|
1711
|
+
});
|
|
1712
|
+
|
|
1713
|
+
// Should render carousel component
|
|
1714
|
+
expect(screen.getByTestId('cap-image-upload')).toBeInTheDocument();
|
|
1715
|
+
});
|
|
1716
|
+
|
|
1717
|
+
it('should validate deep link on change', () => {
|
|
1718
|
+
const updateCarouselLinkError = jest.fn();
|
|
1719
|
+
const onCarouselDataChange = jest.fn();
|
|
1720
|
+
|
|
1721
|
+
// Mock the validation function
|
|
1722
|
+
const { validateDeepLink } = require('../../utils');
|
|
1723
|
+
validateDeepLink.mockReturnValue('Invalid deep link');
|
|
1724
|
+
|
|
1725
|
+
renderComponent({
|
|
1726
|
+
mediaType: 'CAROUSEL',
|
|
1727
|
+
carouselData: [
|
|
1728
|
+
{
|
|
1729
|
+
mediaType: 'image',
|
|
1730
|
+
imageUrl: '',
|
|
1731
|
+
buttons: [{
|
|
1732
|
+
actionOnClick: true,
|
|
1733
|
+
linkType: 'DEEP_LINK',
|
|
1734
|
+
deepLinkValue: 'invalid-link',
|
|
1735
|
+
externalLinkValue: '',
|
|
1736
|
+
}],
|
|
1737
|
+
}
|
|
1738
|
+
],
|
|
1739
|
+
updateCarouselLinkError,
|
|
1740
|
+
onCarouselDataChange,
|
|
1741
|
+
linkProps: {
|
|
1742
|
+
deepLink: [
|
|
1743
|
+
{ value: 'valid-link', label: 'Valid Link' }
|
|
1744
|
+
]
|
|
1745
|
+
}
|
|
1746
|
+
});
|
|
1747
|
+
|
|
1748
|
+
// Should render carousel component
|
|
1749
|
+
expect(screen.getByTestId('cap-image-upload')).toBeInTheDocument();
|
|
1750
|
+
});
|
|
1751
|
+
});
|
|
1752
|
+
|
|
1753
|
+
describe('Carousel asset clearing', () => {
|
|
1754
|
+
it('should clear assets after updating carousel card', () => {
|
|
1755
|
+
const mobilePushActions = {
|
|
1756
|
+
clearAsset: jest.fn(),
|
|
1757
|
+
};
|
|
1758
|
+
const onCarouselDataChange = jest.fn();
|
|
1554
1759
|
|
|
1555
1760
|
renderComponent({
|
|
1556
1761
|
mediaType: 'CAROUSEL',
|
|
@@ -1647,7 +1852,7 @@ describe('MediaUploaders', () => {
|
|
|
1647
1852
|
mediaType: 'image',
|
|
1648
1853
|
imageUrl: 'test.jpg',
|
|
1649
1854
|
buttons: [{
|
|
1650
|
-
actionOnClick: true,
|
|
1855
|
+
actionOnClick: true,
|
|
1651
1856
|
linkType: 'EXTERNAL_LINK',
|
|
1652
1857
|
deepLinkValue: '',
|
|
1653
1858
|
externalLinkValue: 'https://example.com',
|
|
@@ -1742,6 +1947,117 @@ describe('MediaUploaders', () => {
|
|
|
1742
1947
|
expect(screen.getByTestId('cap-video-upload')).toBeInTheDocument();
|
|
1743
1948
|
});
|
|
1744
1949
|
|
|
1950
|
+
it('should handle carousel action on click change', () => {
|
|
1951
|
+
const onCarouselDataChange = jest.fn();
|
|
1952
|
+
renderComponent({
|
|
1953
|
+
mediaType: 'CAROUSEL',
|
|
1954
|
+
carouselData: [
|
|
1955
|
+
{
|
|
1956
|
+
mediaType: 'image',
|
|
1957
|
+
imageUrl: 'test.jpg',
|
|
1958
|
+
buttons: [{
|
|
1959
|
+
actionOnClick: false,
|
|
1960
|
+
linkType: 'DEEP_LINK',
|
|
1961
|
+
deepLinkValue: '',
|
|
1962
|
+
externalLinkValue: '',
|
|
1963
|
+
}],
|
|
1964
|
+
}
|
|
1965
|
+
],
|
|
1966
|
+
onCarouselDataChange,
|
|
1967
|
+
carouselActiveTabIndex: 0,
|
|
1968
|
+
});
|
|
1969
|
+
|
|
1970
|
+
// Should render carousel with buttons
|
|
1971
|
+
const checkbox = screen.getByTestId('cap-checkbox');
|
|
1972
|
+
fireEvent.click(checkbox);
|
|
1973
|
+
|
|
1974
|
+
// Should call onCarouselDataChange when checkbox changes
|
|
1975
|
+
expect(onCarouselDataChange).toHaveBeenCalled();
|
|
1976
|
+
});
|
|
1977
|
+
|
|
1978
|
+
it('should render action links when actionOnClick is enabled', () => {
|
|
1979
|
+
renderComponent({
|
|
1980
|
+
mediaType: 'CAROUSEL',
|
|
1981
|
+
carouselData: [
|
|
1982
|
+
{
|
|
1983
|
+
mediaType: 'image',
|
|
1984
|
+
imageUrl: 'test.jpg',
|
|
1985
|
+
buttons: [{
|
|
1986
|
+
actionOnClick: true, // This triggers action links rendering
|
|
1987
|
+
linkType: 'DEEP_LINK',
|
|
1988
|
+
deepLinkValue: '',
|
|
1989
|
+
externalLinkValue: '',
|
|
1990
|
+
}],
|
|
1991
|
+
}
|
|
1992
|
+
],
|
|
1993
|
+
carouselActiveTabIndex: 0,
|
|
1994
|
+
linkProps: {
|
|
1995
|
+
deepLink: [
|
|
1996
|
+
{ value: 'test-deep-link', label: 'Test Deep Link' }
|
|
1997
|
+
]
|
|
1998
|
+
}
|
|
1999
|
+
});
|
|
2000
|
+
|
|
2001
|
+
// Should render action links components
|
|
2002
|
+
expect(screen.getByTestId('cap-checkbox')).toBeInTheDocument();
|
|
2003
|
+
expect(screen.getAllByTestId('cap-custom-select')).toHaveLength(2); // Link type and deep link selects
|
|
2004
|
+
});
|
|
2005
|
+
|
|
2006
|
+
it('should show carousel link errors when present', () => {
|
|
2007
|
+
renderComponent({
|
|
2008
|
+
mediaType: 'CAROUSEL',
|
|
2009
|
+
carouselData: [
|
|
2010
|
+
{
|
|
2011
|
+
mediaType: 'image',
|
|
2012
|
+
imageUrl: 'test.jpg',
|
|
2013
|
+
buttons: [{
|
|
2014
|
+
actionOnClick: true,
|
|
2015
|
+
linkType: 'DEEP_LINK',
|
|
2016
|
+
deepLinkValue: 'invalid-link',
|
|
2017
|
+
externalLinkValue: '',
|
|
2018
|
+
}],
|
|
2019
|
+
}
|
|
2020
|
+
],
|
|
2021
|
+
carouselActiveTabIndex: 0,
|
|
2022
|
+
carouselLinkErrors: {
|
|
2023
|
+
'0-deepLink': 'Invalid deep link format'
|
|
2024
|
+
},
|
|
2025
|
+
linkProps: {
|
|
2026
|
+
deepLink: [
|
|
2027
|
+
{ value: 'valid-link', label: 'Valid Link' }
|
|
2028
|
+
]
|
|
2029
|
+
}
|
|
2030
|
+
});
|
|
2031
|
+
|
|
2032
|
+
// Should render deep link error
|
|
2033
|
+
expect(screen.getByText('Invalid deep link format')).toBeInTheDocument();
|
|
2034
|
+
});
|
|
2035
|
+
|
|
2036
|
+
it('should show external link error when present', () => {
|
|
2037
|
+
renderComponent({
|
|
2038
|
+
mediaType: 'CAROUSEL',
|
|
2039
|
+
carouselData: [
|
|
2040
|
+
{
|
|
2041
|
+
mediaType: 'image',
|
|
2042
|
+
imageUrl: 'test.jpg',
|
|
2043
|
+
buttons: [{
|
|
2044
|
+
actionOnClick: true,
|
|
2045
|
+
linkType: 'EXTERNAL_LINK',
|
|
2046
|
+
deepLinkValue: '',
|
|
2047
|
+
externalLinkValue: 'invalid-url',
|
|
2048
|
+
}],
|
|
2049
|
+
}
|
|
2050
|
+
],
|
|
2051
|
+
carouselActiveTabIndex: 0,
|
|
2052
|
+
carouselLinkErrors: {
|
|
2053
|
+
'0-externalLink': 'Invalid external link format'
|
|
2054
|
+
}
|
|
2055
|
+
});
|
|
2056
|
+
|
|
2057
|
+
// Should render external link error
|
|
2058
|
+
expect(screen.getByText('Invalid external link format')).toBeInTheDocument();
|
|
2059
|
+
});
|
|
2060
|
+
|
|
1745
2061
|
it('should handle carousel action links with no buttons array', () => {
|
|
1746
2062
|
renderComponent({
|
|
1747
2063
|
mediaType: 'CAROUSEL',
|
|
@@ -1757,7 +2073,7 @@ describe('MediaUploaders', () => {
|
|
|
1757
2073
|
|
|
1758
2074
|
// Should render carousel without action links section
|
|
1759
2075
|
expect(screen.getByTestId('cap-tab')).toBeInTheDocument();
|
|
1760
|
-
expect(screen.
|
|
2076
|
+
expect(screen.queryByTestId('cap-checkbox')).not.toBeInTheDocument();
|
|
1761
2077
|
});
|
|
1762
2078
|
|
|
1763
2079
|
it('should handle multiple carousel cards with tab operations', () => {
|
|
@@ -1988,12 +2304,436 @@ describe('MediaUploaders', () => {
|
|
|
1988
2304
|
expect.arrayContaining([
|
|
1989
2305
|
expect.objectContaining({
|
|
1990
2306
|
videoSrc: 'mock-video-url',
|
|
1991
|
-
videoPreviewImg: 'mock-preview-url',
|
|
1992
2307
|
})
|
|
1993
2308
|
])
|
|
1994
2309
|
);
|
|
1995
2310
|
});
|
|
1996
2311
|
|
|
2312
|
+
it('should handle link type change in carousel actions', () => {
|
|
2313
|
+
const onCarouselDataChange = jest.fn();
|
|
2314
|
+
|
|
2315
|
+
renderComponent({
|
|
2316
|
+
mediaType: 'CAROUSEL',
|
|
2317
|
+
carouselData: [
|
|
2318
|
+
{
|
|
2319
|
+
mediaType: 'image',
|
|
2320
|
+
imageUrl: 'test.jpg',
|
|
2321
|
+
buttons: [{
|
|
2322
|
+
actionOnClick: true,
|
|
2323
|
+
linkType: 'DEEP_LINK',
|
|
2324
|
+
deepLinkValue: '',
|
|
2325
|
+
externalLinkValue: '',
|
|
2326
|
+
}],
|
|
2327
|
+
}
|
|
2328
|
+
],
|
|
2329
|
+
onCarouselDataChange,
|
|
2330
|
+
carouselActiveTabIndex: 0,
|
|
2331
|
+
});
|
|
2332
|
+
|
|
2333
|
+
// Find link type select and change it
|
|
2334
|
+
const linkTypeSelect = screen.getAllByTestId('cap-custom-select')[0];
|
|
2335
|
+
fireEvent.change(linkTypeSelect, { target: { value: 'EXTERNAL_LINK' } });
|
|
2336
|
+
|
|
2337
|
+
// Should call onCarouselDataChange
|
|
2338
|
+
expect(onCarouselDataChange).toHaveBeenCalled();
|
|
2339
|
+
});
|
|
2340
|
+
|
|
2341
|
+
it('should handle deep link change in carousel actions', () => {
|
|
2342
|
+
const onCarouselDataChange = jest.fn();
|
|
2343
|
+
|
|
2344
|
+
renderComponent({
|
|
2345
|
+
mediaType: 'CAROUSEL',
|
|
2346
|
+
carouselData: [
|
|
2347
|
+
{
|
|
2348
|
+
mediaType: 'image',
|
|
2349
|
+
imageUrl: 'test.jpg',
|
|
2350
|
+
buttons: [{
|
|
2351
|
+
actionOnClick: true,
|
|
2352
|
+
linkType: 'DEEP_LINK',
|
|
2353
|
+
deepLinkValue: '',
|
|
2354
|
+
externalLinkValue: '',
|
|
2355
|
+
}],
|
|
2356
|
+
}
|
|
2357
|
+
],
|
|
2358
|
+
onCarouselDataChange,
|
|
2359
|
+
carouselActiveTabIndex: 0,
|
|
2360
|
+
linkProps: {
|
|
2361
|
+
deepLink: [
|
|
2362
|
+
{ value: 'test-deep-link', keys: ['key1', 'key2'] }
|
|
2363
|
+
]
|
|
2364
|
+
}
|
|
2365
|
+
});
|
|
2366
|
+
|
|
2367
|
+
// Find deep link select and change it
|
|
2368
|
+
const deepLinkSelect = screen.getAllByTestId('cap-custom-select')[1];
|
|
2369
|
+
fireEvent.change(deepLinkSelect, { target: { value: 'test-deep-link' } });
|
|
2370
|
+
|
|
2371
|
+
// Should call onCarouselDataChange
|
|
2372
|
+
expect(onCarouselDataChange).toHaveBeenCalled();
|
|
2373
|
+
});
|
|
2374
|
+
});
|
|
2375
|
+
|
|
2376
|
+
// Carousel deep link keys handling - covering lines 609, 612, 614, 625-662
|
|
2377
|
+
it('should handle carousel deep link keys with array from selection', () => {
|
|
2378
|
+
const mockDeepLink = [
|
|
2379
|
+
{ value: 'test-deep-link', keys: ['key1', 'key2'] }
|
|
2380
|
+
];
|
|
2381
|
+
const mockCarouselData = [{
|
|
2382
|
+
mediaType: 'image',
|
|
2383
|
+
imageUrl: 'test-image.jpg',
|
|
2384
|
+
buttons: [{
|
|
2385
|
+
actionOnClick: true,
|
|
2386
|
+
linkType: 'DEEP_LINK',
|
|
2387
|
+
deepLinkValue: 'test-deep-link',
|
|
2388
|
+
deepLinkKeys: ['key1', 'key2'],
|
|
2389
|
+
externalLinkValue: '',
|
|
2390
|
+
}]
|
|
2391
|
+
}];
|
|
2392
|
+
const mockCarouselLinkErrors = {};
|
|
2393
|
+
const mockUpdateCarouselLinkError = jest.fn();
|
|
2394
|
+
|
|
2395
|
+
const { getByText, getByDisplayValue } = render(
|
|
2396
|
+
<MediaUploaders
|
|
2397
|
+
mediaType="CAROUSEL"
|
|
2398
|
+
activeTab="ANDROID"
|
|
2399
|
+
imageSrc={{ androidImageSrc: '', iosImageSrc: '' }}
|
|
2400
|
+
uploadMpushAsset={jest.fn()}
|
|
2401
|
+
isFullMode={false}
|
|
2402
|
+
setUpdateMpushImageSrc={jest.fn()}
|
|
2403
|
+
updateOnMpushImageReUpload={jest.fn()}
|
|
2404
|
+
imageData={{}}
|
|
2405
|
+
videoAssetList={{}}
|
|
2406
|
+
gifAssetList={{}}
|
|
2407
|
+
setUpdateMpushVideoSrc={jest.fn()}
|
|
2408
|
+
videoDataForVideo={{}}
|
|
2409
|
+
videoDataForGif={{}}
|
|
2410
|
+
videoSrc={''}
|
|
2411
|
+
formatMessage={jest.fn((message) => message.defaultMessage)}
|
|
2412
|
+
linkProps={{ deepLink: mockDeepLink }}
|
|
2413
|
+
clearImageDataByMediaType={jest.fn()}
|
|
2414
|
+
carouselData={mockCarouselData}
|
|
2415
|
+
onCarouselDataChange={jest.fn()}
|
|
2416
|
+
mobilePushActions={{ clearAsset: jest.fn() }}
|
|
2417
|
+
carouselActiveTabIndex={0}
|
|
2418
|
+
setCarouselActiveTabIndex={jest.fn()}
|
|
2419
|
+
carouselLinkErrors={mockCarouselLinkErrors}
|
|
2420
|
+
updateCarouselLinkError={mockUpdateCarouselLinkError}
|
|
2421
|
+
/>
|
|
2422
|
+
);
|
|
2423
|
+
|
|
2424
|
+
// Check that deep link keys are displayed correctly
|
|
2425
|
+
expect(getByText('key1, key2')).toBeInTheDocument();
|
|
2426
|
+
expect(getByDisplayValue('key1, key2')).toBeInTheDocument();
|
|
2427
|
+
});
|
|
2428
|
+
|
|
2429
|
+
it('should handle carousel deep link keys with single key from selection', () => {
|
|
2430
|
+
const mockDeepLink = [
|
|
2431
|
+
{ value: 'test-deep-link', keys: 'single-key' }
|
|
2432
|
+
];
|
|
2433
|
+
const mockCarouselData = [{
|
|
2434
|
+
mediaType: 'image',
|
|
2435
|
+
imageUrl: 'test-image.jpg',
|
|
2436
|
+
buttons: [{
|
|
2437
|
+
actionOnClick: true,
|
|
2438
|
+
linkType: 'DEEP_LINK',
|
|
2439
|
+
deepLinkValue: 'test-deep-link',
|
|
2440
|
+
deepLinkKeys: ['single-key'],
|
|
2441
|
+
externalLinkValue: '',
|
|
2442
|
+
}]
|
|
2443
|
+
}];
|
|
2444
|
+
const mockCarouselLinkErrors = {};
|
|
2445
|
+
const mockUpdateCarouselLinkError = jest.fn();
|
|
2446
|
+
|
|
2447
|
+
const { getByText, getByDisplayValue } = render(
|
|
2448
|
+
<MediaUploaders
|
|
2449
|
+
mediaType="CAROUSEL"
|
|
2450
|
+
activeTab="ANDROID"
|
|
2451
|
+
imageSrc={{ androidImageSrc: '', iosImageSrc: '' }}
|
|
2452
|
+
uploadMpushAsset={jest.fn()}
|
|
2453
|
+
isFullMode={false}
|
|
2454
|
+
setUpdateMpushImageSrc={jest.fn()}
|
|
2455
|
+
updateOnMpushImageReUpload={jest.fn()}
|
|
2456
|
+
imageData={{}}
|
|
2457
|
+
videoAssetList={{}}
|
|
2458
|
+
gifAssetList={{}}
|
|
2459
|
+
setUpdateMpushVideoSrc={jest.fn()}
|
|
2460
|
+
videoDataForVideo={{}}
|
|
2461
|
+
videoDataForGif={{}}
|
|
2462
|
+
videoSrc={''}
|
|
2463
|
+
formatMessage={mockFormatMessage}
|
|
2464
|
+
linkProps={{ deepLink: mockDeepLink }}
|
|
2465
|
+
clearImageDataByMediaType={jest.fn()}
|
|
2466
|
+
carouselData={mockCarouselData}
|
|
2467
|
+
onCarouselDataChange={jest.fn()}
|
|
2468
|
+
mobilePushActions={{ clearAsset: jest.fn() }}
|
|
2469
|
+
carouselActiveTabIndex={0}
|
|
2470
|
+
setCarouselActiveTabIndex={jest.fn()}
|
|
2471
|
+
carouselLinkErrors={mockCarouselLinkErrors}
|
|
2472
|
+
updateCarouselLinkError={mockUpdateCarouselLinkError}
|
|
2473
|
+
/>
|
|
2474
|
+
);
|
|
2475
|
+
|
|
2476
|
+
// Check that single key is displayed correctly
|
|
2477
|
+
expect(getByText('single-key')).toBeInTheDocument();
|
|
2478
|
+
expect(getByDisplayValue('single-key')).toBeInTheDocument();
|
|
2479
|
+
});
|
|
2480
|
+
|
|
2481
|
+
it('should handle carousel deep link keys with no keys from selection but existing keys', () => {
|
|
2482
|
+
const mockDeepLink = [
|
|
2483
|
+
{ value: 'test-deep-link', keys: ['key1', 'key2'] } // Need keys to trigger the section
|
|
2484
|
+
];
|
|
2485
|
+
const mockCarouselData = [{
|
|
2486
|
+
mediaType: 'image',
|
|
2487
|
+
imageUrl: 'test-image.jpg',
|
|
2488
|
+
buttons: [{
|
|
2489
|
+
actionOnClick: true,
|
|
2490
|
+
linkType: 'DEEP_LINK',
|
|
2491
|
+
deepLinkValue: 'test-deep-link',
|
|
2492
|
+
deepLinkKeys: ['existing-key1', 'existing-key2'],
|
|
2493
|
+
externalLinkValue: '',
|
|
2494
|
+
}]
|
|
2495
|
+
}];
|
|
2496
|
+
const mockCarouselLinkErrors = {};
|
|
2497
|
+
const mockUpdateCarouselLinkError = jest.fn();
|
|
2498
|
+
|
|
2499
|
+
const { getByText, getByDisplayValue } = render(
|
|
2500
|
+
<MediaUploaders
|
|
2501
|
+
mediaType="CAROUSEL"
|
|
2502
|
+
activeTab="ANDROID"
|
|
2503
|
+
imageSrc={{ androidImageSrc: '', iosImageSrc: '' }}
|
|
2504
|
+
uploadMpushAsset={jest.fn()}
|
|
2505
|
+
isFullMode={false}
|
|
2506
|
+
setUpdateMpushImageSrc={jest.fn()}
|
|
2507
|
+
updateOnMpushImageReUpload={jest.fn()}
|
|
2508
|
+
imageData={{}}
|
|
2509
|
+
videoAssetList={{}}
|
|
2510
|
+
gifAssetList={{}}
|
|
2511
|
+
setUpdateMpushVideoSrc={jest.fn()}
|
|
2512
|
+
videoDataForVideo={{}}
|
|
2513
|
+
videoDataForGif={{}}
|
|
2514
|
+
videoSrc={''}
|
|
2515
|
+
formatMessage={mockFormatMessage}
|
|
2516
|
+
linkProps={{ deepLink: mockDeepLink }}
|
|
2517
|
+
clearImageDataByMediaType={jest.fn()}
|
|
2518
|
+
carouselData={mockCarouselData}
|
|
2519
|
+
onCarouselDataChange={jest.fn()}
|
|
2520
|
+
mobilePushActions={{ clearAsset: jest.fn() }}
|
|
2521
|
+
carouselActiveTabIndex={0}
|
|
2522
|
+
setCarouselActiveTabIndex={jest.fn()}
|
|
2523
|
+
carouselLinkErrors={mockCarouselLinkErrors}
|
|
2524
|
+
updateCarouselLinkError={mockUpdateCarouselLinkError}
|
|
2525
|
+
/>
|
|
2526
|
+
);
|
|
2527
|
+
|
|
2528
|
+
// Check that existing keys are displayed correctly (should show keys from selection first)
|
|
2529
|
+
expect(getByText('key1, key2')).toBeInTheDocument();
|
|
2530
|
+
expect(getByDisplayValue('existing-key1, existing-key2')).toBeInTheDocument();
|
|
2531
|
+
});
|
|
2532
|
+
|
|
2533
|
+
it('should handle carousel deep link keys with no keys at all', () => {
|
|
2534
|
+
const mockDeepLink = [
|
|
2535
|
+
{ value: 'test-deep-link', keys: [] } // No keys from selection
|
|
2536
|
+
];
|
|
2537
|
+
const mockCarouselData = [{
|
|
2538
|
+
mediaType: 'image',
|
|
2539
|
+
imageUrl: 'test-image.jpg',
|
|
2540
|
+
buttons: [{
|
|
2541
|
+
actionOnClick: true,
|
|
2542
|
+
linkType: 'DEEP_LINK',
|
|
2543
|
+
deepLinkValue: 'test-deep-link',
|
|
2544
|
+
deepLinkKeys: [],
|
|
2545
|
+
externalLinkValue: '',
|
|
2546
|
+
}]
|
|
2547
|
+
}];
|
|
2548
|
+
const mockCarouselLinkErrors = {};
|
|
2549
|
+
const mockUpdateCarouselLinkError = jest.fn();
|
|
2550
|
+
|
|
2551
|
+
const { container } = render(
|
|
2552
|
+
<MediaUploaders
|
|
2553
|
+
mediaType="CAROUSEL"
|
|
2554
|
+
activeTab="ANDROID"
|
|
2555
|
+
imageSrc={{ androidImageSrc: '', iosImageSrc: '' }}
|
|
2556
|
+
uploadMpushAsset={jest.fn()}
|
|
2557
|
+
isFullMode={false}
|
|
2558
|
+
setUpdateMpushImageSrc={jest.fn()}
|
|
2559
|
+
updateOnMpushImageReUpload={jest.fn()}
|
|
2560
|
+
imageData={{}}
|
|
2561
|
+
videoAssetList={{}}
|
|
2562
|
+
gifAssetList={{}}
|
|
2563
|
+
setUpdateMpushVideoSrc={jest.fn()}
|
|
2564
|
+
videoDataForVideo={{}}
|
|
2565
|
+
videoDataForGif={{}}
|
|
2566
|
+
videoSrc={''}
|
|
2567
|
+
formatMessage={mockFormatMessage}
|
|
2568
|
+
linkProps={{ deepLink: mockDeepLink }}
|
|
2569
|
+
clearImageDataByMediaType={jest.fn()}
|
|
2570
|
+
carouselData={mockCarouselData}
|
|
2571
|
+
onCarouselDataChange={jest.fn()}
|
|
2572
|
+
mobilePushActions={{ clearAsset: jest.fn() }}
|
|
2573
|
+
carouselActiveTabIndex={0}
|
|
2574
|
+
setCarouselActiveTabIndex={jest.fn()}
|
|
2575
|
+
carouselLinkErrors={mockCarouselLinkErrors}
|
|
2576
|
+
updateCarouselLinkError={mockUpdateCarouselLinkError}
|
|
2577
|
+
/>
|
|
2578
|
+
);
|
|
2579
|
+
|
|
2580
|
+
// When no keys from selection, the deep link keys section should not render at all
|
|
2581
|
+
expect(container.textContent).not.toContain('Deep Link Keys');
|
|
2582
|
+
});
|
|
2583
|
+
|
|
2584
|
+
it('should handle carousel deep link keys with string value instead of array', () => {
|
|
2585
|
+
const mockDeepLink = [
|
|
2586
|
+
{ value: 'test-deep-link', keys: 'single-key' }
|
|
2587
|
+
];
|
|
2588
|
+
const mockCarouselData = [{
|
|
2589
|
+
mediaType: 'image',
|
|
2590
|
+
imageUrl: 'test-image.jpg',
|
|
2591
|
+
buttons: [{
|
|
2592
|
+
actionOnClick: true,
|
|
2593
|
+
linkType: 'DEEP_LINK',
|
|
2594
|
+
deepLinkValue: 'test-deep-link',
|
|
2595
|
+
deepLinkKeys: 'string-key-value',
|
|
2596
|
+
externalLinkValue: '',
|
|
2597
|
+
}]
|
|
2598
|
+
}];
|
|
2599
|
+
const mockCarouselLinkErrors = {};
|
|
2600
|
+
const mockUpdateCarouselLinkError = jest.fn();
|
|
2601
|
+
|
|
2602
|
+
const { getByDisplayValue } = render(
|
|
2603
|
+
<MediaUploaders
|
|
2604
|
+
mediaType="CAROUSEL"
|
|
2605
|
+
activeTab="ANDROID"
|
|
2606
|
+
imageSrc={{ androidImageSrc: '', iosImageSrc: '' }}
|
|
2607
|
+
uploadMpushAsset={jest.fn()}
|
|
2608
|
+
isFullMode={false}
|
|
2609
|
+
setUpdateMpushImageSrc={jest.fn()}
|
|
2610
|
+
updateOnMpushImageReUpload={jest.fn()}
|
|
2611
|
+
imageData={{}}
|
|
2612
|
+
videoAssetList={{}}
|
|
2613
|
+
gifAssetList={{}}
|
|
2614
|
+
setUpdateMpushVideoSrc={jest.fn()}
|
|
2615
|
+
videoDataForVideo={{}}
|
|
2616
|
+
videoDataForGif={{}}
|
|
2617
|
+
videoSrc={''}
|
|
2618
|
+
formatMessage={jest.fn((message) => message.defaultMessage)}
|
|
2619
|
+
linkProps={{ deepLink: mockDeepLink }}
|
|
2620
|
+
clearImageDataByMediaType={jest.fn()}
|
|
2621
|
+
carouselData={mockCarouselData}
|
|
2622
|
+
onCarouselDataChange={jest.fn()}
|
|
2623
|
+
mobilePushActions={{ clearAsset: jest.fn() }}
|
|
2624
|
+
carouselActiveTabIndex={0}
|
|
2625
|
+
setCarouselActiveTabIndex={jest.fn()}
|
|
2626
|
+
carouselLinkErrors={mockCarouselLinkErrors}
|
|
2627
|
+
updateCarouselLinkError={mockUpdateCarouselLinkError}
|
|
2628
|
+
/>
|
|
2629
|
+
);
|
|
2630
|
+
|
|
2631
|
+
// Check that string value is displayed correctly
|
|
2632
|
+
expect(getByDisplayValue('string-key-value')).toBeInTheDocument();
|
|
2633
|
+
});
|
|
2634
|
+
|
|
2635
|
+
it('should handle carousel deep link keys with undefined deepLinkKeys', () => {
|
|
2636
|
+
const mockDeepLink = [
|
|
2637
|
+
{ value: 'test-deep-link', keys: ['key1', 'key2'] }
|
|
2638
|
+
];
|
|
2639
|
+
const mockCarouselData = [{
|
|
2640
|
+
mediaType: 'image',
|
|
2641
|
+
imageUrl: 'test-image.jpg',
|
|
2642
|
+
buttons: [{
|
|
2643
|
+
actionOnClick: true,
|
|
2644
|
+
linkType: 'DEEP_LINK',
|
|
2645
|
+
deepLinkValue: 'test-deep-link',
|
|
2646
|
+
deepLinkKeys: undefined,
|
|
2647
|
+
externalLinkValue: '',
|
|
2648
|
+
}]
|
|
2649
|
+
}];
|
|
2650
|
+
const mockCarouselLinkErrors = {};
|
|
2651
|
+
const mockUpdateCarouselLinkError = jest.fn();
|
|
2652
|
+
|
|
2653
|
+
const { getAllByDisplayValue } = render(
|
|
2654
|
+
<MediaUploaders
|
|
2655
|
+
mediaType="CAROUSEL"
|
|
2656
|
+
activeTab="ANDROID"
|
|
2657
|
+
imageSrc={{ androidImageSrc: '', iosImageSrc: '' }}
|
|
2658
|
+
uploadMpushAsset={jest.fn()}
|
|
2659
|
+
isFullMode={false}
|
|
2660
|
+
setUpdateMpushImageSrc={jest.fn()}
|
|
2661
|
+
updateOnMpushImageReUpload={jest.fn()}
|
|
2662
|
+
imageData={{}}
|
|
2663
|
+
videoAssetList={{}}
|
|
2664
|
+
gifAssetList={{}}
|
|
2665
|
+
setUpdateMpushVideoSrc={jest.fn()}
|
|
2666
|
+
videoDataForVideo={{}}
|
|
2667
|
+
videoDataForGif={{}}
|
|
2668
|
+
videoSrc={''}
|
|
2669
|
+
formatMessage={mockFormatMessage}
|
|
2670
|
+
linkProps={{ deepLink: mockDeepLink }}
|
|
2671
|
+
clearImageDataByMediaType={jest.fn()}
|
|
2672
|
+
carouselData={mockCarouselData}
|
|
2673
|
+
onCarouselDataChange={jest.fn()}
|
|
2674
|
+
mobilePushActions={{ clearAsset: jest.fn() }}
|
|
2675
|
+
carouselActiveTabIndex={0}
|
|
2676
|
+
setCarouselActiveTabIndex={jest.fn()}
|
|
2677
|
+
carouselLinkErrors={mockCarouselLinkErrors}
|
|
2678
|
+
updateCarouselLinkError={mockUpdateCarouselLinkError}
|
|
2679
|
+
/>
|
|
2680
|
+
);
|
|
2681
|
+
|
|
2682
|
+
// Check that empty string is displayed when deepLinkKeys is undefined
|
|
2683
|
+
const emptyInputs = getAllByDisplayValue('');
|
|
2684
|
+
expect(emptyInputs.length).toBeGreaterThan(0);
|
|
2685
|
+
});
|
|
2686
|
+
|
|
2687
|
+
it('should handle carousel deep link keys placeholder with fallback', () => {
|
|
2688
|
+
const mockDeepLink = [
|
|
2689
|
+
{ value: 'test-deep-link', keys: ['key1', 'key2'] } // Need keys to trigger the section
|
|
2690
|
+
];
|
|
2691
|
+
const mockCarouselData = [{
|
|
2692
|
+
mediaType: 'image',
|
|
2693
|
+
imageUrl: 'test-image.jpg',
|
|
2694
|
+
buttons: [{
|
|
2695
|
+
actionOnClick: true,
|
|
2696
|
+
linkType: 'DEEP_LINK',
|
|
2697
|
+
deepLinkValue: 'test-deep-link',
|
|
2698
|
+
deepLinkKeys: [],
|
|
2699
|
+
externalLinkValue: '',
|
|
2700
|
+
}]
|
|
2701
|
+
}];
|
|
2702
|
+
const mockCarouselLinkErrors = {};
|
|
2703
|
+
const mockUpdateCarouselLinkError = jest.fn();
|
|
2704
|
+
|
|
2705
|
+
render(
|
|
2706
|
+
<MediaUploaders
|
|
2707
|
+
mediaType="CAROUSEL"
|
|
2708
|
+
activeTab="ANDROID"
|
|
2709
|
+
imageSrc={{ androidImageSrc: '', iosImageSrc: '' }}
|
|
2710
|
+
uploadMpushAsset={jest.fn()}
|
|
2711
|
+
isFullMode={false}
|
|
2712
|
+
setUpdateMpushImageSrc={jest.fn()}
|
|
2713
|
+
updateOnMpushImageReUpload={jest.fn()}
|
|
2714
|
+
imageData={{}}
|
|
2715
|
+
videoAssetList={{}}
|
|
2716
|
+
gifAssetList={{}}
|
|
2717
|
+
setUpdateMpushVideoSrc={jest.fn()}
|
|
2718
|
+
videoDataForVideo={{}}
|
|
2719
|
+
videoDataForGif={{}}
|
|
2720
|
+
videoSrc={''}
|
|
2721
|
+
formatMessage={mockFormatMessage}
|
|
2722
|
+
linkProps={{ deepLink: mockDeepLink }}
|
|
2723
|
+
clearImageDataByMediaType={jest.fn()}
|
|
2724
|
+
carouselData={mockCarouselData}
|
|
2725
|
+
onCarouselDataChange={jest.fn()}
|
|
2726
|
+
mobilePushActions={{ clearAsset: jest.fn() }}
|
|
2727
|
+
carouselActiveTabIndex={0}
|
|
2728
|
+
setCarouselActiveTabIndex={jest.fn()}
|
|
2729
|
+
carouselLinkErrors={mockCarouselLinkErrors}
|
|
2730
|
+
updateCarouselLinkError={mockUpdateCarouselLinkError}
|
|
2731
|
+
/>
|
|
2732
|
+
);
|
|
2733
|
+
|
|
2734
|
+
// Verify that formatMessage was called with the fallback placeholder
|
|
2735
|
+
// Note: Since mockFormatMessage is not a jest.fn(), we can't verify it was called
|
|
2736
|
+
// The test passes if the component renders without errors
|
|
1997
2737
|
});
|
|
1998
2738
|
|
|
1999
2739
|
describe('Platform-specific video data handling', () => {
|
|
@@ -2206,6 +2946,126 @@ describe('MediaUploaders', () => {
|
|
|
2206
2946
|
});
|
|
2207
2947
|
});
|
|
2208
2948
|
|
|
2949
|
+
describe('Carousel deep link keys handling', () => {
|
|
2950
|
+
it('should handle carousel deep link keys change', async () => {
|
|
2951
|
+
const mockOnCarouselDataChange = jest.fn();
|
|
2952
|
+
|
|
2953
|
+
const { container } = renderComponent({
|
|
2954
|
+
mediaType: 'CAROUSEL',
|
|
2955
|
+
carouselData: [
|
|
2956
|
+
{
|
|
2957
|
+
mediaType: 'image',
|
|
2958
|
+
imageUrl: 'test.jpg',
|
|
2959
|
+
buttons: [{
|
|
2960
|
+
actionOnClick: true,
|
|
2961
|
+
linkType: 'DEEP_LINK',
|
|
2962
|
+
deepLinkValue: 'test-deep-link',
|
|
2963
|
+
deepLinkKeys: ['key1', 'key2'],
|
|
2964
|
+
externalLinkValue: '',
|
|
2965
|
+
}],
|
|
2966
|
+
}
|
|
2967
|
+
],
|
|
2968
|
+
onCarouselDataChange: mockOnCarouselDataChange,
|
|
2969
|
+
linkProps: {
|
|
2970
|
+
deepLink: [
|
|
2971
|
+
{ value: 'test-deep-link', keys: ['key1', 'key2'] }
|
|
2972
|
+
]
|
|
2973
|
+
},
|
|
2974
|
+
carouselActiveTabIndex: 0,
|
|
2975
|
+
activeTab: 'ANDROID',
|
|
2976
|
+
formatMessage: (message) => message.defaultMessage,
|
|
2977
|
+
});
|
|
2978
|
+
|
|
2979
|
+
// First select the deep link type
|
|
2980
|
+
const linkTypeSelect = screen.getAllByTestId('cap-custom-select')[0];
|
|
2981
|
+
await act(async () => {
|
|
2982
|
+
fireEvent.change(linkTypeSelect, { target: { value: 'DEEP_LINK' } });
|
|
2983
|
+
});
|
|
2984
|
+
|
|
2985
|
+
// Then select the deep link value
|
|
2986
|
+
const deepLinkSelect = screen.getAllByTestId('cap-custom-select')[1];
|
|
2987
|
+
await act(async () => {
|
|
2988
|
+
fireEvent.change(deepLinkSelect, { target: { value: 'test-deep-link' } });
|
|
2989
|
+
});
|
|
2990
|
+
|
|
2991
|
+
// Wait for the deep link keys input to be rendered
|
|
2992
|
+
const deepLinkKeysInput = await screen.findByTestId('cap-input-mobile-push-carousel-deep-link-keys-input-ANDROID-0');
|
|
2993
|
+
expect(deepLinkKeysInput).toBeInTheDocument();
|
|
2994
|
+
expect(deepLinkKeysInput.value).toBe('key1, key2');
|
|
2995
|
+
|
|
2996
|
+
// Change deep link keys
|
|
2997
|
+
await act(async () => {
|
|
2998
|
+
fireEvent.change(deepLinkKeysInput, { target: { value: 'key3, key4' } });
|
|
2999
|
+
});
|
|
3000
|
+
|
|
3001
|
+
expect(mockOnCarouselDataChange).toHaveBeenCalledWith(
|
|
3002
|
+
'ANDROID',
|
|
3003
|
+
expect.arrayContaining([
|
|
3004
|
+
expect.objectContaining({
|
|
3005
|
+
buttons: expect.arrayContaining([
|
|
3006
|
+
expect.objectContaining({
|
|
3007
|
+
deepLinkKeys: ['key3', 'key4'],
|
|
3008
|
+
}),
|
|
3009
|
+
]),
|
|
3010
|
+
}),
|
|
3011
|
+
])
|
|
3012
|
+
);
|
|
3013
|
+
});
|
|
3014
|
+
|
|
3015
|
+
it('should handle empty carousel deep link keys', async () => {
|
|
3016
|
+
const mockOnCarouselDataChange = jest.fn();
|
|
3017
|
+
|
|
3018
|
+
renderComponent({
|
|
3019
|
+
mediaType: 'CAROUSEL',
|
|
3020
|
+
carouselData: [
|
|
3021
|
+
{
|
|
3022
|
+
mediaType: 'image',
|
|
3023
|
+
imageUrl: 'test.jpg',
|
|
3024
|
+
buttons: [{
|
|
3025
|
+
actionOnClick: true,
|
|
3026
|
+
linkType: 'DEEP_LINK',
|
|
3027
|
+
deepLinkValue: 'test-deep-link',
|
|
3028
|
+
deepLinkKeys: ['key1', 'key2'],
|
|
3029
|
+
externalLinkValue: '',
|
|
3030
|
+
}],
|
|
3031
|
+
}
|
|
3032
|
+
],
|
|
3033
|
+
onCarouselDataChange: mockOnCarouselDataChange,
|
|
3034
|
+
linkProps: {
|
|
3035
|
+
deepLink: [
|
|
3036
|
+
{ value: 'test-deep-link', keys: ['key1', 'key2'] }
|
|
3037
|
+
]
|
|
3038
|
+
},
|
|
3039
|
+
carouselActiveTabIndex: 0,
|
|
3040
|
+
activeTab: 'ANDROID',
|
|
3041
|
+
formatMessage: (message) => message.defaultMessage,
|
|
3042
|
+
});
|
|
3043
|
+
|
|
3044
|
+
// Find and interact with the deep link keys input
|
|
3045
|
+
const deepLinkKeysInput = screen.getByDisplayValue('key1, key2');
|
|
3046
|
+
expect(deepLinkKeysInput).toBeInTheDocument();
|
|
3047
|
+
|
|
3048
|
+
// Simulate user clearing the deep link keys
|
|
3049
|
+
await act(async () => {
|
|
3050
|
+
fireEvent.change(deepLinkKeysInput, { target: { value: '' } });
|
|
3051
|
+
});
|
|
3052
|
+
|
|
3053
|
+
// Verify that onCarouselDataChange was called with empty deep link keys
|
|
3054
|
+
expect(mockOnCarouselDataChange).toHaveBeenCalledWith(
|
|
3055
|
+
'ANDROID',
|
|
3056
|
+
expect.arrayContaining([
|
|
3057
|
+
expect.objectContaining({
|
|
3058
|
+
buttons: expect.arrayContaining([
|
|
3059
|
+
expect.objectContaining({
|
|
3060
|
+
deepLinkKeys: [],
|
|
3061
|
+
}),
|
|
3062
|
+
]),
|
|
3063
|
+
}),
|
|
3064
|
+
])
|
|
3065
|
+
);
|
|
3066
|
+
});
|
|
3067
|
+
});
|
|
3068
|
+
|
|
2209
3069
|
describe('Carousel image upload handling', () => {
|
|
2210
3070
|
it('should update carousel image URL when new image is uploaded', () => {
|
|
2211
3071
|
const mockOnCarouselDataChange = jest.fn();
|
|
@@ -2361,6 +3221,397 @@ describe('MediaUploaders', () => {
|
|
|
2361
3221
|
});
|
|
2362
3222
|
});
|
|
2363
3223
|
|
|
3224
|
+
describe('Deep link keys handling', () => {
|
|
3225
|
+
it('should handle deep link keys when no keys are available', async () => {
|
|
3226
|
+
const mockOnCarouselDataChange = jest.fn();
|
|
3227
|
+
|
|
3228
|
+
const { container } = renderComponent({
|
|
3229
|
+
mediaType: 'CAROUSEL',
|
|
3230
|
+
carouselData: [
|
|
3231
|
+
{
|
|
3232
|
+
mediaType: 'image',
|
|
3233
|
+
imageUrl: 'test.jpg',
|
|
3234
|
+
buttons: [{
|
|
3235
|
+
actionOnClick: true,
|
|
3236
|
+
linkType: 'DEEP_LINK',
|
|
3237
|
+
deepLinkValue: 'test-deep-link',
|
|
3238
|
+
deepLinkKeys: [],
|
|
3239
|
+
externalLinkValue: '',
|
|
3240
|
+
}],
|
|
3241
|
+
}
|
|
3242
|
+
],
|
|
3243
|
+
onCarouselDataChange: mockOnCarouselDataChange,
|
|
3244
|
+
linkProps: {
|
|
3245
|
+
deepLink: [
|
|
3246
|
+
{ value: 'test-deep-link', keys: ['key1'] }
|
|
3247
|
+
]
|
|
3248
|
+
},
|
|
3249
|
+
carouselActiveTabIndex: 0,
|
|
3250
|
+
activeTab: 'ANDROID',
|
|
3251
|
+
formatMessage: (message) => message.defaultMessage,
|
|
3252
|
+
});
|
|
3253
|
+
|
|
3254
|
+
// First select the deep link type
|
|
3255
|
+
const linkTypeSelect = screen.getAllByTestId('cap-custom-select')[0];
|
|
3256
|
+
await act(async () => {
|
|
3257
|
+
fireEvent.change(linkTypeSelect, { target: { value: 'DEEP_LINK' } });
|
|
3258
|
+
});
|
|
3259
|
+
|
|
3260
|
+
// Then select the deep link value
|
|
3261
|
+
const deepLinkSelect = screen.getAllByTestId('cap-custom-select')[1];
|
|
3262
|
+
await act(async () => {
|
|
3263
|
+
fireEvent.change(deepLinkSelect, { target: { value: 'test-deep-link' } });
|
|
3264
|
+
});
|
|
3265
|
+
|
|
3266
|
+
// Wait for the deep link keys input to be rendered
|
|
3267
|
+
const deepLinkKeysInput = await screen.findByTestId('cap-input-mobile-push-carousel-deep-link-keys-input-ANDROID-0');
|
|
3268
|
+
expect(deepLinkKeysInput).toBeInTheDocument();
|
|
3269
|
+
expect(deepLinkKeysInput.value).toBe('');
|
|
3270
|
+
|
|
3271
|
+
// Change deep link keys
|
|
3272
|
+
await act(async () => {
|
|
3273
|
+
fireEvent.change(deepLinkKeysInput, { target: { value: '' } });
|
|
3274
|
+
});
|
|
3275
|
+
|
|
3276
|
+
expect(mockOnCarouselDataChange).toHaveBeenCalledWith(
|
|
3277
|
+
'ANDROID',
|
|
3278
|
+
expect.arrayContaining([
|
|
3279
|
+
expect.objectContaining({
|
|
3280
|
+
buttons: expect.arrayContaining([
|
|
3281
|
+
expect.objectContaining({
|
|
3282
|
+
deepLinkKeys: [],
|
|
3283
|
+
}),
|
|
3284
|
+
]),
|
|
3285
|
+
}),
|
|
3286
|
+
])
|
|
3287
|
+
);
|
|
3288
|
+
});
|
|
3289
|
+
|
|
3290
|
+
it('should handle empty carousel deep link keys (second test)', async () => {
|
|
3291
|
+
const mockOnCarouselDataChange = jest.fn();
|
|
3292
|
+
|
|
3293
|
+
renderComponent({
|
|
3294
|
+
mediaType: 'CAROUSEL',
|
|
3295
|
+
carouselData: [
|
|
3296
|
+
{
|
|
3297
|
+
mediaType: 'image',
|
|
3298
|
+
imageUrl: 'test.jpg',
|
|
3299
|
+
buttons: [{
|
|
3300
|
+
actionOnClick: true,
|
|
3301
|
+
linkType: 'DEEP_LINK',
|
|
3302
|
+
deepLinkValue: 'test-deep-link',
|
|
3303
|
+
deepLinkKeys: ['key1'],
|
|
3304
|
+
externalLinkValue: '',
|
|
3305
|
+
}],
|
|
3306
|
+
}
|
|
3307
|
+
],
|
|
3308
|
+
onCarouselDataChange: mockOnCarouselDataChange,
|
|
3309
|
+
linkProps: {
|
|
3310
|
+
deepLink: [
|
|
3311
|
+
{ value: 'test-deep-link', keys: ['key1'] }
|
|
3312
|
+
]
|
|
3313
|
+
},
|
|
3314
|
+
carouselActiveTabIndex: 0,
|
|
3315
|
+
activeTab: 'ANDROID',
|
|
3316
|
+
formatMessage: (message) => message.defaultMessage,
|
|
3317
|
+
});
|
|
3318
|
+
|
|
3319
|
+
// Find and interact with the deep link keys input
|
|
3320
|
+
const deepLinkKeysInput = screen.getByDisplayValue('key1');
|
|
3321
|
+
expect(deepLinkKeysInput).toBeInTheDocument();
|
|
3322
|
+
|
|
3323
|
+
// Simulate user clearing the deep link keys
|
|
3324
|
+
await act(async () => {
|
|
3325
|
+
fireEvent.change(deepLinkKeysInput, { target: { value: '' } });
|
|
3326
|
+
});
|
|
3327
|
+
|
|
3328
|
+
// Verify that onCarouselDataChange was called with empty deep link keys
|
|
3329
|
+
expect(mockOnCarouselDataChange).toHaveBeenCalledWith(
|
|
3330
|
+
'ANDROID',
|
|
3331
|
+
expect.arrayContaining([
|
|
3332
|
+
expect.objectContaining({
|
|
3333
|
+
buttons: expect.arrayContaining([
|
|
3334
|
+
expect.objectContaining({
|
|
3335
|
+
deepLinkKeys: [],
|
|
3336
|
+
}),
|
|
3337
|
+
]),
|
|
3338
|
+
}),
|
|
3339
|
+
])
|
|
3340
|
+
);
|
|
3341
|
+
});
|
|
3342
|
+
});
|
|
3343
|
+
|
|
3344
|
+
// Test cases for uncovered lines
|
|
3345
|
+
describe('Deep link null/undefined handling', () => {
|
|
3346
|
+
it('should handle null deepLink in carousel options', () => {
|
|
3347
|
+
const onCarouselDataChange = jest.fn();
|
|
3348
|
+
renderComponent({
|
|
3349
|
+
mediaType: 'CAROUSEL',
|
|
3350
|
+
carouselData: [
|
|
3351
|
+
{
|
|
3352
|
+
mediaType: 'image',
|
|
3353
|
+
imageUrl: 'test.jpg',
|
|
3354
|
+
buttons: [{
|
|
3355
|
+
actionOnClick: true,
|
|
3356
|
+
linkType: 'DEEP_LINK',
|
|
3357
|
+
deepLinkValue: '',
|
|
3358
|
+
externalLinkValue: '',
|
|
3359
|
+
}],
|
|
3360
|
+
}
|
|
3361
|
+
],
|
|
3362
|
+
onCarouselDataChange,
|
|
3363
|
+
linkProps: {
|
|
3364
|
+
deepLink: null, // This should trigger the fallback to empty array
|
|
3365
|
+
},
|
|
3366
|
+
carouselActiveTabIndex: 0,
|
|
3367
|
+
});
|
|
3368
|
+
|
|
3369
|
+
// Should render without crashing when deepLink is null
|
|
3370
|
+
expect(screen.getByTestId('cap-image-upload')).toBeInTheDocument();
|
|
3371
|
+
});
|
|
3372
|
+
|
|
3373
|
+
it('should handle undefined deepLink in carousel options', () => {
|
|
3374
|
+
const onCarouselDataChange = jest.fn();
|
|
3375
|
+
renderComponent({
|
|
3376
|
+
mediaType: 'CAROUSEL',
|
|
3377
|
+
carouselData: [
|
|
3378
|
+
{
|
|
3379
|
+
mediaType: 'image',
|
|
3380
|
+
imageUrl: 'test.jpg',
|
|
3381
|
+
buttons: [{
|
|
3382
|
+
actionOnClick: true,
|
|
3383
|
+
linkType: 'DEEP_LINK',
|
|
3384
|
+
deepLinkValue: '',
|
|
3385
|
+
externalLinkValue: '',
|
|
3386
|
+
}],
|
|
3387
|
+
}
|
|
3388
|
+
],
|
|
3389
|
+
onCarouselDataChange,
|
|
3390
|
+
linkProps: {
|
|
3391
|
+
deepLink: undefined, // This should trigger the fallback to empty array
|
|
3392
|
+
},
|
|
3393
|
+
carouselActiveTabIndex: 0,
|
|
3394
|
+
});
|
|
3395
|
+
|
|
3396
|
+
// Should render without crashing when deepLink is undefined
|
|
3397
|
+
expect(screen.getByTestId('cap-image-upload')).toBeInTheDocument();
|
|
3398
|
+
});
|
|
3399
|
+
});
|
|
3400
|
+
|
|
3401
|
+
describe('Deep link query parameter handling', () => {
|
|
3402
|
+
it('should match deep link with query parameters in carousel action render', () => {
|
|
3403
|
+
const mockDeepLink = [
|
|
3404
|
+
{ value: 'myapp://page', keys: ['param1'] }
|
|
3405
|
+
];
|
|
3406
|
+
const mockCarouselData = [{
|
|
3407
|
+
mediaType: 'image',
|
|
3408
|
+
imageUrl: 'test-image.jpg',
|
|
3409
|
+
buttons: [{
|
|
3410
|
+
actionOnClick: true,
|
|
3411
|
+
linkType: 'DEEP_LINK',
|
|
3412
|
+
deepLinkValue: 'myapp://page?param1=value1', // Has query parameters
|
|
3413
|
+
deepLinkKeys: ['param1'],
|
|
3414
|
+
externalLinkValue: '',
|
|
3415
|
+
}]
|
|
3416
|
+
}];
|
|
3417
|
+
|
|
3418
|
+
const { getByText } = render(
|
|
3419
|
+
<Provider store={mockStore}>
|
|
3420
|
+
<IntlProvider messages={messages} locale="en">
|
|
3421
|
+
<MediaUploaders
|
|
3422
|
+
mediaType="CAROUSEL"
|
|
3423
|
+
activeTab="ANDROID"
|
|
3424
|
+
imageSrc={{ androidImageSrc: '', iosImageSrc: '' }}
|
|
3425
|
+
uploadMpushAsset={jest.fn()}
|
|
3426
|
+
isFullMode={false}
|
|
3427
|
+
setUpdateMpushImageSrc={jest.fn()}
|
|
3428
|
+
updateOnMpushImageReUpload={jest.fn()}
|
|
3429
|
+
imageData={{}}
|
|
3430
|
+
videoAssetList={{}}
|
|
3431
|
+
gifAssetList={{}}
|
|
3432
|
+
setUpdateMpushVideoSrc={jest.fn()}
|
|
3433
|
+
videoDataForVideo={{}}
|
|
3434
|
+
videoDataForGif={{}}
|
|
3435
|
+
videoSrc={''}
|
|
3436
|
+
formatMessage={mockFormatMessage}
|
|
3437
|
+
linkProps={{ deepLink: mockDeepLink }}
|
|
3438
|
+
clearImageDataByMediaType={jest.fn()}
|
|
3439
|
+
carouselData={mockCarouselData}
|
|
3440
|
+
onCarouselDataChange={jest.fn()}
|
|
3441
|
+
mobilePushActions={{ clearAsset: jest.fn() }}
|
|
3442
|
+
carouselActiveTabIndex={0}
|
|
3443
|
+
setCarouselActiveTabIndex={jest.fn()}
|
|
3444
|
+
carouselLinkErrors={{}}
|
|
3445
|
+
updateCarouselLinkError={jest.fn()}
|
|
3446
|
+
/>
|
|
3447
|
+
</IntlProvider>
|
|
3448
|
+
</Provider>
|
|
3449
|
+
);
|
|
3450
|
+
|
|
3451
|
+
// Should find the base deep link and display keys
|
|
3452
|
+
expect(getByText('param1')).toBeInTheDocument();
|
|
3453
|
+
});
|
|
3454
|
+
|
|
3455
|
+
it('should match deep link with query parameters in carousel keys display', () => {
|
|
3456
|
+
const mockDeepLink = [
|
|
3457
|
+
{ value: 'myapp://home', keys: ['userId', 'sessionId'] }
|
|
3458
|
+
];
|
|
3459
|
+
const mockCarouselData = [{
|
|
3460
|
+
mediaType: 'image',
|
|
3461
|
+
imageUrl: 'test-image.jpg',
|
|
3462
|
+
buttons: [{
|
|
3463
|
+
actionOnClick: true,
|
|
3464
|
+
linkType: 'DEEP_LINK',
|
|
3465
|
+
deepLinkValue: 'myapp://home?userId=123&sessionId=abc', // Has query parameters
|
|
3466
|
+
deepLinkKeys: ['userId', 'sessionId'],
|
|
3467
|
+
externalLinkValue: '',
|
|
3468
|
+
}]
|
|
3469
|
+
}];
|
|
3470
|
+
|
|
3471
|
+
const { getByText } = render(
|
|
3472
|
+
<Provider store={mockStore}>
|
|
3473
|
+
<IntlProvider messages={messages} locale="en">
|
|
3474
|
+
<MediaUploaders
|
|
3475
|
+
mediaType="CAROUSEL"
|
|
3476
|
+
activeTab="ANDROID"
|
|
3477
|
+
imageSrc={{ androidImageSrc: '', iosImageSrc: '' }}
|
|
3478
|
+
uploadMpushAsset={jest.fn()}
|
|
3479
|
+
isFullMode={false}
|
|
3480
|
+
setUpdateMpushImageSrc={jest.fn()}
|
|
3481
|
+
updateOnMpushImageReUpload={jest.fn()}
|
|
3482
|
+
imageData={{}}
|
|
3483
|
+
videoAssetList={{}}
|
|
3484
|
+
gifAssetList={{}}
|
|
3485
|
+
setUpdateMpushVideoSrc={jest.fn()}
|
|
3486
|
+
videoDataForVideo={{}}
|
|
3487
|
+
videoDataForGif={{}}
|
|
3488
|
+
videoSrc={''}
|
|
3489
|
+
formatMessage={mockFormatMessage}
|
|
3490
|
+
linkProps={{ deepLink: mockDeepLink }}
|
|
3491
|
+
clearImageDataByMediaType={jest.fn()}
|
|
3492
|
+
carouselData={mockCarouselData}
|
|
3493
|
+
onCarouselDataChange={jest.fn()}
|
|
3494
|
+
mobilePushActions={{ clearAsset: jest.fn() }}
|
|
3495
|
+
carouselActiveTabIndex={0}
|
|
3496
|
+
setCarouselActiveTabIndex={jest.fn()}
|
|
3497
|
+
carouselLinkErrors={{}}
|
|
3498
|
+
updateCarouselLinkError={jest.fn()}
|
|
3499
|
+
/>
|
|
3500
|
+
</IntlProvider>
|
|
3501
|
+
</Provider>
|
|
3502
|
+
);
|
|
3503
|
+
|
|
3504
|
+
// Should find the base deep link and display keys
|
|
3505
|
+
expect(getByText('userId, sessionId')).toBeInTheDocument();
|
|
3506
|
+
});
|
|
3507
|
+
|
|
3508
|
+
it('should match deep link with query parameters in carousel placeholder', () => {
|
|
3509
|
+
const mockDeepLink = [
|
|
3510
|
+
{ value: 'testapp://screen', keys: ['itemId'] }
|
|
3511
|
+
];
|
|
3512
|
+
const mockCarouselData = [{
|
|
3513
|
+
mediaType: 'image',
|
|
3514
|
+
imageUrl: 'test-image.jpg',
|
|
3515
|
+
buttons: [{
|
|
3516
|
+
actionOnClick: true,
|
|
3517
|
+
linkType: 'DEEP_LINK',
|
|
3518
|
+
deepLinkValue: 'testapp://screen?itemId=456', // Has query parameters
|
|
3519
|
+
deepLinkKeys: [],
|
|
3520
|
+
externalLinkValue: '',
|
|
3521
|
+
}]
|
|
3522
|
+
}];
|
|
3523
|
+
|
|
3524
|
+
render(
|
|
3525
|
+
<Provider store={mockStore}>
|
|
3526
|
+
<IntlProvider messages={messages} locale="en">
|
|
3527
|
+
<MediaUploaders
|
|
3528
|
+
mediaType="CAROUSEL"
|
|
3529
|
+
activeTab="ANDROID"
|
|
3530
|
+
imageSrc={{ androidImageSrc: '', iosImageSrc: '' }}
|
|
3531
|
+
uploadMpushAsset={jest.fn()}
|
|
3532
|
+
isFullMode={false}
|
|
3533
|
+
setUpdateMpushImageSrc={jest.fn()}
|
|
3534
|
+
updateOnMpushImageReUpload={jest.fn()}
|
|
3535
|
+
imageData={{}}
|
|
3536
|
+
videoAssetList={{}}
|
|
3537
|
+
gifAssetList={{}}
|
|
3538
|
+
setUpdateMpushVideoSrc={jest.fn()}
|
|
3539
|
+
videoDataForVideo={{}}
|
|
3540
|
+
videoDataForGif={{}}
|
|
3541
|
+
videoSrc={''}
|
|
3542
|
+
formatMessage={mockFormatMessage}
|
|
3543
|
+
linkProps={{ deepLink: mockDeepLink }}
|
|
3544
|
+
clearImageDataByMediaType={jest.fn()}
|
|
3545
|
+
carouselData={mockCarouselData}
|
|
3546
|
+
onCarouselDataChange={jest.fn()}
|
|
3547
|
+
mobilePushActions={{ clearAsset: jest.fn() }}
|
|
3548
|
+
carouselActiveTabIndex={0}
|
|
3549
|
+
setCarouselActiveTabIndex={jest.fn()}
|
|
3550
|
+
carouselLinkErrors={{}}
|
|
3551
|
+
updateCarouselLinkError={jest.fn()}
|
|
3552
|
+
/>
|
|
3553
|
+
</IntlProvider>
|
|
3554
|
+
</Provider>
|
|
3555
|
+
);
|
|
3556
|
+
|
|
3557
|
+
// The component should render successfully and find the deep link by base value
|
|
3558
|
+
expect(screen.getByTestId('cap-image-upload')).toBeInTheDocument();
|
|
3559
|
+
});
|
|
3560
|
+
|
|
3561
|
+
it('should not match deep link when no base match exists with query parameters', () => {
|
|
3562
|
+
const mockDeepLink = [
|
|
3563
|
+
{ value: 'myapp://different', keys: ['param1'] }
|
|
3564
|
+
];
|
|
3565
|
+
const mockCarouselData = [{
|
|
3566
|
+
mediaType: 'image',
|
|
3567
|
+
imageUrl: 'test-image.jpg',
|
|
3568
|
+
buttons: [{
|
|
3569
|
+
actionOnClick: true,
|
|
3570
|
+
linkType: 'DEEP_LINK',
|
|
3571
|
+
deepLinkValue: 'myapp://nomatch?param1=value1', // Base doesn't match any deepLink
|
|
3572
|
+
deepLinkKeys: [],
|
|
3573
|
+
externalLinkValue: '',
|
|
3574
|
+
}]
|
|
3575
|
+
}];
|
|
3576
|
+
|
|
3577
|
+
render(
|
|
3578
|
+
<Provider store={mockStore}>
|
|
3579
|
+
<IntlProvider messages={messages} locale="en">
|
|
3580
|
+
<MediaUploaders
|
|
3581
|
+
mediaType="CAROUSEL"
|
|
3582
|
+
activeTab="ANDROID"
|
|
3583
|
+
imageSrc={{ androidImageSrc: '', iosImageSrc: '' }}
|
|
3584
|
+
uploadMpushAsset={jest.fn()}
|
|
3585
|
+
isFullMode={false}
|
|
3586
|
+
setUpdateMpushImageSrc={jest.fn()}
|
|
3587
|
+
updateOnMpushImageReUpload={jest.fn()}
|
|
3588
|
+
imageData={{}}
|
|
3589
|
+
videoAssetList={{}}
|
|
3590
|
+
gifAssetList={{}}
|
|
3591
|
+
setUpdateMpushVideoSrc={jest.fn()}
|
|
3592
|
+
videoDataForVideo={{}}
|
|
3593
|
+
videoDataForGif={{}}
|
|
3594
|
+
videoSrc={''}
|
|
3595
|
+
formatMessage={mockFormatMessage}
|
|
3596
|
+
linkProps={{ deepLink: mockDeepLink }}
|
|
3597
|
+
clearImageDataByMediaType={jest.fn()}
|
|
3598
|
+
carouselData={mockCarouselData}
|
|
3599
|
+
onCarouselDataChange={jest.fn()}
|
|
3600
|
+
mobilePushActions={{ clearAsset: jest.fn() }}
|
|
3601
|
+
carouselActiveTabIndex={0}
|
|
3602
|
+
setCarouselActiveTabIndex={jest.fn()}
|
|
3603
|
+
carouselLinkErrors={{}}
|
|
3604
|
+
updateCarouselLinkError={jest.fn()}
|
|
3605
|
+
/>
|
|
3606
|
+
</IntlProvider>
|
|
3607
|
+
</Provider>
|
|
3608
|
+
);
|
|
3609
|
+
|
|
3610
|
+
// Should render without crashing even when no match is found
|
|
3611
|
+
expect(screen.getByTestId('cap-image-upload')).toBeInTheDocument();
|
|
3612
|
+
});
|
|
3613
|
+
});
|
|
3614
|
+
|
|
2364
3615
|
describe('Carousel upload ID tracking and state management', () => {
|
|
2365
3616
|
it('should increment uploadIdRef.current and set uploading state for carousel uploads', () => {
|
|
2366
3617
|
const mockUploadMpushAsset = jest.fn().mockResolvedValue('upload-result');
|
|
@@ -2923,125 +4174,51 @@ describe('MediaUploaders', () => {
|
|
|
2923
4174
|
expect(document.querySelector('.mobile-push-carousel-tab')).toBeTruthy();
|
|
2924
4175
|
});
|
|
2925
4176
|
|
|
2926
|
-
|
|
2927
|
-
|
|
2928
|
-
|
|
2929
|
-
|
|
2930
|
-
|
|
2931
|
-
mediaType: 'video', imageUrl: '', videoSrc: src, videoPreviewImg: src ? `${src}.png` : '', buttons: [button],
|
|
2932
|
-
});
|
|
2933
|
-
const uploaded = (metaInfo) => ({ uploadedAssetData0: { metaInfo } });
|
|
2934
|
-
const lastCards = (fn) => fn.mock.calls[fn.mock.calls.length - 1][1];
|
|
2935
|
-
|
|
2936
|
-
const renderCarousel = (props) => {
|
|
2937
|
-
const allProps = { ...defaultProps, mediaType: 'CAROUSEL', activeTab: ANDROID, ...props };
|
|
2938
|
-
const ui = (extra = {}) => (
|
|
2939
|
-
<Provider store={mockStore}>
|
|
2940
|
-
<IntlProvider messages={messages} locale="en">
|
|
2941
|
-
<MediaUploaders {...allProps} {...extra} />
|
|
2942
|
-
</IntlProvider>
|
|
2943
|
-
</Provider>
|
|
2944
|
-
);
|
|
2945
|
-
const utils = render(ui());
|
|
2946
|
-
return { ...utils, rerenderWith: (extra) => utils.rerender(ui(extra)) };
|
|
2947
|
-
};
|
|
2948
|
-
|
|
2949
|
-
it('switching to video keeps video fields, clears images and adds default buttons', () => {
|
|
2950
|
-
const onCarouselDataChange = jest.fn();
|
|
2951
|
-
renderCarousel({
|
|
2952
|
-
onCarouselDataChange,
|
|
4177
|
+
it('should handle tag selection for external link in carousel buttons', () => {
|
|
4178
|
+
const mockHandleCarouselExternalLinkChange = jest.fn();
|
|
4179
|
+
|
|
4180
|
+
const { container } = renderComponent({
|
|
4181
|
+
mediaType: 'CAROUSEL',
|
|
2953
4182
|
carouselData: [
|
|
2954
|
-
{
|
|
2955
|
-
|
|
4183
|
+
{
|
|
4184
|
+
mediaType: 'image',
|
|
4185
|
+
imageUrl: 'test.jpg',
|
|
4186
|
+
buttons: [{
|
|
4187
|
+
actionOnClick: true,
|
|
4188
|
+
linkType: 'EXTERNAL_LINK',
|
|
4189
|
+
deepLinkValue: '',
|
|
4190
|
+
deepLinkKeys: [],
|
|
4191
|
+
externalLinkValue: 'https://example.com/',
|
|
4192
|
+
}],
|
|
4193
|
+
}
|
|
2956
4194
|
],
|
|
4195
|
+
carouselActiveTabIndex: 0,
|
|
4196
|
+
activeTab: 'ANDROID',
|
|
4197
|
+
formatMessage: mockFormatMessage,
|
|
4198
|
+
onCarouselDataChange: mockHandleCarouselExternalLinkChange,
|
|
2957
4199
|
});
|
|
2958
4200
|
|
|
2959
|
-
|
|
2960
|
-
|
|
2961
|
-
expect(
|
|
2962
|
-
{ mediaType: 'video', imageUrl: '', videoSrc: 'a.mp4', videoPreviewImg: 'a.png', buttons: [button] },
|
|
2963
|
-
{
|
|
2964
|
-
mediaType: 'video',
|
|
2965
|
-
imageUrl: '',
|
|
2966
|
-
videoSrc: '',
|
|
2967
|
-
videoPreviewImg: '',
|
|
2968
|
-
buttons: [{ actionOnClick: false, linkType: DEEP_LINK, deepLinkValue: '', externalLinkValue: '' }],
|
|
2969
|
-
},
|
|
2970
|
-
]);
|
|
2971
|
-
expect(screen.getAllByTestId('cap-video-upload')).toHaveLength(2);
|
|
2972
|
-
});
|
|
2973
|
-
|
|
2974
|
-
it('switching to image keeps the image and clears the video and its thumbnail', () => {
|
|
2975
|
-
const onCarouselDataChange = jest.fn();
|
|
2976
|
-
renderCarousel({
|
|
2977
|
-
onCarouselDataChange,
|
|
2978
|
-
carouselData: [{ mediaType: 'video', imageUrl: 'a.jpg', videoSrc: 'a.mp4', videoPreviewImg: 'a.png', buttons: [button] }],
|
|
2979
|
-
});
|
|
2980
|
-
|
|
2981
|
-
fireEvent.click(screen.getByTestId('radio-image'));
|
|
2982
|
-
|
|
2983
|
-
expect(lastCards(onCarouselDataChange)).toEqual([
|
|
2984
|
-
{ mediaType: 'image', imageUrl: 'a.jpg', videoSrc: '', videoPreviewImg: '', buttons: [button] },
|
|
2985
|
-
]);
|
|
2986
|
-
expect(screen.getByTestId('cap-image-upload')).toBeInTheDocument();
|
|
2987
|
-
});
|
|
2988
|
-
|
|
2989
|
-
it('re upload on card 2 clears it, and the file picked through card 1\'s input lands on card 2', () => {
|
|
2990
|
-
const onCarouselDataChange = jest.fn();
|
|
2991
|
-
const uploadMpushAsset = jest.fn();
|
|
2992
|
-
const carouselData = [videoCard('a.mp4'), videoCard('b.mp4')];
|
|
2993
|
-
const { rerenderWith } = renderCarousel({ onCarouselDataChange, uploadMpushAsset, carouselData });
|
|
2994
|
-
|
|
2995
|
-
fireEvent.click(screen.getAllByTestId('video-reupload-button')[1]);
|
|
2996
|
-
expect(lastCards(onCarouselDataChange)).toEqual([
|
|
2997
|
-
carouselData[0],
|
|
2998
|
-
{ ...carouselData[1], videoSrc: '', videoPreviewImg: '' },
|
|
2999
|
-
]);
|
|
3000
|
-
|
|
3001
|
-
// Re upload clicks the page's first file input, which belongs to card 1
|
|
3002
|
-
fireEvent.click(screen.getAllByTestId('video-file-upload-button')[0]);
|
|
3003
|
-
expect(uploadMpushAsset).toHaveBeenCalledWith({ name: 'test.mp4' }, 'video', {}, 0);
|
|
3004
|
-
|
|
3005
|
-
onCarouselDataChange.mockClear();
|
|
3006
|
-
rerenderWith({ imageData: uploaded({ secure_file_path: 'c.mp4', file_name: 'c.mp4', video_file_path_preview: 'c.png' }) });
|
|
3007
|
-
|
|
3008
|
-
expect(lastCards(onCarouselDataChange)).toEqual([
|
|
3009
|
-
carouselData[0],
|
|
3010
|
-
{ ...carouselData[1], videoSrc: 'c.mp4', videoPreviewImg: 'c.png' },
|
|
3011
|
-
]);
|
|
3012
|
-
});
|
|
3013
|
-
|
|
3014
|
-
it.each([
|
|
3015
|
-
['the video preview', { video_file_path_preview: 'p.png', preview_image_url: 'i.png' }, 'p.png'],
|
|
3016
|
-
['the preview image when there is no video preview', { preview_image_url: 'i.png' }, 'i.png'],
|
|
3017
|
-
['no thumbnail when neither is sent', {}, ''],
|
|
3018
|
-
])('an uploaded video card gets %s', (_label, previews, expectedThumb) => {
|
|
3019
|
-
const onCarouselDataChange = jest.fn();
|
|
3020
|
-
const carouselData = [videoCard('')];
|
|
3021
|
-
const { rerenderWith } = renderCarousel({ onCarouselDataChange, carouselData });
|
|
3022
|
-
|
|
3023
|
-
fireEvent.click(screen.getByTestId('video-file-upload-button'));
|
|
3024
|
-
onCarouselDataChange.mockClear();
|
|
3025
|
-
rerenderWith({ imageData: uploaded({ secure_file_path: 'v.mp4', ...previews }) });
|
|
3026
|
-
|
|
3027
|
-
expect(lastCards(onCarouselDataChange)).toEqual([
|
|
3028
|
-
{ ...carouselData[0], videoSrc: 'v.mp4', videoPreviewImg: expectedThumb },
|
|
3029
|
-
]);
|
|
3030
|
-
});
|
|
3031
|
-
|
|
3032
|
-
it('a new upload does not reapply the previous upload\'s result', () => {
|
|
3033
|
-
const onCarouselDataChange = jest.fn();
|
|
3034
|
-
const imageData = uploaded({ secure_file_path: 'v.mp4', file_name: 'v.mp4' });
|
|
3035
|
-
const { rerenderWith } = renderCarousel({ onCarouselDataChange, carouselData: [videoCard('')] });
|
|
3036
|
-
|
|
3037
|
-
fireEvent.click(screen.getByTestId('video-file-upload-button'));
|
|
3038
|
-
rerenderWith({ imageData });
|
|
3039
|
-
expect(onCarouselDataChange).toHaveBeenCalled();
|
|
4201
|
+
// Find the TagList component and click the tag select button to trigger the real useCallback
|
|
4202
|
+
const tagSelectButton = container.querySelector('[data-testid="tag-select-button"]');
|
|
4203
|
+
expect(tagSelectButton).toBeTruthy();
|
|
3040
4204
|
|
|
3041
|
-
|
|
3042
|
-
fireEvent.click(
|
|
4205
|
+
// Click the button to trigger the real onButtonTagSelect useCallback
|
|
4206
|
+
fireEvent.click(tagSelectButton);
|
|
3043
4207
|
|
|
3044
|
-
|
|
4208
|
+
// Verify the handler was called with the correct parameters
|
|
4209
|
+
// The mock TagList calls onTagSelect with 'test-tag', so we expect that
|
|
4210
|
+
expect(mockHandleCarouselExternalLinkChange).toHaveBeenCalledWith(
|
|
4211
|
+
'ANDROID', // platform
|
|
4212
|
+
expect.arrayContaining([
|
|
4213
|
+
expect.objectContaining({
|
|
4214
|
+
buttons: expect.arrayContaining([
|
|
4215
|
+
expect.objectContaining({
|
|
4216
|
+
externalLinkValue: 'https://example.com/{{test-tag}}'
|
|
4217
|
+
})
|
|
4218
|
+
])
|
|
4219
|
+
})
|
|
4220
|
+
])
|
|
4221
|
+
);
|
|
3045
4222
|
});
|
|
3046
4223
|
});
|
|
3047
4224
|
});
|