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

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 (136) hide show
  1. package/constants/unified.js +29 -0
  2. package/package.json +1 -1
  3. package/services/tests/api.test.js +35 -20
  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/rcsPayloadUtils.test.js +226 -0
  8. package/utils/tests/templateVarUtils.test.js +204 -0
  9. package/v2Components/CapActionButton/constants.js +7 -0
  10. package/v2Components/CapActionButton/index.js +166 -108
  11. package/v2Components/CapActionButton/index.scss +157 -6
  12. package/v2Components/CapActionButton/messages.js +19 -3
  13. package/v2Components/CapActionButton/tests/index.test.js +41 -17
  14. package/v2Components/CapTagList/index.js +10 -0
  15. package/v2Components/CommonTestAndPreview/CustomValuesEditor.js +72 -49
  16. package/v2Components/CommonTestAndPreview/DeliverySettings/DeliverySettings.scss +8 -2
  17. package/v2Components/CommonTestAndPreview/DeliverySettings/ModifyDeliverySettings.js +213 -21
  18. package/v2Components/CommonTestAndPreview/DeliverySettings/constants.js +16 -0
  19. package/v2Components/CommonTestAndPreview/DeliverySettings/index.js +85 -10
  20. package/v2Components/CommonTestAndPreview/DeliverySettings/messages.js +30 -0
  21. package/v2Components/CommonTestAndPreview/DeliverySettings/utils/parseSenderDetailsResponse.js +79 -11
  22. package/v2Components/CommonTestAndPreview/SendTestMessage.js +10 -5
  23. package/v2Components/CommonTestAndPreview/UnifiedPreview/PreviewHeader.js +0 -17
  24. package/v2Components/CommonTestAndPreview/UnifiedPreview/RcsPreviewContent.js +157 -15
  25. package/v2Components/CommonTestAndPreview/UnifiedPreview/_unifiedPreview.scss +346 -146
  26. package/v2Components/CommonTestAndPreview/UnifiedPreview/index.js +138 -48
  27. package/v2Components/CommonTestAndPreview/_commonTestAndPreview.scss +11 -0
  28. package/v2Components/CommonTestAndPreview/constants.js +38 -4
  29. package/v2Components/CommonTestAndPreview/index.js +691 -235
  30. package/v2Components/CommonTestAndPreview/messages.js +45 -3
  31. package/v2Components/CommonTestAndPreview/previewApiUtils.js +59 -0
  32. package/v2Components/CommonTestAndPreview/sagas.js +25 -6
  33. package/v2Components/CommonTestAndPreview/tests/CustomValuesEditor.test.js +308 -284
  34. package/v2Components/CommonTestAndPreview/tests/DeliverySettings/ModifyDeliverySettings.test.js +231 -65
  35. package/v2Components/CommonTestAndPreview/tests/DeliverySettings/index.test.js +118 -5
  36. package/v2Components/CommonTestAndPreview/tests/DeliverySettings/utils/parseSenderDetailsResponse.test.js +341 -0
  37. package/v2Components/CommonTestAndPreview/tests/PreviewSection.test.js +8 -1
  38. package/v2Components/CommonTestAndPreview/tests/SendTestMessage.test.js +34 -13
  39. package/v2Components/CommonTestAndPreview/tests/UnifiedPreview/PreviewHeader.test.js +0 -159
  40. package/v2Components/CommonTestAndPreview/tests/UnifiedPreview/RcsPreviewContent.test.js +281 -283
  41. package/v2Components/CommonTestAndPreview/tests/UnifiedPreview/index.test.js +199 -256
  42. package/v2Components/CommonTestAndPreview/tests/constants.test.js +1 -2
  43. package/v2Components/CommonTestAndPreview/tests/index.test.js +132 -198
  44. package/v2Components/CommonTestAndPreview/tests/previewApiUtils.test.js +67 -0
  45. package/v2Components/CommonTestAndPreview/tests/sagas.test.js +36 -26
  46. package/v2Components/FormBuilder/index.js +11 -6
  47. package/v2Components/SmsFallback/SmsFallbackLocalSelector.js +91 -0
  48. package/v2Components/SmsFallback/constants.js +73 -0
  49. package/v2Components/SmsFallback/index.js +956 -0
  50. package/v2Components/SmsFallback/index.scss +265 -0
  51. package/v2Components/SmsFallback/messages.js +78 -0
  52. package/v2Components/SmsFallback/smsFallbackUtils.js +119 -0
  53. package/v2Components/SmsFallback/tests/SmsFallbackLocalSelector.test.js +50 -0
  54. package/v2Components/SmsFallback/tests/rcsSmsFallback.acceptance.test.js +147 -0
  55. package/v2Components/SmsFallback/tests/smsFallbackHandlers.test.js +304 -0
  56. package/v2Components/SmsFallback/tests/smsFallbackUi.test.js +223 -0
  57. package/v2Components/SmsFallback/tests/smsFallbackUtils.test.js +309 -0
  58. package/v2Components/SmsFallback/tests/useLocalTemplateList.test.js +422 -0
  59. package/v2Components/SmsFallback/useLocalTemplateList.js +92 -0
  60. package/v2Components/TemplatePreview/_templatePreview.scss +38 -23
  61. package/v2Components/TemplatePreview/constants.js +2 -0
  62. package/v2Components/TemplatePreview/index.js +143 -31
  63. package/v2Components/TemplatePreview/tests/index.test.js +142 -0
  64. package/v2Components/TestAndPreviewSlidebox/index.js +15 -3
  65. package/v2Components/TestAndPreviewSlidebox/sagas.js +11 -4
  66. package/v2Components/TestAndPreviewSlidebox/tests/saga.test.js +3 -1
  67. package/v2Components/VarSegmentMessageEditor/constants.js +2 -0
  68. package/v2Components/VarSegmentMessageEditor/index.js +125 -0
  69. package/v2Components/VarSegmentMessageEditor/index.scss +46 -0
  70. package/v2Containers/App/constants.js +0 -3
  71. package/v2Containers/CreativesContainer/CreativesSlideBoxWrapper.js +43 -0
  72. package/v2Containers/CreativesContainer/SlideBoxContent.js +36 -4
  73. package/v2Containers/CreativesContainer/SlideBoxFooter.js +10 -1
  74. package/v2Containers/CreativesContainer/SlideBoxHeader.js +29 -4
  75. package/v2Containers/CreativesContainer/constants.js +9 -0
  76. package/v2Containers/CreativesContainer/embeddedSlideboxUtils.js +79 -0
  77. package/v2Containers/CreativesContainer/index.js +322 -103
  78. package/v2Containers/CreativesContainer/index.scss +51 -1
  79. package/v2Containers/CreativesContainer/tests/SlideBoxContent.localTemplates.test.js +90 -0
  80. package/v2Containers/CreativesContainer/tests/SlideBoxFooter.test.js +78 -34
  81. package/v2Containers/CreativesContainer/tests/SlideBoxHeader.test.js +79 -16
  82. package/v2Containers/CreativesContainer/tests/__snapshots__/SlideBoxContent.test.js.snap +8 -0
  83. package/v2Containers/CreativesContainer/tests/__snapshots__/SlideBoxHeader.test.js.snap +357 -98
  84. package/v2Containers/CreativesContainer/tests/__snapshots__/index.test.js.snap +20 -15
  85. package/v2Containers/CreativesContainer/tests/embeddedSlideboxUtils.test.js +258 -0
  86. package/v2Containers/CreativesContainer/tests/index.test.js +71 -9
  87. package/v2Containers/CreativesContainer/tests/useLocalTemplatesProp.test.js +125 -0
  88. package/v2Containers/MobilePush/Create/test/saga.test.js +2 -2
  89. package/v2Containers/Rcs/constants.js +119 -10
  90. package/v2Containers/Rcs/index.js +2445 -813
  91. package/v2Containers/Rcs/index.scss +280 -8
  92. package/v2Containers/Rcs/messages.js +34 -3
  93. package/v2Containers/Rcs/rcsLibraryHydrationUtils.js +225 -0
  94. package/v2Containers/Rcs/tests/__snapshots__/index.test.js.snap +98018 -70073
  95. package/v2Containers/Rcs/tests/__snapshots__/utils.test.js.snap +0 -5
  96. package/v2Containers/Rcs/tests/index.test.js +152 -121
  97. package/v2Containers/Rcs/tests/mockData.js +38 -0
  98. package/v2Containers/Rcs/tests/rcsLibraryHydrationUtils.test.js +318 -0
  99. package/v2Containers/Rcs/tests/utils.test.js +646 -30
  100. package/v2Containers/Rcs/utils.js +478 -11
  101. package/v2Containers/Sms/Create/index.js +106 -40
  102. package/v2Containers/Sms/smsFormDataHelpers.js +67 -0
  103. package/v2Containers/Sms/tests/smsFormDataHelpers.test.js +253 -0
  104. package/v2Containers/SmsTrai/Create/index.js +9 -4
  105. package/v2Containers/SmsTrai/Edit/constants.js +2 -0
  106. package/v2Containers/SmsTrai/Edit/index.js +640 -130
  107. package/v2Containers/SmsTrai/Edit/index.scss +121 -0
  108. package/v2Containers/SmsTrai/Edit/messages.js +14 -4
  109. package/v2Containers/SmsTrai/Edit/tests/__snapshots__/index.test.js.snap +4328 -2375
  110. package/v2Containers/SmsWrapper/index.js +37 -8
  111. package/v2Containers/TagList/index.js +6 -0
  112. package/v2Containers/Templates/TemplatesActionBar.js +101 -0
  113. package/v2Containers/Templates/_templates.scss +166 -9
  114. package/v2Containers/Templates/actions.js +11 -0
  115. package/v2Containers/Templates/constants.js +2 -0
  116. package/v2Containers/Templates/index.js +122 -120
  117. package/v2Containers/Templates/sagas.js +56 -12
  118. package/v2Containers/Templates/tests/TemplatesActionBar.test.js +120 -0
  119. package/v2Containers/Templates/tests/__snapshots__/index.test.js.snap +1062 -1017
  120. package/v2Containers/Templates/tests/sagas.test.js +199 -16
  121. package/v2Containers/Templates/tests/smsTemplatesListApi.test.js +180 -0
  122. package/v2Containers/Templates/utils/smsTemplatesListApi.js +79 -0
  123. package/v2Containers/TemplatesV2/TemplatesV2.style.js +72 -1
  124. package/v2Containers/TemplatesV2/index.js +86 -23
  125. package/v2Containers/TemplatesV2/tests/TemplatesV2.localTemplates.test.js +131 -0
  126. package/v2Containers/WeChat/MapTemplates/test/saga.test.js +9 -9
  127. package/v2Containers/WebPush/Create/index.js +8 -91
  128. package/v2Containers/WebPush/Create/index.scss +0 -7
  129. package/v2Containers/Whatsapp/index.js +3 -20
  130. package/v2Containers/Whatsapp/tests/__snapshots__/index.test.js.snap +578 -34
  131. package/v2Components/CommonTestAndPreview/UnifiedPreview/WebPushPreviewContent.js +0 -169
  132. package/v2Components/CommonTestAndPreview/tests/UnifiedPreview/WebPushPreviewContent.test.js +0 -522
  133. package/v2Containers/App/tests/constants.test.js +0 -61
  134. package/v2Containers/Templates/tests/webpush.test.js +0 -375
  135. package/v2Containers/WebPush/Create/tests/getTemplateContent.test.js +0 -338
  136. package/v2Containers/WebPush/Create/tests/testAndPreviewIntegration.test.js +0 -325
