@capillarytech/creatives-library 9.2.2 → 9.2.3

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (47) hide show
  1. package/constants/unified.js +0 -1
  2. package/package.json +1 -1
  3. package/utils/common.js +0 -6
  4. package/utils/createMobilePushPayload.js +50 -56
  5. package/utils/tests/createMobilePushPayload.test.js +177 -168
  6. package/v2Components/CapMpushCTA/index.js +47 -57
  7. package/v2Components/CapMpushCTA/index.scss +43 -5
  8. package/v2Components/CapMpushCTA/tests/index.test.js +150 -0
  9. package/v2Components/CommonTestAndPreview/UnifiedPreview/MobilePushPreviewContent.js +11 -8
  10. package/v2Components/CommonTestAndPreview/UnifiedPreview/_unifiedPreview.scss +13 -1
  11. package/v2Components/CommonTestAndPreview/constants.js +2 -0
  12. package/v2Components/CommonTestAndPreview/index.js +51 -12
  13. package/v2Components/CommonTestAndPreview/tests/UnifiedPreview/MobilePushPreviewContent.test.js +83 -5
  14. package/v2Components/CommonTestAndPreview/tests/index.test.js +100 -0
  15. package/v2Components/MobilePushPreviewV2/_mobilePushPreviewV2.scss +7 -0
  16. package/v2Components/MobilePushPreviewV2/index.js +22 -9
  17. package/v2Components/MobilePushPreviewV2/tests/index.test.js +55 -0
  18. package/v2Components/TemplatePreview/_mobilePushPhone.scss +72 -0
  19. package/v2Components/TemplatePreview/_templatePreview.scss +18 -2
  20. package/v2Components/TemplatePreview/index.js +20 -18
  21. package/v2Components/TemplatePreview/tests/index.test.js +69 -0
  22. package/v2Containers/CommunicationFlow/steps/ChannelSelectionStep/Tests/extractContentForPreview.test.js +45 -0
  23. package/v2Containers/CommunicationFlow/steps/ChannelSelectionStep/extractContentForPreview.js +12 -2
  24. package/v2Containers/CreativesContainer/SlideBoxContent.js +4 -6
  25. package/v2Containers/CreativesContainer/index.js +2 -1
  26. package/v2Containers/CreativesContainer/tests/SlideBoxContent.test.js +43 -0
  27. package/v2Containers/MobilePushNew/components/CtaButtons.js +52 -47
  28. package/v2Containers/MobilePushNew/components/MediaUploaders.js +105 -345
  29. package/v2Containers/MobilePushNew/components/PlatformContentFields.js +127 -105
  30. package/v2Containers/MobilePushNew/components/TapLinkActions.js +76 -0
  31. package/v2Containers/MobilePushNew/components/tests/CtaButtons.test.js +30 -208
  32. package/v2Containers/MobilePushNew/components/tests/MediaUploaders.test.js +305 -1482
  33. package/v2Containers/MobilePushNew/components/tests/PlatformContentFields.test.js +165 -59
  34. package/v2Containers/MobilePushNew/constants.js +12 -0
  35. package/v2Containers/MobilePushNew/hooks/tests/usePlatformSync.test.js +63 -1
  36. package/v2Containers/MobilePushNew/hooks/tests/useUpload.test.js +78 -0
  37. package/v2Containers/MobilePushNew/hooks/usePlatformSync.js +40 -1
  38. package/v2Containers/MobilePushNew/hooks/useUpload.js +42 -46
  39. package/v2Containers/MobilePushNew/index.js +498 -289
  40. package/v2Containers/MobilePushNew/index.scss +151 -4
  41. package/v2Containers/MobilePushNew/messages.js +106 -6
  42. package/v2Containers/MobilePushNew/tests/index.test.js +483 -1
  43. package/v2Containers/MobilePushNew/tests/utils.test.js +110 -0
  44. package/v2Containers/MobilePushNew/utils.js +83 -0
  45. package/v2Containers/Templates/_templates.scss +10 -2
  46. package/v2Containers/Templates/index.js +86 -81
  47. package/v2Containers/Templates/tests/index.test.js +81 -0
@@ -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 } from '../../constants';
10
+ import { ANDROID, IOS, DEEP_LINK } from '../../constants';
11
11
  import { act } from 'react';
12
12
  import messages from '../../messages';
13
13
 
@@ -97,20 +97,18 @@ jest.mock('@capillarytech/cap-ui-library/CapRadioGroup', () =>
97
97
  }
98
98
  );
99
99
 
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
- }));
100
+ jest.mock('@capillarytech/cap-ui-library/CapSelect', () => function MockCapSelect({ options, value, onChange, placeholder, ...props }) {
101
+ return (
102
+ <select {...props} value={value} onChange={(e) => onChange(e.target.value)}>
103
+ <option value="">{placeholder}</option>
104
+ {options?.map((option, index) => (
105
+ <option key={index} value={option.value}>
106
+ {option.label}
107
+ </option>
108
+ ))}
109
+ </select>
110
+ );
111
+ });
114
112
 
