@capillarytech/creatives-library 8.0.345-alpha.14 → 8.0.345-alpha.15

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 (129) hide show
  1. package/constants/unified.js +29 -0
  2. package/package.json +1 -1
  3. package/services/tests/api.test.js +13 -0
  4. package/utils/commonUtils.js +19 -1
  5. package/utils/rcsPayloadUtils.js +92 -0
  6. package/utils/templateVarUtils.js +201 -0
  7. package/utils/tests/templateVarUtils.test.js +204 -0
  8. package/v2Components/CapActionButton/constants.js +7 -0
  9. package/v2Components/CapActionButton/index.js +167 -109
  10. package/v2Components/CapActionButton/index.scss +157 -6
  11. package/v2Components/CapActionButton/messages.js +19 -3
  12. package/v2Components/CapActionButton/tests/index.test.js +41 -17
  13. package/v2Components/CapTagList/index.js +10 -0
  14. package/v2Components/CommonTestAndPreview/CustomValuesEditor.js +70 -49
  15. package/v2Components/CommonTestAndPreview/DeliverySettings/DeliverySettings.scss +8 -2
  16. package/v2Components/CommonTestAndPreview/DeliverySettings/ModifyDeliverySettings.js +207 -21
  17. package/v2Components/CommonTestAndPreview/DeliverySettings/constants.js +16 -0
  18. package/v2Components/CommonTestAndPreview/DeliverySettings/index.js +85 -10
  19. package/v2Components/CommonTestAndPreview/DeliverySettings/messages.js +30 -0
  20. package/v2Components/CommonTestAndPreview/DeliverySettings/utils/parseSenderDetailsResponse.js +79 -11
  21. package/v2Components/CommonTestAndPreview/SendTestMessage.js +10 -5
  22. package/v2Components/CommonTestAndPreview/UnifiedPreview/RcsPreviewContent.js +160 -15
  23. package/v2Components/CommonTestAndPreview/UnifiedPreview/RcsPreviewContent.js.rej +18 -0
  24. package/v2Components/CommonTestAndPreview/UnifiedPreview/_unifiedPreview.scss +341 -76
  25. package/v2Components/CommonTestAndPreview/UnifiedPreview/index.js +133 -4
  26. package/v2Components/CommonTestAndPreview/_commonTestAndPreview.scss +11 -0
  27. package/v2Components/CommonTestAndPreview/constants.js +38 -2
  28. package/v2Components/CommonTestAndPreview/index.js +676 -186
  29. package/v2Components/CommonTestAndPreview/messages.js +49 -3
  30. package/v2Components/CommonTestAndPreview/previewApiUtils.js +59 -0
  31. package/v2Components/CommonTestAndPreview/sagas.js +15 -6
  32. package/v2Components/CommonTestAndPreview/tests/CustomValuesEditor.test.js +308 -284
  33. package/v2Components/CommonTestAndPreview/tests/DeliverySettings/ModifyDeliverySettings.test.js +231 -65
  34. package/v2Components/CommonTestAndPreview/tests/DeliverySettings/index.test.js +118 -5
  35. package/v2Components/CommonTestAndPreview/tests/DeliverySettings/utils/parseSenderDetailsResponse.test.js +341 -0
  36. package/v2Components/CommonTestAndPreview/tests/PreviewSection.test.js +8 -1
  37. package/v2Components/CommonTestAndPreview/tests/SendTestMessage.test.js +34 -13
  38. package/v2Components/CommonTestAndPreview/tests/UnifiedPreview/RcsPreviewContent.test.js +281 -283
  39. package/v2Components/CommonTestAndPreview/tests/UnifiedPreview/index.test.js +199 -1
  40. package/v2Components/CommonTestAndPreview/tests/index.test.js +132 -4
  41. package/v2Components/CommonTestAndPreview/tests/previewApiUtils.test.js +67 -0
  42. package/v2Components/CommonTestAndPreview/tests/sagas.test.js +2 -2
  43. package/v2Components/FormBuilder/index.js +8 -10
  44. package/v2Components/SmsFallback/SmsFallbackLocalSelector.js +87 -0
  45. package/v2Components/SmsFallback/constants.js +73 -0
  46. package/v2Components/SmsFallback/index.js +955 -0
  47. package/v2Components/SmsFallback/index.scss +265 -0
  48. package/v2Components/SmsFallback/messages.js +78 -0
  49. package/v2Components/SmsFallback/smsFallbackUtils.js +118 -0
  50. package/v2Components/SmsFallback/tests/SmsFallbackLocalSelector.test.js +50 -0
  51. package/v2Components/SmsFallback/tests/rcsSmsFallback.acceptance.test.js +147 -0
  52. package/v2Components/SmsFallback/tests/smsFallbackHandlers.test.js +304 -0
  53. package/v2Components/SmsFallback/tests/smsFallbackUi.test.js +197 -0
  54. package/v2Components/SmsFallback/tests/smsFallbackUtils.test.js +277 -0
  55. package/v2Components/SmsFallback/tests/useLocalTemplateList.test.js +422 -0
  56. package/v2Components/SmsFallback/useLocalTemplateList.js +92 -0
  57. package/v2Components/TemplatePreview/_templatePreview.scss +33 -23
  58. package/v2Components/TemplatePreview/constants.js +2 -0
  59. package/v2Components/TemplatePreview/index.js +143 -28
  60. package/v2Components/TemplatePreview/tests/index.test.js +142 -0
  61. package/v2Components/TestAndPreviewSlidebox/index.js +13 -1
  62. package/v2Components/TestAndPreviewSlidebox/sagas.js +11 -4
  63. package/v2Components/TestAndPreviewSlidebox/tests/saga.test.js +3 -1
  64. package/v2Components/VarSegmentMessageEditor/constants.js +2 -0
  65. package/v2Components/VarSegmentMessageEditor/index.js +125 -0
  66. package/v2Components/VarSegmentMessageEditor/index.scss +46 -0
  67. package/v2Containers/CreativesContainer/CreativesSlideBoxWrapper.js +43 -0
  68. package/v2Containers/CreativesContainer/SlideBoxContent.js +36 -4
  69. package/v2Containers/CreativesContainer/SlideBoxFooter.js +10 -1
  70. package/v2Containers/CreativesContainer/SlideBoxHeader.js +29 -4
  71. package/v2Containers/CreativesContainer/constants.js +9 -0
  72. package/v2Containers/CreativesContainer/embeddedSlideboxUtils.js +67 -0
  73. package/v2Containers/CreativesContainer/index.js +300 -103
  74. package/v2Containers/CreativesContainer/index.scss +51 -1
  75. package/v2Containers/CreativesContainer/tests/SlideBoxContent.localTemplates.test.js +90 -0
  76. package/v2Containers/CreativesContainer/tests/SlideBoxFooter.test.js +78 -34
  77. package/v2Containers/CreativesContainer/tests/SlideBoxHeader.test.js +79 -16
  78. package/v2Containers/CreativesContainer/tests/__snapshots__/SlideBoxContent.test.js.snap +8 -0
  79. package/v2Containers/CreativesContainer/tests/__snapshots__/SlideBoxHeader.test.js.snap +357 -98
  80. package/v2Containers/CreativesContainer/tests/__snapshots__/index.test.js.snap +20 -15
  81. package/v2Containers/CreativesContainer/tests/embeddedSlideboxUtils.test.js +258 -0
  82. package/v2Containers/CreativesContainer/tests/index.test.js +71 -9
  83. package/v2Containers/CreativesContainer/tests/useLocalTemplatesProp.test.js +125 -0
  84. package/v2Containers/Email/reducer.js +3 -11
  85. package/v2Containers/Email/sagas.js +5 -9
  86. package/v2Containers/Email/tests/__snapshots__/reducer.test.js.snap +0 -4
  87. package/v2Containers/Email/tests/sagas.test.js +3 -21
  88. package/v2Containers/Rcs/constants.js +119 -8
  89. package/v2Containers/Rcs/index.js +2379 -807
  90. package/v2Containers/Rcs/index.js.rej +1336 -0
  91. package/v2Containers/Rcs/index.scss +276 -6
  92. package/v2Containers/Rcs/index.scss.rej +74 -0
  93. package/v2Containers/Rcs/messages.js +38 -3
  94. package/v2Containers/Rcs/rcsLibraryHydrationUtils.js +225 -0
  95. package/v2Containers/Rcs/tests/__snapshots__/index.test.js.snap +98018 -70073
  96. package/v2Containers/Rcs/tests/__snapshots__/utils.test.js.snap +0 -5
  97. package/v2Containers/Rcs/tests/__snapshots__/utils.test.js.snap.rej +128 -0
  98. package/v2Containers/Rcs/tests/index.test.js +152 -121
  99. package/v2Containers/Rcs/tests/mockData.js +38 -0
  100. package/v2Containers/Rcs/tests/rcsLibraryHydrationUtils.test.js +318 -0
  101. package/v2Containers/Rcs/tests/utils.test.js +646 -30
  102. package/v2Containers/Rcs/utils.js +478 -11
  103. package/v2Containers/Sms/Create/index.js +100 -40
  104. package/v2Containers/Sms/smsFormDataHelpers.js +67 -0
  105. package/v2Containers/Sms/tests/smsFormDataHelpers.test.js +253 -0
  106. package/v2Containers/SmsTrai/Create/index.js +9 -4
  107. package/v2Containers/SmsTrai/Edit/constants.js +2 -0
  108. package/v2Containers/SmsTrai/Edit/index.js +636 -130
  109. package/v2Containers/SmsTrai/Edit/index.scss +121 -0
  110. package/v2Containers/SmsTrai/Edit/messages.js +14 -4
  111. package/v2Containers/SmsTrai/Edit/tests/__snapshots__/index.test.js.snap +4328 -2375
  112. package/v2Containers/SmsWrapper/index.js +37 -8
  113. package/v2Containers/TagList/index.js +6 -0
  114. package/v2Containers/Templates/TemplatesActionBar.js +101 -0
  115. package/v2Containers/Templates/_templates.scss +163 -2
  116. package/v2Containers/Templates/actions.js +11 -0
  117. package/v2Containers/Templates/constants.js +2 -0
  118. package/v2Containers/Templates/index.js +119 -54
  119. package/v2Containers/Templates/sagas.js +57 -12
  120. package/v2Containers/Templates/tests/TemplatesActionBar.test.js +120 -0
  121. package/v2Containers/Templates/tests/__snapshots__/index.test.js.snap +1043 -1079
  122. package/v2Containers/Templates/tests/sagas.test.js +193 -123
  123. package/v2Containers/Templates/tests/smsTemplatesListApi.test.js +180 -0
  124. package/v2Containers/Templates/utils/smsTemplatesListApi.js +79 -0
  125. package/v2Containers/TemplatesV2/TemplatesV2.style.js +72 -1
  126. package/v2Containers/TemplatesV2/index.js +86 -23
  127. package/v2Containers/TemplatesV2/tests/TemplatesV2.localTemplates.test.js +131 -0
  128. package/v2Containers/Whatsapp/index.js +3 -20
  129. package/v2Containers/Whatsapp/tests/__snapshots__/index.test.js.snap +578 -34
