@capillarytech/creatives-library 8.0.125-alpha.6 → 8.0.126

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 (105) hide show
  1. package/config/app.js +6 -0
  2. package/containers/App/constants.js +0 -1
  3. package/containers/Email/index.js +5 -5
  4. package/containers/WeChat/RichmediaTemplates/Create/index.js +1 -1
  5. package/initialReducer.js +2 -0
  6. package/package.json +1 -1
  7. package/services/api.js +94 -1
  8. package/services/tests/api.test.js +191 -0
  9. package/tests/integration/TemplateCreation/TemplateCreation.integration.test.js +3 -8
  10. package/tests/integration/TemplateCreation/api-response.js +0 -5
  11. package/tests/integration/TemplateCreation/msw-handler.js +63 -42
  12. package/utils/common.js +0 -7
  13. package/utils/commonUtils.js +6 -2
  14. package/v2Components/CapImageUpload/index.js +45 -51
  15. package/v2Components/CapInAppCTA/index.js +0 -1
  16. package/v2Components/CapTagList/index.js +120 -177
  17. package/v2Components/CapVideoUpload/constants.js +0 -3
  18. package/v2Components/CapVideoUpload/index.js +110 -167
  19. package/v2Components/CapVideoUpload/messages.js +0 -16
  20. package/v2Components/Carousel/index.js +13 -15
  21. package/v2Components/CustomerSearchSection/_customerSearch.scss +309 -0
  22. package/v2Components/CustomerSearchSection/constants.js +5 -0
  23. package/v2Components/CustomerSearchSection/index.js +362 -0
  24. package/v2Components/CustomerSearchSection/messages.js +20 -0
  25. package/v2Components/CustomerSearchSection/tests/utils.test.js +334 -0
  26. package/v2Components/CustomerSearchSection/utils.js +49 -0
  27. package/v2Components/ErrorInfoNote/style.scss +0 -1
  28. package/v2Components/MobilePushPreviewV2/index.js +5 -37
  29. package/v2Components/TemplatePreview/_templatePreview.scss +72 -114
  30. package/v2Components/TemplatePreview/index.js +50 -178
  31. package/v2Components/TemplatePreview/messages.js +0 -4
  32. package/v2Components/TestAndPreviewSlidebox/_testAndPreviewSlidebox.scss +543 -0
  33. package/v2Components/TestAndPreviewSlidebox/actions.js +67 -0
  34. package/v2Components/TestAndPreviewSlidebox/constants.js +67 -0
  35. package/v2Components/TestAndPreviewSlidebox/index.js +771 -0
  36. package/v2Components/TestAndPreviewSlidebox/messages.js +147 -0
  37. package/v2Components/TestAndPreviewSlidebox/reducer.js +233 -0
  38. package/v2Components/TestAndPreviewSlidebox/sagas.js +258 -0
  39. package/v2Components/TestAndPreviewSlidebox/selectors.js +142 -0
  40. package/v2Components/TestAndPreviewSlidebox/tests/actions.test.js +80 -0
  41. package/v2Components/TestAndPreviewSlidebox/tests/reducer.test.js +367 -0
  42. package/v2Components/TestAndPreviewSlidebox/tests/saga.rtl.test.js +192 -0
  43. package/v2Components/TestAndPreviewSlidebox/tests/saga.test.js +652 -0
  44. package/v2Components/TestAndPreviewSlidebox/tests/selector.test.js +182 -0
  45. package/v2Containers/CreativesContainer/SlideBoxContent.js +21 -9
  46. package/v2Containers/CreativesContainer/SlideBoxFooter.js +23 -2
  47. package/v2Containers/CreativesContainer/index.js +160 -195
  48. package/v2Containers/CreativesContainer/messages.js +4 -0
  49. package/v2Containers/CreativesContainer/tests/__snapshots__/index.test.js.snap +21 -0
  50. package/v2Containers/Email/index.js +18 -6
  51. package/v2Containers/EmailWrapper/hooks/useEmailWrapper.js +10 -0
  52. package/v2Containers/EmailWrapper/index.js +6 -0
  53. package/v2Containers/InApp/constants.js +0 -1
  54. package/v2Containers/InApp/index.js +13 -13
  55. package/v2Containers/Line/Container/ImageCarousel/tests/__snapshots__/content.test.js.snap +3 -0
  56. package/v2Containers/Line/Container/ImageCarousel/tests/__snapshots__/index.test.js.snap +2 -0
  57. package/v2Containers/Line/Container/Wrapper/tests/__snapshots__/index.test.js.snap +2 -0
  58. package/v2Containers/Line/Container/tests/__snapshots__/index.test.js.snap +9 -0
  59. package/v2Containers/MobilePush/Create/index.js +0 -1
  60. package/v2Containers/MobilePush/commonMethods.js +14 -7
  61. package/v2Containers/Rcs/tests/__snapshots__/index.test.js.snap +23 -5
  62. package/v2Containers/SmsTrai/Edit/tests/__snapshots__/index.test.js.snap +4 -0
  63. package/v2Containers/TagList/index.js +10 -56
  64. package/v2Containers/Templates/_templates.scss +1 -101
  65. package/v2Containers/Templates/index.js +35 -147
  66. package/v2Containers/Templates/messages.js +0 -8
  67. package/v2Containers/Templates/sagas.js +0 -2
  68. package/v2Containers/WeChat/RichmediaTemplates/Create/index.js +1 -1
  69. package/v2Containers/Whatsapp/constants.js +0 -1
  70. package/v2Containers/Whatsapp/tests/__snapshots__/index.test.js.snap +35 -0
  71. package/utils/createPayload.js +0 -270
  72. package/utils/tests/createPayload.test.js +0 -761
  73. package/v2Components/CapMpushCTA/constants.js +0 -25
  74. package/v2Components/CapMpushCTA/index.js +0 -332
  75. package/v2Components/CapMpushCTA/index.scss +0 -95
  76. package/v2Components/CapMpushCTA/messages.js +0 -89
  77. package/v2Components/TemplatePreview/assets/images/Android _ With date and time.svg +0 -29
  78. package/v2Components/TemplatePreview/assets/images/android.svg +0 -9
  79. package/v2Components/TemplatePreview/assets/images/iOS _ With date and time.svg +0 -26
  80. package/v2Components/TemplatePreview/assets/images/ios.svg +0 -9
  81. package/v2Containers/Email/tests/index.test.js +0 -35
  82. package/v2Containers/MobilePushNew/actions.js +0 -116
  83. package/v2Containers/MobilePushNew/components/CtaButtons.js +0 -170
  84. package/v2Containers/MobilePushNew/components/MediaUploaders.js +0 -686
  85. package/v2Containers/MobilePushNew/components/PlatformContentFields.js +0 -279
  86. package/v2Containers/MobilePushNew/components/index.js +0 -5
  87. package/v2Containers/MobilePushNew/components/tests/CtaButtons.test.js +0 -779
  88. package/v2Containers/MobilePushNew/components/tests/MediaUploaders.test.js +0 -2114
  89. package/v2Containers/MobilePushNew/components/tests/PlatformContentFields.test.js +0 -343
  90. package/v2Containers/MobilePushNew/constants.js +0 -115
  91. package/v2Containers/MobilePushNew/hooks/tests/usePlatformSync.test.js +0 -1299
  92. package/v2Containers/MobilePushNew/hooks/tests/useUpload.test.js +0 -1223
  93. package/v2Containers/MobilePushNew/hooks/usePlatformSync.js +0 -246
  94. package/v2Containers/MobilePushNew/hooks/useUpload.js +0 -709
  95. package/v2Containers/MobilePushNew/index.js +0 -2170
  96. package/v2Containers/MobilePushNew/index.scss +0 -308
  97. package/v2Containers/MobilePushNew/messages.js +0 -226
  98. package/v2Containers/MobilePushNew/reducer.js +0 -160
  99. package/v2Containers/MobilePushNew/sagas.js +0 -198
  100. package/v2Containers/MobilePushNew/selectors.js +0 -55
  101. package/v2Containers/MobilePushNew/tests/reducer.test.js +0 -741
  102. package/v2Containers/MobilePushNew/tests/sagas.test.js +0 -863
  103. package/v2Containers/MobilePushNew/tests/selectors.test.js +0 -425
  104. package/v2Containers/MobilePushNew/tests/utils.test.js +0 -322
  105. package/v2Containers/MobilePushNew/utils.js +0 -33
