@capillarytech/creatives-library 9.2.0 → 9.2.1-alpha.sprint-cap-214249.42

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 (41) 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 +56 -51
  5. package/utils/tests/createMobilePushPayload.test.js +162 -10
  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 +48 -10
  13. package/v2Components/CommonTestAndPreview/tests/UnifiedPreview/MobilePushPreviewContent.test.js +83 -5
  14. package/v2Components/CommonTestAndPreview/tests/index.test.js +86 -0
  15. package/v2Components/TemplatePreview/_templatePreview.scss +12 -2
  16. package/v2Components/TemplatePreview/index.js +14 -12
  17. package/v2Components/TemplatePreview/tests/index.test.js +69 -0
  18. package/v2Containers/CreativesContainer/SlideBoxContent.js +4 -6
  19. package/v2Containers/CreativesContainer/index.js +2 -1
  20. package/v2Containers/CreativesContainer/tests/SlideBoxContent.test.js +43 -0
  21. package/v2Containers/MobilePushNew/components/CtaButtons.js +52 -47
  22. package/v2Containers/MobilePushNew/components/MediaUploaders.js +314 -222
  23. package/v2Containers/MobilePushNew/components/PlatformContentFields.js +161 -130
  24. package/v2Containers/MobilePushNew/components/TapLinkActions.js +76 -0
  25. package/v2Containers/MobilePushNew/components/tests/CtaButtons.test.js +30 -208
  26. package/v2Containers/MobilePushNew/components/tests/MediaUploaders.test.js +484 -123
  27. package/v2Containers/MobilePushNew/components/tests/PlatformContentFields.test.js +152 -46
  28. package/v2Containers/MobilePushNew/constants.js +12 -0
  29. package/v2Containers/MobilePushNew/hooks/tests/usePlatformSync.test.js +63 -1
  30. package/v2Containers/MobilePushNew/hooks/tests/useUpload.test.js +78 -0
  31. package/v2Containers/MobilePushNew/hooks/usePlatformSync.js +40 -1
  32. package/v2Containers/MobilePushNew/hooks/useUpload.js +42 -46
  33. package/v2Containers/MobilePushNew/index.js +503 -273
  34. package/v2Containers/MobilePushNew/index.scss +215 -4
  35. package/v2Containers/MobilePushNew/messages.js +106 -6
  36. package/v2Containers/MobilePushNew/tests/index.test.js +482 -1
  37. package/v2Containers/MobilePushNew/tests/utils.test.js +122 -0
  38. package/v2Containers/MobilePushNew/utils.js +107 -0
  39. package/v2Containers/Templates/_templates.scss +10 -2
  40. package/v2Containers/Templates/index.js +83 -81
  41. package/v2Containers/Templates/tests/index.test.js +68 -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
 
@@ -202,11 +202,27 @@ jest.mock('../../../../v2Components/CapVideoUpload', () =>
202
202
  <div data-testid="cap-video-upload">
203
203
  <button
204
204
  type="button"
205
- onClick={() => props.onVideoUploadUpdateAssestList('mock-video-url')}
205
+ // Real CapVideoUpload calls back with (index, data)
206
+ onClick={() => props.onVideoUploadUpdateAssestList(0, { videoSrc: 'mock-video-url', previewUrl: 'mock-preview-url' })}
206
207
  data-testid="video-upload-button"
207
208
  >
208
209
  Upload Video
209
210
  </button>
211
+ <button
212
+ type="button"
213
+ // Real Re upload clears the video, then opens the file picker
214
+ onClick={() => props.onVideoUploadUpdateAssestList(0, { videoSrc: '', previewUrl: '' })}
215
+ data-testid="video-reupload-button"
216
+ >
217
+ Re upload Video
218
+ </button>
219
+ <button
220
+ type="button"
221
+ onClick={() => props.uploadAsset({ name: 'test.mp4' }, 'video', {}, props.index)}
222
+ data-testid="video-file-upload-button"
223
+ >
224
+ Pick Video File
225
+ </button>
210
226
  </div>
211
227
  );
212
228
  }
@@ -351,8 +367,8 @@ jest.mock('@capillarytech/cap-ui-library/CapRow', () =>
351
367
  );
352
368
 
353
369
  jest.mock('@capillarytech/cap-ui-library/CapColumn', () =>
354
- function MockCapColumn({ children, className, span }) {
355
- return <div className={className} data-span={span}>{children}</div>;
370
+ function MockCapColumn({ children, className, span, onClick }) {
371
+ return <div className={className} data-span={span} onClick={onClick}>{children}</div>;
356
372
  }
357
373
  );
358
374
 
@@ -392,6 +408,7 @@ jest.mock('../../constants', () => ({
392
408
 
393
409
  // Mock the utils
394
410
  jest.mock('../../utils', () => ({
411
+ ...jest.requireActual('../../utils'),
395
412
  validateExternalLink: jest.fn(),
396
413
  validateDeepLink: jest.fn(),
397
414
  }));
@@ -488,6 +505,62 @@ jest.mock('../../messages', () => ({
488
505
  id: 'creatives.containersV2.MobilePushNew.actionOnClickBody',
489
506
  defaultMessage: 'Action on click of notification body',
490
507
  },
508
+ tapLinkSaveDisabled: {
509
+ id: 'creatives.containersV2.MobilePushNew.tapLinkSaveDisabled',
510
+ defaultMessage: 'Please complete the above fields to enable Save',
511
+ },
512
+ cardTap: {
513
+ id: 'creatives.containersV2.MobilePushNew.cardTap',
514
+ defaultMessage: 'Card tap',
515
+ },
516
+ deepLinkRequired: {
517
+ id: 'creatives.containersV2.MobilePushNew.deepLinkRequired',
518
+ defaultMessage: 'Select a deep link',
519
+ },
520
+ urlNotValid: {
521
+ id: 'creatives.containersV2.MobilePushNew.urlNotValid',
522
+ defaultMessage: 'URL is not valid',
523
+ },
524
+ completeCardToAdd: {
525
+ id: 'creatives.containersV2.MobilePushNew.completeCardToAdd',
526
+ defaultMessage: 'Please set-up the first card before creating the next ones',
527
+ },
528
+ carouselMaxCardTooltip: {
529
+ id: 'creatives.containersV2.MobilePushNew.carouselMaxCardTooltip',
530
+ defaultMessage: 'Mobile push carousel cannot contain more than {max} content cards.',
531
+ },
532
+ cardTapDescription: {
533
+ id: 'creatives.containersV2.MobilePushNew.cardTapDescription',
534
+ defaultMessage: 'What happens when someone taps this card.',
535
+ },
536
+ cardTapAppHelp: {
537
+ id: 'creatives.containersV2.MobilePushNew.cardTapAppHelp',
538
+ defaultMessage: 'Opens your app. Choose a link to send people to a specific page from this card instead.',
539
+ },
540
+ whenTappedOpen: {
541
+ id: 'creatives.containersV2.MobilePushNew.whenTappedOpen',
542
+ defaultMessage: 'When tapped, open',
543
+ },
544
+ tapActionApp: {
545
+ id: 'creatives.containersV2.MobilePushNew.tapActionApp',
546
+ defaultMessage: 'App (default)',
547
+ },
548
+ tapActionDeepLink: {
549
+ id: 'creatives.containersV2.MobilePushNew.tapActionDeepLink',
550
+ defaultMessage: 'Deep link',
551
+ },
552
+ tapActionExternalLink: {
553
+ id: 'creatives.containersV2.MobilePushNew.tapActionExternalLink',
554
+ defaultMessage: 'External link',
555
+ },
556
+ url: {
557
+ id: 'creatives.containersV2.MobilePushNew.url',
558
+ defaultMessage: 'URL',
559
+ },
560
+ enterUrl: {
561
+ id: 'creatives.containersV2.MobilePushNew.enterUrl',
562
+ defaultMessage: 'Enter URL',
563
+ },
491
564
  },
492
565
  }));
493
566
 
@@ -619,7 +692,7 @@ describe('MediaUploaders', () => {
619
692
  });
620
693
 
621
694
  fireEvent.click(screen.getByTestId('video-upload-button'));
622
- expect(setUpdateMpushVideoSrc).toHaveBeenCalledWith('mock-video-url');
695
+ expect(setUpdateMpushVideoSrc).toHaveBeenCalledWith(0, { videoSrc: 'mock-video-url', previewUrl: 'mock-preview-url' });
623
696
  });
