@capillarytech/creatives-library 9.1.7 → 9.1.8-alpha.sprint-cap-214249.39

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
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 +50 -33
  5. package/utils/tests/createMobilePushPayload.test.js +113 -8
  6. package/v2Components/CapMpushCTA/index.js +10 -9
  7. package/v2Components/CapMpushCTA/index.scss +29 -3
  8. package/v2Components/CapMpushCTA/tests/index.test.js +89 -0
  9. package/v2Components/CommonTestAndPreview/UnifiedPreview/MobilePushPreviewContent.js +20 -12
  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 +81 -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 +24 -16
  17. package/v2Components/TemplatePreview/tests/index.test.js +68 -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 +297 -216
  23. package/v2Containers/MobilePushNew/components/PlatformContentFields.js +158 -125
  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 +464 -108
  27. package/v2Containers/MobilePushNew/components/tests/PlatformContentFields.test.js +106 -35
  28. package/v2Containers/MobilePushNew/constants.js +5 -0
  29. package/v2Containers/MobilePushNew/hooks/tests/usePlatformSync.test.js +63 -1
  30. package/v2Containers/MobilePushNew/hooks/tests/useUpload.test.js +52 -0
  31. package/v2Containers/MobilePushNew/hooks/usePlatformSync.js +40 -1
  32. package/v2Containers/MobilePushNew/hooks/useUpload.js +29 -39
  33. package/v2Containers/MobilePushNew/index.js +487 -235
  34. package/v2Containers/MobilePushNew/index.scss +205 -4
  35. package/v2Containers/MobilePushNew/messages.js +106 -6
  36. package/v2Containers/MobilePushNew/tests/index.test.js +469 -1
  37. package/v2Containers/MobilePushNew/tests/utils.test.js +70 -0
  38. package/v2Containers/MobilePushNew/utils.js +56 -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,7 +2618,7 @@ 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
2624
  deepLinkKeys: ['key1', 'key2'],
