@capillarytech/creatives-library 9.2.1-alpha.sprint-cap-214249.42 → 9.2.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/AppRoot.js +4 -7
- package/constants/unified.js +1 -0
- package/package.json +1 -1
- package/utils/beePluginLoader.js +106 -0
- package/utils/common.js +6 -0
- package/utils/createMobilePushPayload.js +51 -56
- package/utils/tests/beePluginLoader.test.js +199 -0
- package/utils/tests/createMobilePushPayload.test.js +10 -162
- package/v2Components/CapMpushCTA/index.js +57 -47
- package/v2Components/CapMpushCTA/index.scss +5 -43
- package/v2Components/CommonTestAndPreview/UnifiedPreview/MobilePushPreviewContent.js +8 -11
- package/v2Components/CommonTestAndPreview/UnifiedPreview/_unifiedPreview.scss +1 -13
- package/v2Components/CommonTestAndPreview/constants.js +0 -2
- package/v2Components/CommonTestAndPreview/index.js +10 -48
- package/v2Components/CommonTestAndPreview/tests/UnifiedPreview/MobilePushPreviewContent.test.js +5 -83
- package/v2Components/CommonTestAndPreview/tests/index.test.js +0 -86
- package/v2Components/TemplatePreview/_templatePreview.scss +2 -12
- package/v2Components/TemplatePreview/index.js +12 -14
- package/v2Components/TemplatePreview/tests/index.test.js +0 -69
- package/v2Containers/BeeEditor/index.js +49 -22
- package/v2Containers/BeeEditor/index.scss +12 -0
- package/v2Containers/BeeEditor/messages.js +8 -0
- package/v2Containers/BeeEditor/test/index.test.js +78 -0
- package/v2Containers/BeePopupEditor/index.js +22 -11
- package/v2Containers/CreativesContainer/SlideBoxContent.js +9 -5
- package/v2Containers/CreativesContainer/index.js +1 -2
- package/v2Containers/CreativesContainer/tests/SlideBoxContent.test.js +0 -43
- package/v2Containers/Email/index.js +2 -2
- package/v2Containers/EmailWrapper/hooks/useEmailWrapper.js +25 -23
- package/v2Containers/MobilePushNew/components/CtaButtons.js +47 -52
- package/v2Containers/MobilePushNew/components/MediaUploaders.js +222 -314
- package/v2Containers/MobilePushNew/components/PlatformContentFields.js +130 -161
- package/v2Containers/MobilePushNew/components/tests/CtaButtons.test.js +208 -30
- package/v2Containers/MobilePushNew/components/tests/MediaUploaders.test.js +123 -484
- package/v2Containers/MobilePushNew/components/tests/PlatformContentFields.test.js +46 -152
- package/v2Containers/MobilePushNew/constants.js +0 -12
- package/v2Containers/MobilePushNew/hooks/tests/usePlatformSync.test.js +1 -63
- package/v2Containers/MobilePushNew/hooks/tests/useUpload.test.js +0 -78
- package/v2Containers/MobilePushNew/hooks/usePlatformSync.js +1 -40
- package/v2Containers/MobilePushNew/hooks/useUpload.js +46 -42
- package/v2Containers/MobilePushNew/index.js +273 -503
- package/v2Containers/MobilePushNew/index.scss +4 -215
- package/v2Containers/MobilePushNew/messages.js +6 -106
- package/v2Containers/MobilePushNew/tests/index.test.js +1 -482
- package/v2Containers/MobilePushNew/tests/utils.test.js +0 -122
- package/v2Containers/MobilePushNew/utils.js +0 -107
- package/v2Containers/Templates/_templates.scss +2 -10
- package/v2Containers/Templates/index.js +81 -83
- package/v2Containers/Templates/tests/index.test.js +0 -68
- package/v2Components/CapMpushCTA/tests/index.test.js +0 -150
- package/v2Containers/MobilePushNew/components/TapLinkActions.js +0 -76
|
@@ -75,8 +75,6 @@ import {
|
|
|
75
75
|
CTA_TYPE_EXTERNAL_URL,
|
|
76
76
|
STYLE_TYPE_BIG_PICTURE,
|
|
77
77
|
STYLE_TYPE_BIG_TEXT,
|
|
78
|
-
STYLE_TYPE_VIDEO,
|
|
79
|
-
STYLE_TYPE_MANUAL_CAROUSEL,
|
|
80
78
|
DEVICE_TYPE_ANDROID,
|
|
81
79
|
DEVICE_TYPE_IOS,
|
|
82
80
|
BUTTON_TYPE_NONE,
|
|
@@ -1886,10 +1884,6 @@ const CommonTestAndPreview = (props) => {
|
|
|
1886
1884
|
'message-title': formDataObj.androidContent.header || '',
|
|
1887
1885
|
'message-editor': formDataObj.androidContent.bodyText || '',
|
|
1888
1886
|
'image': formDataObj.androidContent.bodyImage || '',
|
|
1889
|
-
// bodyVideo also carries GIFs; send only real videos
|
|
1890
|
-
'video': formDataObj.androidContent.bodyGif ? '' : (formDataObj.androidContent.bodyVideo?.videoSrc || ''),
|
|
1891
|
-
// Saved cards, already in the shape Save sent
|
|
1892
|
-
carouselData: formDataObj.androidContent.carouselData || [],
|
|
1893
1887
|
// Extract CTA info from actions if available
|
|
1894
1888
|
...(formDataObj.androidContent.actions?.[0] && {
|
|
1895
1889
|
'cta-deeplink-label': formDataObj.androidContent.actions[0].label,
|
|
@@ -1908,8 +1902,6 @@ const CommonTestAndPreview = (props) => {
|
|
|
1908
1902
|
'message-title2': formDataObj.iosContent.header || '',
|
|
1909
1903
|
'message-editor2': formDataObj.iosContent.bodyText || '',
|
|
1910
1904
|
'image': formDataObj.iosContent.bodyImage || '',
|
|
1911
|
-
'video': formDataObj.iosContent.bodyGif ? '' : (formDataObj.iosContent.bodyVideo?.videoSrc || ''),
|
|
1912
|
-
carouselData: formDataObj.iosContent.carouselData || [],
|
|
1913
1905
|
// Extract CTA info from actions if available
|
|
1914
1906
|
...(formDataObj.iosContent.actions?.[0] && {
|
|
1915
1907
|
'cta-deeplink2-label': formDataObj.iosContent.actions[0].label,
|
|
@@ -2015,36 +2007,11 @@ const CommonTestAndPreview = (props) => {
|
|
|
2015
2007
|
};
|
|
2016
2008
|
};
|
|
2017
2009
|
|
|
2018
|
-
const hasCarousel = (data) => Array.isArray(data.carouselData) && data.carouselData.length > 0;
|
|
2019
|
-
// Carousel, then video, then image; BIG_TEXT when none
|
|
2020
|
-
const getMpushStyle = (data) => {
|
|
2021
|
-
if (hasCarousel(data)) return STYLE_TYPE_MANUAL_CAROUSEL;
|
|
2022
|
-
if (data.video) return STYLE_TYPE_VIDEO;
|
|
2023
|
-
return data.image ? STYLE_TYPE_BIG_PICTURE : STYLE_TYPE_BIG_TEXT;
|
|
2024
|
-
};
|
|
2025
|
-
const getMpushType = (data) => {
|
|
2026
|
-
if (hasCarousel(data)) return MEDIA_TYPE_CAROUSEL;
|
|
2027
|
-
if (data.video) return MEDIA_TYPE_VIDEO;
|
|
2028
|
-
return data.image ? MEDIA_TYPE_IMAGE : MEDIA_TYPE_TEXT;
|
|
2029
|
-
};
|
|
2030
|
-
// Raw URL, as Save sends it (the CDN helper is an image transform)
|
|
2031
|
-
const toMpushVideoMedia = (url) => [{ url, text: '', type: MEDIA_TYPE_VIDEO }];
|
|
2032
|
-
// Cards plus the spec's media list, as CreativesContainer getMobilePushCarouselData sends to campaigns
|
|
2033
|
-
const addMpushCarousel = (expandableDetails, data) => {
|
|
2034
|
-
Object.assign(expandableDetails, {
|
|
2035
|
-
carouselData: data.carouselData,
|
|
2036
|
-
media: data.carouselData.map((card) => ({
|
|
2037
|
-
url: card?.mediaType?.toUpperCase() === MEDIA_TYPE_VIDEO ? card.videoSrc : card.imageUrl,
|
|
2038
|
-
type: card?.mediaType?.toUpperCase(),
|
|
2039
|
-
text: '',
|
|
2040
|
-
})),
|
|
2041
|
-
});
|
|
2042
|
-
};
|
|
2043
|
-
|
|
2044
2010
|
// Helper function to build expandableDetails for Android
|
|
2045
2011
|
const buildAndroidExpandableDetails = (data) => {
|
|
2012
|
+
// Default style is BIG_TEXT, change to BIG_PICTURE if image exists
|
|
2046
2013
|
const imageLink = data.image;
|
|
2047
|
-
const style =
|
|
2014
|
+
const style = imageLink ? STYLE_TYPE_BIG_PICTURE : STYLE_TYPE_BIG_TEXT;
|
|
2048
2015
|
|
|
2049
2016
|
const expandableDetails = {
|
|
2050
2017
|
style,
|
|
@@ -2053,11 +2020,7 @@ const CommonTestAndPreview = (props) => {
|
|
|
2053
2020
|
};
|
|
2054
2021
|
|
|
2055
2022
|
// Add image if present (transform to CDN URL if needed)
|
|
2056
|
-
if (
|
|
2057
|
-
addMpushCarousel(expandableDetails, data);
|
|
2058
|
-
} else if (data.video) {
|
|
2059
|
-
expandableDetails.media = toMpushVideoMedia(data.video);
|
|
2060
|
-
} else if (imageLink) {
|
|
2023
|
+
if (imageLink) {
|
|
2061
2024
|
expandableDetails.image = getCdnUrl({ url: imageLink, channelName: CHANNEL_NAME_MOBILE_PUSH });
|
|
2062
2025
|
}
|
|
2063
2026
|
|
|
@@ -2136,8 +2099,9 @@ const CommonTestAndPreview = (props) => {
|
|
|
2136
2099
|
|
|
2137
2100
|
// Helper function to build expandableDetails for iOS
|
|
2138
2101
|
const buildIosExpandableDetails = (data) => {
|
|
2102
|
+
// Default style is BIG_TEXT, change to BIG_PICTURE if image exists
|
|
2139
2103
|
const imageLinkIos = data.image;
|
|
2140
|
-
const style =
|
|
2104
|
+
const style = imageLinkIos ? STYLE_TYPE_BIG_PICTURE : STYLE_TYPE_BIG_TEXT;
|
|
2141
2105
|
|
|
2142
2106
|
const expandableDetails = {
|
|
2143
2107
|
style,
|
|
@@ -2146,11 +2110,7 @@ const CommonTestAndPreview = (props) => {
|
|
|
2146
2110
|
};
|
|
2147
2111
|
|
|
2148
2112
|
// Add image if present (transform to CDN URL if needed)
|
|
2149
|
-
if (
|
|
2150
|
-
addMpushCarousel(expandableDetails, data);
|
|
2151
|
-
} else if (data.video) {
|
|
2152
|
-
expandableDetails.media = toMpushVideoMedia(data.video);
|
|
2153
|
-
} else if (imageLinkIos) {
|
|
2113
|
+
if (imageLinkIos) {
|
|
2154
2114
|
expandableDetails.image = getCdnUrl({ url: imageLinkIos, channelName: CHANNEL_NAME_MOBILE_PUSH });
|
|
2155
2115
|
}
|
|
2156
2116
|
|
|
@@ -2227,7 +2187,8 @@ const CommonTestAndPreview = (props) => {
|
|
|
2227
2187
|
const androidExpandableDetails = buildAndroidExpandableDetails(androidData);
|
|
2228
2188
|
const androidCustomProperties = buildCustomProperties(androidData);
|
|
2229
2189
|
|
|
2230
|
-
|
|
2190
|
+
// Determine type based on image presence
|
|
2191
|
+
const androidType = androidData.image ? MEDIA_TYPE_IMAGE : MEDIA_TYPE_TEXT;
|
|
2231
2192
|
|
|
2232
2193
|
const androidContent = {
|
|
2233
2194
|
type: androidType,
|
|
@@ -2246,7 +2207,8 @@ const CommonTestAndPreview = (props) => {
|
|
|
2246
2207
|
const iosExpandableDetails = buildIosExpandableDetails(iosData);
|
|
2247
2208
|
const iosCustomProperties = buildCustomProperties(iosData);
|
|
2248
2209
|
|
|
2249
|
-
|
|
2210
|
+
// Determine type based on image presence
|
|
2211
|
+
const iosType = iosData.image ? MEDIA_TYPE_IMAGE : MEDIA_TYPE_TEXT;
|
|
2250
2212
|
|
|
2251
2213
|
const iosContent = {
|
|
2252
2214
|
type: iosType,
|
package/v2Components/CommonTestAndPreview/tests/UnifiedPreview/MobilePushPreviewContent.test.js
CHANGED
|
@@ -279,8 +279,8 @@ describe('MobilePushPreviewContent', () => {
|
|
|
279
279
|
</TestWrapper>
|
|
280
280
|
);
|
|
281
281
|
|
|
282
|
-
expect(screen.getByText('
|
|
283
|
-
expect(screen.getByText('
|
|
282
|
+
expect(screen.getByText('ACTION 1')).toBeTruthy();
|
|
283
|
+
expect(screen.getByText('ACTION 2')).toBeTruthy();
|
|
284
284
|
});
|
|
285
285
|
|
|
286
286
|
it('should use actionText as fallback for label', () => {
|
|
@@ -304,7 +304,7 @@ describe('MobilePushPreviewContent', () => {
|
|
|
304
304
|
</TestWrapper>
|
|
305
305
|
);
|
|
306
306
|
|
|
307
|
-
expect(screen.getByText('
|
|
307
|
+
expect(screen.getByText('ACTION TEXT')).toBeTruthy();
|
|
308
308
|
});
|
|
309
309
|
|
|
310
310
|
it('should not render actions when carouselData is present', () => {
|
|
@@ -330,7 +330,7 @@ describe('MobilePushPreviewContent', () => {
|
|
|
330
330
|
</TestWrapper>
|
|
331
331
|
);
|
|
332
332
|
|
|
333
|
-
expect(screen.queryByText('
|
|
333
|
+
expect(screen.queryByText('ACTION 1')).toBeNull();
|
|
334
334
|
});
|
|
335
335
|
|
|
336
336
|
it('should filter out actions without label or actionText', () => {
|
|
@@ -354,7 +354,7 @@ describe('MobilePushPreviewContent', () => {
|
|
|
354
354
|
<ComponentToRender {...props} />
|
|
355
355
|
</TestWrapper>
|
|
356
356
|
);
|
|
357
|
-
expect(screen.getByText('
|
|
357
|
+
expect(screen.getByText('ACTION 1')).toBeTruthy();
|
|
358
358
|
});
|
|
359
359
|
});
|
|
360
360
|
|
|
@@ -368,13 +368,11 @@ describe('MobilePushPreviewContent', () => {
|
|
|
368
368
|
bodyText: 'Body',
|
|
369
369
|
carouselData: [
|
|
370
370
|
{
|
|
371
|
-
mediaType: 'IMAGE',
|
|
372
371
|
title: 'Carousel Item 1',
|
|
373
372
|
message: 'Message 1',
|
|
374
373
|
imageUrl: 'https://image1.url',
|
|
375
374
|
},
|
|
376
375
|
{
|
|
377
|
-
mediaType: 'IMAGE',
|
|
378
376
|
title: 'Carousel Item 2',
|
|
379
377
|
message: 'Message 2',
|
|
380
378
|
imageUrl: 'https://image2.url',
|
|
@@ -394,78 +392,6 @@ describe('MobilePushPreviewContent', () => {
|
|
|
394
392
|
expect(screen.getByText('Carousel Item 2')).toBeTruthy();
|
|
395
393
|
});
|
|
396
394
|
|
|
397
|
-
it('should render every card, with or without media, in a horizontal row', () => {
|
|
398
|
-
const props = {
|
|
399
|
-
...defaultProps,
|
|
400
|
-
content: {
|
|
401
|
-
androidContent: {
|
|
402
|
-
header: 'Header',
|
|
403
|
-
carouselData: [
|
|
404
|
-
{ mediaType: 'IMAGE', imageUrl: 'https://a.url', title: 'Card 1' },
|
|
405
|
-
{ mediaType: 'IMAGE', title: 'Empty card' },
|
|
406
|
-
{ mediaType: 'VIDEO', videoPreviewImg: 'https://b.url', title: 'Card 3' },
|
|
407
|
-
],
|
|
408
|
-
},
|
|
409
|
-
},
|
|
410
|
-
};
|
|
411
|
-
|
|
412
|
-
const { container } = render(
|
|
413
|
-
<TestWrapper>
|
|
414
|
-
<ComponentToRender {...props} />
|
|
415
|
-
</TestWrapper>
|
|
416
|
-
);
|
|
417
|
-
|
|
418
|
-
expect(container.querySelectorAll('.mobile-push-carousel-card')).toHaveLength(3);
|
|
419
|
-
expect(screen.getByText('Empty card')).toBeInTheDocument();
|
|
420
|
-
const scrollRow = container.querySelector('.scroll-container');
|
|
421
|
-
expect(scrollRow.className).not.toMatch(/ant-row-legacy|cap-row-vertical/);
|
|
422
|
-
});
|
|
423
|
-
|
|
424
|
-
it('should render a video card with no thumbnail as the video placeholder', () => {
|
|
425
|
-
const props = {
|
|
426
|
-
...defaultProps,
|
|
427
|
-
content: {
|
|
428
|
-
androidContent: {
|
|
429
|
-
header: 'Header',
|
|
430
|
-
carouselData: [{ mediaType: 'video', videoSrc: 'https://v.mp4', title: 'Video card' }],
|
|
431
|
-
},
|
|
432
|
-
},
|
|
433
|
-
};
|
|
434
|
-
|
|
435
|
-
const { container } = render(
|
|
436
|
-
<TestWrapper>
|
|
437
|
-
<ComponentToRender {...props} />
|
|
438
|
-
</TestWrapper>
|
|
439
|
-
);
|
|
440
|
-
|
|
441
|
-
expect(container.querySelectorAll('.mobile-push-carousel-card')).toHaveLength(1);
|
|
442
|
-
expect(container.querySelector('video')).toBeNull();
|
|
443
|
-
// svg imports resolve to the file stub in tests
|
|
444
|
-
expect(container.querySelector('img.carousel-video-preview')).toHaveAttribute('src', 'test-file-stub');
|
|
445
|
-
});
|
|
446
|
-
|
|
447
|
-
it('should render an empty card while no media is uploaded', () => {
|
|
448
|
-
const props = {
|
|
449
|
-
...defaultProps,
|
|
450
|
-
content: {
|
|
451
|
-
androidContent: {
|
|
452
|
-
header: 'Header',
|
|
453
|
-
carouselData: [{ mediaType: 'IMAGE', title: 'Empty card' }],
|
|
454
|
-
},
|
|
455
|
-
},
|
|
456
|
-
};
|
|
457
|
-
|
|
458
|
-
const { container } = render(
|
|
459
|
-
<TestWrapper>
|
|
460
|
-
<ComponentToRender {...props} />
|
|
461
|
-
</TestWrapper>
|
|
462
|
-
);
|
|
463
|
-
|
|
464
|
-
expect(container.querySelector('.mobile-push-carousel-container')).toBeTruthy();
|
|
465
|
-
expect(container.querySelectorAll('.mobile-push-carousel-card')).toHaveLength(1);
|
|
466
|
-
expect(container.querySelector('.carousel-image')).toBeNull();
|
|
467
|
-
});
|
|
468
|
-
|
|
469
395
|
it('should render carousel with image media type', () => {
|
|
470
396
|
const props = {
|
|
471
397
|
...defaultProps,
|
|
@@ -562,8 +488,6 @@ describe('MobilePushPreviewContent', () => {
|
|
|
562
488
|
bodyText: 'Body',
|
|
563
489
|
carouselData: [
|
|
564
490
|
{
|
|
565
|
-
mediaType: 'IMAGE',
|
|
566
|
-
imageUrl: 'https://image.url',
|
|
567
491
|
header: 'Carousel Header',
|
|
568
492
|
message: 'Message',
|
|
569
493
|
},
|
|
@@ -590,8 +514,6 @@ describe('MobilePushPreviewContent', () => {
|
|
|
590
514
|
bodyText: 'Body',
|
|
591
515
|
carouselData: [
|
|
592
516
|
{
|
|
593
|
-
mediaType: 'IMAGE',
|
|
594
|
-
imageUrl: 'https://image.url',
|
|
595
517
|
title: 'Title',
|
|
596
518
|
bodyText: 'Carousel Body',
|
|
597
519
|
},
|
|
@@ -602,92 +602,6 @@ describe('CommonTestAndPreview', () => {
|
|
|
602
602
|
});
|
|
603
603
|
});
|
|
604
604
|
|
|
605
|
-
describe('Mobile push video payload - handleSendTestMessage', () => {
|
|
606
|
-
// resetMocks in the jest config wipes the module mock's implementation before each test
|
|
607
|
-
beforeEach(() => {
|
|
608
|
-
// eslint-disable-next-line global-require
|
|
609
|
-
require('../../../utils/cdnTransformation').getCdnUrl.mockImplementation(({ url }) => `cdn_${url}`);
|
|
610
|
-
});
|
|
611
|
-
|
|
612
|
-
const sendAndGetContent = async (props) => {
|
|
613
|
-
render(
|
|
614
|
-
<TestWrapper>
|
|
615
|
-
<CommonTestAndPreview {...defaultProps} channel={CHANNELS.MOBILEPUSH} {...props} />
|
|
616
|
-
</TestWrapper>
|
|
617
|
-
);
|
|
618
|
-
await waitFor(() => expect(lastSendTestMessageProps).toBeTruthy());
|
|
619
|
-
lastSendTestMessageProps.handleSendTestMessage();
|
|
620
|
-
const [payload] = mockActions.createMessageMetaRequested.mock.calls[0];
|
|
621
|
-
return payload.mpushMessageContent;
|
|
622
|
-
};
|
|
623
|
-
|
|
624
|
-
it('sends a VIDEO style with the raw video url from the edit flow form data', async () => {
|
|
625
|
-
const { androidContent, iosContent } = await sendAndGetContent({
|
|
626
|
-
formData: [
|
|
627
|
-
{ 'message-title': 'T', 'message-editor': 'M', image: 'old.jpg', video: 'https://s3/a.mp4' },
|
|
628
|
-
{ 'message-title2': 'T2', 'message-editor2': 'M2', image: 'ios.jpg', video: '' },
|
|
629
|
-
],
|
|
630
|
-
});
|
|
631
|
-
expect(androidContent.type).toBe('VIDEO');
|
|
632
|
-
expect(androidContent.expandableDetails.style).toBe('VIDEO');
|
|
633
|
-
expect(androidContent.expandableDetails.media).toEqual([{ url: 'https://s3/a.mp4', text: '', type: 'VIDEO' }]);
|
|
634
|
-
expect(androidContent.expandableDetails.image).toBeUndefined();
|
|
635
|
-
expect(iosContent.type).toBe('IMAGE');
|
|
636
|
-
expect(iosContent.expandableDetails.style).toBe('BIG_PICTURE');
|
|
637
|
-
expect(iosContent.expandableDetails.image).toBe('cdn_ios.jpg');
|
|
638
|
-
expect(iosContent.expandableDetails.media).toBeUndefined();
|
|
639
|
-
});
|
|
640
|
-
|
|
641
|
-
it('reads bodyVideo from the list (three-dots) content, but not for a GIF', async () => {
|
|
642
|
-
const { androidContent, iosContent } = await sendAndGetContent({
|
|
643
|
-
formData: undefined,
|
|
644
|
-
content: {
|
|
645
|
-
androidContent: { header: 'T', bodyText: 'M', bodyVideo: { videoSrc: 'https://s3/a.mp4' } },
|
|
646
|
-
iosContent: { header: 'T2', bodyText: 'M2', bodyVideo: { videoSrc: 'https://s3/b.gif' }, bodyGif: 'https://s3/b.gif' },
|
|
647
|
-
},
|
|
648
|
-
});
|
|
649
|
-
expect(androidContent.expandableDetails.media).toEqual([{ url: 'https://s3/a.mp4', text: '', type: 'VIDEO' }]);
|
|
650
|
-
expect(androidContent.type).toBe('VIDEO');
|
|
651
|
-
expect(iosContent.type).toBe('TEXT');
|
|
652
|
-
expect(iosContent.expandableDetails.style).toBe('BIG_TEXT');
|
|
653
|
-
expect(iosContent.expandableDetails.media).toBeUndefined();
|
|
654
|
-
});
|
|
655
|
-
|
|
656
|
-
const imageCard = { mediaType: 'image', imageUrl: 'https://s3/1.png', videoSrc: '', buttons: [] };
|
|
657
|
-
const videoCard = { mediaType: 'video', imageUrl: '', videoSrc: 'https://s3/2.mp4', buttons: [] };
|
|
658
|
-
|
|
659
|
-
it('sends carousel cards and the media list from the edit flow form data', async () => {
|
|
660
|
-
const { androidContent, iosContent } = await sendAndGetContent({
|
|
661
|
-
formData: [
|
|
662
|
-
{ 'message-title': 'T', 'message-editor': 'M', image: '', video: '', carouselData: [imageCard, videoCard] },
|
|
663
|
-
{ 'message-title2': 'T2', 'message-editor2': 'M2', image: '', video: '', carouselData: [] },
|
|
664
|
-
],
|
|
665
|
-
});
|
|
666
|
-
expect(androidContent.type).toBe('CAROUSEL');
|
|
667
|
-
expect(androidContent.expandableDetails.style).toBe('MANUAL_CAROUSEL');
|
|
668
|
-
expect(androidContent.expandableDetails.carouselData).toEqual([imageCard, videoCard]);
|
|
669
|
-
expect(androidContent.expandableDetails.media).toEqual([
|
|
670
|
-
{ url: 'https://s3/1.png', type: 'IMAGE', text: '' },
|
|
671
|
-
{ url: 'https://s3/2.mp4', type: 'VIDEO', text: '' },
|
|
672
|
-
]);
|
|
673
|
-
expect(iosContent.type).toBe('TEXT');
|
|
674
|
-
expect(iosContent.expandableDetails.carouselData).toBeUndefined();
|
|
675
|
-
});
|
|
676
|
-
|
|
677
|
-
it('sends saved carousel cards from the list (three-dots) content', async () => {
|
|
678
|
-
const { iosContent } = await sendAndGetContent({
|
|
679
|
-
formData: undefined,
|
|
680
|
-
content: {
|
|
681
|
-
androidContent: { header: 'T', bodyText: 'M' },
|
|
682
|
-
iosContent: { header: 'T2', bodyText: 'M2', carouselData: [videoCard] },
|
|
683
|
-
},
|
|
684
|
-
});
|
|
685
|
-
expect(iosContent.type).toBe('CAROUSEL');
|
|
686
|
-
expect(iosContent.expandableDetails.style).toBe('MANUAL_CAROUSEL');
|
|
687
|
-
expect(iosContent.expandableDetails.media).toEqual([{ url: 'https://s3/2.mp4', type: 'VIDEO', text: '' }]);
|
|
688
|
-
});
|
|
689
|
-
});
|
|
690
|
-
|
|
691
605
|
describe('Carousel payload (getCarouselMappedData) - handleSendTestMessage', () => {
|
|
692
606
|
it('should map empty carouselData to empty cards when mediaType is CAROUSEL', async () => {
|
|
693
607
|
const props = {
|
|
@@ -745,23 +745,13 @@
|
|
|
745
745
|
justify-content: space-between;
|
|
746
746
|
flex-direction: row;
|
|
747
747
|
gap: $CAP_SPACE_08;
|
|
748
|
-
width: 100%;
|
|
749
|
-
// One button: centred. Two: equal halves, each centred, split by a divider.
|
|
750
748
|
.action{
|
|
751
|
-
flex: 1 1 0;
|
|
752
|
-
min-width: 0;
|
|
753
|
-
text-align: center;
|
|
754
|
-
white-space: nowrap;
|
|
755
|
-
overflow: hidden;
|
|
756
|
-
text-overflow: ellipsis;
|
|
757
749
|
font-size: $FONT_SIZE_S;
|
|
758
750
|
font-weight: 600;
|
|
759
|
-
color:
|
|
751
|
+
color: #1970DA;
|
|
760
752
|
height: 1.25rem;
|
|
753
|
+
text-transform: uppercase;
|
|
761
754
|
cursor: pointer;
|
|
762
|
-
& + .action {
|
|
763
|
-
border-left: 1px solid $CAP_G07;
|
|
764
|
-
}
|
|
765
755
|
&:hover {
|
|
766
756
|
text-decoration: underline;
|
|
767
757
|
}
|
|
@@ -168,15 +168,14 @@ export class TemplatePreview extends React.Component { // eslint-disable-line re
|
|
|
168
168
|
};
|
|
169
169
|
|
|
170
170
|
renderMobilePushCarousel = (content) => {
|
|
171
|
-
// Every card shows, even before its media is uploaded (an empty card keeps its place)
|
|
172
171
|
if (!content?.carouselData || content?.carouselData?.length === 0) {
|
|
173
172
|
return null;
|
|
174
173
|
}
|
|
175
174
|
|
|
176
175
|
return (
|
|
177
176
|
<CapRow type="flex" vertical noWrap className="msg-container-carousel mobile-push-carousel-container">
|
|
178
|
-
<CapRow
|
|
179
|
-
{content
|
|
177
|
+
<CapRow className="scroll-container mobile-push-scroll-container">
|
|
178
|
+
{content?.carouselData?.map((item, idx) => (
|
|
180
179
|
<CapColumn
|
|
181
180
|
key={`carousel-card-${idx}`}
|
|
182
181
|
className="mobile-push-carousel-card message-pop align-left message-pop-carousel"
|
|
@@ -188,11 +187,10 @@ export class TemplatePreview extends React.Component { // eslint-disable-line re
|
|
|
188
187
|
className="carousel-image"
|
|
189
188
|
/>
|
|
190
189
|
)}
|
|
191
|
-
{item?.mediaType?.toLowerCase() === VIDEO &&
|
|
190
|
+
{item?.mediaType?.toLowerCase() === VIDEO && item?.videoPreviewImg && (
|
|
192
191
|
<CapRow className="video-preview">
|
|
193
|
-
{/* No thumbnail from the upload: same placeholder as WhatsApp/RCS */}
|
|
194
192
|
<CapImage
|
|
195
|
-
src={item?.videoPreviewImg ||
|
|
193
|
+
src={item?.videoPreviewImg || item?.url}
|
|
196
194
|
alt="carousel-video-preview"
|
|
197
195
|
className="carousel-video-preview"
|
|
198
196
|
/>
|
|
@@ -909,17 +907,17 @@ export class TemplatePreview extends React.Component { // eslint-disable-line re
|
|
|
909
907
|
)}
|
|
910
908
|
{(content?.actions || []).filter((action) => action?.label)
|
|
911
909
|
.length && content?.carouselData?.length === 0 ? (
|
|
912
|
-
<CapRow
|
|
910
|
+
<CapRow className="actions">
|
|
913
911
|
{_.map(
|
|
914
912
|
content?.actions || [],
|
|
915
|
-
(action
|
|
913
|
+
(action) =>
|
|
916
914
|
!!action?.label && (
|
|
917
915
|
<span
|
|
918
916
|
className="action"
|
|
919
|
-
key={`action-${
|
|
917
|
+
key={`action-${action?.label}`}
|
|
920
918
|
title={action?.url || ''}
|
|
921
919
|
>
|
|
922
|
-
{action?.label}
|
|
920
|
+
{action?.label?.toUpperCase()}
|
|
923
921
|
</span>
|
|
924
922
|
)
|
|
925
923
|
)}
|
|
@@ -973,17 +971,17 @@ export class TemplatePreview extends React.Component { // eslint-disable-line re
|
|
|
973
971
|
)}
|
|
974
972
|
{(content?.actions || []).filter((action) => action?.label)
|
|
975
973
|
.length && content?.carouselData?.length === 0 ? (
|
|
976
|
-
<CapRow
|
|
974
|
+
<CapRow className="actions">
|
|
977
975
|
{_.map(
|
|
978
976
|
content?.actions || [],
|
|
979
|
-
(action
|
|
977
|
+
(action) =>
|
|
980
978
|
!!action?.label && (
|
|
981
979
|
<span
|
|
982
980
|
className="action"
|
|
983
|
-
key={`action-${
|
|
981
|
+
key={`action-${action?.label}`}
|
|
984
982
|
title={action?.url || ''}
|
|
985
983
|
>
|
|
986
|
-
{action?.label}
|
|
984
|
+
{action?.label?.toUpperCase()}
|
|
987
985
|
</span>
|
|
988
986
|
)
|
|
989
987
|
)}
|
|
@@ -73,75 +73,6 @@ describe('Test Templates container', () => {
|
|
|
73
73
|
expect(renderedComponent).toMatchSnapshot();
|
|
74
74
|
});
|
|
75
75
|
|
|
76
|
-
describe('Mobile push action buttons', () => {
|
|
77
|
-
const renderMobilePush = (device, actions) => {
|
|
78
|
-
renderedComponent = shallowWithIntl(
|
|
79
|
-
<TemplatePreview
|
|
80
|
-
channel="MOBILEPUSH"
|
|
81
|
-
device={device}
|
|
82
|
-
content={{ header: 'Title', bodyText: 'Body', actions, carouselData: [] }}
|
|
83
|
-
/>,
|
|
84
|
-
);
|
|
85
|
-
return renderedComponent.find('.actions');
|
|
86
|
-
};
|
|
87
|
-
|
|
88
|
-
it.each(['android', 'ios'])('renders labels as typed on one flex row with index keys (%s)', (device) => {
|
|
89
|
-
const row = renderMobilePush(device, [
|
|
90
|
-
{ label: 'Shop', url: 'https://a.com' },
|
|
91
|
-
{ label: 'Shop' },
|
|
92
|
-
{ label: '' },
|
|
93
|
-
]);
|
|
94
|
-
const buttons = row.find('.action');
|
|
95
|
-
|
|
96
|
-
expect(row.props()).toEqual(expect.objectContaining({ type: 'flex', noWrap: true }));
|
|
97
|
-
expect(buttons).toHaveLength(2);
|
|
98
|
-
expect(buttons.map((button) => button.key())).toEqual(['action-0', 'action-1']);
|
|
99
|
-
expect(buttons.map((button) => button.text())).toEqual(['Shop', 'Shop']);
|
|
100
|
-
expect(buttons.at(0).prop('title')).toBe('https://a.com');
|
|
101
|
-
});
|
|
102
|
-
|
|
103
|
-
const renderCarousel = (device, carouselData) => {
|
|
104
|
-
renderedComponent = shallowWithIntl(
|
|
105
|
-
<TemplatePreview
|
|
106
|
-
channel="MOBILEPUSH"
|
|
107
|
-
device={device}
|
|
108
|
-
content={{ header: 'Title', carouselData }}
|
|
109
|
-
/>,
|
|
110
|
-
);
|
|
111
|
-
};
|
|
112
|
-
|
|
113
|
-
it.each(['android', 'ios'])('shows every card, with or without media, in one horizontal row (%s)', (device) => {
|
|
114
|
-
renderCarousel(device, [
|
|
115
|
-
{ mediaType: 'IMAGE', imageUrl: 'https://a.url' },
|
|
116
|
-
{ mediaType: 'IMAGE' },
|
|
117
|
-
{ mediaType: 'VIDEO', videoPreviewImg: 'https://b.url' },
|
|
118
|
-
]);
|
|
119
|
-
const scrollRow = renderedComponent.find('.scroll-container');
|
|
120
|
-
|
|
121
|
-
expect(scrollRow.props()).toEqual(expect.objectContaining({ type: 'flex', noWrap: true }));
|
|
122
|
-
expect(renderedComponent.find('.mobile-push-carousel-card')).toHaveLength(3);
|
|
123
|
-
});
|
|
124
|
-
|
|
125
|
-
it.each(['android', 'ios'])('shows a video card with no thumbnail as the video placeholder (%s)', (device) => {
|
|
126
|
-
renderCarousel(device, [{ mediaType: 'video', videoSrc: 'https://v.mp4' }]);
|
|
127
|
-
expect(renderedComponent.find('.mobile-push-carousel-card')).toHaveLength(1);
|
|
128
|
-
expect(renderedComponent.find('video')).toHaveLength(0);
|
|
129
|
-
expect(renderedComponent.find('.carousel-video-preview').prop('src')).toBe('test-file-stub');
|
|
130
|
-
});
|
|
131
|
-
|
|
132
|
-
it.each(['android', 'ios'])('shows an empty card while no media is uploaded (%s)', (device) => {
|
|
133
|
-
renderCarousel(device, [{ mediaType: 'IMAGE' }]);
|
|
134
|
-
expect(renderedComponent.find('.mobile-push-carousel-container')).toHaveLength(1);
|
|
135
|
-
expect(renderedComponent.find('.mobile-push-carousel-card')).toHaveLength(1);
|
|
136
|
-
expect(renderedComponent.find('.carousel-image')).toHaveLength(0);
|
|
137
|
-
});
|
|
138
|
-
|
|
139
|
-
it.each(['android', 'ios'])('shows no carousel when there are no cards (%s)', (device) => {
|
|
140
|
-
renderCarousel(device, []);
|
|
141
|
-
expect(renderedComponent.find('.mobile-push-carousel-container')).toHaveLength(0);
|
|
142
|
-
});
|
|
143
|
-
});
|
|
144
|
-
|
|
145
76
|
describe('RCS carousel preview branches', () => {
|
|
146
77
|
const buildRcsContent = (cards) => ({
|
|
147
78
|
rcsPreviewContent: {
|
|
@@ -19,7 +19,10 @@ import CapInput from "@capillarytech/cap-ui-library/CapInput";
|
|
|
19
19
|
import CapSelect from "@capillarytech/cap-ui-library/CapSelect";
|
|
20
20
|
import CapSpin from "@capillarytech/cap-ui-library/CapSpin";
|
|
21
21
|
import CapNotification from "@capillarytech/cap-ui-library/CapNotification";
|
|
22
|
+
import CapError from "@capillarytech/cap-ui-library/CapError";
|
|
23
|
+
import CapColumn from "@capillarytech/cap-ui-library/CapColumn";
|
|
22
24
|
import config from '../../config/app';
|
|
25
|
+
import { destroyBeeInstance, initBeeEditor } from '../../utils/beePluginLoader';
|
|
23
26
|
import makeSelectBEE from './selectors';
|
|
24
27
|
import messages from './messages';
|
|
25
28
|
import * as beeActions from './actions';
|
|
@@ -75,6 +78,9 @@ function BeeEditor(props) {
|
|
|
75
78
|
const [rowMetaInfo, setRowMetaInfo] = useState({});
|
|
76
79
|
const [rowName, setRowName] = useState('');
|
|
77
80
|
const [rowCategory, setRowCategory] = useState('');
|
|
81
|
+
const [isBeePluginLoading, setIsBeePluginLoading] = useState(false);
|
|
82
|
+
const [hasBeePluginLoadError, setHasBeePluginLoadError] = useState(false);
|
|
83
|
+
const [beePluginLoadAttempt, setBeePluginLoadAttempt] = useState(0);
|
|
78
84
|
const beePluginInstanceRef = useRef(null);
|
|
79
85
|
const initializedBeeJsonRef = useRef(null); // Track which beeJson we've initialized for
|
|
80
86
|
const isInitializingRef = useRef(false); // Track if initialization is in progress
|
|
@@ -250,41 +256,48 @@ function BeeEditor(props) {
|
|
|
250
256
|
|
|
251
257
|
// Clean up previous instance if it exists
|
|
252
258
|
if (beePluginInstanceRef.current) {
|
|
253
|
-
|
|
254
|
-
beePluginInstanceRef.current.destroy();
|
|
255
|
-
} catch (e) {
|
|
256
|
-
console.warn('[BeeEditor] useEffect - Error destroying previous BEE plugin:', e);
|
|
257
|
-
}
|
|
259
|
+
destroyBeeInstance(beePluginInstanceRef.current);
|
|
258
260
|
beePluginInstanceRef.current = null;
|
|
259
261
|
}
|
|
260
262
|
|
|
261
|
-
|
|
262
|
-
|
|
263
|
+
let isEffectCancelled = false;
|
|
264
|
+
setHasBeePluginLoadError(false);
|
|
265
|
+
setIsBeePluginLoading(!window.BeePlugin);
|
|
266
|
+
initBeeEditor({
|
|
267
|
+
tokenData: currentTokenData,
|
|
268
|
+
beeConfig,
|
|
269
|
+
getBeeJson: () => beeJson,
|
|
270
|
+
isCancelled: () => isEffectCancelled,
|
|
271
|
+
onPluginLoaded: () => setIsBeePluginLoading(false),
|
|
272
|
+
})
|
|
273
|
+
.then((instance) => {
|
|
274
|
+
if (!instance) {
|
|
275
|
+
return;
|
|
276
|
+
}
|
|
263
277
|
beePluginInstance = instance;
|
|
264
278
|
beePluginInstanceRef.current = instance;
|
|
265
|
-
const parseJson = typeof beeJson === 'string' ? JSON.parse(beeJson) : beeJson;
|
|
266
|
-
beePluginInstance.start(parseJson);
|
|
267
279
|
saveBeeInstance(beePluginInstance);
|
|
268
280
|
// Mark this beeJson as initialized and clear initialization flag
|
|
269
281
|
initializedBeeJsonRef.current = initializationKey;
|
|
270
282
|
isInitializingRef.current = false;
|
|
283
|
+
})
|
|
284
|
+
.catch((error) => {
|
|
285
|
+
if (isEffectCancelled) {
|
|
286
|
+
return;
|
|
287
|
+
}
|
|
288
|
+
console.error('[BeeEditor] Error creating BEE plugin:', error);
|
|
289
|
+
setIsBeePluginLoading(false);
|
|
290
|
+
setHasBeePluginLoadError(true);
|
|
291
|
+
isInitializingRef.current = false;
|
|
271
292
|
});
|
|
272
|
-
} catch (error) {
|
|
273
|
-
// Reset flag on error
|
|
274
|
-
console.error('[BeeEditor] Error creating BEE plugin:', error);
|
|
275
|
-
isInitializingRef.current = false;
|
|
276
|
-
}
|
|
277
293
|
return () => {
|
|
294
|
+
isEffectCancelled = true;
|
|
278
295
|
clearInterval(intervalTimer);
|
|
279
296
|
// Reset initialization flag on cleanup
|
|
280
297
|
isInitializingRef.current = false;
|
|
281
298
|
// Clean up BEE plugin instance if it exists
|
|
282
299
|
if (beePluginInstanceRef.current) {
|
|
283
|
-
|
|
284
|
-
beePluginInstanceRef.current.destroy();
|
|
285
|
-
} catch (e) {
|
|
286
|
-
console.warn('[BeeEditor] useEffect cleanup - Error destroying BEE plugin:', e);
|
|
287
|
-
}
|
|
300
|
+
destroyBeeInstance(beePluginInstanceRef.current);
|
|
288
301
|
beePluginInstanceRef.current = null;
|
|
289
302
|
}
|
|
290
303
|
// Note: We don't reset initializedBeeJsonRef here because:
|
|
@@ -293,7 +306,12 @@ function BeeEditor(props) {
|
|
|
293
306
|
};
|
|
294
307
|
// Only depend on beeJson, uid, and id - not tokenData
|
|
295
308
|
// tokenData is accessed via ref to prevent re-initialization when it changes
|
|
296
|
-
}, [beeJson, uid, id]);
|
|
309
|
+
}, [beeJson, uid, id, beePluginLoadAttempt]);
|
|
310
|
+
|
|
311
|
+
const onRetryBeePluginLoad = () => {
|
|
312
|
+
setBeePluginLoadAttempt((attempt) => attempt + 1);
|
|
313
|
+
};
|
|
314
|
+
|
|
297
315
|
const callbackSaveRow = (status, errorMsg) => {
|
|
298
316
|
if (status === 'success') {
|
|
299
317
|
CapNotification.success({message: formatMessage(messages.rowCreationSuccessMgs), key: 'create-custom-row-success'});
|
|
@@ -367,8 +385,17 @@ function BeeEditor(props) {
|
|
|
367
385
|
</>
|
|
368
386
|
);
|
|
369
387
|
return (
|
|
370
|
-
<CapSpin spinning={saveRowRequest ||
|
|
371
|
-
|
|
388
|
+
<CapSpin spinning={saveRowRequest || isBeePluginLoading}>
|
|
389
|
+
{hasBeePluginLoadError ? (
|
|
390
|
+
<CapColumn className="bee-plugin-load-error">
|
|
391
|
+
<CapError type="error">{formatMessage(messages.beePluginLoadError)}</CapError>
|
|
392
|
+
<CapButton type="secondary" onClick={onRetryBeePluginLoad}>
|
|
393
|
+
{formatMessage(messages.retry)}
|
|
394
|
+
</CapButton>
|
|
395
|
+
</CapColumn>
|
|
396
|
+
) : (
|
|
397
|
+
<CapColumn id="bee-plugin-container" className="bee-plugin-container" />
|
|
398
|
+
)}
|
|
372
399
|
<TagList
|
|
373
400
|
moduleFilterEnabled={moduleFilterEnabled}
|
|
374
401
|
label={label}
|