@capillarytech/creatives-library 8.0.355 → 8.0.356

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 (26) hide show
  1. package/index.html +0 -1
  2. package/package.json +1 -1
  3. package/utils/cdnTransformation.js +3 -63
  4. package/utils/tests/cdnTransformation.test.js +0 -111
  5. package/v2Components/CommonTestAndPreview/UnifiedPreview/PreviewHeader.js +16 -0
  6. package/v2Components/CommonTestAndPreview/UnifiedPreview/WebPushPreviewContent.js +169 -0
  7. package/v2Components/CommonTestAndPreview/UnifiedPreview/_unifiedPreview.scss +54 -0
  8. package/v2Components/CommonTestAndPreview/UnifiedPreview/index.js +52 -6
  9. package/v2Components/CommonTestAndPreview/constants.js +2 -0
  10. package/v2Components/CommonTestAndPreview/index.js +51 -2
  11. package/v2Components/CommonTestAndPreview/tests/UnifiedPreview/PreviewHeader.test.js +163 -0
  12. package/v2Components/CommonTestAndPreview/tests/UnifiedPreview/WebPushPreviewContent.test.js +522 -0
  13. package/v2Components/CommonTestAndPreview/tests/UnifiedPreview/index.test.js +255 -0
  14. package/v2Components/CommonTestAndPreview/tests/constants.test.js +2 -1
  15. package/v2Components/CommonTestAndPreview/tests/index.test.js +194 -0
  16. package/v2Components/TestAndPreviewSlidebox/index.js +2 -2
  17. package/v2Containers/App/constants.js +3 -0
  18. package/v2Containers/App/tests/constants.test.js +61 -0
  19. package/v2Containers/Templates/index.js +72 -2
  20. package/v2Containers/Templates/sagas.js +1 -6
  21. package/v2Containers/Templates/tests/sagas.test.js +6 -23
  22. package/v2Containers/Templates/tests/webpush.test.js +375 -0
  23. package/v2Containers/WebPush/Create/index.js +91 -8
  24. package/v2Containers/WebPush/Create/index.scss +7 -0
  25. package/v2Containers/WebPush/Create/tests/getTemplateContent.test.js +348 -0
  26. package/v2Containers/WebPush/Create/tests/testAndPreviewIntegration.test.js +325 -0
@@ -119,6 +119,21 @@ jest.mock('../../UnifiedPreview/ZaloPreviewContent', () => ({
119
119
  ),
120
120
  }));
121
121
 
