@capillarytech/creatives-library 8.0.353-alpha.6 → 8.0.354

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 (127) hide show
  1. package/constants/unified.js +0 -29
  2. package/index.html +1 -0
  3. package/package.json +1 -1
  4. package/services/tests/api.test.js +20 -35
  5. package/utils/cdnTransformation.js +63 -3
  6. package/utils/commonUtils.js +1 -19
  7. package/utils/tests/cdnTransformation.test.js +111 -0
  8. package/v2Components/CapActionButton/constants.js +0 -7
  9. package/v2Components/CapActionButton/index.js +108 -166
  10. package/v2Components/CapActionButton/index.scss +6 -157
  11. package/v2Components/CapActionButton/messages.js +3 -19
  12. package/v2Components/CapActionButton/tests/index.test.js +17 -41
  13. package/v2Components/CapTagList/index.js +0 -10
  14. package/v2Components/CommonTestAndPreview/CustomValuesEditor.js +49 -72
  15. package/v2Components/CommonTestAndPreview/DeliverySettings/DeliverySettings.scss +2 -8
  16. package/v2Components/CommonTestAndPreview/DeliverySettings/ModifyDeliverySettings.js +21 -213
  17. package/v2Components/CommonTestAndPreview/DeliverySettings/constants.js +0 -16
  18. package/v2Components/CommonTestAndPreview/DeliverySettings/index.js +10 -85
  19. package/v2Components/CommonTestAndPreview/DeliverySettings/messages.js +0 -30
  20. package/v2Components/CommonTestAndPreview/DeliverySettings/utils/parseSenderDetailsResponse.js +11 -79
  21. package/v2Components/CommonTestAndPreview/SendTestMessage.js +5 -10
  22. package/v2Components/CommonTestAndPreview/UnifiedPreview/RcsPreviewContent.js +15 -157
  23. package/v2Components/CommonTestAndPreview/UnifiedPreview/_unifiedPreview.scss +76 -346
  24. package/v2Components/CommonTestAndPreview/UnifiedPreview/index.js +4 -133
  25. package/v2Components/CommonTestAndPreview/_commonTestAndPreview.scss +0 -11
  26. package/v2Components/CommonTestAndPreview/constants.js +2 -38
  27. package/v2Components/CommonTestAndPreview/index.js +186 -691
  28. package/v2Components/CommonTestAndPreview/messages.js +3 -45
  29. package/v2Components/CommonTestAndPreview/sagas.js +6 -25
  30. package/v2Components/CommonTestAndPreview/tests/CustomValuesEditor.test.js +284 -308
  31. package/v2Components/CommonTestAndPreview/tests/DeliverySettings/ModifyDeliverySettings.test.js +65 -231
  32. package/v2Components/CommonTestAndPreview/tests/DeliverySettings/index.test.js +5 -118
  33. package/v2Components/CommonTestAndPreview/tests/DeliverySettings/utils/parseSenderDetailsResponse.test.js +0 -341
  34. package/v2Components/CommonTestAndPreview/tests/PreviewSection.test.js +1 -8
  35. package/v2Components/CommonTestAndPreview/tests/SendTestMessage.test.js +13 -34
  36. package/v2Components/CommonTestAndPreview/tests/UnifiedPreview/RcsPreviewContent.test.js +283 -281
  37. package/v2Components/CommonTestAndPreview/tests/UnifiedPreview/index.test.js +1 -199
  38. package/v2Components/CommonTestAndPreview/tests/index.test.js +4 -132
  39. package/v2Components/CommonTestAndPreview/tests/sagas.test.js +26 -36
  40. package/v2Components/FormBuilder/index.js +6 -11
  41. package/v2Components/TemplatePreview/_templatePreview.scss +23 -38
  42. package/v2Components/TemplatePreview/index.js +31 -143
  43. package/v2Components/TemplatePreview/tests/index.test.js +0 -142
  44. package/v2Components/TestAndPreviewSlidebox/index.js +1 -13
  45. package/v2Components/TestAndPreviewSlidebox/sagas.js +4 -11
  46. package/v2Components/TestAndPreviewSlidebox/tests/saga.test.js +1 -3
  47. package/v2Containers/CreativesContainer/SlideBoxContent.js +4 -36
  48. package/v2Containers/CreativesContainer/SlideBoxFooter.js +1 -10
  49. package/v2Containers/CreativesContainer/SlideBoxHeader.js +4 -29
  50. package/v2Containers/CreativesContainer/constants.js +0 -9
  51. package/v2Containers/CreativesContainer/index.js +103 -322
  52. package/v2Containers/CreativesContainer/index.scss +1 -51
  53. package/v2Containers/CreativesContainer/tests/SlideBoxFooter.test.js +34 -78
  54. package/v2Containers/CreativesContainer/tests/SlideBoxHeader.test.js +16 -79
  55. package/v2Containers/CreativesContainer/tests/__snapshots__/SlideBoxContent.test.js.snap +0 -8
  56. package/v2Containers/CreativesContainer/tests/__snapshots__/SlideBoxHeader.test.js.snap +98 -357
  57. package/v2Containers/CreativesContainer/tests/__snapshots__/index.test.js.snap +15 -20
  58. package/v2Containers/CreativesContainer/tests/index.test.js +9 -71
  59. package/v2Containers/MobilePush/Create/test/saga.test.js +2 -2
  60. package/v2Containers/Rcs/constants.js +10 -119
  61. package/v2Containers/Rcs/index.js +818 -2450
  62. package/v2Containers/Rcs/index.scss +8 -280
  63. package/v2Containers/Rcs/messages.js +3 -34
  64. package/v2Containers/Rcs/tests/__snapshots__/index.test.js.snap +70073 -98018
  65. package/v2Containers/Rcs/tests/__snapshots__/utils.test.js.snap +5 -0
  66. package/v2Containers/Rcs/tests/index.test.js +121 -152
  67. package/v2Containers/Rcs/tests/mockData.js +0 -38
  68. package/v2Containers/Rcs/tests/utils.test.js +30 -646
  69. package/v2Containers/Rcs/utils.js +11 -478
  70. package/v2Containers/Sms/Create/index.js +40 -106
  71. package/v2Containers/SmsTrai/Create/index.js +4 -9
  72. package/v2Containers/SmsTrai/Edit/constants.js +0 -2
  73. package/v2Containers/SmsTrai/Edit/index.js +130 -640
  74. package/v2Containers/SmsTrai/Edit/messages.js +4 -14
  75. package/v2Containers/SmsTrai/Edit/tests/__snapshots__/index.test.js.snap +2296 -4249
  76. package/v2Containers/SmsWrapper/index.js +8 -37
  77. package/v2Containers/TagList/index.js +0 -6
  78. package/v2Containers/Templates/_templates.scss +9 -166
  79. package/v2Containers/Templates/actions.js +0 -11
  80. package/v2Containers/Templates/constants.js +0 -2
  81. package/v2Containers/Templates/index.js +52 -120
  82. package/v2Containers/Templates/sagas.js +18 -57
  83. package/v2Containers/Templates/tests/__snapshots__/index.test.js.snap +1017 -1062
  84. package/v2Containers/Templates/tests/sagas.test.js +39 -205
  85. package/v2Containers/TemplatesV2/TemplatesV2.style.js +1 -72
  86. package/v2Containers/TemplatesV2/index.js +23 -86
  87. package/v2Containers/WeChat/MapTemplates/test/saga.test.js +9 -9
  88. package/v2Containers/Whatsapp/index.js +20 -3
  89. package/v2Containers/Whatsapp/tests/__snapshots__/index.test.js.snap +34 -578
  90. package/utils/rcsPayloadUtils.js +0 -92
  91. package/utils/templateVarUtils.js +0 -201
  92. package/utils/tests/rcsPayloadUtils.test.js +0 -226
  93. package/utils/tests/templateVarUtils.test.js +0 -204
  94. package/v2Components/CommonTestAndPreview/previewApiUtils.js +0 -59
  95. package/v2Components/CommonTestAndPreview/tests/previewApiUtils.test.js +0 -67
  96. package/v2Components/SmsFallback/SmsFallbackLocalSelector.js +0 -91
  97. package/v2Components/SmsFallback/constants.js +0 -73
  98. package/v2Components/SmsFallback/index.js +0 -956
  99. package/v2Components/SmsFallback/index.scss +0 -265
  100. package/v2Components/SmsFallback/messages.js +0 -78
  101. package/v2Components/SmsFallback/smsFallbackUtils.js +0 -119
  102. package/v2Components/SmsFallback/tests/SmsFallbackLocalSelector.test.js +0 -50
  103. package/v2Components/SmsFallback/tests/rcsSmsFallback.acceptance.test.js +0 -147
  104. package/v2Components/SmsFallback/tests/smsFallbackHandlers.test.js +0 -304
  105. package/v2Components/SmsFallback/tests/smsFallbackUi.test.js +0 -223
  106. package/v2Components/SmsFallback/tests/smsFallbackUtils.test.js +0 -309
  107. package/v2Components/SmsFallback/tests/useLocalTemplateList.test.js +0 -422
  108. package/v2Components/SmsFallback/useLocalTemplateList.js +0 -92
  109. package/v2Components/TemplatePreview/constants.js +0 -2
  110. package/v2Components/VarSegmentMessageEditor/constants.js +0 -2
  111. package/v2Components/VarSegmentMessageEditor/index.js +0 -125
  112. package/v2Components/VarSegmentMessageEditor/index.scss +0 -46
  113. package/v2Containers/CreativesContainer/CreativesSlideBoxWrapper.js +0 -43
  114. package/v2Containers/CreativesContainer/embeddedSlideboxUtils.js +0 -79
  115. package/v2Containers/CreativesContainer/tests/SlideBoxContent.localTemplates.test.js +0 -90
  116. package/v2Containers/CreativesContainer/tests/embeddedSlideboxUtils.test.js +0 -258
  117. package/v2Containers/CreativesContainer/tests/useLocalTemplatesProp.test.js +0 -125
  118. package/v2Containers/Rcs/rcsLibraryHydrationUtils.js +0 -225
  119. package/v2Containers/Rcs/tests/rcsLibraryHydrationUtils.test.js +0 -318
  120. package/v2Containers/Sms/smsFormDataHelpers.js +0 -67
  121. package/v2Containers/Sms/tests/smsFormDataHelpers.test.js +0 -253
  122. package/v2Containers/SmsTrai/Edit/index.scss +0 -121
  123. package/v2Containers/Templates/TemplatesActionBar.js +0 -101
  124. package/v2Containers/Templates/tests/TemplatesActionBar.test.js +0 -120
  125. package/v2Containers/Templates/tests/smsTemplatesListApi.test.js +0 -180
  126. package/v2Containers/Templates/utils/smsTemplatesListApi.js +0 -79
  127. package/v2Containers/TemplatesV2/tests/TemplatesV2.localTemplates.test.js +0 -131