115
113
  jest.mock('@capillarytech/cap-ui-library/CapRow', () =>
116
114
  function MockCapRow({ children, ...props }) {
@@ -202,11 +200,27 @@ jest.mock('../../../../v2Components/CapVideoUpload', () =>
202
200
  <div data-testid="cap-video-upload">
203
201
  <button
204
202
  type="button"
205
- onClick={() => props.onVideoUploadUpdateAssestList('mock-video-url')}
203
+ // Real CapVideoUpload calls back with (index, data)
204
+ onClick={() => props.onVideoUploadUpdateAssestList(0, { videoSrc: 'mock-video-url', previewUrl: 'mock-preview-url' })}
206
205
  data-testid="video-upload-button"
207
206
  >
208
207
  Upload Video
209
208
  </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>
210
224
  </div>
211
225
  );
212
226
  }
@@ -325,24 +339,21 @@ jest.mock('@capillarytech/cap-ui-library/CapInput', () => ({
325
339
  },
326
340
  }));
327
341
 
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
- }));
342
+ jest.mock('@capillarytech/cap-ui-library/CapSelect', () => function MockCapSelect({ value, onChange, options }) {
343
+ return (
344
+ <select
345
+ data-testid="cap-select"
346
+ value={value}
347
+ onChange={(e) => onChange && onChange(e.target.value)}
348
+ >
349
+ {options?.map((option) => (
350
+ <option key={option.value} value={option.value}>
351
+ {option.label || option.value}
352
+ </option>
353
+ ))}
354
+ </select>
355
+ );
356
+ });
346
357
 
347
358
  jest.mock('@capillarytech/cap-ui-library/CapRow', () =>
348
359
  function MockCapRow({ children, className, style }) {
@@ -351,8 +362,8 @@ jest.mock('@capillarytech/cap-ui-library/CapRow', () =>
351
362
  );
352
363
 
353
364
  jest.mock('@capillarytech/cap-ui-library/CapColumn', () =>
354
- function MockCapColumn({ children, className, span }) {
355
- return <div className={className} data-span={span}>{children}</div>;
365
+ function MockCapColumn({ children, className, span, onClick }) {
366
+ return <div className={className} data-span={span} onClick={onClick}>{children}</div>;
356
367
  }
357
368
  );
358
369
 
@@ -392,6 +403,7 @@ jest.mock('../../constants', () => ({
392
403
 
393
404
  // Mock the utils
394
405
  jest.mock('../../utils', () => ({
406
+ ...jest.requireActual('../../utils'),
395
407
  validateExternalLink: jest.fn(),
396
408
  validateDeepLink: jest.fn(),
397
409
  }));
@@ -488,6 +500,62 @@ jest.mock('../../messages', () => ({
488
500
  id: 'creatives.containersV2.MobilePushNew.actionOnClickBody',
489
501
  defaultMessage: 'Action on click of notification body',
490
502
  },
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
+ },
491
559
  },
492
560
  }));
493
561
 
@@ -619,7 +687,7 @@ describe('MediaUploaders', () => {
619
687
  });
620
688
 
621
689
  fireEvent.click(screen.getByTestId('video-upload-button'));
622
- expect(setUpdateMpushVideoSrc).toHaveBeenCalledWith('mock-video-url');
690
+ expect(setUpdateMpushVideoSrc).toHaveBeenCalledWith(0, { videoSrc: 'mock-video-url', previewUrl: 'mock-preview-url' });
623
691
  });
624
692
  });
625
693
 
@@ -637,7 +705,7 @@ describe('MediaUploaders', () => {
637
705
  });
638
706
 
639
707
  fireEvent.click(screen.getByTestId('video-upload-button'));
640
- expect(setUpdateMpushVideoSrc).toHaveBeenCalledWith('mock-video-url');
708
+ expect(setUpdateMpushVideoSrc).toHaveBeenCalledWith(0, { videoSrc: 'mock-video-url', previewUrl: 'mock-preview-url' });
641
709
  });
642
710
  });
643
711
 