122
+ jest.mock('../../UnifiedPreview/WebPushPreviewContent', () => ({
123
+ __esModule: true,
124
+ default: (props) => (
125
+ <div data-testid="webpush-preview">
126
+ <div data-testid="webpush-title">{props.notificationTitle}</div>
127
+ <div data-testid="webpush-body">{props.notificationBody}</div>
128
+ <div data-testid="webpush-image">{props.imageSrc}</div>
129
+ <div data-testid="webpush-icon">{props.brandIconSrc}</div>
130
+ <div data-testid="webpush-url">{props.url}</div>
131
+ <div data-testid="webpush-buttons">{JSON.stringify(props.buttons)}</div>
132
+ <div data-testid="webpush-fullscreen">{props.isFullscreenOpen ? 'true' : 'false'}</div>
133
+ </div>
134
+ ),
135
+ }));
136
+
122
137
  jest.mock('../../UnifiedPreview/PreviewHeader', () => ({
123
138
  __esModule: true,
124
139
  default: (props) => (
@@ -976,4 +991,244 @@ describe('UnifiedPreview', () => {
976
991
  consoleSpy.mockRestore();
977
992
  });
978
993
  });
994
+
995
+ describe('Channel Routing - WEBPUSH', () => {
996
+ it('should render WebPushPreviewContent for WEBPUSH channel with object content', () => {
997
+ const content = {
998
+ content: {
999
+ title: 'Hello World',
1000
+ message: 'This is a notification',
1001
+ iconImageUrl: 'https://example.com/icon.png',
1002
+ cta: { actionLink: 'https://example.com' },
1003
+ expandableDetails: {
1004
+ media: [{ url: 'https://example.com/image.jpg' }],
1005
+ ctas: [{ title: 'Click me', actionLink: 'https://example.com/btn', type: 'EXTERNAL_URL' }],
1006
+ },
1007
+ },
1008
+ };
1009
+ const props = { ...defaultProps, channel: CHANNELS.WEBPUSH, content };
1010
+
1011
+ render(
1012
+ <TestWrapper>
1013
+ <ComponentToRender {...props} />
1014
+ </TestWrapper>
1015
+ );
1016
+
1017
+ expect(screen.getByTestId('webpush-preview')).toBeTruthy();
1018
+ expect(screen.getByTestId('webpush-title')).toHaveTextContent('Hello World');
1019
+ expect(screen.getByTestId('webpush-body')).toHaveTextContent('This is a notification');
1020
+ expect(screen.getByTestId('webpush-icon')).toHaveTextContent('https://example.com/icon.png');
1021
+ expect(screen.getByTestId('webpush-url')).toHaveTextContent('https://example.com');
1022
+ });
1023
+
1024
+ it('should render WebPushPreviewContent for WEBPUSH channel with JSON string content', () => {
1025
+ const contentObj = {
1026
+ content: {
1027
+ title: 'Push Title',
1028
+ message: 'Push message body',
1029
+ iconImageUrl: 'https://example.com/brand.png',
1030
+ },
1031
+ };
1032
+ const props = {
1033
+ ...defaultProps,
1034
+ channel: CHANNELS.WEBPUSH,
1035
+ content: JSON.stringify(contentObj),
1036
+ };
1037
+
1038
+ render(
1039
+ <TestWrapper>
1040
+ <ComponentToRender {...props} />
1041
+ </TestWrapper>
1042
+ );
1043
+
1044
+ expect(screen.getByTestId('webpush-preview')).toBeTruthy();
1045
+ expect(screen.getByTestId('webpush-title')).toHaveTextContent('Push Title');
1046
+ expect(screen.getByTestId('webpush-body')).toHaveTextContent('Push message body');
1047
+ expect(screen.getByTestId('webpush-icon')).toHaveTextContent('https://example.com/brand.png');
1048
+ });
1049
+
1050
+ it('should fallback to empty object when JSON parse fails', () => {
1051
+ const props = {
1052
+ ...defaultProps,
1053
+ channel: CHANNELS.WEBPUSH,
1054
+ content: 'INVALID_JSON{{{{',
1055
+ };
1056
+
1057
+ render(
1058
+ <TestWrapper>
1059
+ <ComponentToRender {...props} />
1060
+ </TestWrapper>
1061
+ );
1062
+
1063
+ expect(screen.getByTestId('webpush-preview')).toBeTruthy();
1064
+ expect(screen.getByTestId('webpush-title')).toHaveTextContent('');
1065
+ expect(screen.getByTestId('webpush-body')).toHaveTextContent('');
1066
+ });
1067
+
1068
+ it('should fallback to empty object when content is null', () => {
1069
+ const props = { ...defaultProps, channel: CHANNELS.WEBPUSH, content: null };
1070
+
1071
+ render(
1072
+ <TestWrapper>
1073
+ <ComponentToRender {...props} />
1074
+ </TestWrapper>
1075
+ );
1076
+
1077
+ expect(screen.getByTestId('webpush-preview')).toBeTruthy();
1078
+ expect(screen.getByTestId('webpush-title')).toHaveTextContent('');
1079
+ });
1080
+
1081
+ it('should extract imageSrc from expandableDetails.media[0].url', () => {
1082
+ const content = {
1083
+ content: {
1084
+ title: 'T',
1085
+ message: 'M',
1086
+ expandableDetails: {
1087
+ media: [{ url: 'https://example.com/media.jpg' }],
1088
+ ctas: [],
1089
+ },
1090
+ },
1091
+ };
1092
+ const props = { ...defaultProps, channel: CHANNELS.WEBPUSH, content };
1093
+
1094
+ render(
1095
+ <TestWrapper>
1096
+ <ComponentToRender {...props} />
1097
+ </TestWrapper>
1098
+ );
1099
+
1100
+ expect(screen.getByTestId('webpush-image')).toHaveTextContent('https://example.com/media.jpg');
1101
+ });
1102
+
1103
+ it('should pass empty imageSrc when media array is empty', () => {
1104
+ const content = {
1105
+ content: {
1106
+ title: 'T',
1107
+ message: 'M',
1108
+ expandableDetails: { media: [], ctas: [] },
1109
+ },
1110
+ };
1111
+ const props = { ...defaultProps, channel: CHANNELS.WEBPUSH, content };
1112
+
1113
+ render(
1114
+ <TestWrapper>
1115
+ <ComponentToRender {...props} />
1116
+ </TestWrapper>
1117
+ );
1118
+
1119
+ expect(screen.getByTestId('webpush-image')).toHaveTextContent('');
1120
+ });
1121
+
1122
+ it('should map CTA buttons from expandableDetails.ctas', () => {
1123
+ const content = {
1124
+ content: {
1125
+ title: 'T',
1126
+ message: 'M',
1127
+ expandableDetails: {
1128
+ media: [],
1129
+ ctas: [
1130
+ { title: 'Btn1', actionLink: 'https://a.com', type: 'EXTERNAL_URL' },
1131
+ { title: 'Btn2', actionLink: 'https://b.com', type: 'SITE_URL' },
1132
+ ],
1133
+ },
1134
+ },
1135
+ };
1136
+ const props = { ...defaultProps, channel: CHANNELS.WEBPUSH, content };
1137
+
1138
+ render(
1139
+ <TestWrapper>
1140
+ <ComponentToRender {...props} />
1141
+ </TestWrapper>
1142
+ );
1143
+
1144
+ const buttons = JSON.parse(screen.getByTestId('webpush-buttons').textContent);
1145
+ expect(buttons).toHaveLength(2);
1146
+ expect(buttons[0]).toEqual({ text: 'Btn1', url: 'https://a.com', type: 'EXTERNAL_URL' });
1147
+ expect(buttons[1]).toEqual({ text: 'Btn2', url: 'https://b.com', type: 'SITE_URL' });
1148
+ });
1149
+
1150
+ it('should pass empty buttons array when no ctas', () => {
1151
+ const content = { content: { title: 'T', message: 'M' } };
1152
+ const props = { ...defaultProps, channel: CHANNELS.WEBPUSH, content };
1153
+
1154
+ render(
1155
+ <TestWrapper>
1156
+ <ComponentToRender {...props} />
1157
+ </TestWrapper>
1158
+ );
1159
+
1160
+ const buttons = JSON.parse(screen.getByTestId('webpush-buttons').textContent);
1161
+ expect(buttons).toEqual([]);
1162
+ });
1163
+
1164
+ it('should NOT show device toggle for WEBPUSH channel', () => {
1165
+ const props = {
1166
+ ...defaultProps,
1167
+ channel: CHANNELS.WEBPUSH,
1168
+ showDeviceToggle: true,
1169
+ showHeader: true,
1170
+ selectedCustomer: { name: 'Alice' },
1171
+ };
1172
+
1173
+ render(
1174
+ <TestWrapper>
1175
+ <ComponentToRender {...props} />
1176
+ </TestWrapper>
1177
+ );
1178
+
1179
+ // PreviewHeader is mocked - verify it receives showDeviceToggle=false for WEBPUSH
1180
+ const header = screen.getByTestId('preview-header');
1181
+ expect(header).toBeTruthy();
1182
+ });
1183
+
1184
+ it('should include WEBPUSH in supported channels list', () => {
1185
+ const props = { ...defaultProps, channel: CHANNELS.WEBPUSH, content: {} };
1186
+
1187
+ render(
1188
+ <TestWrapper>
1189
+ <ComponentToRender {...props} />
1190
+ </TestWrapper>
1191
+ );
1192
+
1193
+ // WEBPUSH should render WebPushPreviewContent, not the unsupported placeholder
1194
+ expect(screen.getByTestId('webpush-preview')).toBeTruthy();
1195
+ expect(screen.queryByText(/Coming Soon/)).toBeNull();
1196
+ });
1197
+
1198
+ it('should pass isUpdating to WebPushPreviewContent in loading state', () => {
1199
+ const props = {
1200
+ ...defaultProps,
1201
+ channel: CHANNELS.WEBPUSH,
1202
+ content: { content: { title: 'T', message: 'M' } },
1203
+ isUpdating: true,
1204
+ };
1205
+
1206
+ render(
1207
+ <TestWrapper>
1208
+ <ComponentToRender {...props} />
1209
+ </TestWrapper>
1210
+ );
1211
+
1212
+ // When isUpdating, component shows loading spinner, not WebPushPreviewContent
1213
+ expect(screen.queryByTestId('webpush-preview')).toBeNull();
1214
+ });
1215
+
1216
+ it('should pass error to WebPushPreviewContent in error state', () => {
1217
+ const props = {
1218
+ ...defaultProps,
1219
+ channel: CHANNELS.WEBPUSH,
1220
+ content: { content: { title: 'T', message: 'M' } },
1221
+ error: 'Network error',
1222
+ };
1223
+
1224
+ render(
1225
+ <TestWrapper>
1226
+ <ComponentToRender {...props} />
1227
+ </TestWrapper>
1228
+ );
1229
+
1230
+ // When error, component shows error state, not WebPushPreviewContent
1231
+ expect(screen.queryByTestId('webpush-preview')).toBeNull();
1232
+ });
1233
+ });
979
1234
  });