@@ -1,22 +1,7 @@
1
1
  import React from 'react';
2
2
  import renderer from 'react-test-renderer';
3
3
  import { render, screen } from '../../../utils/test-utils';
4
- import {
5
- getRCSContent,
6
- getRcsStatusType,
7
- getTemplateStatusType,
8
- normalizeCardVarMapped,
9
- coalesceCardVarMappedToTemplate,
10
- getRcsSemanticVarNamesSpanningTitleAndDesc,
11
- resolveCardVarMappedSlotValue,
12
- isRcsTextOnlyCardMediaType,
13
- mapRcsCardContentForConsumerWithResolvedTags,
14
- resolveRcsCardPreviewStrings,
15
- sanitizeCardVarMappedValue,
16
- areAllRcsSmsFallbackVarSlotsFilled,
17
- buildRcsNumericMustachePlaceholderRegex,
18
- } from '../utils';
19
- import { rcsVarRegex } from '../constants';
4
+ import { getRCSContent, getRcsStatusType, getTemplateStatusType } from '../utils';
20
5
  import { RCS, RCS_BUTTON_TYPES, STATUS_OPTIONS, RCS_STATUSES } from '../constants';
21
6
  import { mockData } from './mockData';
22
7
 
@@ -41,61 +26,53 @@ describe('RCS utils - renderRcsSuggestionsPreview', () => {
41
26
  },
42
27
  };
