@capillarytech/creatives-library 8.0.353-alpha.2 → 8.0.353-alpha.5
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/package.json +1 -1
- package/v2Components/CommonTestAndPreview/UnifiedPreview/PreviewHeader.js +17 -0
- package/v2Components/CommonTestAndPreview/UnifiedPreview/WebPushPreviewContent.js +169 -0
- package/v2Components/CommonTestAndPreview/UnifiedPreview/_unifiedPreview.scss +70 -0
- package/v2Components/CommonTestAndPreview/UnifiedPreview/index.js +44 -5
- package/v2Components/CommonTestAndPreview/constants.js +2 -0
- package/v2Components/CommonTestAndPreview/index.js +51 -2
- package/v2Components/CommonTestAndPreview/tests/UnifiedPreview/PreviewHeader.test.js +159 -0
- package/v2Components/CommonTestAndPreview/tests/UnifiedPreview/WebPushPreviewContent.test.js +522 -0
- package/v2Components/CommonTestAndPreview/tests/UnifiedPreview/index.test.js +255 -0
- package/v2Components/CommonTestAndPreview/tests/constants.test.js +2 -1
- package/v2Components/CommonTestAndPreview/tests/index.test.js +194 -0
- package/v2Components/FormBuilder/index.js +10 -48
- package/v2Components/TestAndPreviewSlidebox/index.js +2 -2
- package/v2Containers/App/constants.js +3 -0
- package/v2Containers/App/tests/constants.test.js +61 -0
- package/v2Containers/CreativesContainer/index.js +25 -61
- package/v2Containers/Email/index.js +2 -33
- package/v2Containers/Templates/index.js +68 -2
- package/v2Containers/Templates/tests/webpush.test.js +375 -0
- package/v2Containers/WebPush/Create/index.js +91 -8
- package/v2Containers/WebPush/Create/index.scss +7 -0
- package/v2Containers/WebPush/Create/tests/getTemplateContent.test.js +338 -0
- 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', () => {
|
|
@@ -382,12 +382,7 @@ class FormBuilder extends React.Component { // eslint-disable-line react/prefer-
|
|
|
382
382
|
this.setState({formData: nextProps.formData, tabCount: nextProps.tabCount});
|
|
383
383
|
// this.resetTabKeys(nextProps.formData, nextProps.tabCount);
|
|
384
384
|
} else if (this.props.schema && this.props.schema.channel && this.props.schema.channel.toUpperCase() === 'EMAIL') {
|
|
385
|
-
|
|
386
|
-
// already updated them via updateFieldValueImmediately, so overwriting here
|
|
387
|
-
// would cause a redundant full re-render ~300ms after every keystroke.
|
|
388
|
-
if (!this._isOnlyHighFreqUpdate(nextProps.formData, this.state.formData)) {
|
|
389
|
-
this.setState({formData: nextProps.formData});
|
|
390
|
-
}
|
|
385
|
+
this.setState({formData: nextProps.formData});
|
|
391
386
|
}
|
|
392
387
|
|
|
393
388
|
if (this.state.usingTabContainer && this.state.tabKey === '') {
|
|
@@ -428,24 +423,14 @@ class FormBuilder extends React.Component { // eslint-disable-line react/prefer-
|
|
|
428
423
|
( !this.state.usingTabContainer || (this.state.usingTabContainer && nextProps.tabKey !== ''))
|
|
429
424
|
&& !_.isEqual(nextProps.formData, this.state.formData) &&
|
|
430
425
|
!_.isEqual(nextProps.formData, this.props.formData)) {
|
|
431
|
-
//
|
|
432
|
-
|
|
433
|
-
|
|
434
|
-
|
|
435
|
-
|
|
436
|
-
|
|
437
|
-
|
|
438
|
-
|
|
439
|
-
if (!isEmailHighFreqOnly) {
|
|
440
|
-
// Don't run validation if we're in Test & Preview mode
|
|
441
|
-
if (!nextProps.isTestAndPreviewMode) {
|
|
442
|
-
this.setState({formData: nextProps.formData, tabKey: nextProps.tabKey}, () => {
|
|
443
|
-
this.validateForm();
|
|
444
|
-
});
|
|
445
|
-
} else {
|
|
446
|
-
// Just update formData without validation
|
|
447
|
-
this.setState({formData: nextProps.formData, tabKey: nextProps.tabKey});
|
|
448
|
-
}
|
|
426
|
+
// Don't run validation if we're in Test & Preview mode
|
|
427
|
+
if (!nextProps.isTestAndPreviewMode) {
|
|
428
|
+
this.setState({formData: nextProps.formData, tabKey: nextProps.tabKey}, () => {
|
|
429
|
+
this.validateForm();
|
|
430
|
+
});
|
|
431
|
+
} else {
|
|
432
|
+
// Just update formData without validation
|
|
433
|
+
this.setState({formData: nextProps.formData, tabKey: nextProps.tabKey});
|
|
449
434
|
}
|
|
450
435
|
//this.resetTabKeys(nextProps.formData, nextProps.tabCount);
|
|
451
436
|
} else if ((_.isEmpty(this.props.formData) || !this.props.formData) && _.isEmpty(this.state.formData)) {
|
|
@@ -463,16 +448,7 @@ class FormBuilder extends React.Component { // eslint-disable-line react/prefer-
|
|
|
463
448
|
this.setState({currentTab: nextProps.currentTab});
|
|
464
449
|
}
|
|
465
450
|
|
|
466
|
-
|
|
467
|
-
// and the setState + validateForm cascade triggered by every debounced keystroke.
|
|
468
|
-
const isEmailHighFreqOnly = (
|
|
469
|
-
!_.isEmpty(nextProps.formData) &&
|
|
470
|
-
this.props.schema &&
|
|
471
|
-
this.props.schema.channel &&
|
|
472
|
-
this.props.schema.channel.toUpperCase() === 'EMAIL' &&
|
|
473
|
-
this._isOnlyHighFreqUpdate(nextProps.formData, this.state.formData)
|
|
474
|
-
);
|
|
475
|
-
if (!isEmailHighFreqOnly && !_.isEmpty(nextProps.formData) && !_.isEqual(this.state.formData, nextProps.formData)) {
|
|
451
|
+
if (!_.isEmpty(nextProps.formData) && !_.isEqual(this.state.formData, nextProps.formData)) {
|
|
476
452
|
if (nextProps.isNewVersionFlow) {
|
|
477
453
|
const tabKey = (this.state.tabKey !== nextProps.formData[nextProps.currentTab - 1].tabKey) ? nextProps.formData[nextProps.currentTab - 1].tabKey : this.state.tabKey;
|
|
478
454
|
|
|
@@ -2205,20 +2181,6 @@ class FormBuilder extends React.Component { // eslint-disable-line react/prefer-
|
|
|
2205
2181
|
this.debouncedUpdateFormData(data, val, event, true);
|
|
2206
2182
|
}
|
|
2207
2183
|
|
|
2208
|
-
// Returns true when the only differences between newData and currentData are
|
|
2209
|
-
// the high-frequency standalone fields (template-name / template-subject).
|
|
2210
|
-
// Uses reference equality for all other keys — safe because shallow spreads in
|
|
2211
|
-
// optimizedFormDataUpdate and updateFieldValueImmediately preserve nested refs.
|
|
2212
|
-
_isOnlyHighFreqUpdate(newData, currentData) {
|
|
2213
|
-
if (!newData || !currentData) return false;
|
|
2214
|
-
// isTemplateNameEdited is set alongside template-name by performTemplateNameUpdate
|
|
2215
|
-
// and treated as a high-freq field so it doesn't break the reference equality check.
|
|
2216
|
-
const HIGH_FREQ_FIELDS = ['template-name', 'template-subject', 'isTemplateNameEdited'];
|
|
2217
|
-
return Object.keys(newData).every(
|
|
2218
|
-
key => HIGH_FREQ_FIELDS.includes(key) || newData[key] === currentData[key]
|
|
2219
|
-
);
|
|
2220
|
-
}
|
|
2221
|
-
|
|
2222
2184
|
// Update field value immediately for UI feedback
|
|
2223
2185
|
updateFieldValueImmediately(data, val) {
|
|
2224
2186
|
const currentFormData = this.state.formData;
|
|
@@ -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
|
+
});
|