624
697
  });
625
698
 
@@ -637,7 +710,7 @@ describe('MediaUploaders', () => {
637
710
  });
638
711
 
639
712
  fireEvent.click(screen.getByTestId('video-upload-button'));
640
- expect(setUpdateMpushVideoSrc).toHaveBeenCalledWith('mock-video-url');
713
+ expect(setUpdateMpushVideoSrc).toHaveBeenCalledWith(0, { videoSrc: 'mock-video-url', previewUrl: 'mock-preview-url' });
641
714
  });
642
715
  });
643
716
 
@@ -652,7 +725,7 @@ describe('MediaUploaders', () => {
652
725
  mediaType: 'image',
653
726
  imageUrl: 'test.jpg',
654
727
  buttons: [{
655
- actionOnClick: true,
728
+ actionOnClick: true, isSaved: false,
656
729
  linkType: 'EXTERNAL_LINK',
657
730
  deepLinkValue: '',
658
731
  deepLinkKeys: [],
@@ -674,9 +747,8 @@ describe('MediaUploaders', () => {
674
747
  const carouselCard = screen.getByText('Card 1');
675
748
  expect(carouselCard).toBeInTheDocument();
676
749
 
677
- // Check if the buttons and links section is rendered
678
- const buttonsAndLinks = screen.getByText('Buttons and links');
679
- expect(buttonsAndLinks).toBeInTheDocument();
750
+ expect(screen.getByText('Card tap')).toBeInTheDocument();
751
+ expect(screen.getByText('When tapped, open')).toBeInTheDocument();
680
752
  });
681
753
 
682
754
  it('should initialize carousel data when empty', () => {
@@ -738,7 +810,7 @@ describe('MediaUploaders', () => {
738
810
  mediaType: 'image',
739
811
  imageUrl: 'test.jpg',
740
812
  buttons: [{
741
- actionOnClick: true,
813
+ actionOnClick: true, isSaved: false,
742
814
  linkType: 'EXTERNAL_LINK',
743
815
  deepLinkValue: '',
744
816
  deepLinkKeys: [],
@@ -752,15 +824,8 @@ describe('MediaUploaders', () => {
752
824
  formatMessage: mockFormatMessage,
753
825
  });
754
826
 
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' } });
827
+ expect(screen.getAllByTestId('cap-custom-select')[0]).toHaveValue('EXTERNAL_LINK');
762
828
 
763
- // Wait for the external link input to be rendered
764
829
  const externalLinkInput = screen.getByTestId('cap-input-mobile-push-external-link-input-ANDROID-0');
765
830
  expect(externalLinkInput).toBeInTheDocument();
766
831
  expect(externalLinkInput.value).toBe('https://example.com');
@@ -831,7 +896,7 @@ describe('MediaUploaders', () => {
831
896
  </Provider>
832
897
  );
833
898
 
834
- expect(clearImageDataByMediaType).toHaveBeenCalledWith('IMAGE');
899
+ expect(clearImageDataByMediaType).toHaveBeenCalledWith('IMAGE', ANDROID);
835
900
  });
836
901
 
837
902
  it('should clear image data when switching from CAROUSEL to IMAGE', () => {
@@ -853,7 +918,36 @@ describe('MediaUploaders', () => {
853
918
  </Provider>
854
919
  );
855
920
 
856
- expect(clearImageDataByMediaType).toHaveBeenCalledWith('IMAGE');
921
+ expect(clearImageDataByMediaType).toHaveBeenCalledWith('IMAGE', ANDROID);
922
+ });
923
+
924
+ // A tab switch gives the hidden pane a new clearImageDataByMediaType; that alone must not clear anything
925
+ it('does not clear when only the callbacks change (tab switch), and clears its own platform on a real change', () => {
926
+ const firstClear = jest.fn();
927
+ const onCarouselDataChange = jest.fn();
928
+ const renderPane = (mediaType, clearImageDataByMediaType) => (
929
+ <Provider store={mockStore}>
930
+ <IntlProvider messages={messages} locale="en">
931
+ <MediaUploaders
932
+ {...defaultProps}
933
+ activeTab={IOS}
934
+ mediaType={mediaType}
935
+ clearImageDataByMediaType={clearImageDataByMediaType}
936
+ onCarouselDataChange={onCarouselDataChange}
937
+ />
938
+ </IntlProvider>
939
+ </Provider>
940
+ );
941
+ const { rerender } = render(renderPane('VIDEO', firstClear));
942
+
943
+ const clearAfterTabSwitch = jest.fn();
944
+ rerender(renderPane('VIDEO', clearAfterTabSwitch));
945
+ expect(firstClear).not.toHaveBeenCalled();
946
+ expect(clearAfterTabSwitch).not.toHaveBeenCalled();
947
+ expect(onCarouselDataChange).not.toHaveBeenCalled();
948
+
949
+ rerender(renderPane('NONE', clearAfterTabSwitch));
950
+ expect(clearAfterTabSwitch).toHaveBeenCalledWith('IMAGE', IOS);
857
951
  });
858
952
  });
859
953
 
@@ -977,6 +1071,135 @@ describe('MediaUploaders', () => {
977
1071
  });
978
1072
 
979
1073
  describe('Carousel card management', () => {
1074
+ const doneCard = (mediaType, media) => ({
1075
+ mediaType,
1076
+ imageUrl: mediaType === 'image' ? media : '',
1077
+ videoSrc: mediaType === 'video' ? media : '',
1078
+ buttons: [{ actionOnClick: false, linkType: 'DEEP_LINK', deepLinkValue: '', externalLinkValue: '' }],
1079
+ });
1080
+
1081
+ it('opens the new card after adding it', () => {
1082
+ const onCarouselDataChange = jest.fn();
1083
+ const setCarouselActiveTabIndex = jest.fn();
1084
+ renderComponent({
1085
+ mediaType: 'CAROUSEL',
1086
+ carouselData: [doneCard('image', 'a.jpg'), doneCard('image', 'b.jpg')],
1087
+ onCarouselDataChange,
1088
+ setCarouselActiveTabIndex,
1089
+ });
1090
+ setCarouselActiveTabIndex.mockClear();
1091
+
1092
+ fireEvent.click(document.querySelector('.add-carousel-content-button'));
1093
+
1094
+ expect(onCarouselDataChange).toHaveBeenCalledWith(ANDROID, expect.any(Array));
1095
+ expect(onCarouselDataChange.mock.calls.pop()[1]).toHaveLength(3);
1096
+ expect(setCarouselActiveTabIndex).toHaveBeenCalledWith(2);
1097
+ });
1098
+
1099
+ it.each([
1100
+ ['an image card has no image', [doneCard('image', 'a.jpg'), doneCard('image', '')]],
1101
+ ['a video card has no video', [doneCard('video', 'a.mp4'), doneCard('video', '')]],
1102
+ ])('disables add while %s', (_label, carouselData) => {
1103
+ renderComponent({ mediaType: 'CAROUSEL', carouselData });
1104
+ expect(document.querySelector('.add-carousel-content-button')).toBeDisabled();
1105
+ });
1106
+
1107
+ it('enables add once every video card has its video', () => {
1108
+ renderComponent({ mediaType: 'CAROUSEL', carouselData: [doneCard('video', 'a.mp4'), doneCard('video', 'b.mp4')] });
1109
+ expect(document.querySelector('.add-carousel-content-button')).not.toBeDisabled();
1110
+ });
1111
+
1112
+ const cardWithTap = (button) => ({
1113
+ ...doneCard('image', 'a.jpg'),
1114
+ buttons: [{
1115
+ actionOnClick: true, isSaved: false, deepLinkValue: '', deepLinkKeys: [], externalLinkValue: '', ...button,
1116
+ }],
1117
+ });
1118
+
1119
+ it.each([
1120
+ ['Deep link is chosen with none picked', { linkType: 'DEEP_LINK' }, 'Select a deep link'],
1121
+ ['External link is chosen with no URL', { linkType: 'EXTERNAL_LINK' }, 'URL is not valid'],
1122
+ ])('disables add and the link Save, without an inline message, when %s', (_label, button, message) => {
1123
+ renderComponent({ mediaType: 'CAROUSEL', carouselData: [cardWithTap(button)], formatMessage: mockFormatMessage });
1124
+ expect(document.querySelector('.add-carousel-content-button')).toBeDisabled();
1125
+ expect(document.querySelector('.mpush-tap-save-btn')).toBeDisabled();
1126
+ expect(screen.queryByText(message)).not.toBeInTheDocument();
1127
+ });
1128
+
1129
+ it('disables add until a deep link with keys has its keys', () => {
1130
+ const linkProps = { deepLink: [{ value: 'app://offer', label: 'Offer', keys: ['offerId'] }] };
1131
+ const { unmount } = renderComponent({
1132
+ mediaType: 'CAROUSEL',
1133
+ carouselData: [cardWithTap({ linkType: 'DEEP_LINK', deepLinkValue: 'app://offer' })],
1134
+ linkProps,
1135
+ });
1136
+ expect(document.querySelector('.add-carousel-content-button')).toBeDisabled();
1137
+ unmount();
1138
+
1139
+ renderComponent({
1140
+ mediaType: 'CAROUSEL',
1141
+ carouselData: [cardWithTap({ linkType: 'DEEP_LINK', deepLinkValue: 'app://offer', deepLinkKeys: ['offerId'], isSaved: true })],
1142
+ linkProps,
1143
+ });
1144
+ expect(document.querySelector('.add-carousel-content-button')).not.toBeDisabled();
1145
+ });
1146
+
1147
+ it('enables add once the card tap link is filled', () => {
1148
+ renderComponent({
1149
+ mediaType: 'CAROUSEL',
1150
+ carouselData: [cardWithTap({ linkType: 'EXTERNAL_LINK', externalLinkValue: 'https://example.com', isSaved: true })],
1151
+ formatMessage: mockFormatMessage,
1152
+ });
1153
+ expect(document.querySelector('.add-carousel-content-button')).not.toBeDisabled();
1154
+ expect(screen.queryByText('URL is not valid')).not.toBeInTheDocument();
1155
+ });
1156
+
1157
+ it('keeps "+" off while a filled card link is not saved, and its Save saves it', () => {
1158
+ const onCarouselDataChange = jest.fn();
1159
+ renderComponent({
1160
+ mediaType: 'CAROUSEL',
1161
+ carouselData: [cardWithTap({ linkType: 'EXTERNAL_LINK', externalLinkValue: 'https://example.com' })],
1162
+ onCarouselDataChange,
1163
+ formatMessage: mockFormatMessage,
1164
+ });
1165
+ expect(document.querySelector('.add-carousel-content-button')).toBeDisabled();
1166
+
1167
+ const saveButton = document.querySelector('.mpush-tap-save-btn');
1168
+ expect(saveButton).not.toBeDisabled();
1169
+ fireEvent.click(saveButton);
1170
+ expect(onCarouselDataChange.mock.calls.pop()[1][0].buttons[0]).toEqual(expect.objectContaining({ isSaved: true }));
1171
+ });
1172
+
1173
+ it('keeps the card link Save off while the link is empty', () => {
1174
+ renderComponent({
1175
+ mediaType: 'CAROUSEL',
1176
+ carouselData: [cardWithTap({ linkType: 'DEEP_LINK' })],
1177
+ formatMessage: mockFormatMessage,
1178
+ });
1179
+ expect(document.querySelector('.mpush-tap-save-btn')).toBeDisabled();
1180
+ });
1181
+
1182
+ it('shows a saved card link as one row; edit reopens it, delete sets App', () => {
1183
+ const onCarouselDataChange = jest.fn();
1184
+ renderComponent({
1185
+ mediaType: 'CAROUSEL',
1186
+ carouselData: [cardWithTap({ linkType: 'EXTERNAL_LINK', externalLinkValue: 'https://example.com', isSaved: undefined })],
1187
+ onCarouselDataChange,
1188
+ formatMessage: mockFormatMessage,
1189
+ });
1190
+ expect(document.querySelector('.mpush-saved-tap-link')).toBeInTheDocument();
1191
+ expect(screen.getByText('https://example.com')).toBeInTheDocument();
1192
+ expect(document.querySelector('.mpush-tap-save-btn')).toBeNull();
1193
+
1194
+ fireEvent.click(document.querySelector('.mpush-saved-tap-link-edit-icon'));
1195
+ expect(onCarouselDataChange.mock.calls.pop()[1][0].buttons[0]).toEqual(expect.objectContaining({ isSaved: false }));
1196
+
1197
+ fireEvent.click(document.querySelector('.mpush-saved-tap-link-delete-icon'));
1198
+ expect(onCarouselDataChange.mock.calls.pop()[1][0].buttons[0]).toEqual(
1199
+ expect.objectContaining({ actionOnClick: false, externalLinkValue: '' })
1200
+ );
1201
+ });
1202
+
980
1203
  it('should add new carousel card when add button is clicked', () => {
981
1204
  const onCarouselDataChange = jest.fn();
982
1205
  renderComponent({
@@ -984,7 +1207,7 @@ describe('MediaUploaders', () => {
984
1207
  carouselData: [
985
1208
  {
986
1209
  mediaType: 'image',
987
- imageUrl: '',
1210
+ imageUrl: 'card1.jpg',
988
1211
  buttons: [{
989
1212
  actionOnClick: false,
990
1213
  linkType: 'DEEP_LINK',
@@ -1151,26 +1374,62 @@ describe('MediaUploaders', () => {
1151
1374
  onCarouselDataChange,
1152
1375
  });
1153
1376
 
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
- }
1377
+ const tapSelect = screen.getAllByTestId('cap-custom-select')[0];
1378
+ expect(tapSelect).toHaveValue('APP');
1379
+ expect(screen.getByText('Opens your app. Choose a link to send people to a specific page from this card instead.')).toBeInTheDocument();
1380
+
1381
+ fireEvent.change(tapSelect, { target: { value: 'EXTERNAL_LINK' } });
1382
+ expect(onCarouselDataChange).toHaveBeenCalledWith(
1383
+ ANDROID,
1384
+ expect.arrayContaining([
1385
+ expect.objectContaining({
1386
+ buttons: expect.arrayContaining([
1387
+ expect.objectContaining({ actionOnClick: true, isSaved: false, linkType: 'EXTERNAL_LINK' }),
1388
+ ]),
1389
+ }),
1390
+ ])
1391
+ );
1392
+ });
1393
+
1394
+ it('should turn the card action off and clear links when App is chosen', () => {
1395
+ const onCarouselDataChange = jest.fn();
1396
+ const updateCarouselLinkError = jest.fn();
1397
+ renderComponent({
1398
+ mediaType: 'CAROUSEL',
1399
+ carouselData: [
1400
+ {
1401
+ mediaType: 'image',
1402
+ imageUrl: '',
1403
+ buttons: [{
1404
+ actionOnClick: true, isSaved: false,
1405
+ linkType: 'EXTERNAL_LINK',
1406
+ deepLinkValue: '',
1407
+ deepLinkKeys: [],
1408
+ externalLinkValue: 'https://example.com',
1409
+ }],
1410
+ }
1411
+ ],
1412
+ onCarouselDataChange,
1413
+ updateCarouselLinkError,
1414
+ });
1415
+
1416
+ fireEvent.change(screen.getAllByTestId('cap-custom-select')[0], { target: { value: 'APP' } });
1417
+ expect(onCarouselDataChange).toHaveBeenCalledWith(
1418
+ ANDROID,
1419
+ expect.arrayContaining([
1420
+ expect.objectContaining({
1421
+ buttons: expect.arrayContaining([
1422
+ expect.objectContaining({
1423
+ actionOnClick: false,
1424
+ linkType: 'DEEP_LINK',
1425
+ externalLinkValue: '',
1426
+ deepLinkValue: '',
1427
+ }),
1428
+ ]),
1429
+ }),
1430
+ ])
1431
+ );
1432
+ expect(updateCarouselLinkError).toHaveBeenCalledWith(0, 'externalLink', null);
1174
1433
  });
1175
1434
 
1176
1435
  it('should handle carousel link type change', () => {
@@ -1183,7 +1442,7 @@ describe('MediaUploaders', () => {
1183
1442
  mediaType: 'image',
1184
1443
  imageUrl: '',
1185
1444
  buttons: [{
1186
- actionOnClick: true, // Enable action links
1445
+ actionOnClick: true, isSaved: false, // Enable action links
1187
1446
  linkType: 'DEEP_LINK',
1188
1447
  deepLinkValue: '',
1189
1448
  externalLinkValue: '',
@@ -1194,18 +1453,7 @@ describe('MediaUploaders', () => {
1194
1453
  updateCarouselLinkError,
1195
1454
  });
1196
1455
 
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
- }
1456
+ expect(screen.getAllByTestId('cap-custom-select')[0]).toHaveValue('DEEP_LINK');
1209
1457
  });
1210
1458
 
1211
1459
  it('should validate deep link when value changes', () => {
@@ -1218,7 +1466,7 @@ describe('MediaUploaders', () => {
1218
1466
  mediaType: 'image',
1219
1467
  imageUrl: '',
1220
1468
  buttons: [{
1221
- actionOnClick: true,
1469
+ actionOnClick: true, isSaved: false,
1222
1470
  linkType: 'DEEP_LINK',
1223
1471
  deepLinkValue: '',
1224
1472
  externalLinkValue: '',
@@ -1234,16 +1482,7 @@ describe('MediaUploaders', () => {
1234
1482
  }
1235
1483
  });
1236
1484
 
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
1485
+ expect(screen.getAllByTestId('cap-custom-select')[0]).toHaveValue('DEEP_LINK');
1247
1486
  expect(screen.getByTestId('cap-image-upload')).toBeInTheDocument();
1248
1487
  });
1249
1488
 
@@ -1257,7 +1496,7 @@ describe('MediaUploaders', () => {
1257
1496
  mediaType: 'image',
1258
1497
  imageUrl: '',
1259
1498
  buttons: [{
1260
- actionOnClick: true,
1499
+ actionOnClick: true, isSaved: false,
1261
1500
  linkType: 'EXTERNAL_LINK',
1262
1501
  deepLinkValue: '',
1263
1502
  externalLinkValue: '',
@@ -1329,7 +1568,7 @@ describe('MediaUploaders', () => {
1329
1568
  mediaType: 'image',
1330
1569
  imageUrl: '',
1331
1570
  buttons: [{
1332
- actionOnClick: true,
1571
+ actionOnClick: true, isSaved: false,
1333
1572
  linkType: 'DEEP_LINK',
1334
1573
  deepLinkValue: 'invalid-deep-link',
1335
1574
  externalLinkValue: '',
@@ -1358,7 +1597,7 @@ describe('MediaUploaders', () => {
1358
1597
  mediaType: 'image',
1359
1598
  imageUrl: '',
1360
1599
  buttons: [{
1361
- actionOnClick: true,
1600
+ actionOnClick: true, isSaved: false,
1362
1601
  linkType: 'EXTERNAL_LINK',
1363
1602
  deepLinkValue: '',
1364
1603
  externalLinkValue: 'invalid-url',
@@ -1475,8 +1714,9 @@ describe('MediaUploaders', () => {
1475
1714
  onCarouselDataChange,
1476
1715
  });
1477
1716
 
1478
- // Should render carousel component
1479
- expect(screen.getByTestId('cap-image-upload')).toBeInTheDocument();
1717
+ // Saved video cards open with video boxes, not the default image ones
1718
+ expect(screen.getByTestId('cap-video-upload')).toBeInTheDocument();
1719
+ expect(screen.queryByTestId('cap-image-upload')).toBeNull();
1480
1720
  });
1481
1721
 
1482
1722
  it('should handle carousel video upload when video component is used', () => {
@@ -1523,7 +1763,8 @@ describe('MediaUploaders', () => {
1523
1763
  </Provider>
1524
1764
  );
1525
1765
 
1526
- expect(screen.getByTestId('cap-image-upload')).toBeInTheDocument();
1766
+ expect(screen.getByTestId('cap-video-upload')).toBeInTheDocument();
1767
+ expect(screen.queryByTestId('cap-image-upload')).toBeNull();
1527
1768
  });
1528
1769
  });
1529
1770
 
@@ -1667,7 +1908,7 @@ describe('MediaUploaders', () => {
1667
1908
  mediaType: 'image',
1668
1909
  imageUrl: '',
1669
1910
  buttons: [{
1670
- actionOnClick: true,
1911
+ actionOnClick: true, isSaved: false,
1671
1912
  linkType: 'DEEP_LINK',
1672
1913
  deepLinkValue: 'test',
1673
1914
  externalLinkValue: '',
@@ -1699,7 +1940,7 @@ describe('MediaUploaders', () => {
1699
1940
  mediaType: 'image',
1700
1941
  imageUrl: '',
1701
1942
  buttons: [{
1702
- actionOnClick: true,
1943
+ actionOnClick: true, isSaved: false,
1703
1944
  linkType: 'EXTERNAL_LINK',
1704
1945
  deepLinkValue: '',
1705
1946
  externalLinkValue: 'invalid-url',
@@ -1729,7 +1970,7 @@ describe('MediaUploaders', () => {
1729
1970
  mediaType: 'image',
1730
1971
  imageUrl: '',
1731
1972
  buttons: [{
1732
- actionOnClick: true,
1973
+ actionOnClick: true, isSaved: false,
1733
1974
  linkType: 'DEEP_LINK',
1734
1975
  deepLinkValue: 'invalid-link',
1735
1976
  externalLinkValue: '',
@@ -1852,7 +2093,7 @@ describe('MediaUploaders', () => {
1852
2093
  mediaType: 'image',
1853
2094
  imageUrl: 'test.jpg',
1854
2095
  buttons: [{
1855
- actionOnClick: true,
2096
+ actionOnClick: true, isSaved: false,
1856
2097
  linkType: 'EXTERNAL_LINK',
1857
2098
  deepLinkValue: '',
1858
2099
  externalLinkValue: 'https://example.com',
@@ -1967,11 +2208,7 @@ describe('MediaUploaders', () => {
1967
2208
  carouselActiveTabIndex: 0,
1968
2209
  });
1969
2210
 
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
2211
+ fireEvent.change(screen.getAllByTestId('cap-custom-select')[0], { target: { value: 'DEEP_LINK' } });
1975
2212
  expect(onCarouselDataChange).toHaveBeenCalled();
1976
2213
  });
1977
2214
 
@@ -1983,7 +2220,7 @@ describe('MediaUploaders', () => {
1983
2220
  mediaType: 'image',
1984
2221
  imageUrl: 'test.jpg',
1985
2222
  buttons: [{
1986
- actionOnClick: true, // This triggers action links rendering
2223
+ actionOnClick: true, isSaved: false, // This triggers action links rendering
1987
2224
  linkType: 'DEEP_LINK',
1988
2225
  deepLinkValue: '',
1989
2226
  externalLinkValue: '',
@@ -1998,9 +2235,7 @@ describe('MediaUploaders', () => {
1998
2235
  }
1999
2236
  });
2000
2237
 
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
2238
+ expect(screen.getAllByTestId('cap-custom-select')).toHaveLength(2); // Tap action and deep link selects
2004
2239
  });
2005
2240
 
2006
2241
  it('should show carousel link errors when present', () => {
@@ -2011,7 +2246,7 @@ describe('MediaUploaders', () => {
2011
2246
  mediaType: 'image',
2012
2247
  imageUrl: 'test.jpg',
2013
2248
  buttons: [{
2014
- actionOnClick: true,
2249
+ actionOnClick: true, isSaved: false,
2015
2250
  linkType: 'DEEP_LINK',
2016
2251
  deepLinkValue: 'invalid-link',
2017
2252
  externalLinkValue: '',
@@ -2041,7 +2276,7 @@ describe('MediaUploaders', () => {
2041
2276
  mediaType: 'image',
2042
2277
  imageUrl: 'test.jpg',
2043
2278
  buttons: [{
2044
- actionOnClick: true,
2279
+ actionOnClick: true, isSaved: false,
2045
2280
  linkType: 'EXTERNAL_LINK',
2046
2281
  deepLinkValue: '',
2047
2282
  externalLinkValue: 'invalid-url',
@@ -2073,7 +2308,7 @@ describe('MediaUploaders', () => {
2073
2308
 
2074
2309
  // Should render carousel without action links section
2075
2310
  expect(screen.getByTestId('cap-tab')).toBeInTheDocument();
2076
- expect(screen.queryByTestId('cap-checkbox')).not.toBeInTheDocument();
2311
+ expect(screen.queryByText('When tapped, open')).not.toBeInTheDocument();
2077
2312
  });
2078
2313
 
2079
2314
  it('should handle multiple carousel cards with tab operations', () => {
@@ -2304,6 +2539,7 @@ describe('MediaUploaders', () => {
2304
2539
  expect.arrayContaining([
2305
2540
  expect.objectContaining({
2306
2541
  videoSrc: 'mock-video-url',
2542
+ videoPreviewImg: 'mock-preview-url',
2307
2543
  })
2308
2544
  ])
2309
2545
  );
@@ -2319,7 +2555,7 @@ describe('MediaUploaders', () => {
2319
2555
  mediaType: 'image',
2320
2556
  imageUrl: 'test.jpg',
2321
2557
  buttons: [{
2322
- actionOnClick: true,
2558
+ actionOnClick: true, isSaved: false,
2323
2559
  linkType: 'DEEP_LINK',
2324
2560
  deepLinkValue: '',
2325
2561
  externalLinkValue: '',
@@ -2348,7 +2584,7 @@ describe('MediaUploaders', () => {
2348
2584
  mediaType: 'image',
2349
2585
  imageUrl: 'test.jpg',
2350
2586
  buttons: [{
2351
- actionOnClick: true,
2587
+ actionOnClick: true, isSaved: false,
2352
2588
  linkType: 'DEEP_LINK',
2353
2589
  deepLinkValue: '',
2354
2590
  externalLinkValue: '',
@@ -2382,10 +2618,10 @@ describe('MediaUploaders', () => {
2382
2618
  mediaType: 'image',
2383
2619
  imageUrl: 'test-image.jpg',
2384
2620
  buttons: [{
2385
- actionOnClick: true,
2621
+ actionOnClick: true, isSaved: false,
2386
2622
  linkType: 'DEEP_LINK',
2387
2623
  deepLinkValue: 'test-deep-link',
2388
- deepLinkKeys: ['key1', 'key2'],
2624
+ deepLinkKeys: ['key1=value1', 'key2=value2'],
2389
2625
  externalLinkValue: '',
2390
2626
  }]
2391
2627
  }];
@@ -2422,8 +2658,10 @@ describe('MediaUploaders', () => {
2422
2658
  );
2423
2659
 
2424
2660
  // Check that deep link keys are displayed correctly
2425
- expect(getByText('key1, key2')).toBeInTheDocument();
2426
- expect(getByDisplayValue('key1, key2')).toBeInTheDocument();
2661
+ expect(getByText('key1')).toBeInTheDocument();
2662
+ expect(getByText('key2')).toBeInTheDocument();
2663
+ expect(getByDisplayValue('value1')).toBeInTheDocument();
2664
+ expect(getByDisplayValue('value2')).toBeInTheDocument();
2427
2665
  });
2428
2666
 
2429
2667
  it('should handle carousel deep link keys with single key from selection', () => {
@@ -2434,7 +2672,7 @@ describe('MediaUploaders', () => {
2434
2672
  mediaType: 'image',
2435
2673
  imageUrl: 'test-image.jpg',
2436
2674
  buttons: [{
2437
- actionOnClick: true,
2675
+ actionOnClick: true, isSaved: false,
2438
2676
  linkType: 'DEEP_LINK',
2439
2677
  deepLinkValue: 'test-deep-link',
2440
2678
  deepLinkKeys: ['single-key'],
@@ -2486,10 +2724,10 @@ describe('MediaUploaders', () => {
2486
2724
  mediaType: 'image',
2487
2725
  imageUrl: 'test-image.jpg',
2488
2726
  buttons: [{
2489
- actionOnClick: true,
2727
+ actionOnClick: true, isSaved: false,
2490
2728
  linkType: 'DEEP_LINK',
2491
2729
  deepLinkValue: 'test-deep-link',
2492
- deepLinkKeys: ['existing-key1', 'existing-key2'],
2730
+ deepLinkKeys: ['key1=existing-value1', 'key2=existing-value2'],
2493
2731
  externalLinkValue: '',
2494
2732
  }]
2495
2733
  }];
@@ -2526,8 +2764,9 @@ describe('MediaUploaders', () => {
2526
2764
  );
2527
2765
 
2528
2766
  // 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();
2767
+ expect(getByText('key1')).toBeInTheDocument();
2768
+ expect(getByDisplayValue('existing-value1')).toBeInTheDocument();
2769
+ expect(getByDisplayValue('existing-value2')).toBeInTheDocument();
2531
2770
  });
2532
2771
 
2533
2772
  it('should handle carousel deep link keys with no keys at all', () => {
@@ -2538,7 +2777,7 @@ describe('MediaUploaders', () => {
2538
2777
  mediaType: 'image',
2539
2778
  imageUrl: 'test-image.jpg',
2540
2779
  buttons: [{
2541
- actionOnClick: true,
2780
+ actionOnClick: true, isSaved: false,
2542
2781
  linkType: 'DEEP_LINK',
2543
2782
  deepLinkValue: 'test-deep-link',
2544
2783
  deepLinkKeys: [],
@@ -2589,10 +2828,10 @@ describe('MediaUploaders', () => {
2589
2828
  mediaType: 'image',
2590
2829
  imageUrl: 'test-image.jpg',
2591
2830
  buttons: [{
2592
- actionOnClick: true,
2831
+ actionOnClick: true, isSaved: false,
2593
2832
  linkType: 'DEEP_LINK',
2594
2833
  deepLinkValue: 'test-deep-link',
2595
- deepLinkKeys: 'string-key-value',
2834
+ deepLinkKeys: 'single-key=string-key-value',
2596
2835
  externalLinkValue: '',
2597
2836
  }]
2598
2837
  }];
@@ -2640,7 +2879,7 @@ describe('MediaUploaders', () => {
2640
2879
  mediaType: 'image',
2641
2880
  imageUrl: 'test-image.jpg',
2642
2881
  buttons: [{
2643
- actionOnClick: true,
2882
+ actionOnClick: true, isSaved: false,
2644
2883
  linkType: 'DEEP_LINK',
2645
2884
  deepLinkValue: 'test-deep-link',
2646
2885
  deepLinkKeys: undefined,
@@ -2692,7 +2931,7 @@ describe('MediaUploaders', () => {
2692
2931
  mediaType: 'image',
2693
2932
  imageUrl: 'test-image.jpg',
2694
2933
  buttons: [{
2695
- actionOnClick: true,
2934
+ actionOnClick: true, isSaved: false,
2696
2935
  linkType: 'DEEP_LINK',
2697
2936
  deepLinkValue: 'test-deep-link',
2698
2937
  deepLinkKeys: [],
@@ -2957,7 +3196,7 @@ describe('MediaUploaders', () => {
2957
3196
  mediaType: 'image',
2958
3197
  imageUrl: 'test.jpg',
2959
3198
  buttons: [{
2960
- actionOnClick: true,
3199
+ actionOnClick: true, isSaved: false,
2961
3200
  linkType: 'DEEP_LINK',
2962
3201
  deepLinkValue: 'test-deep-link',
2963
3202
  deepLinkKeys: ['key1', 'key2'],
@@ -2991,11 +3230,12 @@ describe('MediaUploaders', () => {
2991
3230
  // Wait for the deep link keys input to be rendered
2992
3231
  const deepLinkKeysInput = await screen.findByTestId('cap-input-mobile-push-carousel-deep-link-keys-input-ANDROID-0');
2993
3232
  expect(deepLinkKeysInput).toBeInTheDocument();
2994
- expect(deepLinkKeysInput.value).toBe('key1, key2');
3233
+ // Old key-only entries read as key=key
3234
+ expect(deepLinkKeysInput.value).toBe('key1');
2995
3235
 
2996
- // Change deep link keys
3236
+ // Type a value for key1
2997
3237
  await act(async () => {
2998
- fireEvent.change(deepLinkKeysInput, { target: { value: 'key3, key4' } });
3238
+ fireEvent.change(deepLinkKeysInput, { target: { value: 'value3' } });
2999
3239
  });
3000
3240
 
3001
3241
  expect(mockOnCarouselDataChange).toHaveBeenCalledWith(
@@ -3004,7 +3244,7 @@ describe('MediaUploaders', () => {
3004
3244
  expect.objectContaining({
3005
3245
  buttons: expect.arrayContaining([
3006
3246
  expect.objectContaining({
3007
- deepLinkKeys: ['key3', 'key4'],
3247
+ deepLinkKeys: ['key1=value3', 'key2=key2'],
3008
3248
  }),
3009
3249
  ]),
3010
3250
  }),
@@ -3022,10 +3262,10 @@ describe('MediaUploaders', () => {
3022
3262
  mediaType: 'image',
3023
3263
  imageUrl: 'test.jpg',
3024
3264
  buttons: [{
3025
- actionOnClick: true,
3265
+ actionOnClick: true, isSaved: false,
3026
3266
  linkType: 'DEEP_LINK',
3027
3267
  deepLinkValue: 'test-deep-link',
3028
- deepLinkKeys: ['key1', 'key2'],
3268
+ deepLinkKeys: ['key1=value1'],
3029
3269
  externalLinkValue: '',
3030
3270
  }],
3031
3271
  }
@@ -3042,7 +3282,7 @@ describe('MediaUploaders', () => {
3042
3282
  });
3043
3283
 
3044
3284
  // Find and interact with the deep link keys input
3045
- const deepLinkKeysInput = screen.getByDisplayValue('key1, key2');
3285
+ const deepLinkKeysInput = screen.getByDisplayValue('value1');
3046
3286
  expect(deepLinkKeysInput).toBeInTheDocument();
3047
3287
 
3048
3288
  // Simulate user clearing the deep link keys
@@ -3232,7 +3472,7 @@ describe('MediaUploaders', () => {
3232
3472
  mediaType: 'image',
3233
3473
  imageUrl: 'test.jpg',
3234
3474
  buttons: [{
3235
- actionOnClick: true,
3475
+ actionOnClick: true, isSaved: false,
3236
3476
  linkType: 'DEEP_LINK',
3237
3477
  deepLinkValue: 'test-deep-link',
3238
3478
  deepLinkKeys: [],
@@ -3297,7 +3537,7 @@ describe('MediaUploaders', () => {
3297
3537
  mediaType: 'image',
3298
3538
  imageUrl: 'test.jpg',
3299
3539
  buttons: [{
3300
- actionOnClick: true,
3540
+ actionOnClick: true, isSaved: false,
3301
3541
  linkType: 'DEEP_LINK',
3302
3542
  deepLinkValue: 'test-deep-link',
3303
3543
  deepLinkKeys: ['key1'],
@@ -3352,7 +3592,7 @@ describe('MediaUploaders', () => {
3352
3592
  mediaType: 'image',
3353
3593
  imageUrl: 'test.jpg',
3354
3594
  buttons: [{
3355
- actionOnClick: true,
3595
+ actionOnClick: true, isSaved: false,
3356
3596
  linkType: 'DEEP_LINK',
3357
3597
  deepLinkValue: '',
3358
3598
  externalLinkValue: '',
@@ -3379,7 +3619,7 @@ describe('MediaUploaders', () => {
3379
3619
  mediaType: 'image',
3380
3620
  imageUrl: 'test.jpg',
3381
3621
  buttons: [{
3382
- actionOnClick: true,
3622
+ actionOnClick: true, isSaved: false,
3383
3623
  linkType: 'DEEP_LINK',
3384
3624
  deepLinkValue: '',
3385
3625
  externalLinkValue: '',
@@ -3407,7 +3647,7 @@ describe('MediaUploaders', () => {
3407
3647
  mediaType: 'image',
3408
3648
  imageUrl: 'test-image.jpg',
3409
3649
  buttons: [{
3410
- actionOnClick: true,
3650
+ actionOnClick: true, isSaved: false,
3411
3651
  linkType: 'DEEP_LINK',
3412
3652
  deepLinkValue: 'myapp://page?param1=value1', // Has query parameters
3413
3653
  deepLinkKeys: ['param1'],
@@ -3460,7 +3700,7 @@ describe('MediaUploaders', () => {
3460
3700
  mediaType: 'image',
3461
3701
  imageUrl: 'test-image.jpg',
3462
3702
  buttons: [{
3463
- actionOnClick: true,
3703
+ actionOnClick: true, isSaved: false,
3464
3704
  linkType: 'DEEP_LINK',
3465
3705
  deepLinkValue: 'myapp://home?userId=123&sessionId=abc', // Has query parameters
3466
3706
  deepLinkKeys: ['userId', 'sessionId'],
@@ -3501,8 +3741,9 @@ describe('MediaUploaders', () => {
3501
3741
  </Provider>
3502
3742
  );
3503
3743
 
3504
- // Should find the base deep link and display keys
3505
- expect(getByText('userId, sessionId')).toBeInTheDocument();
3744
+ // Matches the base deep link and shows one labelled input per configured key
3745
+ expect(getByText('userId')).toBeInTheDocument();
3746
+ expect(getByText('sessionId')).toBeInTheDocument();
3506
3747
  });
3507
3748
 
3508
3749
  it('should match deep link with query parameters in carousel placeholder', () => {
@@ -3513,7 +3754,7 @@ describe('MediaUploaders', () => {
3513
3754
  mediaType: 'image',
3514
3755
  imageUrl: 'test-image.jpg',
3515
3756
  buttons: [{
3516
- actionOnClick: true,
3757
+ actionOnClick: true, isSaved: false,
3517
3758
  linkType: 'DEEP_LINK',
3518
3759
  deepLinkValue: 'testapp://screen?itemId=456', // Has query parameters
3519
3760
  deepLinkKeys: [],
@@ -3566,7 +3807,7 @@ describe('MediaUploaders', () => {
3566
3807
  mediaType: 'image',
3567
3808
  imageUrl: 'test-image.jpg',
3568
3809
  buttons: [{
3569
- actionOnClick: true,
3810
+ actionOnClick: true, isSaved: false,
3570
3811
  linkType: 'DEEP_LINK',
3571
3812
  deepLinkValue: 'myapp://nomatch?param1=value1', // Base doesn't match any deepLink
3572
3813
  deepLinkKeys: [],
@@ -4184,7 +4425,7 @@ describe('MediaUploaders', () => {
4184
4425
  mediaType: 'image',
4185
4426
  imageUrl: 'test.jpg',
4186
4427
  buttons: [{
4187
- actionOnClick: true,
4428
+ actionOnClick: true, isSaved: false,
4188
4429
  linkType: 'EXTERNAL_LINK',
4189
4430
  deepLinkValue: '',
4190
4431
  deepLinkKeys: [],
@@ -4221,4 +4462,124 @@ describe('MediaUploaders', () => {
4221
4462
  );
4222
4463
  });
4223
4464
  });
4465
+
4466
+ describe('Carousel media switch and video uploads', () => {
4467
+ const button = { actionOnClick: false, linkType: DEEP_LINK, deepLinkValue: '', externalLinkValue: '' };
4468
+ const videoCard = (src) => ({
4469
+ mediaType: 'video', imageUrl: '', videoSrc: src, videoPreviewImg: src ? `${src}.png` : '', buttons: [button],
4470
+ });
4471
+ const uploaded = (metaInfo) => ({ uploadedAssetData0: { metaInfo } });
4472
+ const lastCards = (fn) => fn.mock.calls[fn.mock.calls.length - 1][1];
4473
+
4474
+ const renderCarousel = (props) => {
4475
+ const allProps = { ...defaultProps, mediaType: 'CAROUSEL', activeTab: ANDROID, ...props };
4476
+ const ui = (extra = {}) => (
4477
+ <Provider store={mockStore}>
4478
+ <IntlProvider messages={messages} locale="en">
4479
+ <MediaUploaders {...allProps} {...extra} />
4480
+ </IntlProvider>
4481
+ </Provider>
4482
+ );
4483
+ const utils = render(ui());
4484
+ return { ...utils, rerenderWith: (extra) => utils.rerender(ui(extra)) };
4485
+ };
4486
+
4487
+ it('switching to video keeps video fields, clears images and adds default buttons', () => {
4488
+ const onCarouselDataChange = jest.fn();
4489
+ renderCarousel({
4490
+ onCarouselDataChange,
4491
+ carouselData: [
4492
+ { mediaType: 'image', imageUrl: 'a.jpg', videoSrc: 'a.mp4', videoPreviewImg: 'a.png', buttons: [button] },
4493
+ { mediaType: 'image', imageUrl: 'b.jpg', videoSrc: '', videoPreviewImg: '' },
4494
+ ],
4495
+ });
4496
+
4497
+ fireEvent.click(screen.getByTestId('radio-video'));
4498
+
4499
+ expect(lastCards(onCarouselDataChange)).toEqual([
4500
+ { mediaType: 'video', imageUrl: '', videoSrc: 'a.mp4', videoPreviewImg: 'a.png', buttons: [button] },
4501
+ {
4502
+ mediaType: 'video',
4503
+ imageUrl: '',
4504
+ videoSrc: '',
4505
+ videoPreviewImg: '',
4506
+ buttons: [{ actionOnClick: false, linkType: DEEP_LINK, deepLinkValue: '', externalLinkValue: '' }],
4507
+ },
4508
+ ]);
4509
+ expect(screen.getAllByTestId('cap-video-upload')).toHaveLength(2);
4510
+ });
4511
+
4512
+ it('switching to image keeps the image and clears the video and its thumbnail', () => {
4513
+ const onCarouselDataChange = jest.fn();
4514
+ renderCarousel({
4515
+ onCarouselDataChange,
4516
+ carouselData: [{ mediaType: 'video', imageUrl: 'a.jpg', videoSrc: 'a.mp4', videoPreviewImg: 'a.png', buttons: [button] }],
4517
+ });
4518
+
4519
+ fireEvent.click(screen.getByTestId('radio-image'));
4520
+
4521
+ expect(lastCards(onCarouselDataChange)).toEqual([
4522
+ { mediaType: 'image', imageUrl: 'a.jpg', videoSrc: '', videoPreviewImg: '', buttons: [button] },
4523
+ ]);
4524
+ expect(screen.getByTestId('cap-image-upload')).toBeInTheDocument();
4525
+ });
4526
+
4527
+ it('re upload on card 2 clears it, and the file picked through card 1\'s input lands on card 2', () => {
4528
+ const onCarouselDataChange = jest.fn();
4529
+ const uploadMpushAsset = jest.fn();
4530
+ const carouselData = [videoCard('a.mp4'), videoCard('b.mp4')];
4531
+ const { rerenderWith } = renderCarousel({ onCarouselDataChange, uploadMpushAsset, carouselData });
4532
+
4533
+ fireEvent.click(screen.getAllByTestId('video-reupload-button')[1]);
4534
+ expect(lastCards(onCarouselDataChange)).toEqual([
4535
+ carouselData[0],
4536
+ { ...carouselData[1], videoSrc: '', videoPreviewImg: '' },
4537
+ ]);
4538
+
4539
+ // Re upload clicks the page's first file input, which belongs to card 1
4540
+ fireEvent.click(screen.getAllByTestId('video-file-upload-button')[0]);
4541
+ expect(uploadMpushAsset).toHaveBeenCalledWith({ name: 'test.mp4' }, 'video', {}, 0);
4542
+
4543
+ onCarouselDataChange.mockClear();
4544
+ rerenderWith({ imageData: uploaded({ secure_file_path: 'c.mp4', file_name: 'c.mp4', video_file_path_preview: 'c.png' }) });
4545
+
4546
+ expect(lastCards(onCarouselDataChange)).toEqual([
4547
+ carouselData[0],
4548
+ { ...carouselData[1], videoSrc: 'c.mp4', videoPreviewImg: 'c.png' },
4549
+ ]);
4550
+ });
4551
+
4552
+ it.each([
4553
+ ['the video preview', { video_file_path_preview: 'p.png', preview_image_url: 'i.png' }, 'p.png'],
4554
+ ['the preview image when there is no video preview', { preview_image_url: 'i.png' }, 'i.png'],
4555
+ ['no thumbnail when neither is sent', {}, ''],
4556
+ ])('an uploaded video card gets %s', (_label, previews, expectedThumb) => {
4557
+ const onCarouselDataChange = jest.fn();
4558
+ const carouselData = [videoCard('')];
4559
+ const { rerenderWith } = renderCarousel({ onCarouselDataChange, carouselData });
4560
+
4561
+ fireEvent.click(screen.getByTestId('video-file-upload-button'));
4562
+ onCarouselDataChange.mockClear();
4563
+ rerenderWith({ imageData: uploaded({ secure_file_path: 'v.mp4', ...previews }) });
4564
+
4565
+ expect(lastCards(onCarouselDataChange)).toEqual([
4566
+ { ...carouselData[0], videoSrc: 'v.mp4', videoPreviewImg: expectedThumb },
4567
+ ]);
4568
+ });
4569
+
4570
+ it('a new upload does not reapply the previous upload\'s result', () => {
4571
+ const onCarouselDataChange = jest.fn();
4572
+ const imageData = uploaded({ secure_file_path: 'v.mp4', file_name: 'v.mp4' });
4573
+ const { rerenderWith } = renderCarousel({ onCarouselDataChange, carouselData: [videoCard('')] });
4574
+
4575
+ fireEvent.click(screen.getByTestId('video-file-upload-button'));
4576
+ rerenderWith({ imageData });
4577
+ expect(onCarouselDataChange).toHaveBeenCalled();
4578
+
4579
+ onCarouselDataChange.mockClear();
4580
+ fireEvent.click(screen.getByTestId('video-file-upload-button'));
4581
+
4582
+ expect(onCarouselDataChange).not.toHaveBeenCalled();
4583
+ });
4584
+ });
4224
4585
  });