43
28
 
44
- const renderWithSuggestion = (buttonType, text) => {
29
+ it('renders divider and QUICK_REPLY suggestion with small-link icon', () => {
45
30
  const template = JSON.parse(JSON.stringify(templateBase));
46
31
  template.versions.base.content[RCS].rcsContent.cardContent[0].suggestions = [
47
- { type: buttonType, text },
32
+ { type: RCS_BUTTON_TYPES.QUICK_REPLY, text: 'Reply' },
48
33
  ];
49
34
  render(getRCSContent(template));
50
- };
51
-
52
- it.each([
53
- [RCS_BUTTON_TYPES.QUICK_REPLY, 'Reply', true],
54
- [RCS_BUTTON_TYPES.CTA, 'Visit', false],
55
- [RCS_BUTTON_TYPES.PHONE_NUMBER, 'Call', false],
56
- ])('renders %s suggestion with expected label', (buttonType, text, expectDivider) => {
57
- renderWithSuggestion(buttonType, text);
58
- if (expectDivider) {
59
- expect(document.querySelectorAll('.whatsapp-divider').length).toBeGreaterThan(0);
60
- }
35
+ expect(document.querySelectorAll('.whatsapp-divider').length).toBeGreaterThan(0);
61
36
  const labels = document.querySelectorAll('.rcs-cta-preview');
62
37
  expect(labels.length).toBe(1);
63
- expect(labels[0].textContent).toContain(text);
38
+ expect(labels[0].textContent).toContain('Reply');
64
39
  });
65
40
 
66
- it('renders only divider for unknown suggestion type', () => {
41
+ it('renders CTA suggestion with launch icon', () => {
67
42
  const template = JSON.parse(JSON.stringify(templateBase));
68
43
  template.versions.base.content[RCS].rcsContent.cardContent[0].suggestions = [
69
- { type: RCS_BUTTON_TYPES.NONE, text: 'Ignored' },
44
+ { type: RCS_BUTTON_TYPES.CTA, text: 'Visit' },
70
45
  ];
71
46
  render(getRCSContent(template));
72
- expect(document.querySelectorAll('.rcs-cta-preview').length).toBe(0);
73
- expect(document.querySelectorAll('.whatsapp-divider').length).toBeGreaterThan(0);
47
+ const labels = document.querySelectorAll('.rcs-cta-preview');
48
+ expect(labels.length).toBe(1);
49
+ expect(labels[0].textContent).toContain('Visit');
74
50
  });
75
51
 
76
- it('prefers thumbnailUrl over mediaUrl for preview image', () => {
52
+ it('renders PHONE_NUMBER suggestion with call icon', () => {
77
53
  const template = JSON.parse(JSON.stringify(templateBase));
78
- const card = template.versions.base.content[RCS].rcsContent.cardContent[0];
79
- card.media = { thumbnailUrl: 'thumb.jpg', mediaUrl: 'full.jpg' };
54
+ template.versions.base.content[RCS].rcsContent.cardContent[0].suggestions = [
55
+ { type: RCS_BUTTON_TYPES.PHONE_NUMBER, text: 'Call' },
56
+ ];
80
57
  render(getRCSContent(template));
81
- const img = document.querySelector('.rcs-listing-image');
82
- expect(img?.getAttribute('src')).toBe('thumb.jpg');
58
+ const labels = document.querySelectorAll('.rcs-cta-preview');
59
+ expect(labels.length).toBe(1);
60
+ expect(labels[0].textContent).toContain('Call');
83
61
  });
84
62
  });
85
63
 
86
64
  describe('RCS utils', () => {
87
65
  describe('getRCSContent', () => {
88
- /** Single place for snapshot serialization — keeps test bodies focused on template setup. */
89
- const expectGetRCSContentSnapshot = (template) => {
90
- expect(renderer.create(getRCSContent(template)).toJSON()).toMatchSnapshot();
91
- };
92
-
93
66
  it('renders RCS content with image and CTA suggestion', () => {
94
- expectGetRCSContentSnapshot(mockData.editData1.templateDetails);
67
+ const template = mockData.editData1.templateDetails;
68
+ const tree = renderer.create(getRCSContent(template)).toJSON();
69
+ expect(tree).toMatchSnapshot();
95
70
  });
96
71
 
97
72
  it('renders RCS content with no media', () => {
98
- expectGetRCSContentSnapshot(mockData.editData3.templateDetails);
73
+ const template = mockData.editData3.templateDetails;
74
+ const tree = renderer.create(getRCSContent(template)).toJSON();
75
+ expect(tree).toMatchSnapshot();
99
76
  });
100
77
 
101
78
  it('renders RCS content with multiple suggestion types', () => {
@@ -105,212 +82,19 @@ describe('RCS utils', () => {
105
82
  { type: RCS_BUTTON_TYPES.CTA, text: 'URL Action' },
106
83
  { type: RCS_BUTTON_TYPES.PHONE_NUMBER, text: 'Call Now' },
107
84
  ];
108
- expectGetRCSContentSnapshot(template);
85
+ const tree = renderer.create(getRCSContent(template)).toJSON();
86
+ expect(tree).toMatchSnapshot();
109
87
  });
110
88
 
111
89
  it('renders RCS content with missing cardContent', () => {
112
- expectGetRCSContentSnapshot({ versions: { base: { content: { RCS: { rcsContent: {} } } } } });
90
+ const template = { versions: { base: { content: { RCS: { rcsContent: {} } } } } };
91
+ const tree = renderer.create(getRCSContent(template)).toJSON();
92
+ expect(tree).toMatchSnapshot();
113
93
  });
114
94
 
115
95
  it('renders RCS content with empty template', () => {
116
- expectGetRCSContentSnapshot({});
117
- });
118
-
119
- it('renders RCS carousel listing preview when cardType is carousel', () => {
120
- const template = JSON.parse(JSON.stringify(mockData.editData1.templateDetails));
121
- const rcsContent = template.versions.base.content.RCS.rcsContent;
122
- rcsContent.cardType = 'CAROUSEL';
123
- rcsContent.cardContent = [
124
- {
125
- title: 'Card1',
126
- description: 'Desc1',
127
- media: { mediaUrl: 'https://example.com/1.png' },
128
- suggestions: [],
129
- },
130
- {
131
- title: 'Card2',
132
- description: 'Desc2',
133
- media: { mediaUrl: 'https://example.com/2.png' },
134
- suggestions: [],
135
- },
136
- {
137
- title: 'Card3',
138
- description: 'Desc3',
139
- media: { mediaUrl: 'https://example.com/3.png' },
140
- suggestions: [],
141
- },
142
- {
143
- title: 'Card4',
144
- description: 'Desc4',
145
- media: { mediaUrl: 'https://example.com/4.png' },
146
- suggestions: [],
147
- },
148
- ];
149
-
150
- render(getRCSContent(template));
151
- // "Peek" shows max 3
152
- expect(document.querySelectorAll('.whatsapp-carousel-container').length).toBe(3);
153
- expect(document.querySelectorAll('.scroll-container').length).toBeGreaterThan(0);
154
- });
155
-
156
- const carouselTemplate = (cardContent) => ({
157
- versions: {
158
- base: {
159
- content: {
160
- [RCS]: {
161
- rcsContent: {
162
- cardType: 'carousel',
163
- cardContent,
164
- },
165
- },
166
- },
167
- },
168
- },
169
- });
170
-
171
- const carouselSecondCardFiller = {
172
- title: 'B',
173
- description: 'D',
174
- media: { mediaUrl: 'https://example.com/b.png' },
175
- suggestions: [],
176
- };
177
-
178
- it('carousel: video card with thumbnailUrl uses thumbnail (not placeholder)', () => {
179
- const template = carouselTemplate([
180
- {
181
- title: 'Vid',
182
- description: 'With thumb',
183
- media: {
184
- mediaType: 'VIDEO',
185
- mediaUrl: 'https://example.com/video.mp4',
186
- thumbnailUrl: 'https://example.com/poster.jpg',
187
- },
188
- suggestions: [],
189
- },
190
- carouselSecondCardFiller,
191
- ]);
192
- render(getRCSContent(template));
193
- expect(document.querySelector('.rcs-video-preview-placeholder')).toBeFalsy();
194
- const firstImg = document.querySelector('.whatsapp-carousel-card .whatsapp-image');
195
- expect(firstImg).toBeTruthy();
196
- expect(firstImg.getAttribute('src')).toBe('https://example.com/poster.jpg');
197
- });
198
-
199
- it('carousel: shows video preview placeholder when VIDEO has mediaUrl but no thumbnail (no img src to mp4)', () => {
200
- const template = carouselTemplate([
201
- {
202
- title: 'Clip',
203
- description: 'No thumb',
204
- media: {
205
- mediaType: 'VIDEO',
206
- mediaUrl: 'https://example.com/video.mp4',
207
- },
208
- suggestions: [],
209
- },
210
- carouselSecondCardFiller,
211
- ]);
212
- render(getRCSContent(template));
213
- expect(document.querySelector('.rcs-video-preview-placeholder')).toBeTruthy();
214
- expect(document.querySelector('.rcs-video-preview-label')?.textContent).toContain('Video preview');
215
- });
216
-
217
- it('carousel: uses whatsapp-message-without-media when card has no image/video URL', () => {
218
- const template = carouselTemplate([
219
- {
220
- title: 'Text only',
221
- description: 'No media',
222
- media: {},
223
- suggestions: [],
224
- },
225
- {
226
- title: 'Second',
227
- description: '',
228
- suggestions: [],
229
- },
230
- ]);
231
- render(getRCSContent(template));
232
- const withoutMedia = document.querySelectorAll('.whatsapp-message-without-media');
233
- expect(withoutMedia.length).toBeGreaterThan(0);
234
- });
235
-
236
- it('carousel: body includes description with newline when description is set', () => {
237
- const template = carouselTemplate([
238
- {
239
- title: 'Head',
240
- description: 'Tail line',
241
- media: { mediaUrl: 'https://example.com/x.png' },
242
- suggestions: [],
243
- },
244
- {
245
- title: 'Y',
246
- description: 'Z',
247
- media: { mediaUrl: 'https://example.com/y.png' },
248
- suggestions: [],
249
- },
250
- ]);
251
- render(getRCSContent(template));
252
- const bodies = document.querySelectorAll('.whatsapp-carousel-body');
253
- expect(bodies[0].textContent).toContain('Head');
254
- expect(bodies[0].textContent).toContain('Tail line');
255
- });
256
-
257
- it('carousel: body handles missing title and empty description', () => {
258
- const template = carouselTemplate([
259
- {
260
- description: '',
261
- media: { mediaUrl: 'https://example.com/x.png' },
262
- suggestions: [],
263
- },
264
- {
265
- title: 'Only title',
266
- media: { mediaUrl: 'https://example.com/y.png' },
267
- suggestions: [],
268
- },
269
- ]);
270
- render(getRCSContent(template));
271
- const bodies = document.querySelectorAll('.whatsapp-carousel-body');
272
- expect(bodies[0].textContent.trim()).toBe('');
273
- expect(bodies[1].textContent).toContain('Only title');
274
- });
275
-
276
- it('carousel: renders per-card suggestions via renderRcsSuggestionsPreview', () => {
277
- const template = carouselTemplate([
278
- {
279
- title: 'C1',
280
- description: 'D1',
281
- media: { mediaUrl: 'https://example.com/1.png' },
282
- suggestions: [{ type: RCS_BUTTON_TYPES.CTA, text: 'Go' }],
283
- },
284
- {
285
- title: 'C2',
286
- description: 'D2',
287
- media: { mediaUrl: 'https://example.com/2.png' },
288
- suggestions: [],
289
- },
290
- ]);
291
- render(getRCSContent(template));
292
- expect(document.querySelectorAll('.rcs-cta-preview').length).toBeGreaterThanOrEqual(1);
293
- expect(Array.from(document.querySelectorAll('.rcs-cta-preview')).some((el) => el.textContent.includes('Go'))).toBe(true);
294
- });
295
-
296
- it('carousel: does not render suggestion block when suggestions missing or not an array', () => {
297
- const template = carouselTemplate([
298
- {
299
- title: 'A',
300
- description: 'B',
301
- media: { mediaUrl: 'https://example.com/a.png' },
302
- },
303
- {
304
- title: 'C',
305
- description: 'D',
306
- media: { mediaUrl: 'https://example.com/c.png' },
307
- suggestions: null,
308
- },
309
- ]);
310
- render(getRCSContent(template));
311
- const firstCard = document.querySelectorAll('.whatsapp-carousel-card')[0];
312
- const dividersInFirst = firstCard.querySelectorAll('.whatsapp-divider');
313
- expect(dividersInFirst.length).toBe(0);
96
+ const tree = renderer.create(getRCSContent({})).toJSON();
97
+ expect(tree).toMatchSnapshot();
314
98
  });
315
99
  });
316
100
 
@@ -352,404 +136,4 @@ describe('RCS utils', () => {
352
136
  expect(getTemplateStatusType('some_unknown_status')).toBe('warning');
353
137
  });
354
138
  });
355
-
356
- describe('normalizeCardVarMapped', () => {
357
- it('maps numeric key + placeholder value to tag name', () => {
358
- expect(normalizeCardVarMapped({ 1: '{{user_id_b64}}' })).toEqual({ user_id_b64: '' });
359
- });
360
-
361
- it('maps numeric key + literal value when orderedTagNames is provided', () => {
362
- expect(
363
- normalizeCardVarMapped({ 1: 'hello' }, ['user_id_b64']),
364
- ).toEqual({ user_id_b64: 'hello' });
365
- });
366
-
367
- it('keeps numeric key when no orderedTagNames for literal value', () => {
368
- expect(normalizeCardVarMapped({ 1: 'hello' })).toEqual({ 1: 'hello' });
369
- });
370
-
371
- it('keeps semantic key + different tag token (TagList value)', () => {
372
- expect(normalizeCardVarMapped({ myKey: '{{tag}}' })).toEqual({ myKey: '{{tag}}' });
373
- });
374
-
375
- it('maps numeric slot + chosen tag onto template token when ordered names provided', () => {
376
- expect(
377
- normalizeCardVarMapped({ 1: '{{FirstName}}' }, ['user_name']),
378
- ).toEqual({ user_name: '{{FirstName}}' });
379
- });
380
-
381
- it('returns {} for null, undefined, or non-object raw', () => {
382
- expect(normalizeCardVarMapped(null)).toEqual({});
383
- expect(normalizeCardVarMapped(undefined)).toEqual({});
384
- expect(normalizeCardVarMapped('not-object')).toEqual({});
385
- });
386
-
387
- it('maps numeric key to order slot only when index is within orderedTagNames', () => {
388
- expect(normalizeCardVarMapped({ 3: 'z' }, ['a', 'b'])).toEqual({ 3: 'z' });
389
- });
390
-
391
- it('does not overwrite a literal slot value with a duplicate semantic placeholder entry', () => {
392
- expect(
393
- normalizeCardVarMapped(
394
- { 1: 'hello', user_id_b64: '{{user_id_b64}}' },
395
- ['user_id_b64'],
396
- ),
397
- ).toEqual({ user_id_b64: 'hello' });
398
- });
399
- });
400
-
401
- describe('getRcsSemanticVarNamesSpanningTitleAndDesc', () => {
402
- it('returns names that appear in both title and description', () => {
403
- const set = getRcsSemanticVarNamesSpanningTitleAndDesc(
404
- 'Hello {{adv}}',
405
- 'Body {{adv}} x {{other}}',
406
- rcsVarRegex,
407
- );
408
- expect(Array.from(set).sort()).toEqual(['adv']);
409
- });
410
-
411
- it('is empty when the same name is only repeated in the title', () => {
412
- const set = getRcsSemanticVarNamesSpanningTitleAndDesc(
413
- '{{user_name}} and {{user_name}}',
414
- 'Hi',
415
- rcsVarRegex,
416
- );
417
- expect(set.size).toBe(0);
418
- });
419
- });
420
-
421
- describe('coalesceCardVarMappedToTemplate', () => {
422
- it('does not copy a shared semantic value into the second slot when the tag spans title and description', () => {
423
- const out = coalesceCardVarMappedToTemplate(
424
- { adv: 'shared' },
425
- 'T {{adv}}',
426
- 'D {{adv}}',
427
- rcsVarRegex,
428
- );
429
- expect(out[1]).toBe('shared');
430
- expect(out[2]).toBe('');
431
- expect(out.adv).toBe('shared');
432
- });
433
-
434
- it('maps slot 1 to first token name from title', () => {
435
- expect(
436
- coalesceCardVarMappedToTemplate(
437
- { 1: 'abc' },
438
- 'Hi {{user_name}}',
439
- '',
440
- rcsVarRegex,
441
- ),
442
- ).toEqual({ 1: 'abc', user_name: 'abc' });
443
- });
444
-
445
- it('keeps {{1}} style token as key 1', () => {
446
- expect(
447
- coalesceCardVarMappedToTemplate(
448
- { 1: '' },
449
- 'Hi {{1}}',
450
- '',
451
- rcsVarRegex,
452
- ),
453
- ).toEqual({ 1: '' });
454
- });
455
-
456
- it('returns clone when no tokens', () => {
457
- const raw = { 1: 'x' };
458
- const out = coalesceCardVarMappedToTemplate(raw, 'no vars', '', rcsVarRegex);
459
- expect(out).toEqual({ 1: 'x' });
460
- expect(out).not.toBe(raw);
461
- });
462
-
463
- it('merges tokens from title and description', () => {
464
- const out = coalesceCardVarMappedToTemplate(
465
- { a: '1', b: '2' },
466
- 'T {{a}}',
467
- 'D {{b}}',
468
- rcsVarRegex,
469
- );
470
- expect(out).toEqual({ a: '1', b: '2', 1: '1', 2: '2' });
471
- });
472
-
473
- it('returns {} when there are no tokens and raw is null or not an object', () => {
474
- expect(coalesceCardVarMappedToTemplate(null, 'plain', '', rcsVarRegex)).toEqual({});
475
- expect(coalesceCardVarMappedToTemplate(undefined, 'plain', '', rcsVarRegex)).toEqual({});
476
- });
477
-
478
- it('fills token values from legacy numeric slots when named key is missing', () => {
479
- expect(
480
- coalesceCardVarMappedToTemplate(
481
- { 1: 'legacy-val' },
482
- 'Hello {{name}}',
483
- '',
484
- rcsVarRegex,
485
- ),
486
- ).toEqual({ 1: 'legacy-val', name: 'legacy-val' });
487
- });
488
-
489
- it('maps values when raw is non-null but missing named keys', () => {
490
- expect(
491
- coalesceCardVarMappedToTemplate(
492
- {},
493
- 'X {{a}}',
494
- '',
495
- rcsVarRegex,
496
- ),
497
- ).toEqual({ 1: '', a: '' });
498
- });
499
- });
500
-
501
- describe('resolveCardVarMappedSlotValue', () => {
502
- it('prefers per-slot numeric key when both semantic and numeric are present', () => {
503
- expect(
504
- resolveCardVarMappedSlotValue({ user_name: 'A', 1: 'B' }, 'user_name', 0),
505
- ).toBe('B');
506
- });
507
-
508
- it('falls back to slot 1 when name missing', () => {
509
- expect(resolveCardVarMappedSlotValue({ 1: 'legacy' }, 'user_name', 0)).toBe('legacy');
510
- });
511
-
512
- it('uses global slot index for second variable', () => {
513
- expect(resolveCardVarMappedSlotValue({ 2: 'second' }, 'b', 1)).toBe('second');
514
- });
515
-
516
- it('reads slot from string slot key when varName has no direct mapping', () => {
517
- expect(resolveCardVarMappedSlotValue({ 1: 'only-slot' }, 'missing', 0)).toBe('only-slot');
518
- });
519
-
520
- it('reads numeric object key for slot when string slot key is absent', () => {
521
- expect(resolveCardVarMappedSlotValue({ 2: 'n2' }, 'x', 1)).toBe('n2');
522
- });
523
-
524
- it('returns empty when named key is cleared, not numeric slot fallback', () => {
525
- expect(
526
- resolveCardVarMappedSlotValue({ user_name: '', 1: 'old value' }, 'user_name', 0),
527
- ).toBe('');
528
- });
529
-
530
- it('library mode: semantic empty does not hide non-empty numeric slot (campaign / journey payload)', () => {
531
- expect(
532
- resolveCardVarMappedSlotValue(
533
- { user_id_b64: '', 1: 'selected-from-library' },
534
- 'user_id_b64',
535
- 0,
536
- true,
537
- ),
538
- ).toBe('selected-from-library');
539
- });
540
-
541
- it('empty numeric slot falls back to semantic tag (preview after hydration leaves 1:"")', () => {
542
- expect(
543
- resolveCardVarMappedSlotValue(
544
- { promotion_points: '{{loyalty_points}}', 1: '' },
545
- 'promotion_points',
546
- 0,
547
- ),
548
- ).toBe('{{loyalty_points}}');
549
- });
550
-
551
- it('omitSemanticFallback: duplicate title+desc tag does not read shared semantic for either slot', () => {
552
- expect(
553
- resolveCardVarMappedSlotValue({ adv: '{{adv}}', 1: '', 2: '' }, 'adv', 0, false, true),
554
- ).toBe('');
555
- expect(
556
- resolveCardVarMappedSlotValue({ adv: '{{adv}}', 1: 'A', 2: 'B' }, 'adv', 0, false, true),
557
- ).toBe('A');
558
- expect(
559
- resolveCardVarMappedSlotValue({ adv: '{{adv}}', 1: 'A', 2: 'B' }, 'adv', 1, false, true),
560
- ).toBe('B');
561
- });
562
-
563
- it('omitSemanticFallback: cleared semantic does not force empty when numeric slot has a value', () => {
564
- expect(
565
- resolveCardVarMappedSlotValue({ adv: '', 1: 'first', 2: 'second' }, 'adv', 1, false, true),
566
- ).toBe('second');
567
- });
568
- });
569
-
570
- describe('mapRcsCardContentForConsumerWithResolvedTags', () => {
571
- it('sets title and description to resolved tag strings on each card', () => {
572
- const out = mapRcsCardContentForConsumerWithResolvedTags(
573
- [
574
- {
575
- title: '',
576
- description: 'Visit {{gt}} discount',
577
- mediaType: 'NONE',
578
- cardVarMapped: { gt: '{{loyalty_points}}', 1: '{{loyalty_points}}' },
579
- },
580
- ],
581
- {},
582
- false,
583
- );
584
- expect(out[0].title).toBe('');
585
- expect(out[0].description).toBe('Visit {{loyalty_points}} discount');
586
- });
587
-
588
- it('merges root rcsCardVarMapped with nested cardVarMapped', () => {
589
- const out = mapRcsCardContentForConsumerWithResolvedTags(
590
- [
591
- {
592
- title: 'Hi {{first_name}}',
593
- description: 'Pts {{promotion_points}}',
594
- mediaType: 'IMAGE',
595
- cardVarMapped: {
596
- promotion_points: '{{loyalty_points}}',
597
- 2: '{{loyalty_points}}',
598
- },
599
- },
600
- ],
601
- {
602
- first_name: '{{customer_name}}',
603
- 1: '{{customer_name}}',
604
- },
605
- false,
606
- );
607
- expect(out[0].title).toBe('Hi {{customer_name}}');
608
- expect(out[0].description).toBe('Pts {{loyalty_points}}');
609
- });
610
-
611
- it('passes through null or non-object items in the card array unchanged', () => {
612
- const out = mapRcsCardContentForConsumerWithResolvedTags([null, 'string', 42], {}, false);
613
- expect(out).toEqual([null, 'string', 42]);
614
- });
615
- });
616
-
617
- describe('isRcsTextOnlyCardMediaType', () => {
618
- it('returns true for NONE and TEXT (text message card)', () => {
619
- expect(isRcsTextOnlyCardMediaType('NONE')).toBe(true);
620
- expect(isRcsTextOnlyCardMediaType('TEXT')).toBe(true);
621
- expect(isRcsTextOnlyCardMediaType('text')).toBe(true);
622
- });
623
- it('returns false for rich card media', () => {
624
- expect(isRcsTextOnlyCardMediaType('IMAGE')).toBe(false);
625
- expect(isRcsTextOnlyCardMediaType('VIDEO')).toBe(false);
626
- });
627
- });
628
-
629
- describe('resolveRcsCardPreviewStrings', () => {
630
- it('substitutes mapped tags for title and description (campaign preview parity)', () => {
631
- const { rcsTitle, rcsDesc } = resolveRcsCardPreviewStrings(
632
- 'Hi {{first_name}}',
633
- 'Pts {{promotion_points}}',
634
- {
635
- first_name: '{{customer_name}}',
636
- promotion_points: '{{loyalty_points}}',
637
- 1: '{{customer_name}}',
638
- 2: '{{loyalty_points}}',
639
- },
640
- true,
641
- );
642
- expect(rcsTitle).toBe('Hi {{customer_name}}');
643
- expect(rcsDesc).toBe('Pts {{loyalty_points}}');
644
- });
645
-
646
- it('leaves placeholders when map has no value', () => {
647
- const { rcsTitle, rcsDesc } = resolveRcsCardPreviewStrings(
648
- '{{a}}',
649
- '{{b}}',
650
- {},
651
- false,
652
- );
653
- expect(rcsTitle).toBe('{{a}}');
654
- expect(rcsDesc).toBe('{{b}}');
655
- });
656
-
657
- it('text-only card: ignores stale title and resolves description from global slot 0', () => {
658
- const { rcsTitle, rcsDesc } = resolveRcsCardPreviewStrings(
659
- 'Stale {{old_tag}} title',
660
- 'Visit Store for {{gt}} discount',
661
- { gt: '{{loyalty_points}}', 1: '{{loyalty_points}}' },
662
- true,
663
- true,
664
- );
665
- expect(rcsTitle).toBe('');
666
- expect(rcsDesc).toBe('Visit Store for {{loyalty_points}} discount');
667
- });
668
- });
669
-
670
- describe('sanitizeCardVarMappedValue', () => {
671
- it('returns empty for null', () => {
672
- expect(sanitizeCardVarMappedValue(null)).toBe('');
673
- });
674
-
675
- it('strips numeric-only self-placeholder stored as value', () => {
676
- expect(sanitizeCardVarMappedValue('{{1}}')).toBe('');
677
- expect(sanitizeCardVarMappedValue('{{12}}')).toBe('');
678
- });
679
-
680
- it('keeps semantic mustache values from TagList', () => {
681
- expect(sanitizeCardVarMappedValue('{{FirstName}}')).toBe('{{FirstName}}');
682
- expect(sanitizeCardVarMappedValue('{{user_name}}')).toBe('{{user_name}}');
683
- });
684
-
685
- it('returns original string for non-placeholder values', () => {
686
- expect(sanitizeCardVarMappedValue(' literal ')).toBe(' literal ');
687
- });
688
- });
689
-
690
- describe('areAllRcsSmsFallbackVarSlotsFilled', () => {
691
- it('returns true when template empty', () => {
692
- expect(areAllRcsSmsFallbackVarSlotsFilled('', { '{{a}}_0': 'x' })).toBe(true);
693
- });
694
-
695
- it('returns false when a mustache slot is only whitespace (parity with RCS title/desc vars)', () => {
696
- expect(
697
- areAllRcsSmsFallbackVarSlotsFilled('Hello {{name}}', { '{{name}}_1': ' ' }),
698
- ).toBe(false);
699
- });
700
-
701
- it('returns false when a mustache slot is missing or empty string', () => {
702
- expect(areAllRcsSmsFallbackVarSlotsFilled('Hello {{name}}', {})).toBe(false);
703
- expect(areAllRcsSmsFallbackVarSlotsFilled('Hello {{name}}', { '{{name}}_1': '' })).toBe(
704
- false,
705
- );
706
- });
707
-
708
- it('returns false when a DLT {#var#} slot is empty', () => {
709
- expect(areAllRcsSmsFallbackVarSlotsFilled('Hi {#x#}', { '{#x#}_1': ' ' })).toBe(false);
710
- });
711
-
712
- it('requires mapping for {{optout}} token like any other variable', () => {
713
- expect(areAllRcsSmsFallbackVarSlotsFilled('test {{optout}}', {})).toBe(false);
714
- expect(areAllRcsSmsFallbackVarSlotsFilled('test {{ optout }}', {})).toBe(false);
715
- expect(areAllRcsSmsFallbackVarSlotsFilled('test {{optout}}', { '{{optout}}_1': '{{optout}}' })).toBe(true);
716
- expect(areAllRcsSmsFallbackVarSlotsFilled('test {{optout}}', { '{{optout}}_1': '' })).toBe(false);
717
- });
718
-
719
- it('returns true when template is missing or not a string', () => {
720
- expect(areAllRcsSmsFallbackVarSlotsFilled(null, {})).toBe(true);
721
- expect(areAllRcsSmsFallbackVarSlotsFilled(undefined, {})).toBe(true);
722
- expect(areAllRcsSmsFallbackVarSlotsFilled(123, {})).toBe(true);
723
- });
724
-
725
- it('returns true when all variable slots have non-whitespace values', () => {
726
- expect(
727
- areAllRcsSmsFallbackVarSlotsFilled('Hello {{name}}', { '{{name}}_1': 'Ann' }),
728
- ).toBe(true);
729
- });
730
-
731
- it('coerces non-string slot values with String() so DLT/hydration payloads still count as filled', () => {
732
- expect(
733
- areAllRcsSmsFallbackVarSlotsFilled('Hello {{name}}', { '{{name}}_1': 42 }),
734
- ).toBe(true);
735
- });
736
-
737
- it('accepts legacy 1-based ordinal keys when the only token is at segment index 0 (DLT / API parity)', () => {
738
- expect(areAllRcsSmsFallbackVarSlotsFilled('{#shop#}', { '{#shop#}_1': 'Mart' })).toBe(true);
739
- expect(areAllRcsSmsFallbackVarSlotsFilled('{#shop#}', { '{#shop#}_1': '' })).toBe(false);
740
- });
741
- });
742
-
743
- describe('buildRcsNumericMustachePlaceholderRegex', () => {
744
- it('escapes regex metacharacters in numeric name', () => {
745
- const re = buildRcsNumericMustachePlaceholderRegex('1.5');
746
- expect(re.test('{{1.5}}')).toBe(true);
747
- });
748
-
749
- it('matches simple numeric placeholder', () => {
750
- const re = buildRcsNumericMustachePlaceholderRegex('2');
751
- expect(re.test('{{2}}')).toBe(true);
752
- expect(re.test('{{3}}')).toBe(false);
753
- });
754
- });
755
139
  });