@@ -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
  });
@@ -1174,6 +1174,50 @@ describe('CommonTestAndPreview', () => {
1174
1174
  expect(screen.getByTestId('preview-section')).toBeTruthy();
1175
1175
  });
1176
1176
  });
1177
+
1178
+ it('should handle WEBPUSH channel', async () => {
1179
+ const webpushContent = {
1180
+ content: { title: 'Web Push', message: 'Hello from web push' },
1181
+ accountId: 'acc-001',
1182
+ };
1183
+ const props = {
1184
+ ...defaultProps,
1185
+ channel: CHANNELS.WEBPUSH,
1186
+ content: webpushContent,
1187
+ };
1188
+
1189
+ render(
1190
+ <TestWrapper>
1191
+ <CommonTestAndPreview {...props} />
1192
+ </TestWrapper>
1193
+ );
1194
+
1195
+ await waitFor(() => {
1196
+ expect(screen.getByTestId('left-panel')).toBeTruthy();
1197
+ expect(screen.getByTestId('preview-section')).toBeTruthy();
1198
+ });
1199
+ });
1200
+
1201
+ it('should treat WEBPUSH content as object (same branch as WHATSAPP)', async () => {
1202
+ // The WEBPUSH channel uses the same contentObj branch as WHATSAPP (JSON string or object)
1203
+ const props = {
1204
+ ...defaultProps,
1205
+ channel: CHANNELS.WEBPUSH,
1206
+ content: JSON.stringify({
1207
+ content: { title: 'Stringified', message: 'Content' },
1208
+ }),
1209
+ };
1210
+
1211
+ render(
1212
+ <TestWrapper>
1213
+ <CommonTestAndPreview {...props} />
1214
+ </TestWrapper>
1215
+ );
1216
+
1217
+ await waitFor(() => {
1218
+ expect(screen.getByTestId('preview-section')).toBeTruthy();
1219
+ });
1220
+ });
1177
1221
  });