@@ -1,7 +1,22 @@
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 { getRCSContent, getRcsStatusType, getTemplateStatusType } from '../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';
5
20
  import { RCS, RCS_BUTTON_TYPES, STATUS_OPTIONS, RCS_STATUSES } from '../constants';
6
21
  import { mockData } from './mockData';
7
22
 
@@ -26,53 +41,61 @@ describe('RCS utils - renderRcsSuggestionsPreview', () => {
26
41
  },
27
42
  };
28
43
 
29
- it('renders divider and QUICK_REPLY suggestion with small-link icon', () => {
44
+ const renderWithSuggestion = (buttonType, text) => {
30
45
  const template = JSON.parse(JSON.stringify(templateBase));
31
46
  template.versions.base.content[RCS].rcsContent.cardContent[0].suggestions = [
32
- { type: RCS_BUTTON_TYPES.QUICK_REPLY, text: 'Reply' },
47
+ { type: buttonType, text },
33
48
  ];
34
49
  render(getRCSContent(template));
35
- expect(document.querySelectorAll('.whatsapp-divider').length).toBeGreaterThan(0);
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
+ }
36
61
  const labels = document.querySelectorAll('.rcs-cta-preview');
37
62
  expect(labels.length).toBe(1);
38
- expect(labels[0].textContent).toContain('Reply');
63
+ expect(labels[0].textContent).toContain(text);
39
64
  });
