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

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 (130) hide show
  1. package/constants/unified.js +0 -29
  2. package/package.json +1 -1
  3. package/services/tests/api.test.js +0 -13
  4. package/utils/commonUtils.js +1 -19
  5. package/v2Components/CapActionButton/constants.js +0 -7
  6. package/v2Components/CapActionButton/index.js +109 -167
  7. package/v2Components/CapActionButton/index.scss +6 -157
  8. package/v2Components/CapActionButton/messages.js +3 -19
  9. package/v2Components/CapActionButton/tests/index.test.js +17 -41
  10. package/v2Components/CapTagList/index.js +0 -10
  11. package/v2Components/CommonTestAndPreview/CustomValuesEditor.js +49 -70
  12. package/v2Components/CommonTestAndPreview/DeliverySettings/DeliverySettings.scss +2 -8
  13. package/v2Components/CommonTestAndPreview/DeliverySettings/ModifyDeliverySettings.js +21 -207
  14. package/v2Components/CommonTestAndPreview/DeliverySettings/constants.js +0 -16
  15. package/v2Components/CommonTestAndPreview/DeliverySettings/index.js +10 -85
  16. package/v2Components/CommonTestAndPreview/DeliverySettings/messages.js +0 -30
  17. package/v2Components/CommonTestAndPreview/DeliverySettings/utils/parseSenderDetailsResponse.js +11 -79
  18. package/v2Components/CommonTestAndPreview/SendTestMessage.js +5 -10
  19. package/v2Components/CommonTestAndPreview/UnifiedPreview/RcsPreviewContent.js +15 -160
  20. package/v2Components/CommonTestAndPreview/UnifiedPreview/_unifiedPreview.scss +76 -341
  21. package/v2Components/CommonTestAndPreview/UnifiedPreview/index.js +4 -133
  22. package/v2Components/CommonTestAndPreview/_commonTestAndPreview.scss +0 -11
  23. package/v2Components/CommonTestAndPreview/constants.js +2 -38
  24. package/v2Components/CommonTestAndPreview/index.js +186 -676
  25. package/v2Components/CommonTestAndPreview/messages.js +3 -49
  26. package/v2Components/CommonTestAndPreview/sagas.js +6 -15
  27. package/v2Components/CommonTestAndPreview/tests/CustomValuesEditor.test.js +284 -308
  28. package/v2Components/CommonTestAndPreview/tests/DeliverySettings/ModifyDeliverySettings.test.js +65 -231
  29. package/v2Components/CommonTestAndPreview/tests/DeliverySettings/index.test.js +5 -118
  30. package/v2Components/CommonTestAndPreview/tests/DeliverySettings/utils/parseSenderDetailsResponse.test.js +0 -341
  31. package/v2Components/CommonTestAndPreview/tests/PreviewSection.test.js +1 -8
  32. package/v2Components/CommonTestAndPreview/tests/SendTestMessage.test.js +13 -34
  33. package/v2Components/CommonTestAndPreview/tests/UnifiedPreview/RcsPreviewContent.test.js +283 -281
  34. package/v2Components/CommonTestAndPreview/tests/UnifiedPreview/index.test.js +1 -199
  35. package/v2Components/CommonTestAndPreview/tests/index.test.js +4 -132
  36. package/v2Components/CommonTestAndPreview/tests/sagas.test.js +2 -2
  37. package/v2Components/FormBuilder/index.js +10 -8
  38. package/v2Components/TemplatePreview/_templatePreview.scss +23 -33
  39. package/v2Components/TemplatePreview/index.js +28 -143
  40. package/v2Components/TemplatePreview/tests/index.test.js +0 -142
  41. package/v2Components/TestAndPreviewSlidebox/index.js +1 -13
  42. package/v2Components/TestAndPreviewSlidebox/sagas.js +4 -11
  43. package/v2Components/TestAndPreviewSlidebox/tests/saga.test.js +1 -3
  44. package/v2Containers/CreativesContainer/SlideBoxContent.js +4 -36
  45. package/v2Containers/CreativesContainer/SlideBoxFooter.js +1 -10
  46. package/v2Containers/CreativesContainer/SlideBoxHeader.js +4 -29
  47. package/v2Containers/CreativesContainer/constants.js +0 -9
  48. package/v2Containers/CreativesContainer/index.js +103 -300
  49. package/v2Containers/CreativesContainer/index.scss +1 -51
  50. package/v2Containers/CreativesContainer/tests/SlideBoxFooter.test.js +34 -78
  51. package/v2Containers/CreativesContainer/tests/SlideBoxHeader.test.js +16 -79
  52. package/v2Containers/CreativesContainer/tests/__snapshots__/SlideBoxContent.test.js.snap +0 -8
  53. package/v2Containers/CreativesContainer/tests/__snapshots__/SlideBoxHeader.test.js.snap +98 -357
  54. package/v2Containers/CreativesContainer/tests/__snapshots__/index.test.js.snap +15 -20
  55. package/v2Containers/CreativesContainer/tests/index.test.js +9 -71
  56. package/v2Containers/Email/reducer.js +12 -3
  57. package/v2Containers/Email/sagas.js +9 -4
  58. package/v2Containers/Email/tests/__snapshots__/reducer.test.js.snap +4 -0
  59. package/v2Containers/Email/tests/reducer.test.js +47 -0
  60. package/v2Containers/Email/tests/sagas.test.js +146 -6
  61. package/v2Containers/Rcs/constants.js +8 -119
  62. package/v2Containers/Rcs/index.js +811 -2383
  63. package/v2Containers/Rcs/index.scss +6 -276
  64. package/v2Containers/Rcs/messages.js +3 -38
  65. package/v2Containers/Rcs/tests/__snapshots__/index.test.js.snap +70073 -98018
  66. package/v2Containers/Rcs/tests/__snapshots__/utils.test.js.snap +5 -0
  67. package/v2Containers/Rcs/tests/index.test.js +121 -152
  68. package/v2Containers/Rcs/tests/mockData.js +0 -38
  69. package/v2Containers/Rcs/tests/utils.test.js +30 -646
  70. package/v2Containers/Rcs/utils.js +11 -478
  71. package/v2Containers/Sms/Create/index.js +40 -100
  72. package/v2Containers/SmsTrai/Create/index.js +4 -9
  73. package/v2Containers/SmsTrai/Edit/constants.js +0 -2
  74. package/v2Containers/SmsTrai/Edit/index.js +130 -636
  75. package/v2Containers/SmsTrai/Edit/messages.js +4 -14
  76. package/v2Containers/SmsTrai/Edit/tests/__snapshots__/index.test.js.snap +2296 -4249
  77. package/v2Containers/SmsWrapper/index.js +8 -37
  78. package/v2Containers/TagList/index.js +0 -6
  79. package/v2Containers/Templates/_templates.scss +2 -163
  80. package/v2Containers/Templates/actions.js +0 -11
  81. package/v2Containers/Templates/constants.js +0 -2
  82. package/v2Containers/Templates/index.js +54 -119
  83. package/v2Containers/Templates/sagas.js +12 -57
  84. package/v2Containers/Templates/tests/__snapshots__/index.test.js.snap +1079 -1043
  85. package/v2Containers/Templates/tests/sagas.test.js +123 -193
  86. package/v2Containers/TemplatesV2/TemplatesV2.style.js +1 -72
  87. package/v2Containers/TemplatesV2/index.js +23 -86
  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/templateVarUtils.test.js +0 -204
  93. package/v2Components/CommonTestAndPreview/UnifiedPreview/RcsPreviewContent.js.rej +0 -18
  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 -87
  97. package/v2Components/SmsFallback/constants.js +0 -73
  98. package/v2Components/SmsFallback/index.js +0 -955
  99. package/v2Components/SmsFallback/index.scss +0 -265
  100. package/v2Components/SmsFallback/messages.js +0 -78
  101. package/v2Components/SmsFallback/smsFallbackUtils.js +0 -118
  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 -197
  106. package/v2Components/SmsFallback/tests/smsFallbackUtils.test.js +0 -277
  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 -67
  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/index.js.rej +0 -1336
  119. package/v2Containers/Rcs/index.scss.rej +0 -74
  120. package/v2Containers/Rcs/rcsLibraryHydrationUtils.js +0 -225
  121. package/v2Containers/Rcs/tests/__snapshots__/utils.test.js.snap.rej +0 -128
  122. package/v2Containers/Rcs/tests/rcsLibraryHydrationUtils.test.js +0 -318
  123. package/v2Containers/Sms/smsFormDataHelpers.js +0 -67
  124. package/v2Containers/Sms/tests/smsFormDataHelpers.test.js +0 -253
  125. package/v2Containers/SmsTrai/Edit/index.scss +0 -121
  126. package/v2Containers/Templates/TemplatesActionBar.js +0 -101
  127. package/v2Containers/Templates/tests/TemplatesActionBar.test.js +0 -120
  128. package/v2Containers/Templates/tests/smsTemplatesListApi.test.js +0 -180
  129. package/v2Containers/Templates/utils/smsTemplatesListApi.js +0 -79
  130. package/v2Containers/TemplatesV2/tests/TemplatesV2.localTemplates.test.js +0 -131