@@ -1,741 +0,0 @@
1
- import { fromJS } from 'immutable';
2
- import mobilePushReducer from '../reducer';
3
- import * as types from '../constants';
4
-
5
- describe('MobilePushNew Reducer', () => {
6
- const initialState = fromJS({
7
- createTemplateInProgress: false,
8
- response: {},
9
- editTemplateInProgress: false,
10
- editResponse: {},
11
- getTemplateDetailsInProgress: false,
12
- templateDetails: {},
13
- createTemplateErrorMessage: '',
14
- });
15
-
16
- describe('Initial State', () => {
17
- it('should return the initial state', () => {
18
- expect(mobilePushReducer(undefined, {})).toEqual(initialState);
19
- });
20
- });
21
-
22
- describe('DEFAULT_ACTION', () => {
23
- it('should return the current state unchanged', () => {
24
- const currentState = initialState.set('createTemplateInProgress', true);
25
- const action = { type: types.DEFAULT_ACTION };
26
- expect(mobilePushReducer(currentState, action)).toEqual(currentState);
27
- });
28
- });
29
-
30
- describe('CREATE_TEMPLATE_REQUEST', () => {
31
- it('should set createTemplateInProgress to true and reset error states', () => {
32
- const action = { type: types.CREATE_TEMPLATE_REQUEST };
33
- const expectedState = initialState
34
- .set('createTemplateInProgress', true)
35
- .set('createTemplateError', false)
36
- .set('createTemplateErrorMessage', fromJS(''));
37
-
38
- expect(mobilePushReducer(initialState, action)).toEqual(expectedState);
39
- });
40
-
41
- it('should reset error states when request is made', () => {
42
- const currentState = initialState
43
- .set('createTemplateError', true)
44
- .set('createTemplateErrorMessage', fromJS('Previous error'));
45
-
46
- const action = { type: types.CREATE_TEMPLATE_REQUEST };
47
- const expectedState = currentState
48
- .set('createTemplateInProgress', true)
49
- .set('createTemplateError', false)
50
- .set('createTemplateErrorMessage', fromJS(''));
51
-
52
- expect(mobilePushReducer(currentState, action)).toEqual(expectedState);
53
- });
54
- });
55
-
56
- describe('CREATE_TEMPLATE_SUCCESS', () => {
57
- it('should set createTemplateInProgress to false and store response with successful status', () => {
58
- const mockData = { id: 1, name: 'Test Template' };
59
- const action = {
60
- type: types.CREATE_TEMPLATE_SUCCESS,
61
- data: mockData,
62
- statusCode: 200,
63
- };
64
-
65
- const currentState = initialState.set('createTemplateInProgress', true);
66
- const expectedState = currentState
67
- .set('createTemplateInProgress', false)
68
- .set('response', mockData)
69
- .set('createTemplateError', false);
70
-
71
- expect(mobilePushReducer(currentState, action)).toEqual(expectedState);
72
- });
73
-
74
- it('should set createTemplateError to true when statusCode is greater than 300', () => {
75
- const mockData = { error: 'Template creation failed' };
76
- const action = {
77
- type: types.CREATE_TEMPLATE_SUCCESS,
78
- data: mockData,
79
- statusCode: 400,
80
- };
81
-
82
- const currentState = initialState.set('createTemplateInProgress', true);
83
- const expectedState = currentState
84
- .set('createTemplateInProgress', false)
85
- .set('response', mockData)
86
- .set('createTemplateError', true);
87
-
88
- expect(mobilePushReducer(currentState, action)).toEqual(expectedState);
89
- });
90
-
91
- it('should handle success without statusCode', () => {
92
- const mockData = { id: 1, name: 'Test Template' };
93
- const action = {
94
- type: types.CREATE_TEMPLATE_SUCCESS,
95
- data: mockData,
96
- };
97
-
98
- const currentState = initialState.set('createTemplateInProgress', true);
99
- const expectedState = currentState
100
- .set('createTemplateInProgress', false)
101
- .set('response', mockData)
102
- .set('createTemplateError', false);
103
-
104
- expect(mobilePushReducer(currentState, action)).toEqual(expectedState);
105
- });
106
- });
107
-
108
- describe('CREATE_TEMPLATE_FAILURE', () => {
109
- it('should set createTemplateInProgress to false and store error message', () => {
110
- const errorMessage = 'Template creation failed';
111
- const action = {
112
- type: types.CREATE_TEMPLATE_FAILURE,
113
- error: errorMessage,
114
- };
115
-
116
- const currentState = initialState.set('createTemplateInProgress', true);
117
- const expectedState = currentState
118
- .set('createTemplateInProgress', false)
119
- .set('createTemplateError', true)
120
- .set('createTemplateErrorMessage', fromJS(errorMessage));
121
-
122
- expect(mobilePushReducer(currentState, action)).toEqual(expectedState);
123
- });
124
- });
125
-
126
- describe('CLEAR_CREATE_RESPONSE_REQUEST', () => {
127
- it('should clear the response', () => {
128
- const currentState = initialState.set('response', { id: 1, name: 'Test' });
129
- const action = { type: types.CLEAR_CREATE_RESPONSE_REQUEST };
130
- const expectedState = currentState.set('response', {});
131
-
132
- expect(mobilePushReducer(currentState, action)).toEqual(expectedState);
133
- });
134
- });
135
-
136
- describe('UPLOAD_ASSET_REQUEST', () => {
137
- it('should set uploadAssetSuccess to false and assetUploading to true', () => {
138
- const action = { type: types.UPLOAD_ASSET_REQUEST };
139
- const expectedState = initialState
140
- .set('uploadAssetSuccess', false)
141
- .set('assetUploading', true);
142
-
143
- expect(mobilePushReducer(initialState, action)).toEqual(expectedState);
144
- });
145
- });
146
-
147
- describe('UPLOAD_ASSET_SUCCESS', () => {
148
- it('should set uploadAssetSuccess to true and store asset data with successful status', () => {
149
- const mockData = { url: 'https://example.com/image.jpg' };
150
- const action = {
151
- type: types.UPLOAD_ASSET_SUCCESS,
152
- data: mockData,
153
- statusCode: 200,
154
- };
155
-
156
- const currentState = initialState.set('assetUploading', true);
157
- const expectedState = currentState
158
- .set('uploadAssetSuccess', true)
159
- .set('assetUploading', false)
160
- .set('uploadedAssetData', mockData);
161
-
162
- expect(mobilePushReducer(currentState, action)).toEqual(expectedState);
163
- });
164
-
165
- it('should set uploadAssetSuccess to false when statusCode is greater than or equal to 300', () => {
166
- const mockData = { error: 'Upload failed' };
167
- const action = {
168
- type: types.UPLOAD_ASSET_SUCCESS,
169
- data: mockData,
170
- statusCode: 400,
171
- };
172
-
173
- const currentState = initialState.set('assetUploading', true);
174
- const expectedState = currentState
175
- .set('uploadAssetSuccess', false)
176
- .set('assetUploading', false)
177
- .set('uploadedAssetData', mockData);
178
-
179
- expect(mobilePushReducer(currentState, action)).toEqual(expectedState);
180
- });
181
-
182
- it('should handle success without statusCode', () => {
183
- const mockData = { url: 'https://example.com/image.jpg' };
184
- const action = {
185
- type: types.UPLOAD_ASSET_SUCCESS,
186
- data: mockData,
187
- };
188
-
189
- const currentState = initialState.set('assetUploading', true);
190
- const expectedState = currentState
191
- .set('uploadAssetSuccess', false)
192
- .set('assetUploading', false)
193
- .set('uploadedAssetData', mockData);
194
-
195
- expect(mobilePushReducer(currentState, action)).toEqual(expectedState);
196
- });
197
-
198
- it('should handle empty statusCode', () => {
199
- const mockData = { url: 'https://example.com/image.jpg' };
200
- const action = {
201
- type: types.UPLOAD_ASSET_SUCCESS,
202
- data: mockData,
203
- statusCode: '',
204
- };
205
-
206
- const currentState = initialState.set('assetUploading', true);
207
- const expectedState = currentState
208
- .set('uploadAssetSuccess', false)
209
- .set('assetUploading', false)
210
- .set('uploadedAssetData', mockData);
211
-
212
- expect(mobilePushReducer(currentState, action)).toEqual(expectedState);
213
- });
214
- });
215
-
216
- describe('UPLOAD_ASSET_FAILURE', () => {
217
- it('should set uploadAssetSuccess to false and assetUploading to false', () => {
218
- const action = { type: types.UPLOAD_ASSET_FAILURE };
219
- const currentState = initialState
220
- .set('uploadAssetSuccess', true)
221
- .set('assetUploading', true);
222
-
223
- const expectedState = currentState
224
- .set('uploadAssetSuccess', false)
225
- .set('assetUploading', false);
226
-
227
- expect(mobilePushReducer(currentState, action)).toEqual(expectedState);
228
- });
229
- });
230
-
231
- describe('CLEAR_ASSET', () => {
232
- it('should remove uploadedAssetData from state', () => {
233
- const currentState = initialState.set('uploadedAssetData', { url: 'test.jpg' });
234
- const action = { type: types.CLEAR_ASSET };
235
- const expectedState = currentState.delete('uploadedAssetData');
236
-
237
- expect(mobilePushReducer(currentState, action)).toEqual(expectedState);
238
- });
239
-
240
- it('should handle clearing asset when no asset data exists', () => {
241
- const action = { type: types.CLEAR_ASSET };
242
- const expectedState = initialState.delete('uploadedAssetData');
243
-
244
- expect(mobilePushReducer(initialState, action)).toEqual(expectedState);
245
- });
246
- });
247
-
248
- describe('GET_IOS_CTAS', () => {
249
- it('should set getIosCtasSucccess to false and iosCtasLoading to true', () => {
250
- const action = { type: types.GET_IOS_CTAS };
251
- const expectedState = initialState
252
- .set('getIosCtasSucccess', false)
253
- .set('iosCtasLoading', true);
254
-
255
- expect(mobilePushReducer(initialState, action)).toEqual(expectedState);
256
- });
257
- });
258
-
259
- describe('GET_IOS_CTAS_SUCCESS', () => {
260
- it('should set getIosCtasSucccess to true and store CTA data with successful status', () => {
261
- const mockData = [{ id: 1, text: 'Button 1' }];
262
- const action = {
263
- type: types.GET_IOS_CTAS_SUCCESS,
264
- data: mockData,
265
- statusCode: 200,
266
- };
267
-
268
- const currentState = initialState.set('iosCtasLoading', true);
269
- const expectedState = currentState
270
- .set('getIosCtasSucccess', true)
271
- .set('iosCtasLoading', false)
272
- .set('iosCtasData', mockData);
273
-
274
- expect(mobilePushReducer(currentState, action)).toEqual(expectedState);
275
- });
276
-
277
- it('should set getIosCtasSucccess to false when statusCode is greater than or equal to 300', () => {
278
- const mockData = { error: 'CTA fetch failed' };
279
- const action = {
280
- type: types.GET_IOS_CTAS_SUCCESS,
281
- data: mockData,
282
- statusCode: 400,
283
- };
284
-
285
- const currentState = initialState.set('iosCtasLoading', true);
286
- const expectedState = currentState
287
- .set('getIosCtasSucccess', false)
288
- .set('iosCtasLoading', false)
289
- .set('iosCtasData', mockData);
290
-
291
- expect(mobilePushReducer(currentState, action)).toEqual(expectedState);
292
- });
293
-
294
- it('should handle success without statusCode', () => {
295
- const mockData = [{ id: 1, text: 'Button 1' }];
296
- const action = {
297
- type: types.GET_IOS_CTAS_SUCCESS,
298
- data: mockData,
299
- };
300
-
301
- const currentState = initialState.set('iosCtasLoading', true);
302
- const expectedState = currentState
303
- .set('getIosCtasSucccess', false)
304
- .set('iosCtasLoading', false)
305
- .set('iosCtasData', mockData);
306
-
307
- expect(mobilePushReducer(currentState, action)).toEqual(expectedState);
308
- });
309
- });
310
-
311
- describe('GET_IOS_CTAS_FAILURE', () => {
312
- it('should set getIosCtasSucccess to false and iosCtasLoading to false', () => {
313
- const action = { type: types.GET_IOS_CTAS_FAILURE };
314
- const currentState = initialState
315
- .set('getIosCtasSucccess', true)
316
- .set('iosCtasLoading', true);
317
-
318
- const expectedState = currentState
319
- .set('getIosCtasSucccess', false)
320
- .set('iosCtasLoading', false);
321
-
322
- expect(mobilePushReducer(currentState, action)).toEqual(expectedState);
323
- });
324
- });
325
-
326
- describe('RESET_STORE', () => {
327
- it('should remove uploadedAssetData and iosCtasData from state', () => {
328
- const currentState = initialState
329
- .set('uploadedAssetData', { url: 'test.jpg' })
330
- .set('iosCtasData', [{ id: 1, text: 'Button' }]);
331
-
332
- const action = { type: types.RESET_STORE };
333
- const expectedState = currentState
334
- .delete('uploadedAssetData')
335
- .delete('iosCtasData');
336
-
337
- expect(mobilePushReducer(currentState, action)).toEqual(expectedState);
338
- });
339
-
340
- it('should handle reset when no data exists', () => {
341
- const action = { type: types.RESET_STORE };
342
- const expectedState = initialState
343
- .delete('uploadedAssetData')
344
- .delete('iosCtasData');
345
-
346
- expect(mobilePushReducer(initialState, action)).toEqual(expectedState);
347
- });
348
- });
349
-
350
- describe('EDIT_TEMPLATE_REQUEST', () => {
351
- it('should set editTemplateInProgress to true and reset error states', () => {
352
- const action = { type: types.EDIT_TEMPLATE_REQUEST };
353
- const expectedState = initialState
354
- .set('editTemplateInProgress', true)
355
- .set('editTemplateError', false)
356
- .set('editTemplateErrorMessage', fromJS(''));
357
-
358
- expect(mobilePushReducer(initialState, action)).toEqual(expectedState);
359
- });
360
-
361
- it('should reset error states when request is made', () => {
362
- const currentState = initialState
363
- .set('editTemplateError', true)
364
- .set('editTemplateErrorMessage', fromJS('Previous error'));
365
-
366
- const action = { type: types.EDIT_TEMPLATE_REQUEST };
367
- const expectedState = currentState
368
- .set('editTemplateInProgress', true)
369
- .set('editTemplateError', false)
370
- .set('editTemplateErrorMessage', fromJS(''));
371
-
372
- expect(mobilePushReducer(currentState, action)).toEqual(expectedState);
373
- });
374
- });
375
-
376
- describe('EDIT_TEMPLATE_SUCCESS', () => {
377
- it('should set editTemplateInProgress to false and store response with successful status', () => {
378
- const mockData = { id: 1, name: 'Updated Template' };
379
- const errorMsg = 'Success';
380
- const action = {
381
- type: types.EDIT_TEMPLATE_SUCCESS,
382
- data: mockData,
383
- statusCode: 200,
384
- errorMsg,
385
- };
386
-
387
- const currentState = initialState.set('editTemplateInProgress', true);
388
- const expectedState = currentState
389
- .set('editTemplateInProgress', false)
390
- .set('editResponse', mockData)
391
- .set('editTemplateError', false)
392
- .set('editTemplateErrorMessage', fromJS(errorMsg));
393
-
394
- expect(mobilePushReducer(currentState, action)).toEqual(expectedState);
395
- });
396
-
397
- it('should set editTemplateError to true when statusCode is greater than 300', () => {
398
- const mockData = { error: 'Template update failed' };
399
- const errorMsg = 'Update failed';
400
- const action = {
401
- type: types.EDIT_TEMPLATE_SUCCESS,
402
- data: mockData,
403
- statusCode: 400,
404
- errorMsg,
405
- };
406
-
407
- const currentState = initialState.set('editTemplateInProgress', true);
408
- const expectedState = currentState
409
- .set('editTemplateInProgress', false)
410
- .set('editResponse', mockData)
411
- .set('editTemplateError', true)
412
- .set('editTemplateErrorMessage', fromJS(errorMsg));
413
-
414
- expect(mobilePushReducer(currentState, action)).toEqual(expectedState);
415
- });
416
-
417
- it('should handle success without statusCode', () => {
418
- const mockData = { id: 1, name: 'Updated Template' };
419
- const errorMsg = 'Success';
420
- const action = {
421
- type: types.EDIT_TEMPLATE_SUCCESS,
422
- data: mockData,
423
- errorMsg,
424
- };
425
-
426
- const currentState = initialState.set('editTemplateInProgress', true);
427
- const expectedState = currentState
428
- .set('editTemplateInProgress', false)
429
- .set('editResponse', mockData)
430
- .set('editTemplateError', false)
431
- .set('editTemplateErrorMessage', fromJS(errorMsg));
432
-
433
- expect(mobilePushReducer(currentState, action)).toEqual(expectedState);
434
- });
435
- });
436
-
437
- describe('EDIT_TEMPLATE_FAILURE', () => {
438
- it('should set editTemplateInProgress to false and store error message', () => {
439
- const errorMessage = 'Template update failed';
440
- const action = {
441
- type: types.EDIT_TEMPLATE_FAILURE,
442
- errorMsg: errorMessage,
443
- };
444
-
445
- const currentState = initialState.set('editTemplateInProgress', true);
446
- const expectedState = currentState
447
- .set('editTemplateInProgress', false)
448
- .set('editTemplateError', true)
449
- .set('editTemplateErrorMessage', fromJS(errorMessage));
450
-
451
- expect(mobilePushReducer(currentState, action)).toEqual(expectedState);
452
- });
453
- });
454
-
455
- describe('GET_TEMPLATE_DETAILS_REQUEST', () => {
456
- it('should set getTemplateDetailsInProgress to true', () => {
457
- const action = { type: types.GET_TEMPLATE_DETAILS_REQUEST };
458
- const expectedState = initialState.set('getTemplateDetailsInProgress', true);
459
-
460
- expect(mobilePushReducer(initialState, action)).toEqual(expectedState);
461
- });
462
- });
463
-
464
- describe('GET_TEMPLATE_DETAILS_SUCCESS', () => {
465
- it('should set getTemplateDetailsInProgress to false and store template details', () => {
466
- const mockData = { id: 1, name: 'Template Details', content: 'Template content' };
467
- const action = {
468
- type: types.GET_TEMPLATE_DETAILS_SUCCESS,
469
- data: mockData,
470
- };
471
-
472
- const currentState = initialState.set('getTemplateDetailsInProgress', true);
473
- const expectedState = currentState
474
- .set('getTemplateDetailsInProgress', false)
475
- .set('templateDetails', mockData);
476
-
477
- expect(mobilePushReducer(currentState, action)).toEqual(expectedState);
478
- });
479
- });
480
-
481
- describe('SET_SELECTED_TEMPLATE', () => {
482
- it('should set getTemplateDetailsInProgress to false and store template details', () => {
483
- const mockData = { id: 2, name: 'Selected Template', content: 'Selected content' };
484
- const action = {
485
- type: types.SET_SELECTED_TEMPLATE,
486
- data: mockData,
487
- };
488
-
489
- const currentState = initialState.set('getTemplateDetailsInProgress', true);
490
- const expectedState = currentState
491
- .set('getTemplateDetailsInProgress', false)
492
- .set('templateDetails', mockData);
493
-
494
- expect(mobilePushReducer(currentState, action)).toEqual(expectedState);
495
- });
496
- });
497
-
498
- describe('GET_TEMPLATE_DETAILS_FAILURE', () => {
499
- it('should set getTemplateDetailsInProgress to false', () => {
500
- const action = { type: types.GET_TEMPLATE_DETAILS_FAILURE };
501
- const currentState = initialState.set('getTemplateDetailsInProgress', true);
502
- const expectedState = currentState.set('getTemplateDetailsInProgress', false);
503
-
504
- expect(mobilePushReducer(currentState, action)).toEqual(expectedState);
505
- });
506
- });
507
-
508
- describe('CLEAR_EDIT_RESPONSE_REQUEST', () => {
509
- it('should clear the edit response', () => {
510
- const currentState = initialState.set('editResponse', { id: 1, name: 'Test' });
511
- const action = { type: types.CLEAR_EDIT_RESPONSE_REQUEST };
512
- const expectedState = currentState.set('editResponse', {});
513
-
514
- expect(mobilePushReducer(currentState, action)).toEqual(expectedState);
515
- });
516
- });
517
-
518
- describe('CLEAR_DATA', () => {
519
- it('should remove uploadedAssetData, metaEntities, templateDetails, and iosCtasData from state', () => {
520
- const currentState = initialState
521
- .set('uploadedAssetData', { url: 'test.jpg' })
522
- .set('metaEntities', { entities: [] })
523
- .set('templateDetails', { id: 1, name: 'Template' })
524
- .set('iosCtasData', [{ id: 1, text: 'Button' }]);
525
-
526
- const action = { type: types.CLEAR_DATA };
527
- const expectedState = currentState
528
- .delete('uploadedAssetData')
529
- .delete('metaEntities')
530
- .delete('templateDetails')
531
- .delete('iosCtasData');
532
-
533
- expect(mobilePushReducer(currentState, action)).toEqual(expectedState);
534
- });
535
-
536
- it('should handle clearing data when no data exists', () => {
537
- const action = { type: types.CLEAR_DATA };
538
- const expectedState = initialState
539
- .delete('uploadedAssetData')
540
- .delete('metaEntities')
541
- .delete('templateDetails')
542
- .delete('iosCtasData');
543
-
544
- expect(mobilePushReducer(initialState, action)).toEqual(expectedState);
545
- });
546
- });
547
-
548
- describe('GET_WECRM_ACCOUNTS_REQUEST', () => {
549
- it('should set fetchingWeCrmAccounts to true and weCrmAccountFetchingError to false', () => {
550
- const action = { type: types.GET_WECRM_ACCOUNTS_REQUEST };
551
- const expectedState = initialState
552
- .set('fetchingWeCrmAccounts', true)
553
- .set('weCrmAccountFetchingError', false);
554
-
555
- expect(mobilePushReducer(initialState, action)).toEqual(expectedState);
556
- });
557
-
558
- it('should reset error state when request is made', () => {
559
- const currentState = initialState.set('weCrmAccountFetchingError', true);
560
- const action = { type: types.GET_WECRM_ACCOUNTS_REQUEST };
561
- const expectedState = currentState
562
- .set('fetchingWeCrmAccounts', true)
563
- .set('weCrmAccountFetchingError', false);
564
-
565
- expect(mobilePushReducer(currentState, action)).toEqual(expectedState);
566
- });
567
- });
568
-
569
- describe('GET_WECRM_ACCOUNTS_SUCCESS', () => {
570
- it('should set fetchingWeCrmAccounts to false and store accounts data', () => {
571
- const mockData = [{ id: 1, name: 'Account 1' }, { id: 2, name: 'Account 2' }];
572
- const action = {
573
- type: types.GET_WECRM_ACCOUNTS_SUCCESS,
574
- data: mockData,
575
- };
576
-
577
- const currentState = initialState.set('fetchingWeCrmAccounts', true);
578
- const expectedState = currentState
579
- .set('fetchingWeCrmAccounts', false)
580
- .set('weCrmAccounts', fromJS(mockData));
581
-
582
- expect(mobilePushReducer(currentState, action)).toEqual(expectedState);
583
- });
584
- });
585
-
586
- describe('GET_WECRM_ACCOUNTS_FAILURE', () => {
587
- it('should set fetchingWeCrmAccounts to false and weCrmAccountFetchingError to true', () => {
588
- const action = { type: types.GET_WECRM_ACCOUNTS_FAILURE };
589
- const currentState = initialState.set('fetchingWeCrmAccounts', true);
590
- const expectedState = currentState
591
- .set('fetchingWeCrmAccounts', false)
592
- .set('weCrmAccountFetchingError', true);
593
-
594
- expect(mobilePushReducer(currentState, action)).toEqual(expectedState);
595
- });
596
- });
597
-
598
- describe('SET_WECHAT_ACCOUNT', () => {
599
- it('should set selectedWeChatAccount and remove mobilepushTemplates', () => {
600
- const mockWeChatAccount = { id: 1, name: 'WeChat Account' };
601
- const action = {
602
- type: types.SET_WECHAT_ACCOUNT,
603
- weChatAccount: mockWeChatAccount,
604
- };
605
-
606
- const currentState = initialState.set('mobilepushTemplates', [{ id: 1, name: 'Template' }]);
607
- const expectedState = currentState
608
- .set('selectedWeChatAccount', fromJS(mockWeChatAccount))
609
- .delete('mobilepushTemplates');
610
-
611
- expect(mobilePushReducer(currentState, action)).toEqual(expectedState);
612
- });
613
-
614
- it('should handle setting WeChat account when no templates exist', () => {
615
- const mockWeChatAccount = { id: 1, name: 'WeChat Account' };
616
- const action = {
617
- type: types.SET_WECHAT_ACCOUNT,
618
- weChatAccount: mockWeChatAccount,
619
- };
620
-
621
- const expectedState = initialState
622
- .set('selectedWeChatAccount', fromJS(mockWeChatAccount))
623
- .delete('mobilepushTemplates');
624
-
625
- expect(mobilePushReducer(initialState, action)).toEqual(expectedState);
626
- });
627
- });
628
-
629
- describe('GET_MOBILEPUSH_TEMPLATES_LIST_REQUEST', () => {
630
- it('should set fetchingDefaultTemplates to true', () => {
631
- const action = { type: types.GET_MOBILEPUSH_TEMPLATES_LIST_REQUEST };
632
- const expectedState = initialState.set('fetchingDefaultTemplates', true);
633
-
634
- expect(mobilePushReducer(initialState, action)).toEqual(expectedState);
635
- });
636
- });
637
-
638
- describe('GET_MOBILEPUSH_TEMPLATES_LIST_SUCCESS', () => {
639
- it('should set fetchingDefaultTemplates to false and store templates data', () => {
640
- const mockData = [{ id: 1, name: 'Template 1' }, { id: 2, name: 'Template 2' }];
641
- const action = {
642
- type: types.GET_MOBILEPUSH_TEMPLATES_LIST_SUCCESS,
643
- data: mockData,
644
- };
645
-
646
- const currentState = initialState.set('fetchingDefaultTemplates', true);
647
- const expectedState = currentState
648
- .set('fetchingDefaultTemplates', false)
649
- .set('mobilepushTemplates', fromJS(mockData));
650
-
651
- expect(mobilePushReducer(currentState, action)).toEqual(expectedState);
652
- });
653
- });
654
-
655
- describe('GET_MOBILEPUSH_TEMPLATES_LIST_FAILURE', () => {
656
- it('should set fetchingDefaultTemplates to false and errorFetchingDefaultTempalte to true', () => {
657
- const action = { type: types.GET_MOBILEPUSH_TEMPLATES_LIST_FAILURE };
658
- const currentState = initialState.set('fetchingDefaultTemplates', true);
659
- const expectedState = currentState
660
- .set('fetchingDefaultTemplates', false)
661
- .set('errorFetchingDefaultTempalte', true);
662
-
663
- expect(mobilePushReducer(currentState, action)).toEqual(expectedState);
664
- });
665
- });
666
-
667
- describe('Unknown Action', () => {
668
- it('should return the current state for unknown action types', () => {
669
- const unknownAction = { type: 'UNKNOWN_ACTION' };
670
- const currentState = initialState.set('createTemplateInProgress', true);
671
-
672
- expect(mobilePushReducer(currentState, unknownAction)).toEqual(currentState);
673
- });
674
- });
675
-
676
- describe('Edge Cases', () => {
677
- it('should handle null action', () => {
678
- expect(mobilePushReducer(initialState, null)).toEqual(initialState);
679
- });
680
-
681
- it('should handle undefined action', () => {
682
- expect(mobilePushReducer(initialState, undefined)).toEqual(initialState);
683
- });
684
-
685
- it('should handle action without type', () => {
686
- expect(mobilePushReducer(initialState, {})).toEqual(initialState);
687
- });
688
-
689
- it('should handle action with null data', () => {
690
- const action = {
691
- type: types.CREATE_TEMPLATE_SUCCESS,
692
- data: null,
693
- statusCode: 200,
694
- };
695
-
696
- const currentState = initialState.set('createTemplateInProgress', true);
697
- const expectedState = currentState
698
- .set('createTemplateInProgress', false)
699
- .set('response', null)
700
- .set('createTemplateError', false);
701
-
702
- expect(mobilePushReducer(currentState, action)).toEqual(expectedState);
703
- });
704
-
705
- it('should handle action with undefined data', () => {
706
- const action = {
707
- type: types.GET_TEMPLATE_DETAILS_SUCCESS,
708
- data: undefined,
709
- };
710
-
711
- const currentState = initialState.set('getTemplateDetailsInProgress', true);
712
- const expectedState = currentState
713
- .set('getTemplateDetailsInProgress', false)
714
- .set('templateDetails', undefined);
715
-
716
- expect(mobilePushReducer(currentState, action)).toEqual(expectedState);
717
- });
718
-
719
- it('should handle multiple consecutive actions', () => {
720
- let state = initialState;
721
-
722
- // First action
723
- state = mobilePushReducer(state, { type: types.CREATE_TEMPLATE_REQUEST });
724
- expect(state.get('createTemplateInProgress')).toBe(true);
725
-
726
- // Second action
727
- state = mobilePushReducer(state, {
728
- type: types.CREATE_TEMPLATE_SUCCESS,
729
- data: { id: 1 },
730
- statusCode: 200,
731
- });
732
- expect(state.get('createTemplateInProgress')).toBe(false);
733
- expect(state.get('response')).toEqual({ id: 1 });
734
- expect(state.get('createTemplateError')).toBe(false);
735
-
736
- // Third action
737
- state = mobilePushReducer(state, { type: types.CLEAR_CREATE_RESPONSE_REQUEST });
738
- expect(state.get('response')).toEqual({});
739
- });
740
- });
741
- });