@@ -1,20 +1,22 @@
1
1
  import { expectSaga } from 'redux-saga-test-plan';
2
+ import {
3
+ take, call, takeLatest, takeEvery, put,
4
+ } from 'redux-saga/effects';
2
5
  import * as matchers from 'redux-saga-test-plan/matchers';
3
6
  import { throwError } from 'redux-saga-test-plan/providers';
4
- import { call, takeLatest, put } from 'redux-saga/effects';
5
7
  import * as api from '../../../services/api';
6
8
  import * as types from '../constants';
7
9
  import * as cdnUtils from '../../../utils/cdnTransformation';
8
10
  import {
9
11
  getCdnTransformationConfig,
10
12
  getAllTemplates,
13
+ getLocalSmsTemplates,
11
14
  watchGetCdnTransformationConfig,
12
15
  watchGetAllTemplates,
13
16
  getSenderDetails,
14
17
  fetchWeCrmAccounts,
15
18
  sendZippedFile,
16
19
  fetchUserList,
17
- watchGetUserList,
18
20
  deleteRcsTemplate,
19
21
  watchDeleteRcsTemplate,
20
22
  watchForGetTemplateInfoById,
@@ -39,10 +41,14 @@ import {
39
41
  watchUnarchiveTemplate,
40
42
  watchBulkArchive,
41
43
  watchBulkUnarchive,
44
+ watchGetUserList,
42
45
  } from '../sagas';
43
- import { getTemplateInfoById } from '../../Zalo/saga';
44
- import { ZALO_TEMPLATE_INFO_REQUEST } from '../../Zalo/constants';
46
+
45
47
  import * as mockData from './mockData';
48
+ import { fetchSmsTemplatesFromQuery } from '../utils/smsTemplatesListApi';
49
+ import { ZALO } from '../../CreativesContainer/constants';
50
+ import { VIET_GUYS, ZALO_TEMPLATE_INFO_REQUEST } from '../../Zalo/constants';
51
+ import { getTemplateInfoById } from '../../Zalo/saga';
46
52
 
47
53
  jest.mock('@capillarytech/cap-ui-library', () => ({
48
54
  CapNotification: {
@@ -150,8 +156,8 @@ describe('templateList saga', () => {
150
156
  ],
151
157
  ]).put({
152
158
  type: types.GET_ALL_TEMPLATES_SUCCESS,
153
- data: mockData.getAllTemplatesListSuccess,
154
- weCRMTemplate: mockData.getAllTemplatesListSuccess,
159
+ data: mockData.getAllTemplatesListSuccess.response,
160
+ weCRMTemplate: mockData.getAllTemplatesListSuccess.response?.unMapped,
155
161
  isReset: mockData.getAllTemplatesListSuccess?.queryParams?.page === 1,
156
162
  })
157
163
  .run();
@@ -167,8 +173,8 @@ describe('templateList saga', () => {
167
173
  ],
168
174
  ]).put({
169
175
  type: types.GET_ALL_TEMPLATES_SUCCESS,
170
- data: mockData.getAllTemplatesListSuccess,
171
- weCRMTemplate: mockData.getAllTemplatesListSuccess,
176
+ data: mockData.getAllTemplatesListSuccess.response,
177
+ weCRMTemplate: mockData.getAllTemplatesListSuccess.response?.unMapped,
172
178
  isReset: mockData.getAllTemplatesListSuccess?.queryParams?.page === 1,
173
179
  })
174
180
  .run();
@@ -187,6 +193,163 @@ describe('templateList saga', () => {
187
193
  })
188
194
  .run();
189
195
  });
196
+
197
+ it('SMS channel uses fetchSmsTemplatesFromQuery', () => {
198
+ const smsAction = {
199
+ type: types.GET_ALL_TEMPLATES_REQUEST,
200
+ channel: 'Sms',
201
+ queryParams: { page: 1, perPage: 25, name: '', sortBy: 'Most Recent' },
202
+ intlCopyOf: 'Kopie',
203
+ };
204
+ const fetched = {
205
+ channelTemplates: { templates: [{ name: 'Kopie Foo' }], totalCount: 1 },
206
+ weCRMTemplate: undefined,
207
+ raw: {},
208
+ };
209
+ return expectSaga(getAllTemplates, smsAction)
210
+ .provide([
211
+ [call(fetchSmsTemplatesFromQuery, smsAction.queryParams, smsAction.intlCopyOf), fetched],
212
+ ])
213
+ .put({
214
+ type: types.GET_ALL_TEMPLATES_SUCCESS,
215
+ data: fetched.channelTemplates,
216
+ weCRMTemplate: fetched.weCRMTemplate,
217
+ isReset: true,
218
+ })
219
+ .run();
220
+ });
221
+
222
+ it('SMS channel propagates fetchSmsTemplatesFromQuery errors', () => {
223
+ const smsAction = {
224
+ type: types.GET_ALL_TEMPLATES_REQUEST,
225
+ channel: 'SMS',
226
+ queryParams: { page: 2, perPage: 25 },
227
+ intlCopyOf: '',
228
+ };
229
+ const error = new Error('sms list fail');
230
+ return expectSaga(getAllTemplates, smsAction)
231
+ .provide([
232
+ [call(fetchSmsTemplatesFromQuery, smsAction.queryParams, smsAction.intlCopyOf), throwError(error)],
233
+ ])
234
+ .put({
235
+ type: types.GET_ALL_TEMPLATES_FAILURE,
236
+ error,
237
+ })
238
+ .run();
239
+ });
240
+
241
+ it('wechat channel merges mapped and richmedia and applies Most Recent sort', () => {
242
+ const wechatApiResponse = {
243
+ response: {
244
+ mapped: [
245
+ { name: 'B', updatedAt: '2024-01-02T00:00:00Z' },
246
+ { name: 'A', updatedAt: '2024-01-01T00:00:00Z' },
247
+ ],
248
+ richmedia: [{ name: 'C', updatedAt: '2024-01-03T00:00:00Z' }],
249
+ unMapped: [],
250
+ },
251
+ };
252
+ const action = {
253
+ channel: 'wechat',
254
+ queryParams: { sortBy: 'Most Recent', page: 1 },
255
+ intlCopyOf: '',
256
+ };
257
+ return expectSaga(getAllTemplates, action)
258
+ .provide([[matchers.call.fn(api.getAllTemplates), wechatApiResponse]])
259
+ .put.actionType(types.GET_ALL_TEMPLATES_SUCCESS)
260
+ .run();
261
+ });
262
+
263
+ it('wechat channel applies Alphabetically sort', () => {
264
+ const wechatApiResponse = {
265
+ response: {
266
+ mapped: [{ name: 'Zebra', updatedAt: '2024-01-02T00:00:00Z' }],
267
+ richmedia: [{ name: 'Apple', updatedAt: '2024-01-01T00:00:00Z' }],
268
+ unMapped: [],
269
+ },
270
+ };
271
+ const action = {
272
+ channel: 'wechat',
273
+ queryParams: { sortBy: 'Alphabetically', page: 1 },
274
+ intlCopyOf: '',
275
+ };
276
+ return expectSaga(getAllTemplates, action)
277
+ .provide([[matchers.call.fn(api.getAllTemplates), wechatApiResponse]])
278
+ .put.actionType(types.GET_ALL_TEMPLATES_SUCCESS)
279
+ .run();
280
+ });
281
+
282
+ it('wechat channel replaces Copy-of prefix when intlCopyOf is set', () => {
283
+ const wechatApiResponse = {
284
+ response: {
285
+ mapped: [{ name: 'Copy of Promo', updatedAt: '2024-01-01T00:00:00Z' }],
286
+ richmedia: [],
287
+ unMapped: [],
288
+ },
289
+ };
290
+ const action = {
291
+ channel: 'wechat',
292
+ queryParams: { page: 1 },
293
+ intlCopyOf: 'Kopia av ',
294
+ };
295
+ return expectSaga(getAllTemplates, action)
296
+ .provide([[matchers.call.fn(api.getAllTemplates), wechatApiResponse]])
297
+ .put.actionType(types.GET_ALL_TEMPLATES_SUCCESS)
298
+ .run();
299
+ });
300
+ });
301
+
302
+ describe('getLocalSmsTemplates saga', () => {
303
+ it('invokes onSuccess with fetched data', () => {
304
+ const onSuccess = jest.fn();
305
+ const action = {
306
+ queryParams: { page: 1 },
307
+ intlCopyOf: '',
308
+ onSuccess,
309
+ };
310
+ const fetched = { channelTemplates: { templates: [] }, raw: {} };
311
+ return expectSaga(getLocalSmsTemplates, action)
312
+ .provide([[call(fetchSmsTemplatesFromQuery, action.queryParams, action.intlCopyOf), fetched]])
313
+ .call(onSuccess, fetched)
314
+ .run();
315
+ });
316
+
317
+ it('invokes onFailure when fetch throws', () => {
318
+ const onFailure = jest.fn();
319
+ const error = new Error('local list fail');
320
+ const action = {
321
+ queryParams: { page: 1 },
322
+ intlCopyOf: 'Kopie',
323
+ onFailure,
324
+ };
325
+ return expectSaga(getLocalSmsTemplates, action)
326
+ .provide([
327
+ [call(fetchSmsTemplatesFromQuery, action.queryParams, action.intlCopyOf), throwError(error)],
328
+ ])
329
+ .call(onFailure, error)
330
+ .run();
331
+ });
332
+
333
+ it('does not throw when callbacks are omitted', () => {
334
+ const action = { queryParams: { page: 1 }, intlCopyOf: '' };
335
+ return expectSaga(getLocalSmsTemplates, action)
336
+ .provide([
337
+ [call(fetchSmsTemplatesFromQuery, action.queryParams, action.intlCopyOf), throwError(new Error('x'))],
338
+ ])
339
+ .run();
340
+ });
341
+
342
+ it('does not call onSuccess when it is not a function', () => {
343
+ const action = {
344
+ queryParams: { page: 1 },
345
+ intlCopyOf: '',
346
+ onSuccess: 'not-a-fn',
347
+ };
348
+ const fetched = { channelTemplates: { templates: [] } };
349
+ return expectSaga(getLocalSmsTemplates, action)
350
+ .provide([[call(fetchSmsTemplatesFromQuery, action.queryParams, action.intlCopyOf), fetched]])
351
+ .run();
352
+ });
190
353
  });
