@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.
Files changed (147) hide show
  1. package/constants/unified.js +29 -0
  2. package/index.html +1 -0
  3. package/package.json +1 -1
  4. package/services/tests/api.test.js +35 -20
  5. package/utils/cdnTransformation.js +75 -3
  6. package/utils/commonUtils.js +19 -1
  7. package/utils/rcsPayloadUtils.js +92 -0
  8. package/utils/templateVarUtils.js +201 -0
  9. package/utils/tests/cdnTransformation.test.js +127 -0
  10. package/utils/tests/rcsPayloadUtils.test.js +226 -0
  11. package/utils/tests/templateVarUtils.test.js +204 -0
  12. package/v2Components/CapActionButton/constants.js +7 -0
  13. package/v2Components/CapActionButton/index.js +166 -108
  14. package/v2Components/CapActionButton/index.scss +157 -6
  15. package/v2Components/CapActionButton/messages.js +19 -3
  16. package/v2Components/CapActionButton/tests/index.test.js +41 -17
  17. package/v2Components/CapImageUpload/index.js +2 -2
  18. package/v2Components/CapTagList/index.js +10 -0
  19. package/v2Components/CommonTestAndPreview/CustomValuesEditor.js +72 -49
  20. package/v2Components/CommonTestAndPreview/DeliverySettings/DeliverySettings.scss +8 -2
  21. package/v2Components/CommonTestAndPreview/DeliverySettings/ModifyDeliverySettings.js +214 -21
  22. package/v2Components/CommonTestAndPreview/DeliverySettings/constants.js +16 -0
  23. package/v2Components/CommonTestAndPreview/DeliverySettings/index.js +83 -9
  24. package/v2Components/CommonTestAndPreview/DeliverySettings/messages.js +30 -0
  25. package/v2Components/CommonTestAndPreview/DeliverySettings/utils/parseSenderDetailsResponse.js +79 -11
  26. package/v2Components/CommonTestAndPreview/SendTestMessage.js +10 -5
  27. package/v2Components/CommonTestAndPreview/UnifiedPreview/PreviewHeader.js +16 -0
  28. package/v2Components/CommonTestAndPreview/UnifiedPreview/RcsPreviewContent.js +157 -15
  29. package/v2Components/CommonTestAndPreview/UnifiedPreview/ViberPreviewContent.js +14 -132
  30. package/v2Components/CommonTestAndPreview/UnifiedPreview/WebPushPreviewContent.js +169 -0
  31. package/v2Components/CommonTestAndPreview/UnifiedPreview/_unifiedPreview.scss +400 -239
  32. package/v2Components/CommonTestAndPreview/UnifiedPreview/index.js +202 -10
  33. package/v2Components/CommonTestAndPreview/_commonTestAndPreview.scss +11 -0
  34. package/v2Components/CommonTestAndPreview/constants.js +40 -2
  35. package/v2Components/CommonTestAndPreview/index.js +887 -453
  36. package/v2Components/CommonTestAndPreview/messages.js +45 -3
  37. package/v2Components/CommonTestAndPreview/previewApiUtils.js +59 -0
  38. package/v2Components/CommonTestAndPreview/sagas.js +25 -6
  39. package/v2Components/CommonTestAndPreview/tests/CustomValuesEditor.test.js +308 -284
  40. package/v2Components/CommonTestAndPreview/tests/DeliverySettings/ModifyDeliverySettings.test.js +231 -65
  41. package/v2Components/CommonTestAndPreview/tests/DeliverySettings/index.test.js +118 -5
  42. package/v2Components/CommonTestAndPreview/tests/DeliverySettings/utils/parseSenderDetailsResponse.test.js +341 -0
  43. package/v2Components/CommonTestAndPreview/tests/PreviewSection.test.js +8 -1
  44. package/v2Components/CommonTestAndPreview/tests/SendTestMessage.test.js +34 -13
  45. package/v2Components/CommonTestAndPreview/tests/UnifiedPreview/PreviewHeader.test.js +163 -0
  46. package/v2Components/CommonTestAndPreview/tests/UnifiedPreview/RcsPreviewContent.test.js +281 -283
  47. package/v2Components/CommonTestAndPreview/tests/UnifiedPreview/ViberPreviewContent.test.js +0 -364
  48. package/v2Components/CommonTestAndPreview/tests/UnifiedPreview/WebPushPreviewContent.test.js +522 -0
  49. package/v2Components/CommonTestAndPreview/tests/UnifiedPreview/index.test.js +454 -1
  50. package/v2Components/CommonTestAndPreview/tests/constants.test.js +2 -1
  51. package/v2Components/CommonTestAndPreview/tests/index.test.js +327 -4
  52. package/v2Components/CommonTestAndPreview/tests/previewApiUtils.test.js +67 -0
  53. package/v2Components/CommonTestAndPreview/tests/sagas.test.js +31 -24
  54. package/v2Components/FormBuilder/index.js +167 -56
  55. package/v2Components/SmsFallback/SmsFallbackLocalSelector.js +91 -0
  56. package/v2Components/SmsFallback/constants.js +73 -0
  57. package/v2Components/SmsFallback/index.js +956 -0
  58. package/v2Components/SmsFallback/index.scss +265 -0
  59. package/v2Components/SmsFallback/messages.js +78 -0
  60. package/v2Components/SmsFallback/smsFallbackUtils.js +119 -0
  61. package/v2Components/SmsFallback/tests/SmsFallbackLocalSelector.test.js +50 -0
  62. package/v2Components/SmsFallback/tests/rcsSmsFallback.acceptance.test.js +147 -0
  63. package/v2Components/SmsFallback/tests/smsFallbackHandlers.test.js +304 -0
  64. package/v2Components/SmsFallback/tests/smsFallbackUi.test.js +223 -0
  65. package/v2Components/SmsFallback/tests/smsFallbackUtils.test.js +309 -0
  66. package/v2Components/SmsFallback/tests/useLocalTemplateList.test.js +422 -0
  67. package/v2Components/SmsFallback/useLocalTemplateList.js +92 -0
  68. package/v2Components/TemplatePreview/_templatePreview.scss +37 -22
  69. package/v2Components/TemplatePreview/constants.js +2 -0
  70. package/v2Components/TemplatePreview/index.js +143 -31
  71. package/v2Components/TemplatePreview/tests/index.test.js +142 -0
  72. package/v2Components/TestAndPreviewSlidebox/index.js +15 -3
  73. package/v2Components/TestAndPreviewSlidebox/sagas.js +11 -4
  74. package/v2Components/TestAndPreviewSlidebox/tests/saga.test.js +3 -1
  75. package/v2Components/VarSegmentMessageEditor/constants.js +2 -0
  76. package/v2Components/VarSegmentMessageEditor/index.js +125 -0
  77. package/v2Components/VarSegmentMessageEditor/index.scss +46 -0
  78. package/v2Containers/App/constants.js +3 -0
  79. package/v2Containers/App/tests/constants.test.js +61 -0
  80. package/v2Containers/CreativesContainer/CreativesSlideBoxWrapper.js +17 -0
  81. package/v2Containers/CreativesContainer/SlideBoxContent.js +36 -4
  82. package/v2Containers/CreativesContainer/SlideBoxFooter.js +14 -5
  83. package/v2Containers/CreativesContainer/SlideBoxHeader.js +36 -5
  84. package/v2Containers/CreativesContainer/constants.js +9 -0
  85. package/v2Containers/CreativesContainer/embeddedSlideboxUtils.js +79 -0
  86. package/v2Containers/CreativesContainer/index.js +382 -127
  87. package/v2Containers/CreativesContainer/index.scss +83 -1
  88. package/v2Containers/CreativesContainer/tests/SlideBoxContent.localTemplates.test.js +90 -0
  89. package/v2Containers/CreativesContainer/tests/SlideBoxFooter.test.js +79 -34
  90. package/v2Containers/CreativesContainer/tests/SlideBoxHeader.test.js +79 -16
  91. package/v2Containers/CreativesContainer/tests/__snapshots__/SlideBoxContent.test.js.snap +8 -0
  92. package/v2Containers/CreativesContainer/tests/__snapshots__/SlideBoxHeader.test.js.snap +357 -98
  93. package/v2Containers/CreativesContainer/tests/__snapshots__/index.test.js.snap +20 -15
  94. package/v2Containers/CreativesContainer/tests/embeddedSlideboxUtils.test.js +258 -0
  95. package/v2Containers/CreativesContainer/tests/index.test.js +71 -9
  96. package/v2Containers/CreativesContainer/tests/useLocalTemplatesProp.test.js +125 -0
  97. package/v2Containers/MobilePush/Create/test/saga.test.js +2 -2
  98. package/v2Containers/Rcs/constants.js +120 -11
  99. package/v2Containers/Rcs/index.js +2577 -812
  100. package/v2Containers/Rcs/index.scss +281 -8
  101. package/v2Containers/Rcs/messages.js +34 -3
  102. package/v2Containers/Rcs/rcsLibraryHydrationUtils.js +225 -0
  103. package/v2Containers/Rcs/tests/__snapshots__/index.test.js.snap +98036 -70145
  104. package/v2Containers/Rcs/tests/__snapshots__/utils.test.js.snap +0 -5
  105. package/v2Containers/Rcs/tests/index.test.js +152 -121
  106. package/v2Containers/Rcs/tests/mockData.js +38 -0
  107. package/v2Containers/Rcs/tests/rcsLibraryHydrationUtils.test.js +318 -0
  108. package/v2Containers/Rcs/tests/utils.test.js +646 -30
  109. package/v2Containers/Rcs/utils.js +478 -11
  110. package/v2Containers/Sms/Create/index.js +106 -40
  111. package/v2Containers/Sms/smsFormDataHelpers.js +67 -0
  112. package/v2Containers/Sms/tests/smsFormDataHelpers.test.js +253 -0
  113. package/v2Containers/SmsTrai/Create/index.js +9 -4
  114. package/v2Containers/SmsTrai/Edit/constants.js +2 -0
  115. package/v2Containers/SmsTrai/Edit/index.js +640 -130
  116. package/v2Containers/SmsTrai/Edit/index.scss +121 -0
  117. package/v2Containers/SmsTrai/Edit/messages.js +14 -4
  118. package/v2Containers/SmsTrai/Edit/tests/__snapshots__/index.test.js.snap +4328 -2375
  119. package/v2Containers/SmsWrapper/index.js +37 -8
  120. package/v2Containers/TagList/index.js +6 -0
  121. package/v2Containers/Templates/TemplatesActionBar.js +101 -0
  122. package/v2Containers/Templates/_templates.scss +166 -86
  123. package/v2Containers/Templates/actions.js +11 -0
  124. package/v2Containers/Templates/constants.js +2 -0
  125. package/v2Containers/Templates/index.js +203 -145
  126. package/v2Containers/Templates/sagas.js +62 -13
  127. package/v2Containers/Templates/tests/TemplatesActionBar.test.js +120 -0
  128. package/v2Containers/Templates/tests/__snapshots__/index.test.js.snap +1062 -1017
  129. package/v2Containers/Templates/tests/sagas.test.js +222 -22
  130. package/v2Containers/Templates/tests/smsTemplatesListApi.test.js +180 -0
  131. package/v2Containers/Templates/tests/webpush.test.js +375 -0
  132. package/v2Containers/Templates/utils/smsTemplatesListApi.js +79 -0
  133. package/v2Containers/TemplatesV2/TemplatesV2.style.js +72 -1
  134. package/v2Containers/TemplatesV2/index.js +86 -23
  135. package/v2Containers/TemplatesV2/tests/TemplatesV2.localTemplates.test.js +131 -0
  136. package/v2Containers/Viber/constants.js +0 -19
  137. package/v2Containers/Viber/index.js +47 -714
  138. package/v2Containers/Viber/index.scss +0 -148
  139. package/v2Containers/Viber/messages.js +0 -116
  140. package/v2Containers/Viber/tests/index.test.js +0 -80
  141. package/v2Containers/WeChat/MapTemplates/test/saga.test.js +9 -9
  142. package/v2Containers/WebPush/Create/index.js +91 -8
  143. package/v2Containers/WebPush/Create/index.scss +7 -0
  144. package/v2Containers/WebPush/Create/tests/getTemplateContent.test.js +348 -0
  145. package/v2Containers/WebPush/Create/tests/testAndPreviewIntegration.test.js +325 -0
  146. package/v2Containers/Whatsapp/index.js +3 -20
  147. package/v2Containers/Whatsapp/tests/__snapshots__/index.test.js.snap +578 -34
