@capillarytech/creatives-library 8.0.359-alpha.0 → 8.0.359-alpha.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/constants/unified.js +29 -0
- package/index.html +1 -0
- package/package.json +1 -1
- package/services/tests/api.test.js +35 -20
- package/utils/cdnTransformation.js +75 -3
- package/utils/commonUtils.js +19 -1
- package/utils/rcsPayloadUtils.js +92 -0
- package/utils/templateVarUtils.js +201 -0
- package/utils/tests/cdnTransformation.test.js +127 -0
- package/utils/tests/rcsPayloadUtils.test.js +226 -0
- package/utils/tests/templateVarUtils.test.js +204 -0
- package/v2Components/CapActionButton/constants.js +7 -0
- package/v2Components/CapActionButton/index.js +166 -108
- package/v2Components/CapActionButton/index.scss +157 -6
- package/v2Components/CapActionButton/messages.js +19 -3
- package/v2Components/CapActionButton/tests/index.test.js +41 -17
- package/v2Components/CapImageUpload/index.js +2 -2
- package/v2Components/CapTagList/index.js +10 -0
- package/v2Components/CommonTestAndPreview/CustomValuesEditor.js +72 -49
- package/v2Components/CommonTestAndPreview/DeliverySettings/DeliverySettings.scss +8 -2
- package/v2Components/CommonTestAndPreview/DeliverySettings/ModifyDeliverySettings.js +214 -21
- package/v2Components/CommonTestAndPreview/DeliverySettings/constants.js +16 -0
- package/v2Components/CommonTestAndPreview/DeliverySettings/index.js +83 -9
- package/v2Components/CommonTestAndPreview/DeliverySettings/messages.js +30 -0
- package/v2Components/CommonTestAndPreview/DeliverySettings/utils/parseSenderDetailsResponse.js +79 -11
- package/v2Components/CommonTestAndPreview/SendTestMessage.js +10 -5
- package/v2Components/CommonTestAndPreview/UnifiedPreview/PreviewHeader.js +16 -0
- package/v2Components/CommonTestAndPreview/UnifiedPreview/RcsPreviewContent.js +157 -15
- package/v2Components/CommonTestAndPreview/UnifiedPreview/ViberPreviewContent.js +14 -132
- package/v2Components/CommonTestAndPreview/UnifiedPreview/WebPushPreviewContent.js +169 -0
- package/v2Components/CommonTestAndPreview/UnifiedPreview/_unifiedPreview.scss +400 -239
- package/v2Components/CommonTestAndPreview/UnifiedPreview/index.js +202 -10
- package/v2Components/CommonTestAndPreview/_commonTestAndPreview.scss +11 -0
- package/v2Components/CommonTestAndPreview/constants.js +40 -2
- package/v2Components/CommonTestAndPreview/index.js +887 -453
- package/v2Components/CommonTestAndPreview/messages.js +45 -3
- package/v2Components/CommonTestAndPreview/previewApiUtils.js +59 -0
- package/v2Components/CommonTestAndPreview/sagas.js +25 -6
- package/v2Components/CommonTestAndPreview/tests/CustomValuesEditor.test.js +308 -284
- package/v2Components/CommonTestAndPreview/tests/DeliverySettings/ModifyDeliverySettings.test.js +231 -65
- package/v2Components/CommonTestAndPreview/tests/DeliverySettings/index.test.js +118 -5
- package/v2Components/CommonTestAndPreview/tests/DeliverySettings/utils/parseSenderDetailsResponse.test.js +341 -0
- package/v2Components/CommonTestAndPreview/tests/PreviewSection.test.js +8 -1
- package/v2Components/CommonTestAndPreview/tests/SendTestMessage.test.js +34 -13
- package/v2Components/CommonTestAndPreview/tests/UnifiedPreview/PreviewHeader.test.js +163 -0
- package/v2Components/CommonTestAndPreview/tests/UnifiedPreview/RcsPreviewContent.test.js +281 -283
- package/v2Components/CommonTestAndPreview/tests/UnifiedPreview/ViberPreviewContent.test.js +0 -364
- package/v2Components/CommonTestAndPreview/tests/UnifiedPreview/WebPushPreviewContent.test.js +522 -0
- package/v2Components/CommonTestAndPreview/tests/UnifiedPreview/index.test.js +454 -1
- package/v2Components/CommonTestAndPreview/tests/constants.test.js +2 -1
- package/v2Components/CommonTestAndPreview/tests/index.test.js +327 -4
- package/v2Components/CommonTestAndPreview/tests/previewApiUtils.test.js +67 -0
- package/v2Components/CommonTestAndPreview/tests/sagas.test.js +31 -24
- package/v2Components/FormBuilder/index.js +167 -56
- package/v2Components/SmsFallback/SmsFallbackLocalSelector.js +91 -0
- package/v2Components/SmsFallback/constants.js +73 -0
- package/v2Components/SmsFallback/index.js +956 -0
- package/v2Components/SmsFallback/index.scss +265 -0
- package/v2Components/SmsFallback/messages.js +78 -0
- package/v2Components/SmsFallback/smsFallbackUtils.js +119 -0
- package/v2Components/SmsFallback/tests/SmsFallbackLocalSelector.test.js +50 -0
- package/v2Components/SmsFallback/tests/rcsSmsFallback.acceptance.test.js +147 -0
- package/v2Components/SmsFallback/tests/smsFallbackHandlers.test.js +304 -0
- package/v2Components/SmsFallback/tests/smsFallbackUi.test.js +223 -0
- package/v2Components/SmsFallback/tests/smsFallbackUtils.test.js +309 -0
- package/v2Components/SmsFallback/tests/useLocalTemplateList.test.js +422 -0
- package/v2Components/SmsFallback/useLocalTemplateList.js +92 -0
- package/v2Components/TemplatePreview/_templatePreview.scss +37 -22
- package/v2Components/TemplatePreview/constants.js +2 -0
- package/v2Components/TemplatePreview/index.js +143 -31
- package/v2Components/TemplatePreview/tests/index.test.js +142 -0
- package/v2Components/TestAndPreviewSlidebox/index.js +15 -3
- package/v2Components/TestAndPreviewSlidebox/sagas.js +11 -4
- package/v2Components/TestAndPreviewSlidebox/tests/saga.test.js +3 -1
- package/v2Components/VarSegmentMessageEditor/constants.js +2 -0
- package/v2Components/VarSegmentMessageEditor/index.js +125 -0
- package/v2Components/VarSegmentMessageEditor/index.scss +46 -0
- package/v2Containers/App/constants.js +3 -0
- package/v2Containers/App/tests/constants.test.js +61 -0
- package/v2Containers/CreativesContainer/CreativesSlideBoxWrapper.js +17 -0
- package/v2Containers/CreativesContainer/SlideBoxContent.js +36 -4
- package/v2Containers/CreativesContainer/SlideBoxFooter.js +14 -5
- package/v2Containers/CreativesContainer/SlideBoxHeader.js +36 -5
- package/v2Containers/CreativesContainer/constants.js +9 -0
- package/v2Containers/CreativesContainer/embeddedSlideboxUtils.js +79 -0
- package/v2Containers/CreativesContainer/index.js +382 -127
- package/v2Containers/CreativesContainer/index.scss +83 -1
- package/v2Containers/CreativesContainer/tests/SlideBoxContent.localTemplates.test.js +90 -0
- package/v2Containers/CreativesContainer/tests/SlideBoxFooter.test.js +79 -34
- package/v2Containers/CreativesContainer/tests/SlideBoxHeader.test.js +79 -16
- package/v2Containers/CreativesContainer/tests/__snapshots__/SlideBoxContent.test.js.snap +8 -0
- package/v2Containers/CreativesContainer/tests/__snapshots__/SlideBoxHeader.test.js.snap +357 -98
- package/v2Containers/CreativesContainer/tests/__snapshots__/index.test.js.snap +20 -15
- package/v2Containers/CreativesContainer/tests/embeddedSlideboxUtils.test.js +258 -0
- package/v2Containers/CreativesContainer/tests/index.test.js +71 -9
- package/v2Containers/CreativesContainer/tests/useLocalTemplatesProp.test.js +125 -0
- package/v2Containers/MobilePush/Create/test/saga.test.js +2 -2
- package/v2Containers/Rcs/constants.js +120 -11
- package/v2Containers/Rcs/index.js +2577 -812
- package/v2Containers/Rcs/index.scss +281 -8
- package/v2Containers/Rcs/messages.js +34 -3
- package/v2Containers/Rcs/rcsLibraryHydrationUtils.js +225 -0
- package/v2Containers/Rcs/tests/__snapshots__/index.test.js.snap +98036 -70145
- package/v2Containers/Rcs/tests/__snapshots__/utils.test.js.snap +0 -5
- package/v2Containers/Rcs/tests/index.test.js +152 -121
- package/v2Containers/Rcs/tests/mockData.js +38 -0
- package/v2Containers/Rcs/tests/rcsLibraryHydrationUtils.test.js +318 -0
- package/v2Containers/Rcs/tests/utils.test.js +646 -30
- package/v2Containers/Rcs/utils.js +478 -11
- package/v2Containers/Sms/Create/index.js +106 -40
- package/v2Containers/Sms/smsFormDataHelpers.js +67 -0
- package/v2Containers/Sms/tests/smsFormDataHelpers.test.js +253 -0
- package/v2Containers/SmsTrai/Create/index.js +9 -4
- package/v2Containers/SmsTrai/Edit/constants.js +2 -0
- package/v2Containers/SmsTrai/Edit/index.js +640 -130
- package/v2Containers/SmsTrai/Edit/index.scss +121 -0
- package/v2Containers/SmsTrai/Edit/messages.js +14 -4
- package/v2Containers/SmsTrai/Edit/tests/__snapshots__/index.test.js.snap +4328 -2375
- package/v2Containers/SmsWrapper/index.js +37 -8
- package/v2Containers/TagList/index.js +6 -0
- package/v2Containers/Templates/TemplatesActionBar.js +101 -0
- package/v2Containers/Templates/_templates.scss +166 -86
- package/v2Containers/Templates/actions.js +11 -0
- package/v2Containers/Templates/constants.js +2 -0
- package/v2Containers/Templates/index.js +203 -145
- package/v2Containers/Templates/sagas.js +62 -13
- package/v2Containers/Templates/tests/TemplatesActionBar.test.js +120 -0
- package/v2Containers/Templates/tests/__snapshots__/index.test.js.snap +1062 -1017
- package/v2Containers/Templates/tests/sagas.test.js +222 -22
- package/v2Containers/Templates/tests/smsTemplatesListApi.test.js +180 -0
- package/v2Containers/Templates/tests/webpush.test.js +375 -0
- package/v2Containers/Templates/utils/smsTemplatesListApi.js +79 -0
- package/v2Containers/TemplatesV2/TemplatesV2.style.js +72 -1
- package/v2Containers/TemplatesV2/index.js +86 -23
- package/v2Containers/TemplatesV2/tests/TemplatesV2.localTemplates.test.js +131 -0
- package/v2Containers/Viber/constants.js +0 -19
- package/v2Containers/Viber/index.js +47 -714
- package/v2Containers/Viber/index.scss +0 -148
- package/v2Containers/Viber/messages.js +0 -116
- package/v2Containers/Viber/tests/index.test.js +0 -80
- package/v2Containers/WeChat/MapTemplates/test/saga.test.js +9 -9
- package/v2Containers/WebPush/Create/index.js +91 -8
- package/v2Containers/WebPush/Create/index.scss +7 -0
- package/v2Containers/WebPush/Create/tests/getTemplateContent.test.js +348 -0
- package/v2Containers/WebPush/Create/tests/testAndPreviewIntegration.test.js +325 -0
- package/v2Containers/Whatsapp/index.js +3 -20
- package/v2Containers/Whatsapp/tests/__snapshots__/index.test.js.snap +578 -34
|
@@ -9,7 +9,16 @@ import { render, screen } from '@testing-library/react';
|
|
|
9
9
|
import '@testing-library/jest-dom';
|
|
10
10
|
import { injectIntl, IntlProvider } from 'react-intl';
|
|
11
11
|
import UnifiedPreview from '../../UnifiedPreview';
|
|
12
|
-
import {
|
|
12
|
+
import {
|
|
13
|
+
CHANNELS,
|
|
14
|
+
DESKTOP,
|
|
15
|
+
TABLET,
|
|
16
|
+
MOBILE,
|
|
17
|
+
ANDROID,
|
|
18
|
+
IOS,
|
|
19
|
+
PREVIEW_TAB_RCS,
|
|
20
|
+
PREVIEW_TAB_SMS_FALLBACK,
|
|
21
|
+
} from '../../constants';
|
|
13
22
|
import messages from '../../messages';
|
|
14
23
|
|
|
15
24
|
// Convert messages object to format expected by IntlProvider
|
|
@@ -119,6 +128,21 @@ jest.mock('../../UnifiedPreview/ZaloPreviewContent', () => ({
|
|
|
119
128
|
),
|
|
120
129
|
}));
|
|
121
130
|
|
|
131
|
+
jest.mock('../../UnifiedPreview/WebPushPreviewContent', () => ({
|
|
132
|
+
__esModule: true,
|
|
133
|
+
default: (props) => (
|
|
134
|
+
<div data-testid="webpush-preview">
|
|
135
|
+
<div data-testid="webpush-title">{props.notificationTitle}</div>
|
|
136
|
+
<div data-testid="webpush-body">{props.notificationBody}</div>
|
|
137
|
+
<div data-testid="webpush-image">{props.imageSrc}</div>
|
|
138
|
+
<div data-testid="webpush-icon">{props.brandIconSrc}</div>
|
|
139
|
+
<div data-testid="webpush-url">{props.url}</div>
|
|
140
|
+
<div data-testid="webpush-buttons">{JSON.stringify(props.buttons)}</div>
|
|
141
|
+
<div data-testid="webpush-fullscreen">{props.isFullscreenOpen ? 'true' : 'false'}</div>
|
|
142
|
+
</div>
|
|
143
|
+
),
|
|
144
|
+
}));
|
|
145
|
+
|
|
122
146
|
jest.mock('../../UnifiedPreview/PreviewHeader', () => ({
|
|
123
147
|
__esModule: true,
|
|
124
148
|
default: (props) => (
|
|
@@ -547,6 +571,195 @@ describe('UnifiedPreview', () => {
|
|
|
547
571
|
|
|
548
572
|
expect(screen.getByTestId('rcs-sender-id')).toHaveTextContent('RCS_SENDER');
|
|
549
573
|
});
|
|
574
|
+
|
|
575
|
+
describe('RCS SMS fallback — Test & Preview tabs', () => {
|
|
576
|
+
it('without SMS fallback selected, shows only RCS preview (no RCS+SMS tab layout)', () => {
|
|
577
|
+
const props = {
|
|
578
|
+
...defaultProps,
|
|
579
|
+
channel: CHANNELS.RCS,
|
|
580
|
+
content: { rcsTitle: 'Hello RCS' },
|
|
581
|
+
smsFallbackContent: undefined,
|
|
582
|
+
};
|
|
583
|
+
|
|
584
|
+
const { container } = render(
|
|
585
|
+
<TestWrapper>
|
|
586
|
+
<ComponentToRender {...props} />
|
|
587
|
+
</TestWrapper>
|
|
588
|
+
);
|
|
589
|
+
|
|
590
|
+
expect(container.querySelector('.unified-preview-rcs-tabs')).toBeNull();
|
|
591
|
+
expect(screen.getByTestId('rcs-preview')).toBeInTheDocument();
|
|
592
|
+
expect(screen.queryByTestId('sms-preview')).not.toBeInTheDocument();
|
|
593
|
+
});
|
|
594
|
+
|
|
595
|
+
it('with SMS fallback template body, shows RCS and Fallback SMS tabs', () => {
|
|
596
|
+
const props = {
|
|
597
|
+
...defaultProps,
|
|
598
|
+
channel: CHANNELS.RCS,
|
|
599
|
+
content: { rcsTitle: 'Hello RCS' },
|
|
600
|
+
smsFallbackContent: {
|
|
601
|
+
content: 'SMS fallback body',
|
|
602
|
+
templateContent: 'SMS fallback body',
|
|
603
|
+
},
|
|
604
|
+
};
|
|
605
|
+
|
|
606
|
+
const { container } = render(
|
|
607
|
+
<TestWrapper>
|
|
608
|
+
<ComponentToRender {...props} />
|
|
609
|
+
</TestWrapper>
|
|
610
|
+
);
|
|
611
|
+
|
|
612
|
+
expect(container.querySelector('.unified-preview-rcs-tabs')).toBeInTheDocument();
|
|
613
|
+
expect(
|
|
614
|
+
screen.getByRole('tab', { name: messages.rcsTab.defaultMessage })
|
|
615
|
+
).toBeInTheDocument();
|
|
616
|
+
expect(
|
|
617
|
+
screen.getByRole('tab', { name: messages.smsFallbackTab.defaultMessage })
|
|
618
|
+
).toBeInTheDocument();
|
|
619
|
+
});
|
|
620
|
+
|
|
621
|
+
it('on SMS fallback tab, renders SMS preview with resolved fallback text when smsFallbackResolvedText is set', () => {
|
|
622
|
+
const props = {
|
|
623
|
+
...defaultProps,
|
|
624
|
+
channel: CHANNELS.RCS,
|
|
625
|
+
content: { rcsTitle: 'Hello RCS' },
|
|
626
|
+
smsFallbackContent: {
|
|
627
|
+
content: '{{var}}',
|
|
628
|
+
templateContent: '{{var}}',
|
|
629
|
+
},
|
|
630
|
+
smsFallbackResolvedText: 'Resolved SMS for preview',
|
|
631
|
+
activePreviewTab: PREVIEW_TAB_SMS_FALLBACK,
|
|
632
|
+
onPreviewTabChange: jest.fn(),
|
|
633
|
+
};
|
|
634
|
+
|
|
635
|
+
render(
|
|
636
|
+
<TestWrapper>
|
|
637
|
+
<ComponentToRender {...props} />
|
|
638
|
+
</TestWrapper>
|
|
639
|
+
);
|
|
640
|
+
|
|
641
|
+
expect(screen.getByTestId('sms-content')).toHaveTextContent('Resolved SMS for preview');
|
|
642
|
+
});
|
|
643
|
+
|
|
644
|
+
it('on RCS tab (default), renders RCS preview when dual tabs are shown', () => {
|
|
645
|
+
const props = {
|
|
646
|
+
...defaultProps,
|
|
647
|
+
channel: CHANNELS.RCS,
|
|
648
|
+
content: { rcsTitle: 'Only RCS pane' },
|
|
649
|
+
smsFallbackContent: { content: 'SMS', templateContent: 'SMS' },
|
|
650
|
+
activePreviewTab: PREVIEW_TAB_RCS,
|
|
651
|
+
onPreviewTabChange: jest.fn(),
|
|
652
|
+
};
|
|
653
|
+
|
|
654
|
+
render(
|
|
655
|
+
<TestWrapper>
|
|
656
|
+
<ComponentToRender {...props} />
|
|
657
|
+
</TestWrapper>
|
|
658
|
+
);
|
|
659
|
+
|
|
660
|
+
expect(screen.getByTestId('rcs-preview')).toBeInTheDocument();
|
|
661
|
+
expect(screen.getByTestId('rcs-content')).toHaveTextContent(/Only RCS pane/);
|
|
662
|
+
});
|
|
663
|
+
|
|
664
|
+
it('on SMS fallback tab, shows raw template when no varmap and no resolved text', () => {
|
|
665
|
+
const props = {
|
|
666
|
+
...defaultProps,
|
|
667
|
+
channel: CHANNELS.RCS,
|
|
668
|
+
content: { rcsTitle: 'Hello RCS' },
|
|
669
|
+
smsFallbackContent: {
|
|
670
|
+
content: 'Hello {{name}}',
|
|
671
|
+
templateContent: 'Hello {{name}}',
|
|
672
|
+
// no rcsSmsFallbackVarMapped
|
|
673
|
+
},
|
|
674
|
+
smsFallbackResolvedText: undefined,
|
|
675
|
+
activePreviewTab: PREVIEW_TAB_SMS_FALLBACK,
|
|
676
|
+
onPreviewTabChange: jest.fn(),
|
|
677
|
+
};
|
|
678
|
+
|
|
679
|
+
render(
|
|
680
|
+
<TestWrapper>
|
|
681
|
+
<ComponentToRender {...props} />
|
|
682
|
+
</TestWrapper>
|
|
683
|
+
);
|
|
684
|
+
|
|
685
|
+
// rawFallbackTemplate is shown directly — {{tags}} remain visible
|
|
686
|
+
expect(screen.getByTestId('sms-content')).toHaveTextContent('Hello {{name}}');
|
|
687
|
+
});
|
|
688
|
+
|
|
689
|
+
it('on SMS fallback tab, treats empty resolved text as absent and shows raw template', () => {
|
|
690
|
+
const props = {
|
|
691
|
+
...defaultProps,
|
|
692
|
+
channel: CHANNELS.RCS,
|
|
693
|
+
content: { rcsTitle: 'Hello RCS' },
|
|
694
|
+
smsFallbackContent: {
|
|
695
|
+
content: 'Raw {{var}} template',
|
|
696
|
+
templateContent: 'Raw {{var}} template',
|
|
697
|
+
},
|
|
698
|
+
smsFallbackResolvedText: '',
|
|
699
|
+
activePreviewTab: PREVIEW_TAB_SMS_FALLBACK,
|
|
700
|
+
onPreviewTabChange: jest.fn(),
|
|
701
|
+
};
|
|
702
|
+
|
|
703
|
+
render(
|
|
704
|
+
<TestWrapper>
|
|
705
|
+
<ComponentToRender {...props} />
|
|
706
|
+
</TestWrapper>
|
|
707
|
+
);
|
|
708
|
+
|
|
709
|
+
expect(screen.getByTestId('sms-content')).toHaveTextContent('Raw {{var}} template');
|
|
710
|
+
});
|
|
711
|
+
|
|
712
|
+
it('on SMS fallback tab, applies varmap slot substitution when varmap entries exist and no resolved text', () => {
|
|
713
|
+
// getFallbackResolvedContent key format: `${fullToken}_${segmentIndex}`
|
|
714
|
+
// 'Hello {{name}}' → segments ['Hello ', '{{name}}'], so {{name}} is at index 1 → key '{{name}}_1'
|
|
715
|
+
const props = {
|
|
716
|
+
...defaultProps,
|
|
717
|
+
channel: CHANNELS.RCS,
|
|
718
|
+
content: { rcsTitle: 'Hello RCS' },
|
|
719
|
+
smsFallbackContent: {
|
|
720
|
+
content: 'Hello {{name}}',
|
|
721
|
+
templateContent: 'Hello {{name}}',
|
|
722
|
+
rcsSmsFallbackVarMapped: { '{{name}}_1': 'World' },
|
|
723
|
+
},
|
|
724
|
+
smsFallbackResolvedText: undefined,
|
|
725
|
+
activePreviewTab: PREVIEW_TAB_SMS_FALLBACK,
|
|
726
|
+
onPreviewTabChange: jest.fn(),
|
|
727
|
+
};
|
|
728
|
+
|
|
729
|
+
render(
|
|
730
|
+
<TestWrapper>
|
|
731
|
+
<ComponentToRender {...props} />
|
|
732
|
+
</TestWrapper>
|
|
733
|
+
);
|
|
734
|
+
|
|
735
|
+
expect(screen.getByTestId('sms-content')).toHaveTextContent('Hello World');
|
|
736
|
+
});
|
|
737
|
+
|
|
738
|
+
it('on SMS fallback tab, resolved text takes priority over varmap entries', () => {
|
|
739
|
+
const props = {
|
|
740
|
+
...defaultProps,
|
|
741
|
+
channel: CHANNELS.RCS,
|
|
742
|
+
content: { rcsTitle: 'Hello RCS' },
|
|
743
|
+
smsFallbackContent: {
|
|
744
|
+
content: 'Hello {{name}}',
|
|
745
|
+
templateContent: 'Hello {{name}}',
|
|
746
|
+
rcsSmsFallbackVarMapped: { '{{name}}_1': 'World' },
|
|
747
|
+
},
|
|
748
|
+
smsFallbackResolvedText: 'Hello John',
|
|
749
|
+
activePreviewTab: PREVIEW_TAB_SMS_FALLBACK,
|
|
750
|
+
onPreviewTabChange: jest.fn(),
|
|
751
|
+
};
|
|
752
|
+
|
|
753
|
+
render(
|
|
754
|
+
<TestWrapper>
|
|
755
|
+
<ComponentToRender {...props} />
|
|
756
|
+
</TestWrapper>
|
|
757
|
+
);
|
|
758
|
+
|
|
759
|
+
// resolvedText wins over varmap substitution
|
|
760
|
+
expect(screen.getByTestId('sms-content')).toHaveTextContent('Hello John');
|
|
761
|
+
});
|
|
762
|
+
});
|
|
550
763
|
});
|
|
551
764
|
|
|
552
765
|
describe('Channel Routing - INAPP', () => {
|
|
@@ -976,4 +1189,244 @@ describe('UnifiedPreview', () => {
|
|
|
976
1189
|
consoleSpy.mockRestore();
|
|
977
1190
|
});
|
|
978
1191
|
});
|
|
1192
|
+
|
|
1193
|
+
describe('Channel Routing - WEBPUSH', () => {
|
|
1194
|
+
it('should render WebPushPreviewContent for WEBPUSH channel with object content', () => {
|
|
1195
|
+
const content = {
|
|
1196
|
+
content: {
|
|
1197
|
+
title: 'Hello World',
|
|
1198
|
+
message: 'This is a notification',
|
|
1199
|
+
iconImageUrl: 'https://example.com/icon.png',
|
|
1200
|
+
cta: { actionLink: 'https://example.com' },
|
|
1201
|
+
expandableDetails: {
|
|
1202
|
+
media: [{ url: 'https://example.com/image.jpg' }],
|
|
1203
|
+
ctas: [{ title: 'Click me', actionLink: 'https://example.com/btn', type: 'EXTERNAL_URL' }],
|
|
1204
|
+
},
|
|
1205
|
+
},
|
|
1206
|
+
};
|
|
1207
|
+
const props = { ...defaultProps, channel: CHANNELS.WEBPUSH, content };
|
|
1208
|
+
|
|
1209
|
+
render(
|
|
1210
|
+
<TestWrapper>
|
|
1211
|
+
<ComponentToRender {...props} />
|
|
1212
|
+
</TestWrapper>
|
|
1213
|
+
);
|
|
1214
|
+
|
|
1215
|
+
expect(screen.getByTestId('webpush-preview')).toBeTruthy();
|
|
1216
|
+
expect(screen.getByTestId('webpush-title')).toHaveTextContent('Hello World');
|
|
1217
|
+
expect(screen.getByTestId('webpush-body')).toHaveTextContent('This is a notification');
|
|
1218
|
+
expect(screen.getByTestId('webpush-icon')).toHaveTextContent('https://example.com/icon.png');
|
|
1219
|
+
expect(screen.getByTestId('webpush-url')).toHaveTextContent('https://example.com');
|
|
1220
|
+
});
|
|
1221
|
+
|
|
1222
|
+
it('should render WebPushPreviewContent for WEBPUSH channel with JSON string content', () => {
|
|
1223
|
+
const contentObj = {
|
|
1224
|
+
content: {
|
|
1225
|
+
title: 'Push Title',
|
|
1226
|
+
message: 'Push message body',
|
|
1227
|
+
iconImageUrl: 'https://example.com/brand.png',
|
|
1228
|
+
},
|
|
1229
|
+
};
|
|
1230
|
+
const props = {
|
|
1231
|
+
...defaultProps,
|
|
1232
|
+
channel: CHANNELS.WEBPUSH,
|
|
1233
|
+
content: JSON.stringify(contentObj),
|
|
1234
|
+
};
|
|
1235
|
+
|
|
1236
|
+
render(
|
|
1237
|
+
<TestWrapper>
|
|
1238
|
+
<ComponentToRender {...props} />
|
|
1239
|
+
</TestWrapper>
|
|
1240
|
+
);
|
|
1241
|
+
|
|
1242
|
+
expect(screen.getByTestId('webpush-preview')).toBeTruthy();
|
|
1243
|
+
expect(screen.getByTestId('webpush-title')).toHaveTextContent('Push Title');
|
|
1244
|
+
expect(screen.getByTestId('webpush-body')).toHaveTextContent('Push message body');
|
|
1245
|
+
expect(screen.getByTestId('webpush-icon')).toHaveTextContent('https://example.com/brand.png');
|
|
1246
|
+
});
|
|
1247
|
+
|
|
1248
|
+
it('should fallback to empty object when JSON parse fails', () => {
|
|
1249
|
+
const props = {
|
|
1250
|
+
...defaultProps,
|
|
1251
|
+
channel: CHANNELS.WEBPUSH,
|
|
1252
|
+
content: 'INVALID_JSON{{{{',
|
|
1253
|
+
};
|
|
1254
|
+
|
|
1255
|
+
render(
|
|
1256
|
+
<TestWrapper>
|
|
1257
|
+
<ComponentToRender {...props} />
|
|
1258
|
+
</TestWrapper>
|
|
1259
|
+
);
|
|
1260
|
+
|
|
1261
|
+
expect(screen.getByTestId('webpush-preview')).toBeTruthy();
|
|
1262
|
+
expect(screen.getByTestId('webpush-title')).toHaveTextContent('');
|
|
1263
|
+
expect(screen.getByTestId('webpush-body')).toHaveTextContent('');
|
|
1264
|
+
});
|
|
1265
|
+
|
|
1266
|
+
it('should fallback to empty object when content is null', () => {
|
|
1267
|
+
const props = { ...defaultProps, channel: CHANNELS.WEBPUSH, content: null };
|
|
1268
|
+
|
|
1269
|
+
render(
|
|
1270
|
+
<TestWrapper>
|
|
1271
|
+
<ComponentToRender {...props} />
|
|
1272
|
+
</TestWrapper>
|
|
1273
|
+
);
|
|
1274
|
+
|
|
1275
|
+
expect(screen.getByTestId('webpush-preview')).toBeTruthy();
|
|
1276
|
+
expect(screen.getByTestId('webpush-title')).toHaveTextContent('');
|
|
1277
|
+
});
|
|
1278
|
+
|
|
1279
|
+
it('should extract imageSrc from expandableDetails.media[0].url', () => {
|
|
1280
|
+
const content = {
|
|
1281
|
+
content: {
|
|
1282
|
+
title: 'T',
|
|
1283
|
+
message: 'M',
|
|
1284
|
+
expandableDetails: {
|
|
1285
|
+
media: [{ url: 'https://example.com/media.jpg' }],
|
|
1286
|
+
ctas: [],
|
|
1287
|
+
},
|
|
1288
|
+
},
|
|
1289
|
+
};
|
|
1290
|
+
const props = { ...defaultProps, channel: CHANNELS.WEBPUSH, content };
|
|
1291
|
+
|
|
1292
|
+
render(
|
|
1293
|
+
<TestWrapper>
|
|
1294
|
+
<ComponentToRender {...props} />
|
|
1295
|
+
</TestWrapper>
|
|
1296
|
+
);
|
|
1297
|
+
|
|
1298
|
+
expect(screen.getByTestId('webpush-image')).toHaveTextContent('https://example.com/media.jpg');
|
|
1299
|
+
});
|
|
1300
|
+
|
|
1301
|
+
it('should pass empty imageSrc when media array is empty', () => {
|
|
1302
|
+
const content = {
|
|
1303
|
+
content: {
|
|
1304
|
+
title: 'T',
|
|
1305
|
+
message: 'M',
|
|
1306
|
+
expandableDetails: { media: [], ctas: [] },
|
|
1307
|
+
},
|
|
1308
|
+
};
|
|
1309
|
+
const props = { ...defaultProps, channel: CHANNELS.WEBPUSH, content };
|
|
1310
|
+
|
|
1311
|
+
render(
|
|
1312
|
+
<TestWrapper>
|
|
1313
|
+
<ComponentToRender {...props} />
|
|
1314
|
+
</TestWrapper>
|
|
1315
|
+
);
|
|
1316
|
+
|
|
1317
|
+
expect(screen.getByTestId('webpush-image')).toHaveTextContent('');
|
|
1318
|
+
});
|
|
1319
|
+
|
|
1320
|
+
it('should map CTA buttons from expandableDetails.ctas', () => {
|
|
1321
|
+
const content = {
|
|
1322
|
+
content: {
|
|
1323
|
+
title: 'T',
|
|
1324
|
+
message: 'M',
|
|
1325
|
+
expandableDetails: {
|
|
1326
|
+
media: [],
|
|
1327
|
+
ctas: [
|
|
1328
|
+
{ title: 'Btn1', actionLink: 'https://a.com', type: 'EXTERNAL_URL' },
|
|
1329
|
+
{ title: 'Btn2', actionLink: 'https://b.com', type: 'SITE_URL' },
|
|
1330
|
+
],
|
|
1331
|
+
},
|
|
1332
|
+
},
|
|
1333
|
+
};
|
|
1334
|
+
const props = { ...defaultProps, channel: CHANNELS.WEBPUSH, content };
|
|
1335
|
+
|
|
1336
|
+
render(
|
|
1337
|
+
<TestWrapper>
|
|
1338
|
+
<ComponentToRender {...props} />
|
|
1339
|
+
</TestWrapper>
|
|
1340
|
+
);
|
|
1341
|
+
|
|
1342
|
+
const buttons = JSON.parse(screen.getByTestId('webpush-buttons').textContent);
|
|
1343
|
+
expect(buttons).toHaveLength(2);
|
|
1344
|
+
expect(buttons[0]).toEqual({ text: 'Btn1', url: 'https://a.com', type: 'EXTERNAL_URL' });
|
|
1345
|
+
expect(buttons[1]).toEqual({ text: 'Btn2', url: 'https://b.com', type: 'SITE_URL' });
|
|
1346
|
+
});
|
|
1347
|
+
|
|
1348
|
+
it('should pass empty buttons array when no ctas', () => {
|
|
1349
|
+
const content = { content: { title: 'T', message: 'M' } };
|
|
1350
|
+
const props = { ...defaultProps, channel: CHANNELS.WEBPUSH, content };
|
|
1351
|
+
|
|
1352
|
+
render(
|
|
1353
|
+
<TestWrapper>
|
|
1354
|
+
<ComponentToRender {...props} />
|
|
1355
|
+
</TestWrapper>
|
|
1356
|
+
);
|
|
1357
|
+
|
|
1358
|
+
const buttons = JSON.parse(screen.getByTestId('webpush-buttons').textContent);
|
|
1359
|
+
expect(buttons).toEqual([]);
|
|
1360
|
+
});
|
|
1361
|
+
|
|
1362
|
+
it('should NOT show device toggle for WEBPUSH channel', () => {
|
|
1363
|
+
const props = {
|
|
1364
|
+
...defaultProps,
|
|
1365
|
+
channel: CHANNELS.WEBPUSH,
|
|
1366
|
+
showDeviceToggle: true,
|
|
1367
|
+
showHeader: true,
|
|
1368
|
+
selectedCustomer: { name: 'Alice' },
|
|
1369
|
+
};
|
|
1370
|
+
|
|
1371
|
+
render(
|
|
1372
|
+
<TestWrapper>
|
|
1373
|
+
<ComponentToRender {...props} />
|
|
1374
|
+
</TestWrapper>
|
|
1375
|
+
);
|
|
1376
|
+
|
|
1377
|
+
// PreviewHeader is mocked - verify it receives showDeviceToggle=false for WEBPUSH
|
|
1378
|
+
const header = screen.getByTestId('preview-header');
|
|
1379
|
+
expect(header).toBeTruthy();
|
|
1380
|
+
});
|
|
1381
|
+
|
|
1382
|
+
it('should include WEBPUSH in supported channels list', () => {
|
|
1383
|
+
const props = { ...defaultProps, channel: CHANNELS.WEBPUSH, content: {} };
|
|
1384
|
+
|
|
1385
|
+
render(
|
|
1386
|
+
<TestWrapper>
|
|
1387
|
+
<ComponentToRender {...props} />
|
|
1388
|
+
</TestWrapper>
|
|
1389
|
+
);
|
|
1390
|
+
|
|
1391
|
+
// WEBPUSH should render WebPushPreviewContent, not the unsupported placeholder
|
|
1392
|
+
expect(screen.getByTestId('webpush-preview')).toBeTruthy();
|
|
1393
|
+
expect(screen.queryByText(/Coming Soon/)).toBeNull();
|
|
1394
|
+
});
|
|
1395
|
+
|
|
1396
|
+
it('should pass isUpdating to WebPushPreviewContent in loading state', () => {
|
|
1397
|
+
const props = {
|
|
1398
|
+
...defaultProps,
|
|
1399
|
+
channel: CHANNELS.WEBPUSH,
|
|
1400
|
+
content: { content: { title: 'T', message: 'M' } },
|
|
1401
|
+
isUpdating: true,
|
|
1402
|
+
};
|
|
1403
|
+
|
|
1404
|
+
render(
|
|
1405
|
+
<TestWrapper>
|
|
1406
|
+
<ComponentToRender {...props} />
|
|
1407
|
+
</TestWrapper>
|
|
1408
|
+
);
|
|
1409
|
+
|
|
1410
|
+
// When isUpdating, component shows loading spinner, not WebPushPreviewContent
|
|
1411
|
+
expect(screen.queryByTestId('webpush-preview')).toBeNull();
|
|
1412
|
+
});
|
|
1413
|
+
|
|
1414
|
+
it('should pass error to WebPushPreviewContent in error state', () => {
|
|
1415
|
+
const props = {
|
|
1416
|
+
...defaultProps,
|
|
1417
|
+
channel: CHANNELS.WEBPUSH,
|
|
1418
|
+
content: { content: { title: 'T', message: 'M' } },
|
|
1419
|
+
error: 'Network error',
|
|
1420
|
+
};
|
|
1421
|
+
|
|
1422
|
+
render(
|
|
1423
|
+
<TestWrapper>
|
|
1424
|
+
<ComponentToRender {...props} />
|
|
1425
|
+
</TestWrapper>
|
|
1426
|
+
);
|
|
1427
|
+
|
|
1428
|
+
// When error, component shows error state, not WebPushPreviewContent
|
|
1429
|
+
expect(screen.queryByTestId('webpush-preview')).toBeNull();
|
|
1430
|
+
});
|
|
1431
|
+
});
|
|
979
1432
|
});
|
|
@@ -179,10 +179,11 @@ describe('CommonTestAndPreview Constants', () => {
|
|
|
179
179
|
expect(CHANNELS.MOBILEPUSH).toBe('MOBILEPUSH');
|
|
180
180
|
expect(CHANNELS.VIBER).toBe('VIBER');
|
|
181
181
|
expect(CHANNELS.ZALO).toBe('ZALO');
|
|
182
|
+
expect(CHANNELS.WEBPUSH).toBe('WEBPUSH');
|
|
182
183
|
});
|
|
183
184
|
|
|
184
185
|
it('should have all required channel keys', () => {
|
|
185
|
-
const expectedChannels = ['EMAIL', 'SMS', 'RCS', 'WHATSAPP', 'INAPP', 'MOBILEPUSH', 'VIBER', 'ZALO'];
|
|
186
|
+
const expectedChannels = ['EMAIL', 'SMS', 'RCS', 'WHATSAPP', 'INAPP', 'MOBILEPUSH', 'VIBER', 'ZALO', 'WEBPUSH'];
|
|
186
187
|
expect(Object.keys(CHANNELS)).toEqual(expect.arrayContaining(expectedChannels));
|
|
187
188
|
expect(Object.keys(CHANNELS).length).toBe(expectedChannels.length);
|
|
188
189
|
});
|