1178
1222
 
1179
1223
  describe('Device Initialization', () => {
@@ -2629,6 +2673,156 @@ describe('CommonTestAndPreview', () => {
2629
2673
  });
2630
2674
  });
2631
2675
  });
2676
+
2677
+ describe('preparePreviewPayload - WEBPUSH', () => {
2678
+ it('should build WEBPUSH payload with title and message', async () => {
2679
+ const webpushContent = {
2680
+ content: {
2681
+ title: 'Push Title',
2682
+ message: 'Push message body',
2683
+ },
2684
+ accountId: 'acc-123',
2685
+ messageSubject: 'Push Title',
2686
+ };
2687
+ const props = {
2688
+ ...defaultProps,
2689
+ channel: CHANNELS.WEBPUSH,
2690
+ content: JSON.stringify(webpushContent),
2691
+ };
2692
+
2693
+ render(
2694
+ <TestWrapper>
2695
+ <CommonTestAndPreview {...props} />
2696
+ </TestWrapper>
2697
+ );
2698
+
2699
+ await waitFor(() => {
2700
+ expect(screen.getByTestId('left-panel')).toBeTruthy();
2701
+ expect(screen.getByTestId('preview-section')).toBeTruthy();
2702
+ });
2703
+ });
2704
+
2705
+ it('should handle WEBPUSH content with iconImageUrl', async () => {
2706
+ const webpushContent = {
2707
+ content: {
2708
+ title: 'Hello',
2709
+ message: 'World',
2710
+ iconImageUrl: 'https://example.com/icon.png',
2711
+ },
2712
+ accountId: 'acc-123',
2713
+ };
2714
+ const props = {
2715
+ ...defaultProps,
2716
+ channel: CHANNELS.WEBPUSH,
2717
+ content: webpushContent,
2718
+ };
2719
+
2720
+ render(
2721
+ <TestWrapper>
2722
+ <CommonTestAndPreview {...props} />
2723
+ </TestWrapper>
2724
+ );
2725
+
2726
+ await waitFor(() => {
2727
+ expect(screen.getByTestId('preview-section')).toBeTruthy();
2728
+ });
2729
+ });
2730
+
2731
+ it('should handle WEBPUSH content with cta', async () => {
2732
+ const webpushContent = {
2733
+ content: {
2734
+ title: 'Hello',
2735
+ message: 'World',
2736
+ cta: { type: 'EXTERNAL_URL', actionLink: 'https://example.com' },
2737
+ },
2738
+ accountId: 'acc-123',
2739
+ };
2740
+ const props = {
2741
+ ...defaultProps,
2742
+ channel: CHANNELS.WEBPUSH,
2743
+ content: webpushContent,
2744
+ };
2745
+
2746
+ render(
2747
+ <TestWrapper>
2748
+ <CommonTestAndPreview {...props} />
2749
+ </TestWrapper>
2750
+ );
2751
+
2752
+ await waitFor(() => {
2753
+ expect(screen.getByTestId('preview-section')).toBeTruthy();
2754
+ });
2755
+ });
2756
+
2757
+ it('should handle WEBPUSH content with expandableDetails', async () => {
2758
+ const webpushContent = {
2759
+ content: {
2760
+ title: 'Hello',
2761
+ message: 'World',
2762
+ expandableDetails: {
2763
+ media: [{ url: 'https://example.com/image.jpg', type: 'IMAGE' }],
2764
+ ctas: [{ title: 'Click', actionLink: 'https://example.com', type: 'EXTERNAL_URL' }],
2765
+ },
2766
+ },
2767
+ accountId: 'acc-123',
2768
+ };
2769
+ const props = {
2770
+ ...defaultProps,
2771
+ channel: CHANNELS.WEBPUSH,
2772
+ content: webpushContent,
2773
+ };
2774
+
2775
+ render(
2776
+ <TestWrapper>
2777
+ <CommonTestAndPreview {...props} />
2778
+ </TestWrapper>
2779
+ );
2780
+
2781
+ await waitFor(() => {
2782
+ expect(screen.getByTestId('preview-section')).toBeTruthy();
2783
+ });
2784
+ });
2785
+
2786
+ it('should handle WEBPUSH with null formData gracefully', async () => {
2787
+ const props = {
2788
+ ...defaultProps,
2789
+ channel: CHANNELS.WEBPUSH,
2790
+ formData: null,
2791
+ content: null,
2792
+ };
2793
+
2794
+ render(
2795
+ <TestWrapper>
2796
+ <CommonTestAndPreview {...props} />
2797
+ </TestWrapper>
2798
+ );
2799
+
2800
+ await waitFor(() => {
2801
+ expect(screen.getByTestId('preview-section')).toBeTruthy();
2802
+ });
2803
+ });
2804
+
2805
+ it('should handle WEBPUSH channel with object content (non-string)', async () => {
2806
+ const props = {
2807
+ ...defaultProps,
2808
+ channel: CHANNELS.WEBPUSH,
2809
+ content: {
2810
+ content: { title: 'ObjTitle', message: 'ObjMessage' },
2811
+ accountId: 'acc-999',
2812
+ },
2813
+ };
2814
+
2815
+ render(
2816
+ <TestWrapper>
2817
+ <CommonTestAndPreview {...props} />
2818
+ </TestWrapper>
2819
+ );
2820
+
2821
+ await waitFor(() => {
2822
+ expect(screen.getByTestId('preview-section')).toBeTruthy();
2823
+ });
2824
+ });
2825
+ });
2632
2826
  });