@@ -652,7 +720,7 @@ describe('MediaUploaders', () => {
652
720
  mediaType: 'image',
653
721
  imageUrl: 'test.jpg',
654
722
  buttons: [{
655
- actionOnClick: true,
723
+ actionOnClick: true, isSaved: false,
656
724
  linkType: 'EXTERNAL_LINK',
657
725
  deepLinkValue: '',
658
726
  deepLinkKeys: [],
@@ -674,9 +742,9 @@ describe('MediaUploaders', () => {
674
742
  const carouselCard = screen.getByText('Card 1');
675
743
  expect(carouselCard).toBeInTheDocument();
676
744
 
677
- // Check if the buttons and links section is rendered
678
- const buttonsAndLinks = screen.getByText('Buttons and links');
679
- expect(buttonsAndLinks).toBeInTheDocument();
745
+ // No per-card tap: the notification tap is for the whole notification
746
+ expect(screen.queryByText('Card tap')).not.toBeInTheDocument();
747
+ expect(screen.queryByText('When tapped, open')).not.toBeInTheDocument();
680
748
  });
681
749
 
682
750
  it('should initialize carousel data when empty', () => {
@@ -728,59 +796,6 @@ describe('MediaUploaders', () => {
728
796
  expect(onCarouselDataChange).toHaveBeenCalledWith(ANDROID, []);
729
797
  });
730
798
 
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
- });
784
799
  });
785
800
 
786
801
  describe('Platform switching', () => {
@@ -831,7 +846,7 @@ describe('MediaUploaders', () => {
831
846
  </Provider>
832
847
  );
833
848
 
834
- expect(clearImageDataByMediaType).toHaveBeenCalledWith('IMAGE');
849
+ expect(clearImageDataByMediaType).toHaveBeenCalledWith('IMAGE', ANDROID);
835
850
  });
836
851
 
837
852
  it('should clear image data when switching from CAROUSEL to IMAGE', () => {
@@ -853,7 +868,36 @@ describe('MediaUploaders', () => {
853
868
  </Provider>
854
869
  );
855
870
 
856
- expect(clearImageDataByMediaType).toHaveBeenCalledWith('IMAGE');
871
+ expect(clearImageDataByMediaType).toHaveBeenCalledWith('IMAGE', ANDROID);
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);
857
901
  });
858
902
  });
859
903
 
@@ -977,6 +1021,44 @@ describe('MediaUploaders', () => {
977
1021
  });
978
1022
 
979
1023
  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
+
980
1062
  it('should add new carousel card when add button is clicked', () => {
981
1063
  const onCarouselDataChange = jest.fn();
982
1064
  renderComponent({
@@ -984,7 +1066,7 @@ describe('MediaUploaders', () => {
984
1066
  carouselData: [
985
1067
  {
986
1068
  mediaType: 'image',
987
- imageUrl: '',
1069
+ imageUrl: 'card1.jpg',
988
1070
  buttons: [{
989
1071
  actionOnClick: false,
990
1072
  linkType: 'DEEP_LINK',
@@ -1132,147 +1214,6 @@ describe('MediaUploaders', () => {
1132
1214
  });
1133
1215
 
1134
1216
  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
- });
1276
1217
 
1277
1218
  it('should handle carousel image change', () => {
1278
1219
  const onCarouselDataChange = jest.fn();
@@ -1320,61 +1261,6 @@ describe('MediaUploaders', () => {
1320
1261
  });
1321
1262
  });
1322
1263
 
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
-
1378
1264
  describe('Carousel maximum cards limit', () => {
1379
1265
  it('should disable add button when maximum carousel cards reached', () => {
1380
1266
  const carouselData = Array(10).fill().map((_, index) => ({
@@ -1475,8 +1361,9 @@ describe('MediaUploaders', () => {
1475
1361
  onCarouselDataChange,
1476
1362
  });
1477
1363
 
1478
- // Should render carousel component
1479
- expect(screen.getByTestId('cap-image-upload')).toBeInTheDocument();
1364
+ // Saved video cards open with video boxes, not the default image ones
1365
+ expect(screen.getByTestId('cap-video-upload')).toBeInTheDocument();
1366
+ expect(screen.queryByTestId('cap-image-upload')).toBeNull();
1480
1367
  });
1481
1368
 
1482
1369
  it('should handle carousel video upload when video component is used', () => {
@@ -1523,7 +1410,8 @@ describe('MediaUploaders', () => {
1523
1410
  </Provider>
1524
1411
  );
1525
1412
 
1526
- expect(screen.getByTestId('cap-image-upload')).toBeInTheDocument();
1413
+ expect(screen.getByTestId('cap-video-upload')).toBeInTheDocument();
1414
+ expect(screen.queryByTestId('cap-image-upload')).toBeNull();
1527
1415
  });
1528
1416
  });
1529
1417
 
@@ -1657,99 +1545,6 @@ describe('MediaUploaders', () => {
1657
1545
  });
1658
1546
  });
1659
1547
 
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
1548
  describe('Carousel asset clearing', () => {
1754
1549
  it('should clear assets after updating carousel card', () => {
1755
1550
  const mobilePushActions = {
@@ -1852,7 +1647,7 @@ describe('MediaUploaders', () => {
1852
1647
  mediaType: 'image',
1853
1648
  imageUrl: 'test.jpg',
1854
1649
  buttons: [{
1855
- actionOnClick: true,
1650
+ actionOnClick: true, isSaved: false,
1856
1651
  linkType: 'EXTERNAL_LINK',
1857
1652
  deepLinkValue: '',
1858
1653
  externalLinkValue: 'https://example.com',
@@ -1947,117 +1742,6 @@ describe('MediaUploaders', () => {
1947
1742
  expect(screen.getByTestId('cap-video-upload')).toBeInTheDocument();
1948
1743
  });
1949
1744
 
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
-
2061
1745
  it('should handle carousel action links with no buttons array', () => {
2062
1746
  renderComponent({
2063
1747
  mediaType: 'CAROUSEL',
@@ -2073,7 +1757,7 @@ describe('MediaUploaders', () => {
2073
1757
 
2074
1758
  // Should render carousel without action links section
2075
1759
  expect(screen.getByTestId('cap-tab')).toBeInTheDocument();
2076
- expect(screen.queryByTestId('cap-checkbox')).not.toBeInTheDocument();
1760
+ expect(screen.queryByText('When tapped, open')).not.toBeInTheDocument();
2077
1761
  });
2078
1762
 
2079
1763
  it('should handle multiple carousel cards with tab operations', () => {
@@ -2304,436 +1988,12 @@ describe('MediaUploaders', () => {
2304
1988
  expect.arrayContaining([
2305
1989
  expect.objectContaining({
2306
1990
  videoSrc: 'mock-video-url',
1991
+ videoPreviewImg: 'mock-preview-url',
2307
1992
  })
2308
1993
  ])
2309
1994
  );
2310
1995
  });
2311
1996
 
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
2737
1997
  });
2738
1998
 
2739
1999
  describe('Platform-specific video data handling', () => {
@@ -2939,130 +2199,10 @@ describe('MediaUploaders', () => {
2939
2199
 
2940
2200
  // Should clear asset and update carousel data
2941
2201
  expect(mockMobilePushActions.clearAsset).toHaveBeenCalledWith(0);
2942
- expect(mockUpdateOnMpushImageReUpload).toHaveBeenCalled();
2943
- expect(mockOnCarouselDataChange).toHaveBeenCalled();
2944
-
2945
- jest.useRealTimers();
2946
- });
2947
- });
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
- );
2202
+ expect(mockUpdateOnMpushImageReUpload).toHaveBeenCalled();
2203
+ expect(mockOnCarouselDataChange).toHaveBeenCalled();
2204
+
2205
+ jest.useRealTimers();
3066
2206
  });
3067
2207
  });
3068
2208
 
@@ -3221,397 +2361,6 @@ describe('MediaUploaders', () => {
3221
2361
  });
3222
2362
  });
3223
2363
 
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
-
3615
2364
  describe('Carousel upload ID tracking and state management', () => {
3616
2365
  it('should increment uploadIdRef.current and set uploading state for carousel uploads', () => {
3617
2366
  const mockUploadMpushAsset = jest.fn().mockResolvedValue('upload-result');
@@ -4174,51 +2923,125 @@ describe('MediaUploaders', () => {
4174
2923
  expect(document.querySelector('.mobile-push-carousel-tab')).toBeTruthy();
4175
2924
  });
4176
2925
 
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',
2926
+ });
2927
+
2928
+ describe('Carousel media switch and video uploads', () => {
2929
+ const button = { actionOnClick: false, linkType: DEEP_LINK, deepLinkValue: '', externalLinkValue: '' };
2930
+ const videoCard = (src) => ({
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,
4182
2953
  carouselData: [
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
- }
2954
+ { mediaType: 'image', imageUrl: 'a.jpg', videoSrc: 'a.mp4', videoPreviewImg: 'a.png', buttons: [button] },
2955
+ { mediaType: 'image', imageUrl: 'b.jpg', videoSrc: '', videoPreviewImg: '' },
4194
2956
  ],
4195
- carouselActiveTabIndex: 0,
4196
- activeTab: 'ANDROID',
4197
- formatMessage: mockFormatMessage,
4198
- onCarouselDataChange: mockHandleCarouselExternalLinkChange,
4199
2957
  });
4200
2958
 
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();
2959
+ fireEvent.click(screen.getByTestId('radio-video'));
4204
2960
 
4205
- // Click the button to trigger the real onButtonTagSelect useCallback
4206
- fireEvent.click(tagSelectButton);
2961
+ expect(lastCards(onCarouselDataChange)).toEqual([
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
+ });
4207
2973
 
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
- );
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();
3040
+
3041
+ onCarouselDataChange.mockClear();
3042
+ fireEvent.click(screen.getByTestId('video-file-upload-button'));
3043
+
3044
+ expect(onCarouselDataChange).not.toHaveBeenCalled();
4222
3045
  });
4223
3046
  });
4224
3047
  });