40
65
 
41
- it('renders CTA suggestion with launch icon', () => {
66
+ it('renders only divider for unknown suggestion type', () => {
42
67
  const template = JSON.parse(JSON.stringify(templateBase));
43
68
  template.versions.base.content[RCS].rcsContent.cardContent[0].suggestions = [
44
- { type: RCS_BUTTON_TYPES.CTA, text: 'Visit' },
69
+ { type: RCS_BUTTON_TYPES.NONE, text: 'Ignored' },
45
70
  ];
46
71
  render(getRCSContent(template));
47
- const labels = document.querySelectorAll('.rcs-cta-preview');
48
- expect(labels.length).toBe(1);
49
- expect(labels[0].textContent).toContain('Visit');
72
+ expect(document.querySelectorAll('.rcs-cta-preview').length).toBe(0);
73
+ expect(document.querySelectorAll('.whatsapp-divider').length).toBeGreaterThan(0);
50
74
  });
51
75
 
52
- it('renders PHONE_NUMBER suggestion with call icon', () => {
76
+ it('prefers thumbnailUrl over mediaUrl for preview image', () => {
53
77
  const template = JSON.parse(JSON.stringify(templateBase));
54
- template.versions.base.content[RCS].rcsContent.cardContent[0].suggestions = [
55
- { type: RCS_BUTTON_TYPES.PHONE_NUMBER, text: 'Call' },
56
- ];
78
+ const card = template.versions.base.content[RCS].rcsContent.cardContent[0];
79
+ card.media = { thumbnailUrl: 'thumb.jpg', mediaUrl: 'full.jpg' };
57
80
  render(getRCSContent(template));
58
- const labels = document.querySelectorAll('.rcs-cta-preview');
59
- expect(labels.length).toBe(1);
60
- expect(labels[0].textContent).toContain('Call');
81
+ const img = document.querySelector('.rcs-listing-image');
82
+ expect(img?.getAttribute('src')).toBe('thumb.jpg');
61
83
  });
62
84
  });
63
85
 
64
86
  describe('RCS utils', () => {
65
87
  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
+
66
93
  it('renders RCS content with image and CTA suggestion', () => {
67
- const template = mockData.editData1.templateDetails;
68
- const tree = renderer.create(getRCSContent(template)).toJSON();
69
- expect(tree).toMatchSnapshot();
94
+ expectGetRCSContentSnapshot(mockData.editData1.templateDetails);
70
95
  });
71
96
 
72
97
  it('renders RCS content with no media', () => {
73
- const template = mockData.editData3.templateDetails;
74
- const tree = renderer.create(getRCSContent(template)).toJSON();
75
- expect(tree).toMatchSnapshot();
98
+ expectGetRCSContentSnapshot(mockData.editData3.templateDetails);
76
99
  });
77
100
 
78
101
  it('renders RCS content with multiple suggestion types', () => {
@@ -82,19 +105,212 @@ describe('RCS utils', () => {
82
105
  { type: RCS_BUTTON_TYPES.CTA, text: 'URL Action' },
83
106
  { type: RCS_BUTTON_TYPES.PHONE_NUMBER, text: 'Call Now' },
84
107
  ];
85
- const tree = renderer.create(getRCSContent(template)).toJSON();
86
- expect(tree).toMatchSnapshot();
108
+ expectGetRCSContentSnapshot(template);
87
109
  });
88
110
 
89
111
  it('renders RCS content with missing cardContent', () => {
90
- const template = { versions: { base: { content: { RCS: { rcsContent: {} } } } } };
91
- const tree = renderer.create(getRCSContent(template)).toJSON();
92
- expect(tree).toMatchSnapshot();
112
+ expectGetRCSContentSnapshot({ versions: { base: { content: { RCS: { rcsContent: {} } } } } });
93
113
  });
94
114
 
95
115
  it('renders RCS content with empty template', () => {
96
- const tree = renderer.create(getRCSContent({})).toJSON();
97
- expect(tree).toMatchSnapshot();
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);
98
314
  });
99
315
  });
100
316
 
@@ -136,4 +352,404 @@ describe('RCS utils', () => {
136
352
  expect(getTemplateStatusType('some_unknown_status')).toBe('warning');
137
353
  });
138
354
  });
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
+ });
139
755
  });