@@ -30,23 +30,28 @@ jest.mock('@capillarytech/cap-ui-library/CapNotification', () => ({
30
30
  }));
31
31
 
32
32
  // Mock child components - must use React.createElement to avoid hoisting issues
33
+ let lastLeftPanelContentProps = null;
33
34
  jest.mock('../LeftPanelContent', () => {
34
35
  // eslint-disable-next-line global-require, import/no-extraneous-dependencies
35
36
  const ReactLib = require('react');
36
37
  return {
37
38
  __esModule: true,
38
- default: function MockLeftPanelContent() {
39
- return ReactLib.createElement('div', { 'data-testid': 'left-panel' }, 'Left Panel');
39
+ default: function MockLeftPanelContent(props) {
40
+ lastLeftPanelContentProps = props;
41
+ const editorEl = props.renderCustomValuesEditor ? props.renderCustomValuesEditor() : null;
42
+ return ReactLib.createElement('div', { 'data-testid': 'left-panel' }, 'Left Panel', editorEl);
40
43
  },
41
44
  };
42
45
  });
43
46
 
47
+ let lastCustomValuesEditorProps = null;
44
48
  jest.mock('../CustomValuesEditor', () => {
45
49
  // eslint-disable-next-line global-require, import/no-extraneous-dependencies
46
50
  const ReactLib = require('react');
47
51
  return {
48
52
  __esModule: true,
49
- default: function MockCustomValuesEditor() {
53
+ default: function MockCustomValuesEditor(props) {
54
+ lastCustomValuesEditorProps = props;
50
55
  return ReactLib.createElement('div', { 'data-testid': 'custom-values-editor' }, 'Custom Values Editor');
51
56
  },
52
57
  };
@@ -191,6 +196,8 @@ describe('CommonTestAndPreview', () => {
191
196
  beforeEach(() => {
192
197
  jest.clearAllMocks();
193
198
  lastSendTestMessageProps = null;
199
+ lastLeftPanelContentProps = null;
200
+ lastCustomValuesEditorProps = null;
194
201
  // Reset all mock function implementations
195
202
  Object.values(mockActions).forEach((mockFn) => {
196
203
  if (jest.isMockFunction(mockFn)) {
@@ -245,6 +252,25 @@ describe('CommonTestAndPreview', () => {
245
252
  });
246
253
  });
247
254
 
255
+ it('should call getSenderDetailsRequested for RCS and SMS when channel is RCS', async () => {
256
+ render(
257
+ <TestWrapper>
258
+ <CommonTestAndPreview {...defaultProps} channel={CHANNELS.RCS} />
259
+ </TestWrapper>
260
+ );
261
+ await waitFor(() => {
262
+ expect(mockActions.getSenderDetailsRequested).toHaveBeenCalledTimes(2);
263
+ expect(mockActions.getSenderDetailsRequested).toHaveBeenNthCalledWith(1, {
264
+ channel: CHANNELS.RCS,
265
+ orgUnitId: -1,
266
+ });
267
+ expect(mockActions.getSenderDetailsRequested).toHaveBeenNthCalledWith(2, {
268
+ channel: CHANNELS.SMS,
269
+ orgUnitId: -1,
270
+ });
271
+ });
272
+ });
273
+
248
274
  it('should not call getSenderDetailsRequested when channel is INAPP', async () => {
249
275
  render(
250
276
  <TestWrapper>
@@ -303,7 +329,7 @@ describe('CommonTestAndPreview', () => {
303
329
  });
304
330
  expect(lastSendTestMessageProps).toBeDefined();
305
331
  expect(lastSendTestMessageProps.deliverySettings).toBeDefined();
306
- expect(lastSendTestMessageProps.senderDetailsOptions).toEqual(senderDetailsByChannel[CHANNELS.SMS]);
332
+ expect(lastSendTestMessageProps.senderDetailsByChannel).toEqual(senderDetailsByChannel);
307
333
  expect(lastSendTestMessageProps.wecrmAccounts).toEqual([]);
308
334
  expect(typeof lastSendTestMessageProps.onSaveDeliverySettings).toBe('function');
309
335
  expect(lastSendTestMessageProps.isLoadingSenderDetails).toBe(false);
@@ -1174,6 +1200,50 @@ describe('CommonTestAndPreview', () => {
1174
1200
  expect(screen.getByTestId('preview-section')).toBeTruthy();
1175
1201
  });
1176
1202
  });
1203
+
1204
+ it('should handle WEBPUSH channel', async () => {
1205
+ const webpushContent = {
1206
+ content: { title: 'Web Push', message: 'Hello from web push' },
1207
+ accountId: 'acc-001',
1208
+ };
1209
+ const props = {
1210
+ ...defaultProps,
1211
+ channel: CHANNELS.WEBPUSH,
1212
+ content: webpushContent,
1213
+ };
1214
+
1215
+ render(
1216
+ <TestWrapper>
1217
+ <CommonTestAndPreview {...props} />
1218
+ </TestWrapper>
1219
+ );
1220
+
1221
+ await waitFor(() => {
1222
+ expect(screen.getByTestId('left-panel')).toBeTruthy();
1223
+ expect(screen.getByTestId('preview-section')).toBeTruthy();
1224
+ });
1225
+ });
1226
+
1227
+ it('should treat WEBPUSH content as object (same branch as WHATSAPP)', async () => {
1228
+ // The WEBPUSH channel uses the same contentObj branch as WHATSAPP (JSON string or object)
1229
+ const props = {
1230
+ ...defaultProps,
1231
+ channel: CHANNELS.WEBPUSH,
1232
+ content: JSON.stringify({
1233
+ content: { title: 'Stringified', message: 'Content' },
1234
+ }),
1235
+ };
1236
+
1237
+ render(
1238
+ <TestWrapper>
1239
+ <CommonTestAndPreview {...props} />
1240
+ </TestWrapper>
1241
+ );
1242
+
1243
+ await waitFor(() => {
1244
+ expect(screen.getByTestId('preview-section')).toBeTruthy();
1245
+ });
1246
+ });
1177
1247
  });
1178
1248
 
1179
1249
  describe('Device Initialization', () => {
@@ -2629,6 +2699,156 @@ describe('CommonTestAndPreview', () => {
2629
2699
  });
2630
2700
  });
2631
2701
  });
2702
+
2703
+ describe('preparePreviewPayload - WEBPUSH', () => {
2704
+ it('should build WEBPUSH payload with title and message', async () => {
2705
+ const webpushContent = {
2706
+ content: {
2707
+ title: 'Push Title',
2708
+ message: 'Push message body',
2709
+ },
2710
+ accountId: 'acc-123',
2711
+ messageSubject: 'Push Title',
2712
+ };
2713
+ const props = {
2714
+ ...defaultProps,
2715
+ channel: CHANNELS.WEBPUSH,
2716
+ content: JSON.stringify(webpushContent),
2717
+ };
2718
+
2719
+ render(
2720
+ <TestWrapper>
2721
+ <CommonTestAndPreview {...props} />
2722
+ </TestWrapper>
2723
+ );
2724
+
2725
+ await waitFor(() => {
2726
+ expect(screen.getByTestId('left-panel')).toBeTruthy();
2727
+ expect(screen.getByTestId('preview-section')).toBeTruthy();
2728
+ });
2729
+ });
2730
+
2731
+ it('should handle WEBPUSH content with iconImageUrl', async () => {
2732
+ const webpushContent = {
2733
+ content: {
2734
+ title: 'Hello',
2735
+ message: 'World',
2736
+ iconImageUrl: 'https://example.com/icon.png',
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 cta', async () => {
2758
+ const webpushContent = {
2759
+ content: {
2760
+ title: 'Hello',
2761
+ message: 'World',
2762
+ cta: { type: 'EXTERNAL_URL', actionLink: 'https://example.com' },
2763
+ },
2764
+ accountId: 'acc-123',
2765
+ };
2766
+ const props = {
2767
+ ...defaultProps,
2768
+ channel: CHANNELS.WEBPUSH,
2769
+ content: webpushContent,
2770
+ };
2771
+
2772
+ render(
2773
+ <TestWrapper>
2774
+ <CommonTestAndPreview {...props} />
2775
+ </TestWrapper>
2776
+ );
2777
+
2778
+ await waitFor(() => {
2779
+ expect(screen.getByTestId('preview-section')).toBeTruthy();
2780
+ });
2781
+ });
2782
+
2783
+ it('should handle WEBPUSH content with expandableDetails', async () => {
2784
+ const webpushContent = {
2785
+ content: {
2786
+ title: 'Hello',
2787
+ message: 'World',
2788
+ expandableDetails: {
2789
+ media: [{ url: 'https://example.com/image.jpg', type: 'IMAGE' }],
2790
+ ctas: [{ title: 'Click', actionLink: 'https://example.com', type: 'EXTERNAL_URL' }],
2791
+ },
2792
+ },
2793
+ accountId: 'acc-123',
2794
+ };
2795
+ const props = {
2796
+ ...defaultProps,
2797
+ channel: CHANNELS.WEBPUSH,
2798
+ content: webpushContent,
2799
+ };
2800
+
2801
+ render(
2802
+ <TestWrapper>
2803
+ <CommonTestAndPreview {...props} />
2804
+ </TestWrapper>
2805
+ );
2806
+
2807
+ await waitFor(() => {
2808
+ expect(screen.getByTestId('preview-section')).toBeTruthy();
2809
+ });
2810
+ });
2811
+
2812
+ it('should handle WEBPUSH with null formData gracefully', async () => {
2813
+ const props = {
2814
+ ...defaultProps,
2815
+ channel: CHANNELS.WEBPUSH,
2816
+ formData: null,
2817
+ content: null,
2818
+ };
2819
+
2820
+ render(
2821
+ <TestWrapper>
2822
+ <CommonTestAndPreview {...props} />
2823
+ </TestWrapper>
2824
+ );
2825
+
2826
+ await waitFor(() => {
2827
+ expect(screen.getByTestId('preview-section')).toBeTruthy();
2828
+ });
2829
+ });
2830
+
2831
+ it('should handle WEBPUSH channel with object content (non-string)', async () => {
2832
+ const props = {
2833
+ ...defaultProps,
2834
+ channel: CHANNELS.WEBPUSH,
2835
+ content: {
2836
+ content: { title: 'ObjTitle', message: 'ObjMessage' },
2837
+ accountId: 'acc-999',
2838
+ },
2839
+ };
2840
+
2841
+ render(
2842
+ <TestWrapper>
2843
+ <CommonTestAndPreview {...props} />
2844
+ </TestWrapper>
2845
+ );
2846
+
2847
+ await waitFor(() => {
2848
+ expect(screen.getByTestId('preview-section')).toBeTruthy();
2849
+ });
2850
+ });
2851
+ });
2632
2852
  });
2633
2853
 
2634
2854
  describe('Tag Extraction', () => {
@@ -3281,4 +3501,107 @@ describe('CommonTestAndPreview', () => {
3281
3501
  });
3282
3502
  });
3283
3503
  });
3504
+
3505
+ describe('SMS DLT and mustache tag discrimination (smsTemplateHasMustacheTags / buildSyntheticSmsMustacheTags)', () => {
3506
+ it('should return no tags for SMS content that contains only DLT {#var#} tokens', async () => {
3507
+ render(
3508
+ <TestWrapper>
3509
+ <CommonTestAndPreview
3510
+ {...defaultProps}
3511
+ channel={CHANNELS.SMS}
3512
+ formData={{ 0: { 'sms-editor': 'Order {#orderId#} is confirmed' } }}
3513
+ extractedTags={[]}
3514
+ />
3515
+ </TestWrapper>
3516
+ );
3517
+
3518
+ await waitFor(() => expect(lastLeftPanelContentProps).not.toBeNull());
3519
+
3520
+ // smsTemplateHasMustacheTags returns false for DLT-only → extractedTags is []
3521
+ expect(lastLeftPanelContentProps.extractedTags).toEqual([]);
3522
+ });
3523
+
3524
+ it('should build synthetic tags from {{mustache}} tokens, excluding DLT {#var#} tokens', async () => {
3525
+ render(
3526
+ <TestWrapper>
3527
+ <CommonTestAndPreview
3528
+ {...defaultProps}
3529
+ channel={CHANNELS.SMS}
3530
+ formData={{ 0: { 'sms-editor': 'Hi {{name}}, order {#orderId#} shipped' } }}
3531
+ extractedTags={[]}
3532
+ />
3533
+ </TestWrapper>
3534
+ );
3535
+
3536
+ await waitFor(() => expect(lastLeftPanelContentProps).not.toBeNull());
3537
+
3538
+ const tags = lastLeftPanelContentProps.extractedTags;
3539
+ // Only {{name}} should become a tag — {#orderId#} must be excluded
3540
+ expect(tags).toHaveLength(1);
3541
+ expect(tags[0].name).toBe('name');
3542
+ });
3543
+
3544
+ it('should use API-extracted tags when present instead of building synthetic ones', async () => {
3545
+ const apiTags = [{ name: 'firstName', metaData: { userDriven: true }, children: [] }];
3546
+ render(
3547
+ <TestWrapper>
3548
+ <CommonTestAndPreview
3549
+ {...defaultProps}
3550
+ channel={CHANNELS.SMS}
3551
+ formData={{ 0: { 'sms-editor': 'Hi {{firstName}}' } }}
3552
+ extractedTags={apiTags}
3553
+ />
3554
+ </TestWrapper>
3555
+ );
3556
+
3557
+ await waitFor(() => expect(lastLeftPanelContentProps).not.toBeNull());
3558
+
3559
+ // API tags take priority over buildSyntheticSmsMustacheTags
3560
+ expect(lastLeftPanelContentProps.extractedTags).toEqual(apiTags);
3561
+ });
3562
+ });
3563
+
3564
+ describe('handleDiscardCustomValues — preview reset', () => {
3565
+ it('should call updatePreviewRequested when handleDiscardCustomValues is invoked', async () => {
3566
+ render(
3567
+ <TestWrapper>
3568
+ <CommonTestAndPreview
3569
+ {...defaultProps}
3570
+ channel={CHANNELS.SMS}
3571
+ formData={{ 0: { 'sms-editor': 'Hi {{name}}' } }}
3572
+ />
3573
+ </TestWrapper>
3574
+ );
3575
+
3576
+ await waitFor(() => expect(lastCustomValuesEditorProps).not.toBeNull());
3577
+
3578
+ lastCustomValuesEditorProps.handleDiscardCustomValues();
3579
+
3580
+ expect(mockActions.updatePreviewRequested).toHaveBeenCalledTimes(1);
3581
+ });
3582
+
3583
+ it('should call updatePreviewRequested with RCS channel when handleDiscardCustomValues is invoked for RCS with fallback', async () => {
3584
+ render(
3585
+ <TestWrapper>
3586
+ <CommonTestAndPreview
3587
+ {...defaultProps}
3588
+ channel={CHANNELS.RCS}
3589
+ smsFallbackContent={{
3590
+ templateContent: 'Fallback {{name}}',
3591
+ content: 'Fallback {{name}}',
3592
+ }}
3593
+ formData={{}}
3594
+ />
3595
+ </TestWrapper>
3596
+ );
3597
+
3598
+ await waitFor(() => expect(lastCustomValuesEditorProps).not.toBeNull());
3599
+
3600
+ lastCustomValuesEditorProps.handleDiscardCustomValues();
3601
+
3602
+ // updatePreviewRequested is called; syncSmsFallbackPreview (which hits Api directly) is NOT called
3603
+ expect(mockActions.updatePreviewRequested).toHaveBeenCalledTimes(1);
3604
+ });
3605
+ });
3284
3606
  });
3607
+
@@ -0,0 +1,67 @@
1
+ import {
2
+ normalizePreviewApiPayload,
3
+ extractPreviewFromLiquidResponse,
4
+ getSmsFallbackTextForTagExtraction,
5
+ } from '../previewApiUtils';
6
+ import { RCS_SMS_FALLBACK_VAR_MAPPED_PROP } from '../constants';
7
+
8
+ describe('previewApiUtils', () => {
9
+ describe('normalizePreviewApiPayload', () => {
10
+ it('maps messageBody to resolvedBody when resolvedBody is missing', () => {
11
+ expect(normalizePreviewApiPayload({ messageBody: 'Hello' }).resolvedBody).toBe('Hello');
12
+ });
13
+ });
14
+
15
+ describe('extractPreviewFromLiquidResponse', () => {
16
+ it('accepts nested data shape', () => {
17
+ const r = { data: { resolvedBody: 'ok' } };
18
+ expect(extractPreviewFromLiquidResponse(r)).toEqual({ resolvedBody: 'ok' });
19
+ });
20
+
21
+ it('accepts top-level preview (typical SMS)', () => {
22
+ const r = { messageBody: 'sms text' };
23
+ expect(extractPreviewFromLiquidResponse(r)).toMatchObject({
24
+ messageBody: 'sms text',
25
+ resolvedBody: 'sms text',
26
+ });
27
+ });
28
+
29
+ it('returns null when errors array is non-empty', () => {
30
+ expect(extractPreviewFromLiquidResponse({ errors: [{ code: 1 }] })).toBeNull();
31
+ });
32
+ });
33
+
34
+ describe('getSmsFallbackTextForTagExtraction', () => {
35
+ it('returns empty string when context is missing or has no template body', () => {
36
+ expect(getSmsFallbackTextForTagExtraction(null)).toBe('');
37
+ expect(getSmsFallbackTextForTagExtraction({})).toBe('');
38
+ expect(getSmsFallbackTextForTagExtraction({ templateContent: '', content: '' })).toBe('');
39
+ });
40
+
41
+ it('returns raw template when rcsSmsFallbackVarMapped is absent or empty', () => {
42
+ const raw = '{{optout}} {{fullname}} test SMS';
43
+ expect(getSmsFallbackTextForTagExtraction({ templateContent: raw })).toBe(raw);
44
+ expect(getSmsFallbackTextForTagExtraction({
45
+ content: raw,
46
+ [RCS_SMS_FALLBACK_VAR_MAPPED_PROP]: {},
47
+ })).toBe(raw);
48
+ });
49
+
50
+ it('prefers templateContent over content when both are set', () => {
51
+ expect(getSmsFallbackTextForTagExtraction({
52
+ templateContent: 'A',
53
+ content: 'B',
54
+ })).toBe('A');
55
+ });
56
+
57
+ it('applies VarSegment slot map so preview / meta payloads are not stale vs raw template', () => {
58
+ const rawTemplateWithSlots = '{{optout}} tail';
59
+ const rcsSmsFallbackVarMappedSlots = { '{{optout}}_0': 'STOP' };
60
+ const resolvedFallbackText = getSmsFallbackTextForTagExtraction({
61
+ templateContent: rawTemplateWithSlots,
62
+ [RCS_SMS_FALLBACK_VAR_MAPPED_PROP]: rcsSmsFallbackVarMappedSlots,
63
+ });
64
+ expect(resolvedFallbackText).toBe('STOP tail');
65
+ });
66
+ });
67
+ });
@@ -5,7 +5,7 @@
5
5
  */
6
6
 
7
7
  import {
8
- call, put, takeLatest, all,
8
+ call, put, takeLatest, takeEvery, all, take, fork, cancel,
9
9
  } from 'redux-saga/effects';
10
10
  import {
11
11
  searchCustomersSaga,
@@ -1333,9 +1333,26 @@ describe('CommonTestAndPreview Sagas', () => {
1333
1333
  it('should watch for GET_SENDER_DETAILS_REQUESTED', () => {
1334
1334
  const generator = watchGetSenderDetails();
1335
1335
  expect(generator.next().value).toEqual(
1336
- takeLatest('app/CommonTestAndPreview/GET_SENDER_DETAILS_REQUESTED', getSenderDetailsSaga)
1336
+ take('app/CommonTestAndPreview/GET_SENDER_DETAILS_REQUESTED')
1337
+ );
1338
+ const firstAction = {
1339
+ payload: { channel: 'RCS', orgUnitId: 10 },
1340
+ };
1341
+ expect(generator.next(firstAction).value).toEqual(
1342
+ fork(getSenderDetailsSaga, firstAction)
1343
+ );
1344
+ expect(generator.next({ '@@redux-saga/TASK': true }).value).toEqual(
1345
+ take('app/CommonTestAndPreview/GET_SENDER_DETAILS_REQUESTED')
1346
+ );
1347
+ const secondAction = {
1348
+ payload: { channel: 'RCS', orgUnitId: 20 },
1349
+ };
1350
+ expect(generator.next(secondAction).value).toEqual(
1351
+ cancel({ '@@redux-saga/TASK': true })
1352
+ );
1353
+ expect(generator.next().value).toEqual(
1354
+ fork(getSenderDetailsSaga, secondAction)
1337
1355
  );
1338
- expect(generator.next().done).toBe(true);
1339
1356
  });
1340
1357
 
1341
1358
  it('should watch for GET_WECRM_ACCOUNTS_REQUESTED', () => {
@@ -1454,34 +1471,24 @@ describe('CommonTestAndPreview Sagas', () => {
1454
1471
  const action = { payload: {} };
1455
1472
  const generator = getWeCrmAccountsSaga(action);
1456
1473
  generator.next();
1457
- const err = generator.throw(new Error('API failed'));
1458
- expect(err.value).toEqual(
1474
+ const throwResult = generator.throw(new Error('API failed'));
1475
+ expect(throwResult.value).toEqual(
1459
1476
  put({ type: GET_WECRM_ACCOUNTS_FAILURE, payload: { error: 'API failed' } })
1460
1477
  );
1461
1478
  expect(generator.next().done).toBe(true);
1462
1479
  });
1463
1480
  });
1464
1481
 
1465
- describe('commonTestAndPreviewSaga', () => {
1466
- it('should fork all watcher sagas', () => {
1467
- const generator = commonTestAndPreviewSaga();
1482
+ it('should initialize all watcher sagas', () => {
1483
+ const generator = commonTestAndPreviewSaga();
1468
1484
 
1469
- expect(generator.next().value).toEqual(
1470
- all([
1471
- watchSearchCustomers(),
1472
- watchExtractTags(),
1473
- watchUpdatePreview(),
1474
- watchSendTestMessage(),
1475
- watchFetchTestCustomers(),
1476
- watchFetchTestGroups(),
1477
- watchCreateMessageMeta(),
1478
- watchGetPrefilledValues(),
1479
- watchGetSenderDetails(),
1480
- watchGetWeCrmAccounts(),
1481
- ])
1482
- );
1485
+ const effect = generator.next().value;
1483
1486
 
1484
- expect(generator.next().done).toBe(true);
1485
- });
1487
+ // redux-saga v0.x stores the array under effect[ALL] key; v1.x uses effect.payload
1488
+ const effectData = effect?.payload || effect?.ALL;
1489
+ const watchers = Array.isArray(effectData) ? effectData : Object.values(effectData || {});
1490
+ expect(Array.isArray(watchers)).toBe(true);
1491
+ expect(watchers.length).toBeGreaterThan(0);
1492
+ expect(generator.next().done).toBe(true);
1486
1493
  });
1487
1494
  });