@@ -2434,7 +2670,7 @@ describe('MediaUploaders', () => {
2434
2670
  mediaType: 'image',
2435
2671
  imageUrl: 'test-image.jpg',
2436
2672
  buttons: [{
2437
- actionOnClick: true,
2673
+ actionOnClick: true, isSaved: false,
2438
2674
  linkType: 'DEEP_LINK',
2439
2675
  deepLinkValue: 'test-deep-link',
2440
2676
  deepLinkKeys: ['single-key'],
@@ -2486,7 +2722,7 @@ describe('MediaUploaders', () => {
2486
2722
  mediaType: 'image',
2487
2723
  imageUrl: 'test-image.jpg',
2488
2724
  buttons: [{
2489
- actionOnClick: true,
2725
+ actionOnClick: true, isSaved: false,
2490
2726
  linkType: 'DEEP_LINK',
2491
2727
  deepLinkValue: 'test-deep-link',
2492
2728
  deepLinkKeys: ['existing-key1', 'existing-key2'],
@@ -2538,7 +2774,7 @@ describe('MediaUploaders', () => {
2538
2774
  mediaType: 'image',
2539
2775
  imageUrl: 'test-image.jpg',
2540
2776
  buttons: [{
2541
- actionOnClick: true,
2777
+ actionOnClick: true, isSaved: false,
2542
2778
  linkType: 'DEEP_LINK',
2543
2779
  deepLinkValue: 'test-deep-link',
2544
2780
  deepLinkKeys: [],
@@ -2589,7 +2825,7 @@ describe('MediaUploaders', () => {
2589
2825
  mediaType: 'image',
2590
2826
  imageUrl: 'test-image.jpg',
2591
2827
  buttons: [{
2592
- actionOnClick: true,
2828
+ actionOnClick: true, isSaved: false,
2593
2829
  linkType: 'DEEP_LINK',
2594
2830
  deepLinkValue: 'test-deep-link',
2595
2831
  deepLinkKeys: 'string-key-value',
@@ -2640,7 +2876,7 @@ describe('MediaUploaders', () => {
2640
2876
  mediaType: 'image',
2641
2877
  imageUrl: 'test-image.jpg',
2642
2878
  buttons: [{
2643
- actionOnClick: true,
2879
+ actionOnClick: true, isSaved: false,
2644
2880
  linkType: 'DEEP_LINK',
2645
2881
  deepLinkValue: 'test-deep-link',
2646
2882
  deepLinkKeys: undefined,
@@ -2692,7 +2928,7 @@ describe('MediaUploaders', () => {
2692
2928
  mediaType: 'image',
2693
2929
  imageUrl: 'test-image.jpg',
2694
2930
  buttons: [{
2695
- actionOnClick: true,
2931
+ actionOnClick: true, isSaved: false,
2696
2932
  linkType: 'DEEP_LINK',
2697
2933
  deepLinkValue: 'test-deep-link',
2698
2934
  deepLinkKeys: [],
@@ -2957,7 +3193,7 @@ describe('MediaUploaders', () => {
2957
3193
  mediaType: 'image',
2958
3194
  imageUrl: 'test.jpg',
2959
3195
  buttons: [{
2960
- actionOnClick: true,
3196
+ actionOnClick: true, isSaved: false,
2961
3197
  linkType: 'DEEP_LINK',
2962
3198
  deepLinkValue: 'test-deep-link',
2963
3199
  deepLinkKeys: ['key1', 'key2'],
@@ -3022,7 +3258,7 @@ describe('MediaUploaders', () => {
3022
3258
  mediaType: 'image',
3023
3259
  imageUrl: 'test.jpg',
3024
3260
  buttons: [{
3025
- actionOnClick: true,
3261
+ actionOnClick: true, isSaved: false,
3026
3262
  linkType: 'DEEP_LINK',
3027
3263
  deepLinkValue: 'test-deep-link',
3028
3264
  deepLinkKeys: ['key1', 'key2'],
@@ -3232,7 +3468,7 @@ describe('MediaUploaders', () => {
3232
3468
  mediaType: 'image',
3233
3469
  imageUrl: 'test.jpg',
3234
3470
  buttons: [{
3235
- actionOnClick: true,
3471
+ actionOnClick: true, isSaved: false,
3236
3472
  linkType: 'DEEP_LINK',
3237
3473
  deepLinkValue: 'test-deep-link',
3238
3474
  deepLinkKeys: [],
@@ -3297,7 +3533,7 @@ describe('MediaUploaders', () => {
3297
3533
  mediaType: 'image',
3298
3534
  imageUrl: 'test.jpg',
3299
3535
  buttons: [{
3300
- actionOnClick: true,
3536
+ actionOnClick: true, isSaved: false,
3301
3537
  linkType: 'DEEP_LINK',
3302
3538
  deepLinkValue: 'test-deep-link',
3303
3539
  deepLinkKeys: ['key1'],
@@ -3352,7 +3588,7 @@ describe('MediaUploaders', () => {
3352
3588
  mediaType: 'image',
3353
3589
  imageUrl: 'test.jpg',
3354
3590
  buttons: [{
3355
- actionOnClick: true,
3591
+ actionOnClick: true, isSaved: false,
3356
3592
  linkType: 'DEEP_LINK',
3357
3593
  deepLinkValue: '',
3358
3594
  externalLinkValue: '',
@@ -3379,7 +3615,7 @@ describe('MediaUploaders', () => {
3379
3615
  mediaType: 'image',
3380
3616
  imageUrl: 'test.jpg',
3381
3617
  buttons: [{
3382
- actionOnClick: true,
3618
+ actionOnClick: true, isSaved: false,
3383
3619
  linkType: 'DEEP_LINK',
3384
3620
  deepLinkValue: '',
3385
3621
  externalLinkValue: '',
@@ -3407,7 +3643,7 @@ describe('MediaUploaders', () => {
3407
3643
  mediaType: 'image',
3408
3644
  imageUrl: 'test-image.jpg',
3409
3645
  buttons: [{
3410
- actionOnClick: true,
3646
+ actionOnClick: true, isSaved: false,
3411
3647
  linkType: 'DEEP_LINK',
3412
3648
  deepLinkValue: 'myapp://page?param1=value1', // Has query parameters
3413
3649
  deepLinkKeys: ['param1'],
@@ -3460,7 +3696,7 @@ describe('MediaUploaders', () => {
3460
3696
  mediaType: 'image',
3461
3697
  imageUrl: 'test-image.jpg',
3462
3698
  buttons: [{
3463
- actionOnClick: true,
3699
+ actionOnClick: true, isSaved: false,
3464
3700
  linkType: 'DEEP_LINK',
3465
3701
  deepLinkValue: 'myapp://home?userId=123&sessionId=abc', // Has query parameters
3466
3702
  deepLinkKeys: ['userId', 'sessionId'],
@@ -3513,7 +3749,7 @@ describe('MediaUploaders', () => {
3513
3749
  mediaType: 'image',
3514
3750
  imageUrl: 'test-image.jpg',
3515
3751
  buttons: [{
3516
- actionOnClick: true,
3752
+ actionOnClick: true, isSaved: false,
3517
3753
  linkType: 'DEEP_LINK',
3518
3754
  deepLinkValue: 'testapp://screen?itemId=456', // Has query parameters
3519
3755
  deepLinkKeys: [],
@@ -3566,7 +3802,7 @@ describe('MediaUploaders', () => {
3566
3802
  mediaType: 'image',
3567
3803
  imageUrl: 'test-image.jpg',
3568
3804
  buttons: [{
3569
- actionOnClick: true,
3805
+ actionOnClick: true, isSaved: false,
3570
3806
  linkType: 'DEEP_LINK',
3571
3807
  deepLinkValue: 'myapp://nomatch?param1=value1', // Base doesn't match any deepLink
3572
3808
  deepLinkKeys: [],
@@ -4184,7 +4420,7 @@ describe('MediaUploaders', () => {
4184
4420
  mediaType: 'image',
4185
4421
  imageUrl: 'test.jpg',
4186
4422
  buttons: [{
4187
- actionOnClick: true,
4423
+ actionOnClick: true, isSaved: false,
4188
4424
  linkType: 'EXTERNAL_LINK',
4189
4425
  deepLinkValue: '',
4190
4426
  deepLinkKeys: [],
@@ -4221,4 +4457,124 @@ describe('MediaUploaders', () => {
4221
4457
  );
4222
4458
  });
4223
4459
  });
4460
+
4461
+ describe('Carousel media switch and video uploads', () => {
4462
+ const button = { actionOnClick: false, linkType: DEEP_LINK, deepLinkValue: '', externalLinkValue: '' };
4463
+ const videoCard = (src) => ({
4464
+ mediaType: 'video', imageUrl: '', videoSrc: src, videoPreviewImg: src ? `${src}.png` : '', buttons: [button],
4465
+ });
4466
+ const uploaded = (metaInfo) => ({ uploadedAssetData0: { metaInfo } });
4467
+ const lastCards = (fn) => fn.mock.calls[fn.mock.calls.length - 1][1];
4468
+
4469
+ const renderCarousel = (props) => {
4470
+ const allProps = { ...defaultProps, mediaType: 'CAROUSEL', activeTab: ANDROID, ...props };
4471
+ const ui = (extra = {}) => (
4472
+ <Provider store={mockStore}>
4473
+ <IntlProvider messages={messages} locale="en">
4474
+ <MediaUploaders {...allProps} {...extra} />
4475
+ </IntlProvider>
4476
+ </Provider>
4477
+ );
4478
+ const utils = render(ui());
4479
+ return { ...utils, rerenderWith: (extra) => utils.rerender(ui(extra)) };
4480
+ };
4481
+
4482
+ it('switching to video keeps video fields, clears images and adds default buttons', () => {
4483
+ const onCarouselDataChange = jest.fn();
4484
+ renderCarousel({
4485
+ onCarouselDataChange,
4486
+ carouselData: [
4487
+ { mediaType: 'image', imageUrl: 'a.jpg', videoSrc: 'a.mp4', videoPreviewImg: 'a.png', buttons: [button] },
4488
+ { mediaType: 'image', imageUrl: 'b.jpg', videoSrc: '', videoPreviewImg: '' },
4489
+ ],
4490
+ });
4491
+
4492
+ fireEvent.click(screen.getByTestId('radio-video'));
4493
+
4494
+ expect(lastCards(onCarouselDataChange)).toEqual([
4495
+ { mediaType: 'video', imageUrl: '', videoSrc: 'a.mp4', videoPreviewImg: 'a.png', buttons: [button] },
4496
+ {
4497
+ mediaType: 'video',
4498
+ imageUrl: '',
4499
+ videoSrc: '',
4500
+ videoPreviewImg: '',
4501
+ buttons: [{ actionOnClick: false, linkType: DEEP_LINK, deepLinkValue: '', externalLinkValue: '' }],
4502
+ },
4503
+ ]);
4504
+ expect(screen.getAllByTestId('cap-video-upload')).toHaveLength(2);
4505
+ });
4506
+
4507
+ it('switching to image keeps the image and clears the video and its thumbnail', () => {
4508
+ const onCarouselDataChange = jest.fn();
4509
+ renderCarousel({
4510
+ onCarouselDataChange,
4511
+ carouselData: [{ mediaType: 'video', imageUrl: 'a.jpg', videoSrc: 'a.mp4', videoPreviewImg: 'a.png', buttons: [button] }],
4512
+ });
4513
+
4514
+ fireEvent.click(screen.getByTestId('radio-image'));
4515
+
4516
+ expect(lastCards(onCarouselDataChange)).toEqual([
4517
+ { mediaType: 'image', imageUrl: 'a.jpg', videoSrc: '', videoPreviewImg: '', buttons: [button] },
4518
+ ]);
4519
+ expect(screen.getByTestId('cap-image-upload')).toBeInTheDocument();
4520
+ });
4521
+
4522
+ it('re upload on card 2 clears it, and the file picked through card 1\'s input lands on card 2', () => {
4523
+ const onCarouselDataChange = jest.fn();
4524
+ const uploadMpushAsset = jest.fn();
4525
+ const carouselData = [videoCard('a.mp4'), videoCard('b.mp4')];
4526
+ const { rerenderWith } = renderCarousel({ onCarouselDataChange, uploadMpushAsset, carouselData });
4527
+
4528
+ fireEvent.click(screen.getAllByTestId('video-reupload-button')[1]);
4529
+ expect(lastCards(onCarouselDataChange)).toEqual([
4530
+ carouselData[0],
4531
+ { ...carouselData[1], videoSrc: '', videoPreviewImg: '' },
4532
+ ]);
4533
+
4534
+ // Re upload clicks the page's first file input, which belongs to card 1
4535
+ fireEvent.click(screen.getAllByTestId('video-file-upload-button')[0]);
4536
+ expect(uploadMpushAsset).toHaveBeenCalledWith({ name: 'test.mp4' }, 'video', {}, 0);
4537
+
4538
+ onCarouselDataChange.mockClear();
4539
+ rerenderWith({ imageData: uploaded({ secure_file_path: 'c.mp4', file_name: 'c.mp4', video_file_path_preview: 'c.png' }) });
4540
+
4541
+ expect(lastCards(onCarouselDataChange)).toEqual([
4542
+ carouselData[0],
4543
+ { ...carouselData[1], videoSrc: 'c.mp4', videoPreviewImg: 'c.png' },
4544
+ ]);
4545
+ });
4546
+
4547
+ it.each([
4548
+ ['the video preview', { video_file_path_preview: 'p.png', preview_image_url: 'i.png' }, 'p.png'],
4549
+ ['the preview image when there is no video preview', { preview_image_url: 'i.png' }, 'i.png'],
4550
+ ['no thumbnail when neither is sent', {}, ''],
4551
+ ])('an uploaded video card gets %s', (_label, previews, expectedThumb) => {
4552
+ const onCarouselDataChange = jest.fn();
4553
+ const carouselData = [videoCard('')];
4554
+ const { rerenderWith } = renderCarousel({ onCarouselDataChange, carouselData });
4555
+
4556
+ fireEvent.click(screen.getByTestId('video-file-upload-button'));
4557
+ onCarouselDataChange.mockClear();
4558
+ rerenderWith({ imageData: uploaded({ secure_file_path: 'v.mp4', ...previews }) });
4559
+
4560
+ expect(lastCards(onCarouselDataChange)).toEqual([
4561
+ { ...carouselData[0], videoSrc: 'v.mp4', videoPreviewImg: expectedThumb },
4562
+ ]);
4563
+ });
4564
+
4565
+ it('a new upload does not reapply the previous upload\'s result', () => {
4566
+ const onCarouselDataChange = jest.fn();
4567
+ const imageData = uploaded({ secure_file_path: 'v.mp4', file_name: 'v.mp4' });
4568
+ const { rerenderWith } = renderCarousel({ onCarouselDataChange, carouselData: [videoCard('')] });
4569
+
4570
+ fireEvent.click(screen.getByTestId('video-file-upload-button'));
4571
+ rerenderWith({ imageData });
4572
+ expect(onCarouselDataChange).toHaveBeenCalled();
4573
+
4574
+ onCarouselDataChange.mockClear();
4575
+ fireEvent.click(screen.getByTestId('video-file-upload-button'));
4576
+
4577
+ expect(onCarouselDataChange).not.toHaveBeenCalled();
4578
+ });
4579
+ });
4224
4580
  });