@@ -1,318 +0,0 @@
1
- import {
2
- getUnmappedDesc,
3
- hasRcsVarTokens,
4
- normalizeLibraryLoadedTitleDesc,
5
- mergeRcsSmsFallBackContentFromDetails,
6
- mergeRcsSmsFallbackVarMapLayers,
7
- pickFirstSmsFallbackTemplateString,
8
- syncCardVarMappedSemanticsFromSlots,
9
- hasMeaningfulSmsFallbackShape,
10
- getLibrarySmsFallbackApiBaselineFromTemplateData,
11
- extractRegisteredSenderIdsFromSmsFallbackRecord,
12
- pickRcsCardVarMappedEntries,
13
- } from '../rcsLibraryHydrationUtils';
14
- import { rcsVarRegex } from '../constants';
15
-
16
- describe('rcsLibraryHydrationUtils', () => {
17
- describe('mergeRcsSmsFallBackContentFromDetails', () => {
18
- it('returns empty object for missing details', () => {
19
- expect(mergeRcsSmsFallBackContentFromDetails(null)).toEqual({});
20
- expect(mergeRcsSmsFallBackContentFromDetails(undefined)).toEqual({});
21
- });
22
-
23
- it('merges nested RCS smsFallBackContent with root mirror; nested wins on overlap', () => {
24
- const details = {
25
- versions: {
26
- base: {
27
- content: {
28
- RCS: {
29
- smsFallBackContent: {
30
- smsTemplateName: 'OldName',
31
- message: 'from nested',
32
- smsContent: 'nested body',
33
- },
34
- },
35
- },
36
- },
37
- },
38
- smsFallBackContent: {
39
- message: 'from root',
40
- },
41
- };
42
- const out = mergeRcsSmsFallBackContentFromDetails(details);
43
- expect(out.message).toBe('from nested');
44
- expect(out.smsContent).toBe('nested body');
45
- expect(out.smsTemplateName).toBe('OldName');
46
- });
47
-
48
- it('uses root when nested path is absent', () => {
49
- const details = {
50
- smsFallBackContent: { message: 'only root' },
51
- };
52
- expect(mergeRcsSmsFallBackContentFromDetails(details)).toEqual({ message: 'only root' });
53
- });
54
- });
55
-
56
- describe('mergeRcsSmsFallbackVarMapLayers', () => {
57
- it('merges API map with local so empty local object does not wipe API slots', () => {
58
- const api = { rcsSmsFallbackVarMapped: { '{#a#}_0': 'x' } };
59
- const local = { rcsSmsFallbackVarMapped: {} };
60
- expect(mergeRcsSmsFallbackVarMapLayers(api, local)).toEqual({ '{#a#}_0': 'x' });
61
- });
62
-
63
- it('local slot values win on same key', () => {
64
- const api = { rcsSmsFallbackVarMapped: { '{#a#}_0': 'old' } };
65
- const local = { rcsSmsFallbackVarMapped: { '{#a#}_0': 'new' } };
66
- expect(mergeRcsSmsFallbackVarMapLayers(api, local)).toEqual({ '{#a#}_0': 'new' });
67
- });
68
-
69
- it('reads kebab-case var map from a layer when camel is absent', () => {
70
- const api = { 'rcs-sms-fallback-var-mapped': { '{#b#}_1': 'y' } };
71
- expect(mergeRcsSmsFallbackVarMapLayers(api, {})).toEqual({ '{#b#}_1': 'y' });
72
- });
73
- });
74
-
75
- describe('hasMeaningfulSmsFallbackShape', () => {
76
- it('is false for empty / missing', () => {
77
- expect(hasMeaningfulSmsFallbackShape(null)).toBe(false);
78
- expect(hasMeaningfulSmsFallbackShape({})).toBe(false);
79
- });
80
-
81
- it('is true when template body or name or var map exists', () => {
82
- expect(hasMeaningfulSmsFallbackShape({ message: 'hi' })).toBe(true);
83
- expect(hasMeaningfulSmsFallbackShape({ smsTemplateName: 'T' })).toBe(true);
84
- expect(hasMeaningfulSmsFallbackShape({ rcsSmsFallbackVarMapped: { '{#a#}_0': 'x' } })).toBe(true);
85
- });
86
- });
87
-
88
- describe('getLibrarySmsFallbackApiBaselineFromTemplateData', () => {
89
- it('merges root and nested; nested wins on overlap', () => {
90
- const templateData = {
91
- smsFallBackContent: { message: 'root' },
92
- versions: {
93
- base: {
94
- content: {
95
- RCS: {
96
- smsFallBackContent: { message: 'nested', smsTemplateName: 'N' },
97
- },
98
- },
99
- },
100
- },
101
- };
102
- const out = getLibrarySmsFallbackApiBaselineFromTemplateData(templateData);
103
- expect(out.message).toBe('nested');
104
- expect(out.smsTemplateName).toBe('N');
105
- });
106
- });
107
-
108
- describe('extractRegisteredSenderIdsFromSmsFallbackRecord', () => {
109
- it('returns null for missing / empty', () => {
110
- expect(extractRegisteredSenderIdsFromSmsFallbackRecord(null)).toBe(null);
111
- expect(extractRegisteredSenderIdsFromSmsFallbackRecord({})).toBe(null);
112
- expect(
113
- extractRegisteredSenderIdsFromSmsFallbackRecord({ registeredSenderIds: [] }),
114
- ).toBe(null);
115
- });
116
-
117
- it('prefers top-level registeredSenderIds', () => {
118
- expect(
119
- extractRegisteredSenderIdsFromSmsFallbackRecord({
120
- registeredSenderIds: ['A'],
121
- templateConfigs: { registeredSenderIds: ['B'] },
122
- }),
123
- ).toEqual(['A']);
124
- });
125
-
126
- it('reads templateConfigs.registeredSenderIds when top-level absent', () => {
127
- expect(
128
- extractRegisteredSenderIdsFromSmsFallbackRecord({
129
- templateConfigs: { registeredSenderIds: ['DLT1', 'DLT2'] },
130
- }),
131
- ).toEqual(['DLT1', 'DLT2']);
132
- });
133
-
134
- it('falls back to templateConfigs.header array', () => {
135
- expect(
136
- extractRegisteredSenderIdsFromSmsFallbackRecord({
137
- templateConfigs: { header: ['H1'] },
138
- }),
139
- ).toEqual(['H1']);
140
- });
141
- });
142
-
143
- describe('pickFirstSmsFallbackTemplateString', () => {
144
- it('prefers smsTemplateContent over resolved message so DLT tokens stay in the string', () => {
145
- const sms = {
146
- message: 'Hello user',
147
- smsTemplateContent: 'Hello {#name#}',
148
- };
149
- expect(pickFirstSmsFallbackTemplateString(sms)).toBe('Hello {#name#}');
150
- });
151
-
152
- it('skips whitespace-only templateContent and uses next field', () => {
153
- expect(
154
- pickFirstSmsFallbackTemplateString({
155
- templateContent: ' ',
156
- message: 'x',
157
- }),
158
- ).toBe('x');
159
- });
160
- });
161
-
162
- describe('getUnmappedDesc', () => {
163
- it('returns empty string for falsy str', () => {
164
- expect(getUnmappedDesc('', { a: '1' })).toBe('');
165
- expect(getUnmappedDesc(null, { a: '1' })).toBe('');
166
- });
167
-
168
- it('returns str when mapping is empty or missing', () => {
169
- expect(getUnmappedDesc('hello', null)).toBe('hello');
170
- expect(getUnmappedDesc('hello', {})).toBe('hello');
171
- });
172
-
173
- it('replaces literal values with {{key}} placeholders', () => {
174
- expect(getUnmappedDesc('Hi Alice', { user_name: 'Alice' })).toBe('Hi {{user_name}}');
175
- });
176
-
177
- it('skips mapping entries with empty or whitespace-only values', () => {
178
- expect(getUnmappedDesc('x', { a: '', b: ' ' })).toBe('x');
179
- });
180
-
181
- it('treats already-braced raw values without duplicating braced needle', () => {
182
- expect(getUnmappedDesc('v {{user_id}}', { user_id: '{{user_id}}' })).toContain('{{user_id}}');
183
- });
184
-
185
- it('adds braced needle when resolved value is not already in {{…}} form', () => {
186
- const out = getUnmappedDesc('Hello Bob', { nick: 'Bob' });
187
- expect(out).toBe('Hello {{nick}}');
188
- });
189
-
190
- it('ignores undefined mapping values', () => {
191
- expect(getUnmappedDesc('x', { a: undefined })).toBe('x');
192
- });
193
-
194
- it('matches longer needles first to avoid partial replaces', () => {
195
- const out = getUnmappedDesc('ab', { x: 'a', y: 'ab' });
196
- expect(out).toBe('{{y}}');
197
- });
198
-
199
- it('escapes regex metacharacters in resolved values', () => {
200
- expect(getUnmappedDesc('price 9.99', { p: '9.99' })).toBe('price {{p}}');
201
- });
202
- });
203
-
204
- describe('hasRcsVarTokens', () => {
205
- it('is false for empty or non-matching strings', () => {
206
- expect(hasRcsVarTokens('', rcsVarRegex)).toBe(false);
207
- expect(hasRcsVarTokens('plain', rcsVarRegex)).toBe(false);
208
- });
209
-
210
- it('is true when string contains {{word}} tokens', () => {
211
- expect(hasRcsVarTokens('{{1}} hi', rcsVarRegex)).toBe(true);
212
- expect(hasRcsVarTokens('{{user_id}}', rcsVarRegex)).toBe(true);
213
- expect(hasRcsVarTokens('{{dynamic_expiry_date_after_3_days.FORMAT_1}}', rcsVarRegex)).toBe(true);
214
- });
215
- });
216
-
217
- describe('normalizeLibraryLoadedTitleDesc', () => {
218
- const cardVarMappedAfterHydration = { user_id: '123' };
219
-
220
- it('returns originals in full mode', () => {
221
- const out = normalizeLibraryLoadedTitleDesc({
222
- loadedTitle: 'Hello 123',
223
- loadedDesc: 'Desc',
224
- isFullMode: true,
225
- cardVarMappedAfterHydration,
226
- rcsVarRegex,
227
- });
228
- expect(out).toEqual({ normalizedTitle: 'Hello 123', normalizedDesc: 'Desc' });
229
- });
230
-
231
- it('unmaps when library mode, map present, and no mustache tokens', () => {
232
- const out = normalizeLibraryLoadedTitleDesc({
233
- loadedTitle: 'Hello 123',
234
- loadedDesc: 'World 123',
235
- isFullMode: false,
236
- cardVarMappedAfterHydration,
237
- rcsVarRegex,
238
- });
239
- expect(out.normalizedTitle).toBe('Hello {{user_id}}');
240
- expect(out.normalizedDesc).toBe('World {{user_id}}');
241
- });
242
-
243
- it('keeps {{numeric}} slots when tokens already exist', () => {
244
- const out = normalizeLibraryLoadedTitleDesc({
245
- loadedTitle: 'Hi {{1}}',
246
- loadedDesc: 'Body 123',
247
- isFullMode: false,
248
- cardVarMappedAfterHydration,
249
- rcsVarRegex,
250
- });
251
- expect(out.normalizedTitle).toBe('Hi {{1}}');
252
- expect(out.normalizedDesc).toBe('Body {{user_id}}');
253
- });
254
-
255
- it('does not unmap when cardVarMappedAfterHydration is empty', () => {
256
- const out = normalizeLibraryLoadedTitleDesc({
257
- loadedTitle: 'Hello',
258
- loadedDesc: 'D',
259
- isFullMode: false,
260
- cardVarMappedAfterHydration: {},
261
- rcsVarRegex,
262
- });
263
- expect(out).toEqual({ normalizedTitle: 'Hello', normalizedDesc: 'D' });
264
- });
265
- });
266
-
267
- describe('syncCardVarMappedSemanticsFromSlots', () => {
268
- it('copies numeric slot values onto empty semantic keys (campaign round-trip)', () => {
269
- const out = syncCardVarMappedSemanticsFromSlots(
270
- { 1: '[FirstName]', user_name: '', 2: 'x', other: '' },
271
- 'Hi {{user_name}}',
272
- 'More {{other}}',
273
- rcsVarRegex,
274
- );
275
- expect(out.user_name).toBe('[FirstName]');
276
- expect(out.other).toBe('x');
277
- });
278
-
279
- it('does not overwrite non-empty semantic keys', () => {
280
- const out = syncCardVarMappedSemanticsFromSlots(
281
- { 1: 'from-slot', user_name: 'kept' },
282
- 'Hello {{user_name}}',
283
- '',
284
- rcsVarRegex,
285
- );
286
- expect(out.user_name).toBe('kept');
287
- });
288
- });
289
-
290
- describe('pickRcsCardVarMappedEntries', () => {
291
- it('returns {} for null, undefined, and array inputs', () => {
292
- expect(pickRcsCardVarMappedEntries(null)).toEqual({});
293
- expect(pickRcsCardVarMappedEntries(undefined)).toEqual({});
294
- expect(pickRcsCardVarMappedEntries(['{#v#}_0', 'x'])).toEqual({});
295
- });
296
-
297
- it('keeps numeric slot keys', () => {
298
- expect(pickRcsCardVarMappedEntries({ 1: 'a', 2: 'b' })).toEqual({ 1: 'a', 2: 'b' });
299
- });
300
-
301
- it('keeps semantic word keys', () => {
302
- expect(pickRcsCardVarMappedEntries({ user_name: 'Alice', gt: '{{tag}}' })).toEqual({
303
- user_name: 'Alice',
304
- gt: '{{tag}}',
305
- });
306
- });
307
-
308
- it('strips SMS fallback slot keys like {#var#}_0', () => {
309
- const input = { 1: 'x', user_name: 'y', '{#promo#}_0': 'z', '{{name}}_1': 'w' };
310
- const out = pickRcsCardVarMappedEntries(input);
311
- expect(out).toEqual({ 1: 'x', user_name: 'y' });
312
- });
313
-
314
- it('returns {} for an empty object', () => {
315
- expect(pickRcsCardVarMappedEntries({})).toEqual({});
316
- });
317
- });
318
- });
@@ -1,67 +0,0 @@
1
- /**
2
- * Shared SMS FormBuilder formData helpers for Sms/Create (and any embedded host).
3
- */
4
-
5
- /**
6
- * @param {object} formData FormBuilder state (same shape as Sms/Create `this.state.formData`)
7
- * @param {number} currentTab 1-based tab index
8
- * @returns {string} Raw message body or ''
9
- */
10
- export function getSmsMessageFromFormData(formData, currentTab) {
11
- if (formData == null || typeof formData !== 'object') {
12
- return '';
13
- }
14
- const tab = currentTab != null && currentTab > 0 ? currentTab : 1;
15
- const currentTabData = formData[tab - 1];
16
- if (currentTabData && typeof currentTabData === 'object') {
17
- const versionedKey = tab > 1 ? `sms-editor${tab}` : 'sms-editor';
18
- if (Object.prototype.hasOwnProperty.call(currentTabData, versionedKey)) {
19
- const v = currentTabData[versionedKey];
20
- // Key exists — commit to this version's value rather than falling through to base.
21
- // Treat null/undefined as empty so a cleared version correctly reports as empty.
22
- return (v != null && v !== '') ? String(v) : '';
23
- }
24
- if (currentTabData['sms-editor'] != null) {
25
- return String(currentTabData['sms-editor']);
26
- }
27
- const activeTab = currentTabData.activeTab || 'base';
28
- if (currentTabData[activeTab]?.['sms-editor'] != null) {
29
- return String(currentTabData[activeTab]['sms-editor']);
30
- }
31
- if (currentTabData.base?.['sms-editor'] != null) {
32
- return String(currentTabData.base['sms-editor']);
33
- }
34
- }
35
- const rootBase = formData.base;
36
- if (rootBase && typeof rootBase === 'object' && rootBase['sms-editor'] != null) {
37
- return String(rootBase['sms-editor']);
38
- }
39
- return '';
40
- }
41
-
42
- /**
43
- * @param {number} [tabCount] Total number of versions/tabs. When >1 all versions are checked.
44
- * @returns {{ isTemplateNameEmpty: boolean, isMessageEmpty: boolean }}
45
- */
46
- export function getSmsEmbeddedFooterValidity(formData, tabCount) {
47
- const rawName = formData?.['template-name'];
48
- const name = rawName != null && rawName !== '' ? String(rawName).trim() : '';
49
-
50
- // Check ALL versions: if any version's message is empty, Done should be disabled.
51
- // With a single version this is equivalent to the previous single-tab check.
52
- const count = tabCount != null && tabCount > 1 ? tabCount : 1;
53
- let isMessageEmpty = false;
54
- for (let i = 1; i <= count; i++) {
55
- const content = getSmsMessageFromFormData(formData, i);
56
- const msg = content != null && content !== '' ? String(content).trim() : '';
57
- if (!msg) {
58
- isMessageEmpty = true;
59
- break;
60
- }
61
- }
62
-
63
- return {
64
- isTemplateNameEmpty: !name,
65
- isMessageEmpty,
66
- };
67
- }
@@ -1,253 +0,0 @@
1
- import {
2
- getSmsMessageFromFormData,
3
- getSmsEmbeddedFooterValidity,
4
- } from '../smsFormDataHelpers';
5
-
6
- // ---------------------------------------------------------------------------
7
- // getSmsMessageFromFormData
8
- // ---------------------------------------------------------------------------
9
-
10
- describe('getSmsMessageFromFormData', () => {
11
- describe('null / invalid formData guard', () => {
12
- it('returns empty string when formData is null', () => {
13
- expect(getSmsMessageFromFormData(null, 1)).toBe('');
14
- });
15
-
16
- it('returns empty string when formData is undefined', () => {
17
- expect(getSmsMessageFromFormData(undefined, 1)).toBe('');
18
- });
19
-
20
- it('returns empty string when formData is a string (not an object)', () => {
21
- expect(getSmsMessageFromFormData('bad', 1)).toBe('');
22
- });
23
-
24
- it('returns empty string when formData is a number', () => {
25
- expect(getSmsMessageFromFormData(42, 1)).toBe('');
26
- });
27
- });
28
-
29
- describe('currentTab normalisation', () => {
30
- it('defaults to tab 1 when currentTab is null', () => {
31
- const formData = { 0: { 'sms-editor': 'hello' } };
32
- expect(getSmsMessageFromFormData(formData, null)).toBe('hello');
33
- });
34
-
35
- it('defaults to tab 1 when currentTab is undefined', () => {
36
- const formData = { 0: { 'sms-editor': 'hello' } };
37
- expect(getSmsMessageFromFormData(formData, undefined)).toBe('hello');
38
- });
39
-
40
- it('defaults to tab 1 when currentTab is 0', () => {
41
- const formData = { 0: { 'sms-editor': 'hello' } };
42
- expect(getSmsMessageFromFormData(formData, 0)).toBe('hello');
43
- });
44
-
45
- it('defaults to tab 1 when currentTab is negative', () => {
46
- const formData = { 0: { 'sms-editor': 'hello' } };
47
- expect(getSmsMessageFromFormData(formData, -5)).toBe('hello');
48
- });
49
- });
50
-
51
- describe('versioned key lookup', () => {
52
- it('uses "sms-editor" key for tab 1', () => {
53
- const formData = { 0: { 'sms-editor': 'tab1 msg' } };
54
- expect(getSmsMessageFromFormData(formData, 1)).toBe('tab1 msg');
55
- });
56
-
57
- it('uses "sms-editor2" versioned key for tab 2', () => {
58
- const formData = { 1: { 'sms-editor2': 'tab2 msg', 'sms-editor': 'fallback' } };
59
- expect(getSmsMessageFromFormData(formData, 2)).toBe('tab2 msg');
60
- });
61
-
62
- it('uses "sms-editor3" versioned key for tab 3', () => {
63
- const formData = { 2: { 'sms-editor3': 'tab3 msg' } };
64
- expect(getSmsMessageFromFormData(formData, 3)).toBe('tab3 msg');
65
- });
66
-
67
- it('returns empty string when versioned key exists but is null (cleared version)', () => {
68
- const formData = { 1: { 'sms-editor2': null } };
69
- expect(getSmsMessageFromFormData(formData, 2)).toBe('');
70
- });
71
-
72
- it('returns empty string when versioned key exists but is empty string', () => {
73
- const formData = { 1: { 'sms-editor2': '' } };
74
- expect(getSmsMessageFromFormData(formData, 2)).toBe('');
75
- });
76
-
77
- it('coerces a numeric value in versioned key to string', () => {
78
- const formData = { 1: { 'sms-editor2': 12345 } };
79
- expect(getSmsMessageFromFormData(formData, 2)).toBe('12345');
80
- });
81
- });
82
-
83
- describe('"sms-editor" flat key fallback (versioned key absent)', () => {
84
- it('falls back to "sms-editor" when versioned key is absent for tab 2', () => {
85
- const formData = { 1: { 'sms-editor': 'flat fallback' } };
86
- expect(getSmsMessageFromFormData(formData, 2)).toBe('flat fallback');
87
- });
88
- });
89
-
90
- describe('activeTab nested fallback', () => {
91
- it('falls back to activeTab["sms-editor"] when neither versioned key nor flat "sms-editor" is present', () => {
92
- // The versioned key must be absent entirely for the activeTab fallback to be reached.
93
- // (If 'sms-editor' exists but is null, the function commits to '' without falling through.)
94
- const formData = {
95
- 0: {
96
- activeTab: 'variant1',
97
- variant1: { 'sms-editor': 'variant msg' },
98
- },
99
- };
100
- expect(getSmsMessageFromFormData(formData, 1)).toBe('variant msg');
101
- });
102
-
103
- it('falls back to base["sms-editor"] when activeTab entry lacks "sms-editor" and flat key is absent', () => {
104
- const formData = {
105
- 0: {
106
- activeTab: 'variant1',
107
- variant1: {},
108
- base: { 'sms-editor': 'base msg' },
109
- },
110
- };
111
- expect(getSmsMessageFromFormData(formData, 1)).toBe('base msg');
112
- });
113
-
114
- it('defaults activeTab to "base" when activeTab prop is not set and flat key is absent', () => {
115
- const formData = {
116
- 0: {
117
- base: { 'sms-editor': 'default base msg' },
118
- },
119
- };
120
- expect(getSmsMessageFromFormData(formData, 1)).toBe('default base msg');
121
- });
122
- });
123
-
124
- describe('root formData.base fallback', () => {
125
- it('falls back to formData.base["sms-editor"] when tab slot is missing', () => {
126
- const formData = {
127
- base: { 'sms-editor': 'root base msg' },
128
- };
129
- expect(getSmsMessageFromFormData(formData, 1)).toBe('root base msg');
130
- });
131
-
132
- it('returns empty string when even root base has no "sms-editor"', () => {
133
- const formData = { base: {} };
134
- expect(getSmsMessageFromFormData(formData, 1)).toBe('');
135
- });
136
-
137
- it('returns empty string when formData has no relevant keys at all', () => {
138
- expect(getSmsMessageFromFormData({}, 1)).toBe('');
139
- });
140
- });
141
- });
142
-
143
- // ---------------------------------------------------------------------------
144
- // getSmsEmbeddedFooterValidity
145
- // ---------------------------------------------------------------------------
146
-
147
- describe('getSmsEmbeddedFooterValidity', () => {
148
- describe('isTemplateNameEmpty', () => {
149
- it('is true when template-name is absent', () => {
150
- const formData = { 0: { 'sms-editor': 'msg' } };
151
- const { isTemplateNameEmpty } = getSmsEmbeddedFooterValidity(formData, 1);
152
- expect(isTemplateNameEmpty).toBe(true);
153
- });
154
-
155
- it('is true when template-name is empty string', () => {
156
- const formData = { 'template-name': '', 0: { 'sms-editor': 'msg' } };
157
- const { isTemplateNameEmpty } = getSmsEmbeddedFooterValidity(formData, 1);
158
- expect(isTemplateNameEmpty).toBe(true);
159
- });
160
-
161
- it('is true when template-name is whitespace only', () => {
162
- const formData = { 'template-name': ' ', 0: { 'sms-editor': 'msg' } };
163
- const { isTemplateNameEmpty } = getSmsEmbeddedFooterValidity(formData, 1);
164
- expect(isTemplateNameEmpty).toBe(true);
165
- });
166
-
167
- it('is false when template-name is a non-empty string', () => {
168
- const formData = { 'template-name': 'My Template', 0: { 'sms-editor': 'msg' } };
169
- const { isTemplateNameEmpty } = getSmsEmbeddedFooterValidity(formData, 1);
170
- expect(isTemplateNameEmpty).toBe(false);
171
- });
172
- });
173
-
174
- describe('isMessageEmpty — single tab', () => {
175
- it('is true when message is empty string', () => {
176
- const formData = { 'template-name': 'T', 0: { 'sms-editor': '' } };
177
- const { isMessageEmpty } = getSmsEmbeddedFooterValidity(formData, 1);
178
- expect(isMessageEmpty).toBe(true);
179
- });
180
-
181
- it('is true when message is whitespace only', () => {
182
- const formData = { 'template-name': 'T', 0: { 'sms-editor': ' ' } };
183
- const { isMessageEmpty } = getSmsEmbeddedFooterValidity(formData, 1);
184
- expect(isMessageEmpty).toBe(true);
185
- });
186
-
187
- it('is true when no sms-editor key at all', () => {
188
- const formData = { 'template-name': 'T', 0: {} };
189
- const { isMessageEmpty } = getSmsEmbeddedFooterValidity(formData, 1);
190
- expect(isMessageEmpty).toBe(true);
191
- });
192
-
193
- it('is false when message is non-empty', () => {
194
- const formData = { 'template-name': 'T', 0: { 'sms-editor': 'Hello world' } };
195
- const { isMessageEmpty } = getSmsEmbeddedFooterValidity(formData, 1);
196
- expect(isMessageEmpty).toBe(false);
197
- });
198
- });
199
-
200
- describe('isMessageEmpty — multiple tabs', () => {
201
- it('is false when all tabs have non-empty messages', () => {
202
- const formData = {
203
- 'template-name': 'T',
204
- 0: { 'sms-editor': 'Tab 1 message' },
205
- 1: { 'sms-editor2': 'Tab 2 message' },
206
- 2: { 'sms-editor3': 'Tab 3 message' },
207
- };
208
- const { isMessageEmpty } = getSmsEmbeddedFooterValidity(formData, 3);
209
- expect(isMessageEmpty).toBe(false);
210
- });
211
-
212
- it('is true when the second tab has an empty message', () => {
213
- const formData = {
214
- 'template-name': 'T',
215
- 0: { 'sms-editor': 'Tab 1 message' },
216
- 1: { 'sms-editor2': '' },
217
- };
218
- const { isMessageEmpty } = getSmsEmbeddedFooterValidity(formData, 2);
219
- expect(isMessageEmpty).toBe(true);
220
- });
221
-
222
- it('is true when the third tab has no message', () => {
223
- const formData = {
224
- 'template-name': 'T',
225
- 0: { 'sms-editor': 'msg1' },
226
- 1: { 'sms-editor2': 'msg2' },
227
- 2: {},
228
- };
229
- const { isMessageEmpty } = getSmsEmbeddedFooterValidity(formData, 3);
230
- expect(isMessageEmpty).toBe(true);
231
- });
232
-
233
- it('treats tabCount=1 as single-tab check even when not explicitly provided', () => {
234
- const formData = { 'template-name': 'T', 0: { 'sms-editor': 'msg' } };
235
- const { isMessageEmpty } = getSmsEmbeddedFooterValidity(formData);
236
- expect(isMessageEmpty).toBe(false);
237
- });
238
- });
239
-
240
- describe('both fields together', () => {
241
- it('returns both empty when template name absent and message empty', () => {
242
- const formData = { 0: { 'sms-editor': '' } };
243
- const result = getSmsEmbeddedFooterValidity(formData, 1);
244
- expect(result).toEqual({ isTemplateNameEmpty: true, isMessageEmpty: true });
245
- });
246
-
247
- it('returns both non-empty when template name and message are present', () => {
248
- const formData = { 'template-name': 'My Template', 0: { 'sms-editor': 'Hello!' } };
249
- const result = getSmsEmbeddedFooterValidity(formData, 1);
250
- expect(result).toEqual({ isTemplateNameEmpty: false, isMessageEmpty: false });
251
- });
252
- });
253
- });