191
354
 
192
355
  describe('watchForTemplates saga', () => {
@@ -380,7 +543,7 @@ describe('getSenderDetails Saga', () => {
380
543
 
381
544
  describe('fetchWeCrmAccounts Saga', () => {
382
545
  const action = { source: 'CRM' };
383
- test.concurrent('handles successful fetching of WeCRM accounts', () => {
546
+ it('handles successful fetching of WeCRM accounts', () => {
384
547
  const fakeResponse = {
385
548
  response: [{ id: 1, name: 'Account One' }]
386
549
  };
@@ -393,14 +556,11 @@ describe('fetchWeCrmAccounts Saga', () => {
393
556
  })
394
557
  );
395
558
  });
396
- test.concurrent('handles error thrown from api', () => {
559
+ it('handles error thrown from api', () => {
397
560
  const error = new Error('Fetch failed');
398
- expectSaga(fetchWeCrmAccounts, action.source)
561
+ expectSaga(fetchWeCrmAccounts, action)
399
562
  .provide([
400
- [
401
- call(api.fetchWeCrmAccounts),
402
- throwError(error)
403
- ],
563
+ [call(api.fetchWeCrmAccounts, action.source), throwError(error)],
404
564
  ])
405
565
  .put({
406
566
  type: types.GET_WECRM_ACCOUNTS_FAILURE,
@@ -442,6 +602,29 @@ describe('sendZippedFile Saga', () => {
442
602
  expect(generator.next().value).toEqual(call(api.sendZippedFile, action.selectedFile));
443
603
  });
444
604
 
605
+ it('calls errorHandler with message and returns early when isError is true', () => {
606
+ const errorHandler = jest.fn();
607
+ const successHandler = jest.fn();
608
+ const errorAction = {
609
+ selectedFile: 'upload.zip',
610
+ errorHandler,
611
+ successHandler,
612
+ };
613
+ const fakeErrorResponse = {
614
+ status: { isError: true },
615
+ message: 'Upload failed',
616
+ };
617
+ const generator = sendZippedFile(errorAction);
618
+ expect(generator.next().value).toEqual(call(api.sendZippedFile, errorAction.selectedFile));
619
+ // Advancing with isError response causes the saga to call errorHandler and yield
620
+ const yieldStep = generator.next(fakeErrorResponse);
621
+ expect(errorHandler).toHaveBeenCalledWith('Upload failed');
622
+ expect(yieldStep.done).toBe(false);
623
+ // After resuming from the yield, the return statement completes the generator
624
+ expect(generator.next().done).toBe(true);
625
+ expect(successHandler).not.toHaveBeenCalled();
626
+ });
627
+
445
628
  it('handles error thrown from api', () => {
446
629
  const error = new Error('Fetch failed');
447
630
  expectSaga(sendZippedFile, action)
@@ -1207,7 +1390,7 @@ describe('v2TemplateSaga', () => {
1207
1390
  // all() returns an IO object with an ALL key containing the array of effects
1208
1391
  expect(step.value).toHaveProperty('@@redux-saga/IO', true);
1209
1392
  expect(step.value).toHaveProperty('ALL');
1210
- expect(step.value.ALL).toHaveLength(14);
1393
+ expect(step.value.ALL).toHaveLength(15);
1211
1394
  expect(step.done).toBe(false);
1212
1395
  });
1213
1396
  });
@@ -0,0 +1,180 @@
1
+ import * as Api from '../../../services/api';
2
+ import { isTraiDLTEnable } from '../../../utils/common';
3
+
4
+ jest.mock('../../../services/api', () => ({
5
+ getAllTemplates: jest.fn(),
6
+ }));
7
+
8
+ jest.mock('../../../utils/common', () => ({
9
+ isTraiDLTEnable: jest.fn(),
10
+ }));
11
+
12
+ import {
13
+ buildSmsTemplatesListQueryParams,
14
+ fetchSmsTemplatesFromQuery,
15
+ fetchSmsTemplatesListPage,
16
+ SMS_TEMPLATES_LIST_SORT_MOST_RECENT,
17
+ } from '../utils/smsTemplatesListApi';
18
+
19
+ describe('smsTemplatesListApi', () => {
20
+ beforeEach(() => {
21
+ jest.clearAllMocks();
22
+ });
23
+
24
+ describe('buildSmsTemplatesListQueryParams', () => {
25
+ it('includes traiEnable when TRAI DLT is enabled', () => {
26
+ isTraiDLTEnable.mockReturnValue(true);
27
+ const q = buildSmsTemplatesListQueryParams({
28
+ page: 1,
29
+ perPage: 25,
30
+ name: 'x',
31
+ sortBy: SMS_TEMPLATES_LIST_SORT_MOST_RECENT,
32
+ isFullMode: true,
33
+ smsRegister: {},
34
+ });
35
+ expect(q).toEqual({
36
+ page: 1,
37
+ perPage: 25,
38
+ sortBy: SMS_TEMPLATES_LIST_SORT_MOST_RECENT,
39
+ name: 'x',
40
+ traiEnable: true,
41
+ });
42
+ });
43
+
44
+ it('omits traiEnable when TRAI DLT is disabled', () => {
45
+ isTraiDLTEnable.mockReturnValue(false);
46
+ const q = buildSmsTemplatesListQueryParams({
47
+ page: 2,
48
+ perPage: 10,
49
+ isFullMode: false,
50
+ smsRegister: null,
51
+ });
52
+ expect(q.traiEnable).toBeUndefined();
53
+ expect(q.name).toBe('');
54
+ expect(q.sortBy).toBe(SMS_TEMPLATES_LIST_SORT_MOST_RECENT);
55
+ });
56
+ });
57
+
58
+ describe('fetchSmsTemplatesFromQuery', () => {
59
+ it('returns channelTemplates, weCRMTemplate, and raw; maps intl copy on names', async () => {
60
+ Api.getAllTemplates.mockResolvedValue({
61
+ response: {
62
+ templates: [{ name: 'Copy of A', _id: '1' }],
63
+ unMapped: { u: 1 },
64
+ totalCount: 5,
65
+ },
66
+ });
67
+
68
+ const out = await fetchSmsTemplatesFromQuery(
69
+ { page: 1, perPage: 25 },
70
+ 'Kopie',
71
+ );
72
+
73
+ expect(Api.getAllTemplates).toHaveBeenCalledWith({
74
+ channel: 'Sms',
75
+ queryParams: { page: 1, perPage: 25 },
76
+ });
77
+ expect(out.weCRMTemplate).toEqual({ u: 1 });
78
+ expect(out.raw.response.templates[0].name).toBe('Copy of A');
79
+ expect(out.channelTemplates.templates[0].name).toBe('Kopie A');
80
+ expect(out.channelTemplates.totalCount).toBe(5);
81
+ });
82
+
83
+ it('skips name mapping when intlCopyOf is empty', async () => {
84
+ Api.getAllTemplates.mockResolvedValue({
85
+ response: {
86
+ templates: [{ name: 'Copy of A' }],
87
+ },
88
+ });
89
+ const out = await fetchSmsTemplatesFromQuery({ page: 1 }, '');
90
+ expect(out.channelTemplates.templates[0].name).toBe('Copy of A');
91
+ });
92
+
93
+ it('handles missing response.templates', async () => {
94
+ Api.getAllTemplates.mockResolvedValue({ response: {} });
95
+ const out = await fetchSmsTemplatesFromQuery({}, '');
96
+ expect(out.channelTemplates.templates).toEqual([]);
97
+ });
98
+
99
+ it('uses empty response when raw.response is missing', async () => {
100
+ Api.getAllTemplates.mockResolvedValue({});
101
+ const out = await fetchSmsTemplatesFromQuery({}, '');
102
+ expect(out.channelTemplates.templates).toEqual([]);
103
+ expect(out.weCRMTemplate).toBeUndefined();
104
+ });
105
+
106
+ it('does not map names when intlCopyOf is set but templates list is empty', async () => {
107
+ Api.getAllTemplates.mockResolvedValue({
108
+ response: { templates: [] },
109
+ });
110
+ const out = await fetchSmsTemplatesFromQuery({ page: 1 }, 'X');
111
+ expect(out.channelTemplates.templates).toEqual([]);
112
+ });
113
+
114
+ it('uses empty string when template name is missing during intl mapping', async () => {
115
+ Api.getAllTemplates.mockResolvedValue({
116
+ response: {
117
+ templates: [{ _id: 'n', name: undefined }],
118
+ },
119
+ });
120
+ const out = await fetchSmsTemplatesFromQuery({ page: 1 }, 'Lbl');
121
+ expect(out.channelTemplates.templates[0].name).toBe('');
122
+ });
123
+ });
124
+
125
+ describe('fetchSmsTemplatesListPage', () => {
126
+ it('falls back to total when totalCount is absent', async () => {
127
+ isTraiDLTEnable.mockReturnValue(false);
128
+ Api.getAllTemplates.mockResolvedValue({
129
+ response: {
130
+ templates: [{ _id: 'a' }],
131
+ total: 7,
132
+ },
133
+ });
134
+
135
+ const page = await fetchSmsTemplatesListPage({
136
+ page: 1,
137
+ perPage: 25,
138
+ name: '',
139
+ sortBy: SMS_TEMPLATES_LIST_SORT_MOST_RECENT,
140
+ isFullMode: true,
141
+ smsRegister: {},
142
+ intlCopyOf: '',
143
+ });
144
+
145
+ expect(page.templates).toEqual([{ _id: 'a' }]);
146
+ expect(page.totalCount).toBe(7);
147
+ });
148
+
149
+ it('uses totalCount when set', async () => {
150
+ isTraiDLTEnable.mockReturnValue(false);
151
+ Api.getAllTemplates.mockResolvedValue({
152
+ response: {
153
+ templates: [],
154
+ totalCount: 12,
155
+ },
156
+ });
157
+ const page = await fetchSmsTemplatesListPage({
158
+ page: 1,
159
+ perPage: 25,
160
+ isFullMode: false,
161
+ smsRegister: {},
162
+ });
163
+ expect(page.totalCount).toBe(12);
164
+ });
165
+
166
+ it('normalizes total to 0 when missing counts', async () => {
167
+ isTraiDLTEnable.mockReturnValue(false);
168
+ Api.getAllTemplates.mockResolvedValue({
169
+ response: { templates: [] },
170
+ });
171
+ const page = await fetchSmsTemplatesListPage({
172
+ page: 1,
173
+ perPage: 25,
174
+ isFullMode: false,
175
+ smsRegister: {},
176
+ });
177
+ expect(page.totalCount).toBe(0);
178
+ });
179
+ });
180
+ });
@@ -0,0 +1,79 @@
1
+ import get from 'lodash/get';
2
+ import * as Api from '../../../services/api';
3
+ import { COPY_OF } from '../../../constants/unified';
4
+ import { isTraiDLTEnable } from '../../../utils/common';
5
+
6
+ /** Matches Templates `getAllTemplates` default for SMS. */
7
+ export const SMS_TEMPLATES_LIST_SORT_MOST_RECENT = 'Most Recent';
8
+
9
+ /**
10
+ * Same query shape as Redux `GET_ALL_TEMPLATES` for channel Sms (DLT vs non-DLT via traiEnable).
11
+ */
12
+ export function buildSmsTemplatesListQueryParams({
13
+ page,
14
+ perPage,
15
+ name = '',
16
+ sortBy = SMS_TEMPLATES_LIST_SORT_MOST_RECENT,
17
+ isFullMode,
18
+ smsRegister,
19
+ }) {
20
+ const traiDlt = isTraiDLTEnable(isFullMode, smsRegister);
21
+ return {
22
+ page,
23
+ perPage,
24
+ sortBy,
25
+ name: name || '',
26
+ ...(traiDlt ? { traiEnable: true } : {}),
27
+ };
28
+ }
29
+
30
+ /**
31
+ * SMS list for Redux saga: uses queryParams already built by Templates (incl. traiEnable).
32
+ * Applies the same "Copy of" → intl label as the former inline saga logic.
33
+ */
34
+ export async function fetchSmsTemplatesFromQuery(queryParams, intlCopyOf = '') {
35
+ const raw = await Api.getAllTemplates({ channel: 'Sms', queryParams });
36
+ const response = raw.response || {};
37
+ let templates = get(response, 'templates', []) || [];
38
+ if (intlCopyOf && templates.length) {
39
+ templates = templates.map((template) => ({
40
+ ...template,
41
+ name: (template.name || '').replace(new RegExp(COPY_OF, 'g'), intlCopyOf),
42
+ }));
43
+ }
44
+ const channelTemplates = { ...response, templates };
45
+ return {
46
+ channelTemplates,
47
+ weCRMTemplate: response.unMapped,
48
+ raw,
49
+ };
50
+ }
51
+
52
+ /**
53
+ * SMS list for the RCS SMS fallback picker only.
54
+ * Called from `useLocalTemplateList` in SmsFallback — keeps data in component state and pairs with
55
+ * `localTemplatesConfig` / `useLocalTemplates` in TemplatesV2. Does **not** use GET_ALL_TEMPLATES saga.
56
+ * Same HTTP call shape as `fetchSmsTemplatesFromQuery` (used by the main SMS GET_ALL_TEMPLATES saga).
57
+ */
58
+ export async function fetchSmsTemplatesListPage({
59
+ page,
60
+ perPage,
61
+ name,
62
+ sortBy,
63
+ isFullMode,
64
+ smsRegister,
65
+ intlCopyOf = '',
66
+ }) {
67
+ const queryParams = buildSmsTemplatesListQueryParams({
68
+ page,
69
+ perPage,
70
+ name,
71
+ sortBy,
72
+ isFullMode,
73
+ smsRegister,
74
+ });
75
+ const { channelTemplates } = await fetchSmsTemplatesFromQuery(queryParams, intlCopyOf);
76
+ const templates = channelTemplates.templates || [];
77
+ const totalCount = get(channelTemplates, 'totalCount', get(channelTemplates, 'total', 0)) || 0;
78
+ return { templates, totalCount };
79
+ }
@@ -10,7 +10,7 @@ export default css`
10
10
 
11
11
  .component-wrapper {
12
12
  ${(props) => props.isFullMode ? `
13
- max-width: 1140px;
13
+ max-width: 71.25rem;
14
14
  margin: 0 auto;
15
15
  width: 100%;
16
16
  padding: 0.714rem 0;
@@ -23,6 +23,77 @@ export default css`
23
23
  height: calc(100vh - 11.25rem);
24
24
  } `}
25
25
  }
26
+
27
+ /* SMS fallback / local list: single pane skips .cap-tab-v2, so flex-fill the grid instead of viewport-fixed pagination height */
28
+ .creatives-templates-container--local-sms.library-mode {
29
+ display: flex;
30
+ flex-direction: column;
31
+ flex: 1;
32
+ min-height: 0;
33
+ height: 100%;
34
+
35
+ .component-wrapper {
36
+ display: flex;
37
+ flex-direction: column;
38
+ flex: 1;
39
+ min-height: 0;
40
+ height: 100%;
41
+ }
42
+
43
+ .templates-v2-local-sms-pane {
44
+ display: flex;
45
+ flex-direction: column;
46
+ flex: 1;
47
+ min-height: 0;
48
+ overflow: hidden;
49
+ height: 100%;
50
+ }
51
+
52
+ .templates-v2-local-sms-pane .creatives-templates-list.library-mode {
53
+ display: flex;
54
+ flex-direction: column;
55
+ flex: 1;
56
+ min-height: 0;
57
+ overflow: hidden;
58
+ height: 100%;
59
+ }
60
+
61
+ .templates-v2-local-sms-pane .creatives-templates-list.library-mode > .cap-row:first-of-type {
62
+ flex: 1;
63
+ min-height: 0;
64
+ display: flex;
65
+ flex-direction: column;
66
+ overflow: hidden;
67
+ }
68
+
69
+ .templates-v2-local-sms-pane .creatives-templates-list.library-mode > .cap-row:first-of-type > div {
70
+ flex: 1;
71
+ min-height: 0;
72
+ display: flex;
73
+ flex-direction: column;
74
+ overflow: hidden;
75
+ }
76
+
77
+ .templates-v2-local-sms-pane .creatives-templates-list.library-mode > .cap-row:first-of-type > div > div:first-child {
78
+ flex: 1;
79
+ min-height: 0;
80
+ display: flex;
81
+ flex-direction: column;
82
+ overflow: hidden;
83
+ }
84
+
85
+ .templates-v2-local-sms-pane .v2-pagination-container,
86
+ .templates-v2-local-sms-pane .v2-pagination-container-half {
87
+ /* Match _templates local-SMS: bounded height so overflow-y scroll works (flex+100% alone often doesn’t) */
88
+ flex: 0 1 auto;
89
+ min-height: 0;
90
+ height: calc(100vh - 12rem);
91
+ max-height: calc(100vh - 12rem);
92
+ overflow-y: auto;
93
+ overflow-x: hidden;
94
+ -webkit-overflow-scrolling: touch;
95
+ }
96
+ }
26
97
  `;
27
98
 
28
99
  export const CapTabStyle = css`