2633
2827
 
2634
2828
  describe('Tag Extraction', () => {
@@ -69,8 +69,8 @@ const TestAndPreviewSlidebox = (props) => {
69
69
 
70
70
  TestAndPreviewSlidebox.propTypes = {
71
71
  // Channel prop - supports all channels
72
- channel: PropTypes.oneOf([CHANNELS.EMAIL, CHANNELS.SMS, CHANNELS.RCS, CHANNELS.WHATSAPP, CHANNELS.INAPP, CHANNELS.MOBILEPUSH]),
73
- currentChannel: PropTypes.oneOf([CHANNELS.EMAIL, CHANNELS.SMS, CHANNELS.RCS, CHANNELS.WHATSAPP, CHANNELS.INAPP, CHANNELS.MOBILEPUSH]), // Alternative prop name for backward compatibility
72
+ channel: PropTypes.oneOf([CHANNELS.EMAIL, CHANNELS.SMS, CHANNELS.RCS, CHANNELS.WHATSAPP, CHANNELS.INAPP, CHANNELS.MOBILEPUSH, CHANNELS.VIBER, CHANNELS.ZALO, CHANNELS.WEBPUSH]),
73
+ currentChannel: PropTypes.oneOf([CHANNELS.EMAIL, CHANNELS.SMS, CHANNELS.RCS, CHANNELS.WHATSAPP, CHANNELS.INAPP, CHANNELS.MOBILEPUSH, CHANNELS.VIBER, CHANNELS.ZALO, CHANNELS.WEBPUSH]), // Alternative prop name for backward compatibility
74
74
  // All original props are passed through
75
75
  show: PropTypes.bool.isRequired,
76
76
  onClose: PropTypes.func.isRequired,
@@ -124,3 +124,6 @@ export const LOYALTY = 'loyalty';
124
124
  export const FAILURE = 'FAILURE';
125
125
  export const DATE_DISPLAY_FORMAT = 'D MMM YYYY';
126
126
  export const TIME_DISPLAY_FORMAT = 'hh:mm A';
127
+ export const EXTERNAL_URL = 'EXTERNAL_URL';
128
+ export const URL = 'URL';
129
+ export const SITE_URL = 'SITE_URL';
@@ -0,0 +1,61 @@
1
+ /**
2
+ * Tests for App container constants
3
+ *
4
+ * Covers newly added URL type constants: EXTERNAL_URL, URL, SITE_URL
5
+ */
6
+
7
+ import {
8
+ EXTERNAL_URL,
9
+ URL,
10
+ SITE_URL,
11
+ LOYALTY,
12
+ FAILURE,
13
+ DATE_DISPLAY_FORMAT,
14
+ TIME_DISPLAY_FORMAT,
15
+ } from '../constants';
16
+
17
+ describe('App constants', () => {
18
+ describe('URL type constants', () => {
19
+ it('should export EXTERNAL_URL with correct value', () => {
20
+ expect(EXTERNAL_URL).toBe('EXTERNAL_URL');
21
+ });
22
+
23
+ it('should export URL with correct value', () => {
24
+ expect(URL).toBe('URL');
25
+ });
26
+
27
+ it('should export SITE_URL with correct value', () => {
28
+ expect(SITE_URL).toBe('SITE_URL');
29
+ });
30
+
31
+ it('should have distinct values for all three URL constants', () => {
32
+ expect(EXTERNAL_URL).not.toBe(URL);
33
+ expect(EXTERNAL_URL).not.toBe(SITE_URL);
34
+ expect(URL).not.toBe(SITE_URL);
35
+ });
36
+
37
+ it('should be strings', () => {
38
+ expect(typeof EXTERNAL_URL).toBe('string');
39
+ expect(typeof URL).toBe('string');
40
+ expect(typeof SITE_URL).toBe('string');
41
+ });
42
+ });
43
+
44
+ describe('Other existing constants still exported correctly', () => {
45
+ it('should export LOYALTY', () => {
46
+ expect(LOYALTY).toBe('loyalty');
47
+ });
48
+
49
+ it('should export FAILURE', () => {
50
+ expect(FAILURE).toBe('FAILURE');
51
+ });
52
+
53
+ it('should export DATE_DISPLAY_FORMAT', () => {
54
+ expect(DATE_DISPLAY_FORMAT).toBe('D MMM YYYY');
55
+ });
56
+
57
+ it('should export TIME_DISPLAY_FORMAT', () => {
58
+ expect(TIME_DISPLAY_FORMAT).toBe('hh:mm A');
59
+ });
60
+ });
61
+ });
@@ -104,6 +104,9 @@ import {
104
104
  VIBER as VIBER_CHANNEL,
105
105
  FACEBOOK as FACEBOOK_CHANNEL,
106
106
  CREATE,
107
+ EXTERNAL_URL,
108
+ URL,
109
+ SITE_URL,
107
110
  } from '../App/constants';
108
111
  import {MAX_WHATSAPP_TEMPLATES, WARNING_WHATSAPP_TEMPLATES , ACCOUNT_MAPPING_ON_CHANNEL, noFilteredWhatsappZaloTemplatesTitle, noFilteredWhatsappZaloTemplatesDesc, noApprovedWhatsappZaloTemplatesTitle, noApprovedWhatsappTemplatesDesc, zaloDescIllustration, noApprovedRcsTemplatesTitle, noApprovedRcsTemplatesDesc, ARCHIVE_STATUS_ACTIVE, ARCHIVE_STATUS_ARCHIVED, ARCHIVE_REFRESH_TYPE_ARCHIVE, ARCHIVE_REFRESH_TYPE_UNARCHIVE} from './constants';
109
112
  import { COPY_OF, EMBEDDED } from '../../constants/unified';
@@ -1399,6 +1402,73 @@ export class Templates extends React.Component { // eslint-disable-line react/pr
1399
1402
  };
1400
1403
  }
1401
1404
 
1405
+ case WEBPUSH: {
1406
+ // WebPush content is stored in creatives format (brandIcon, onClickAction, ctas)
1407
+ // Must be transformed to campaign/test-message format matching getTemplateContent() in WebPush/Create/index.js
1408
+ const webpushContent = get(baseContent, 'content.webpush', {});
1409
+ const {
1410
+ title = '',
1411
+ message = '',
1412
+ brandIcon,
1413
+ iconImageUrl: existingIconImageUrl,
1414
+ onClickAction,
1415
+ cta: existingCta,
1416
+ image,
1417
+ ctas: rawCtas,
1418
+ expandableDetails: existingExpandable,
1419
+ } = webpushContent;
1420
+ const accountId = get(template, 'definition.accountId', null);
1421
+ const templateName = template?.name || '';
1422
+
1423
+ // iconImageUrl stored as brandIcon in creatives format
1424
+ const iconImageUrl = brandIcon || existingIconImageUrl || undefined;
1425
+
1426
+ // cta stored as onClickAction in creatives format (type: URL|SITE_URL, url)
1427
+ // or already as cta in campaign format (type: EXTERNAL_URL|SITE_URL, actionLink)
1428
+ let cta = null;
1429
+ if (onClickAction) {
1430
+ const ctaType = onClickAction.type === URL ? EXTERNAL_URL : (onClickAction.type || SITE_URL);
1431
+ cta = { type: ctaType, actionLink: onClickAction.url || '' };
1432
+ } else if (existingCta) {
1433
+ cta = { type: existingCta.type || EXTERNAL_URL, actionLink: existingCta.actionLink || '' };
1434
+ }
1435
+
1436
+ // expandableDetails: image → media[], ctas[] → mapped ctas
1437
+ let expandableDetails = null;
1438
+ const hasImage = !!image;
1439
+ const hasCtas = Array.isArray(rawCtas) && rawCtas.length > 0;
1440
+ if (hasImage || hasCtas) {
1441
+ expandableDetails = {
1442
+ media: hasImage ? [{ url: image, type: IMAGE }] : [],
1443
+ ctas: hasCtas ? rawCtas.map((ctaItem) => ({
1444
+ type: ctaItem?.type === URL ? EXTERNAL_URL : (ctaItem?.type || EXTERNAL_URL),
1445
+ action: ctaItem?.action || '',
1446
+ title: ctaItem?.actionText || ctaItem?.title || '',
1447
+ actionLink: ctaItem?.actionLink || '',
1448
+ })) : [],
1449
+ };
1450
+ } else if (existingExpandable) {
1451
+ expandableDetails = {
1452
+ media: existingExpandable?.media || [],
1453
+ ctas: existingExpandable?.ctas || [],
1454
+ };
1455
+ }
1456
+
1457
+ return {
1458
+ channel: WEBPUSH,
1459
+ accountId,
1460
+ content: {
1461
+ title,
1462
+ message,
1463
+ ...(iconImageUrl ? { iconImageUrl } : {}),
1464
+ ...(cta ? { cta } : {}),
1465
+ ...(expandableDetails ? { expandableDetails } : {}),
1466
+ },
1467
+ messageSubject: templateName || title,
1468
+ offers: [],
1469
+ };
1470
+ }
1471
+
1402
1472
  default:
1403
1473
  console.warn(`Unsupported channel for content extraction: ${channelUpper}`);
1404
1474
  return null;
@@ -1411,7 +1481,7 @@ export class Templates extends React.Component { // eslint-disable-line react/pr
1411
1481
  * @returns {Boolean} - True if channel supports Test and Preview
1412
1482
  */
1413
1483
  isTestAndPreviewSupported = () => {
1414
- const supportedChannels = [EMAIL, SMS, INAPP, MOBILE_PUSH, VIBER, ZALO];
1484
+ const supportedChannels = [EMAIL, SMS, INAPP, MOBILE_PUSH, VIBER, ZALO, WEBPUSH];
1415
1485
  return supportedChannels.includes(this.state.channel.toUpperCase());
1416
1486
  }
1417
1487
 
@@ -1971,7 +2041,7 @@ export class Templates extends React.Component { // eslint-disable-line react/pr
1971
2041
  // Show preview icon only for channels that don't support Test and Preview
1972
2042
  (() => {
1973
2043
  // Channels that have Test and Preview integrated
1974
- const testAndPreviewChannels = [EMAIL, SMS, WHATSAPP, RCS, INAPP, MOBILE_PUSH, VIBER, ZALO];
2044
+ const testAndPreviewChannels = [EMAIL, SMS, WHATSAPP, RCS, INAPP, MOBILE_PUSH, VIBER, ZALO, WEBPUSH];
1975
2045
  const isTestAndPreviewSupported = testAndPreviewChannels.includes(currentChannel.toUpperCase());
1976
2046
 
1977
2047
  // Don't show preview icon if channel supports Test and Preview
@@ -6,7 +6,7 @@ import { CapNotification } from '@capillarytech/cap-ui-library';
6
6
  // import { schema, normalize } from 'normalizr';
7
7
  import * as Api from '../../services/api';
8
8
  import * as types from './constants';
9
- import { saveCdnConfigs, removeAllCdnLocalStorageItems, initCdnConfigFromEnv } from '../../utils/cdnTransformation';
9
+ import { saveCdnConfigs, removeAllCdnLocalStorageItems } from '../../utils/cdnTransformation';
10
10
  import { COPY_OF } from '../../constants/unified';
11
11
  import { ZALO_TEMPLATE_INFO_REQUEST } from '../Zalo/constants';
12
12
  import { getTemplateInfoById } from '../Zalo/saga';
@@ -107,11 +107,6 @@ export function* getOrgLevelCampaignSettings() {
107
107
 
108
108
  export function* getCdnTransformationConfig() {
109
109
  try {
110
- // VAPT CAP-183204: prefer env vars injected via window.APP_ENV — avoids the
111
- // API response that leaked CDN/S3 infrastructure details. Fallback to API
112
- // keeps clusters that haven't received the env vars yet working during rollout.
113
- if (initCdnConfigFromEnv()) return;
114
-
115
110
  const res = yield call(Api.getCdnTransformationConfig);
116
111
  if (res?.success && res?.status?.code === 200) {
117
112
  const cdnConfigs = res?.response;