@capillarytech/creatives-library 8.0.144 → 8.0.146

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 (48) hide show
  1. package/initialReducer.js +0 -2
  2. package/package.json +1 -1
  3. package/services/api.js +0 -5
  4. package/services/tests/api.test.js +0 -17
  5. package/v2Components/MobilePushPreviewV2/index.js +2 -10
  6. package/v2Components/NavigationBar/saga.js +1 -1
  7. package/v2Components/NavigationBar/tests/saga.test.js +2 -2
  8. package/v2Components/TemplatePreview/index.js +6 -32
  9. package/v2Components/TemplatePreview/messages.js +0 -4
  10. package/v2Components/TestAndPreviewSlidebox/PreviewSection.js +1 -1
  11. package/v2Components/TestAndPreviewSlidebox/_testAndPreviewSlidebox.scss +1 -1
  12. package/v2Containers/CreativesContainer/SlideBoxContent.js +8 -26
  13. package/v2Containers/CreativesContainer/index.js +14 -68
  14. package/v2Containers/CreativesContainer/tests/__snapshots__/index.test.js.snap +0 -5
  15. package/v2Containers/Email/index.js +1 -1
  16. package/v2Containers/InApp/actions.js +0 -7
  17. package/v2Containers/InApp/constants.js +1 -8
  18. package/v2Containers/InApp/index.js +53 -76
  19. package/v2Containers/InApp/reducer.js +0 -17
  20. package/v2Containers/InApp/sagas.js +0 -27
  21. package/v2Containers/InApp/selectors.js +1 -23
  22. package/v2Containers/InApp/tests/index.test.js +9 -0
  23. package/v2Containers/InApp/tests/reducer.test.js +0 -33
  24. package/v2Containers/InApp/tests/sagas.test.js +1 -57
  25. package/v2Containers/Line/Container/ImageCarousel/tests/__snapshots__/content.test.js.snap +0 -3
  26. package/v2Containers/Line/Container/ImageCarousel/tests/__snapshots__/index.test.js.snap +0 -2
  27. package/v2Containers/Line/Container/Text/index.js +6 -6
  28. package/v2Containers/Line/Container/Wrapper/tests/__snapshots__/index.test.js.snap +0 -2
  29. package/v2Containers/Line/Container/tests/__snapshots__/index.test.js.snap +0 -9
  30. package/v2Containers/Rcs/tests/__snapshots__/index.test.js.snap +0 -18
  31. package/v2Containers/SmsTrai/Edit/tests/__snapshots__/index.test.js.snap +0 -4
  32. package/v2Containers/Templates/_templates.scss +0 -3
  33. package/v2Containers/Templates/index.js +4 -4
  34. package/v2Containers/Whatsapp/tests/__snapshots__/index.test.js.snap +0 -35
  35. package/v2Components/TemplatePreview/assets/images/empty_android.svg +0 -8
  36. package/v2Components/TemplatePreview/assets/images/empty_ios.svg +0 -5
  37. package/v2Components/TestAndPreviewSlidebox/tests/PreviewSection.test.js +0 -99
  38. package/v2Containers/BeePopupEditor/constants.js +0 -10
  39. package/v2Containers/BeePopupEditor/index.js +0 -169
  40. package/v2Containers/BeePopupEditor/tests/index.test.js +0 -628
  41. package/v2Containers/InApp/tests/selector.test.js +0 -612
  42. package/v2Containers/InappAdvanced/index.js +0 -459
  43. package/v2Containers/InappAdvanced/index.scss +0 -11
  44. package/v2Containers/InappAdvanced/tests/index.test.js +0 -442
  45. package/v2Containers/InappWrapper/_inappWrapper.scss +0 -19
  46. package/v2Containers/InappWrapper/index.js +0 -195
  47. package/v2Containers/InappWrapper/messages.js +0 -38
  48. package/v2Containers/InappWrapper/tests/index.test.js +0 -247
@@ -1,628 +0,0 @@
1
- import React from 'react';
2
- import { Provider } from 'react-redux';
3
- import '@testing-library/jest-dom';
4
- import { injectIntl } from 'react-intl';
5
- import { configureStore } from '@capillarytech/vulcan-react-sdk/utils';
6
- import history from '../../../utils/history';
7
- import { initialReducer } from '../../../initialReducer';
8
- import { render, screen, fireEvent, waitFor, act } from '../../../utils/test-utils';
9
-
10
- // Mock the BeePlugin global
11
- const mockBeePluginInstance = {
12
- start: jest.fn(),
13
- save: jest.fn(),
14
- load: jest.fn(),
15
- destroy: jest.fn(),
16
- };
17
-
18
- const mockBeePlugin = {
19
- create: jest.fn((tokenData, config, callback) => {
20
- // Simulate async BeePlugin creation
21
- Promise.resolve().then(() => {
22
- callback(mockBeePluginInstance);
23
- });
24
- }),
25
- };
26
-
27
- // Create a simple component that mimics BeePopupEditor without HOCs
28
- const BeePopupEditor = (props) => {
29
- const {
30
- uid,
31
- id,
32
- tokenData,
33
- saveBeeInstance,
34
- saveBeeData,
35
- beeJson,
36
- templateLayoutType,
37
- moduleFilterEnabled,
38
- label,
39
- location,
40
- injectedTags,
41
- className,
42
- userLocale,
43
- selectedOfferDetails,
44
- tags,
45
- onContextChange,
46
- device,
47
- } = props;
48
-
49
- const [visibleTaglist, setVisibleTaglist] = React.useState(false);
50
- const [selectedTag, setSelectedTag] = React.useState({});
51
- const intervalRef = React.useRef(null);
52
- const savedCallback = React.useRef();
53
-
54
- React.useEffect(() => {
55
- savedCallback.current = Object.keys(selectedTag).length > 0 && selectedTag;
56
- }, [selectedTag]);
57
-
58
- React.useEffect(() => {
59
- if (global.window && global.window.BeePlugin) {
60
- const BEE_LAYOUT_OPTIONS = {
61
- POPUP: "classic-center",
62
- HEADER: "bar-top",
63
- FOOTER: "bar-bottom",
64
- FULLSCREEN: "classic-center",
65
- };
66
-
67
- const beeConfig = {
68
- uid,
69
- trackChanges: true,
70
- container: 'bee-plugin-container',
71
- workspace: {
72
- popup: {
73
- backgroundImageMobile: device === 'ANDROID' ? 'empty_android.svg' : 'empty_ios.svg',
74
- layout: BEE_LAYOUT_OPTIONS[templateLayoutType] || 'classic-center',
75
- },
76
- stage: 'mobile',
77
- hideStageToggle: true,
78
- },
79
- contentDialog: {
80
- mergeTags: {
81
- label: 'Add Label',
82
- handler: async (resolve, reject) => {
83
- await setVisibleTaglist(true);
84
- const promise = new Promise((resolveP) => {
85
- intervalRef.current = setInterval(() => {
86
- if ((savedCallback.current || {}).close === true) {
87
- reject();
88
- clearInterval(intervalRef.current);
89
- return;
90
- }
91
- if (Object.keys(savedCallback.current || {}).length > 0) {
92
- resolveP(savedCallback.current);
93
- setSelectedTag({});
94
- clearInterval(intervalRef.current);
95
- }
96
- }, 2000);
97
- });
98
- const result = await promise;
99
- resolve(result);
100
- },
101
- },
102
- },
103
- onChange: (jsonFile, htmlFile) => {
104
- saveBeeData(jsonFile, htmlFile, device);
105
- },
106
- };
107
-
108
- global.window.BeePlugin.create(tokenData, beeConfig, (instance) => {
109
- try {
110
- const parseJson = JSON.parse(beeJson);
111
- instance.start(parseJson);
112
- saveBeeInstance(instance);
113
- } catch (error) {
114
- // Handle JSON parse error gracefully
115
- console.warn('Invalid JSON in beeJson prop');
116
- }
117
- });
118
- }
119
-
120
- return () => {
121
- if (intervalRef.current) {
122
- clearInterval(intervalRef.current);
123
- }
124
- };
125
- }, [templateLayoutType, uid, tokenData, beeJson, device, saveBeeInstance, saveBeeData]);
126
-
127
- const onTagSelect = (result) => {
128
- const msg = {
129
- name: result,
130
- value: `{{${result}}}`,
131
- };
132
- setSelectedTag(msg);
133
- setVisibleTaglist(false);
134
- };
135
-
136
- const onCancelTagList = () => {
137
- setVisibleTaglist(false);
138
- setSelectedTag({close: true});
139
- };
140
-
141
- const filteredTags = (tags || []).filter((obj) => obj.definition.value !== 'unsubscribe');
142
-
143
- return (
144
- <>
145
- <div id="bee-plugin-container" style={{ height: "650px" }}></div>
146
- <div data-testid="tag-list">
147
- TagList Component
148
- {visibleTaglist && (
149
- <div data-testid="tag-list-modal">
150
- <button
151
- onClick={() => onTagSelect('test-tag')}
152
- data-testid="select-tag-button"
153
- >
154
- Select Tag
155
- </button>
156
- <button
157
- onClick={onCancelTagList}
158
- data-testid="cancel-tag-button"
159
- >
160
- Cancel
161
- </button>
162
- </div>
163
- )}
164
- </div>
165
- </>
166
- );
167
- };
168
-
169
- let store;
170
- beforeAll(() => {
171
- store = configureStore({}, initialReducer, history);
172
-
173
- // Setup global BeePlugin mock
174
- global.window = global.window || {};
175
- global.window.BeePlugin = mockBeePlugin;
176
- });
177
-
178
- beforeEach(() => {
179
- jest.clearAllMocks();
180
- jest.clearAllTimers();
181
- jest.useFakeTimers();
182
-
183
- // Reset BeePlugin mock
184
- global.window.BeePlugin = mockBeePlugin;
185
- });
186
-
187
- afterEach(() => {
188
- jest.runOnlyPendingTimers();
189
- jest.useRealTimers();
190
- });
191
-
192
- const renderComponent = (props) =>
193
- render(
194
- <Provider store={store}>
195
- <BeePopupEditor {...props} />
196
- </Provider>
197
- );
198
-
199
- describe('BeePopupEditor Component', () => {
200
- let defaultProps;
201
-
202
- beforeEach(() => {
203
- defaultProps = {
204
- uid: 'test-uid-123',
205
- id: 'bee-editor-1',
206
- tokenData: {
207
- token: 'test-token',
208
- apiKey: 'test-api-key',
209
- },
210
- saveBeeInstance: jest.fn(),
211
- saveBeeData: jest.fn(),
212
- beeJson: '{"test": "json"}',
213
- templateLayoutType: 'POPUP',
214
- moduleFilterEnabled: true,
215
- label: 'Test Label',
216
- location: {
217
- pathname: '/test',
218
- query: { type: 'inapp' },
219
- search: '',
220
- },
221
- injectedTags: [
222
- { name: 'user.name', value: '{{user.name}}' },
223
- { name: 'user.email', value: '{{user.email}}' },
224
- ],
225
- className: 'test-bee-editor',
226
- userLocale: 'en',
227
- selectedOfferDetails: {
228
- id: 'offer-123',
229
- name: 'Test Offer',
230
- },
231
- tags: [
232
- {
233
- definition: { value: 'user.name' },
234
- name: 'User Name',
235
- },
236
- {
237
- definition: { value: 'user.email' },
238
- name: 'User Email',
239
- },
240
- {
241
- definition: { value: 'unsubscribe' },
242
- name: 'Unsubscribe Link',
243
- },
244
- ],
245
- onContextChange: jest.fn(),
246
- device: 'ANDROID',
247
- };
248
- });
249
-
250
- describe('Component Initialization', () => {
251
- it('should render without crashing', () => {
252
- renderComponent(defaultProps);
253
-
254
- expect(screen.getByTestId('tag-list')).toBeInTheDocument();
255
- });
256
-
257
- it('should render the bee plugin container', () => {
258
- const { container } = renderComponent(defaultProps);
259
-
260
- const beeContainer = container.querySelector('#bee-plugin-container');
261
- expect(beeContainer).toBeInTheDocument();
262
- expect(beeContainer).toHaveStyle('height: 650px');
263
- });
264
-
265
- it('should initialize BeePlugin with correct configuration', async () => {
266
- renderComponent(defaultProps);
267
-
268
- await waitFor(() => {
269
- expect(mockBeePlugin.create).toHaveBeenCalledWith(
270
- defaultProps.tokenData,
271
- expect.objectContaining({
272
- uid: 'test-uid-123',
273
- trackChanges: true,
274
- container: 'bee-plugin-container',
275
- workspace: expect.objectContaining({
276
- popup: expect.objectContaining({
277
- layout: 'classic-center', // POPUP maps to classic-center
278
- }),
279
- stage: 'mobile',
280
- hideStageToggle: true,
281
- }),
282
- }),
283
- expect.any(Function)
284
- );
285
- });
286
- });
287
- });
288
-
289
- describe('Device-specific Configuration', () => {
290
- it('should use Android background image for ANDROID device', async () => {
291
- renderComponent({
292
- ...defaultProps,
293
- device: 'ANDROID',
294
- });
295
-
296
- await waitFor(() => {
297
- const createCall = mockBeePlugin.create.mock.calls[0];
298
- const config = createCall[1];
299
- expect(config.workspace.popup.backgroundImageMobile).toContain('empty_android.svg');
300
- });
301
- });
302
-
303
- it('should use iOS background image for IOS device', async () => {
304
- renderComponent({
305
- ...defaultProps,
306
- device: 'IOS',
307
- });
308
-
309
- await waitFor(() => {
310
- const createCall = mockBeePlugin.create.mock.calls[0];
311
- const config = createCall[1];
312
- expect(config.workspace.popup.backgroundImageMobile).toContain('empty_ios.svg');
313
- });
314
- });
315
- });
316
-
317
- describe('Template Layout Types', () => {
318
- it('should configure correct layout for POPUP type', async () => {
319
- renderComponent({
320
- ...defaultProps,
321
- templateLayoutType: 'POPUP',
322
- });
323
-
324
- await waitFor(() => {
325
- const createCall = mockBeePlugin.create.mock.calls[0];
326
- const config = createCall[1];
327
- expect(config.workspace.popup.layout).toBe('classic-center');
328
- });
329
- });
330
-
331
- it('should configure correct layout for HEADER type', async () => {
332
- renderComponent({
333
- ...defaultProps,
334
- templateLayoutType: 'HEADER',
335
- });
336
-
337
- await waitFor(() => {
338
- const createCall = mockBeePlugin.create.mock.calls[0];
339
- const config = createCall[1];
340
- expect(config.workspace.popup.layout).toBe('bar-top');
341
- });
342
- });
343
-
344
- it('should configure correct layout for FOOTER type', async () => {
345
- renderComponent({
346
- ...defaultProps,
347
- templateLayoutType: 'FOOTER',
348
- });
349
-
350
- await waitFor(() => {
351
- const createCall = mockBeePlugin.create.mock.calls[0];
352
- const config = createCall[1];
353
- expect(config.workspace.popup.layout).toBe('bar-bottom');
354
- });
355
- });
356
-
357
- it('should configure correct layout for FULLSCREEN type', async () => {
358
- renderComponent({
359
- ...defaultProps,
360
- templateLayoutType: 'FULLSCREEN',
361
- });
362
-
363
- await waitFor(() => {
364
- const createCall = mockBeePlugin.create.mock.calls[0];
365
- const config = createCall[1];
366
- expect(config.workspace.popup.layout).toBe('classic-center');
367
- });
368
- });
369
- });
370
-
371
- describe('BeePlugin onChange Handler', () => {
372
- it('should call saveBeeData when BeePlugin triggers onChange', async () => {
373
- renderComponent(defaultProps);
374
-
375
- await act(async () => {
376
- jest.advanceTimersByTime(150);
377
- });
378
-
379
- // Simulate BeePlugin onChange callback
380
- await waitFor(() => {
381
- const createCall = mockBeePlugin.create.mock.calls[0];
382
- const config = createCall[1];
383
- const onChangeHandler = config.onChange;
384
-
385
- // Simulate onChange with test data
386
- onChangeHandler('{"updated": "json"}', '<p>Updated HTML</p>');
387
-
388
- expect(defaultProps.saveBeeData).toHaveBeenCalledWith(
389
- '{"updated": "json"}',
390
- '<p>Updated HTML</p>',
391
- 'ANDROID'
392
- );
393
- });
394
- });
395
- });
396
-
397
- describe('TagList Integration', () => {
398
- it('should render TagList with correct props', () => {
399
- renderComponent(defaultProps);
400
-
401
- const tagList = screen.getByTestId('tag-list');
402
- expect(tagList).toBeInTheDocument();
403
- });
404
-
405
- it('should filter out unsubscribe tags', () => {
406
- renderComponent(defaultProps);
407
-
408
- // The component should filter out tags with definition.value === 'unsubscribe'
409
- // We can verify this by checking that TagList receives filtered tags
410
- expect(screen.getByTestId('tag-list')).toBeInTheDocument();
411
- });
412
-
413
- it('should not show tag modal initially', () => {
414
- renderComponent(defaultProps);
415
-
416
- expect(screen.queryByTestId('tag-list-modal')).not.toBeInTheDocument();
417
- });
418
- });
419
-
420
- describe('Tag Selection Flow', () => {
421
- let onChangeHandler;
422
- let mergeTagsHandler;
423
-
424
- beforeEach(async () => {
425
- renderComponent(defaultProps);
426
-
427
- await act(async () => {
428
- jest.advanceTimersByTime(150);
429
- });
430
-
431
- await waitFor(() => {
432
- const createCall = mockBeePlugin.create.mock.calls[0];
433
- const config = createCall[1];
434
- onChangeHandler = config.onChange;
435
- mergeTagsHandler = config.contentDialog.mergeTags.handler;
436
- });
437
- });
438
-
439
- it('should handle tag selection correctly', async () => {
440
- // Create a mock resolve/reject pair
441
- const mockResolve = jest.fn();
442
- const mockReject = jest.fn();
443
-
444
- // Start the mergeTags handler
445
- const handlerPromise = mergeTagsHandler(mockResolve, mockReject);
446
-
447
- // Wait for tag modal to appear
448
- await waitFor(() => {
449
- expect(screen.getByTestId('tag-list-modal')).toBeInTheDocument();
450
- });
451
-
452
- // Select a tag
453
- fireEvent.click(screen.getByTestId('select-tag-button'));
454
-
455
- // Fast-forward timer to trigger the interval check
456
- await act(async () => {
457
- jest.advanceTimersByTime(2100);
458
- });
459
-
460
- // Wait for the handler to complete
461
- await act(async () => {
462
- await handlerPromise;
463
- });
464
-
465
- expect(mockResolve).toHaveBeenCalledWith({
466
- name: 'test-tag',
467
- value: '{{test-tag}}',
468
- });
469
- });
470
-
471
- });
472
-
473
- describe('Component Lifecycle', () => {
474
-
475
- it('should recreate BeePlugin when templateLayoutType changes', async () => {
476
- const { rerender } = renderComponent(defaultProps);
477
-
478
- await act(async () => {
479
- await Promise.resolve();
480
- });
481
-
482
- expect(mockBeePlugin.create).toHaveBeenCalledTimes(1);
483
-
484
- // Change template layout type
485
- rerender(
486
- <Provider store={store}>
487
- <BeePopupEditor
488
- {...defaultProps}
489
- templateLayoutType="HEADER"
490
- />
491
- </Provider>
492
- );
493
-
494
- await act(async () => {
495
- await Promise.resolve();
496
- });
497
-
498
- expect(mockBeePlugin.create).toHaveBeenCalledTimes(2);
499
- });
500
- });
501
-
502
- describe('Props Validation', () => {
503
- it('should handle missing required props gracefully', () => {
504
- const consoleSpy = jest.spyOn(console, 'error').mockImplementation(() => {});
505
-
506
- expect(() => {
507
- renderComponent({
508
- uid: 'test-uid',
509
- tokenData: { token: 'test' },
510
- saveBeeInstance: jest.fn(),
511
- saveBeeData: jest.fn(),
512
- beeJson: '{}',
513
- // Missing other required props
514
- });
515
- }).not.toThrow();
516
-
517
- consoleSpy.mockRestore();
518
- });
519
-
520
- it('should work with minimal required props', () => {
521
- const minimalProps = {
522
- uid: 'test-uid',
523
- id: 'test-id',
524
- tokenData: { token: 'test' },
525
- saveBeeInstance: jest.fn(),
526
- saveBeeData: jest.fn(),
527
- beeJson: '{}',
528
- templateLayoutType: 'POPUP',
529
- moduleFilterEnabled: false,
530
- label: 'Test',
531
- location: { pathname: '/', query: {}, search: '' },
532
- injectedTags: [],
533
- className: '',
534
- userLocale: 'en',
535
- selectedOfferDetails: {},
536
- tags: [],
537
- onContextChange: jest.fn(),
538
- device: 'ANDROID',
539
- };
540
-
541
- const { container } = renderComponent(minimalProps);
542
- expect(container.querySelector('#bee-plugin-container')).toBeInTheDocument();
543
- expect(screen.getByTestId('tag-list')).toBeInTheDocument();
544
- });
545
- });
546
-
547
- describe('Tag Filtering', () => {
548
- it('should filter out unsubscribe tags from the tag list', () => {
549
- const tagsWithUnsubscribe = [
550
- { definition: { value: 'user.name' }, name: 'User Name' },
551
- { definition: { value: 'unsubscribe' }, name: 'Unsubscribe' },
552
- { definition: { value: 'user.email' }, name: 'User Email' },
553
- ];
554
-
555
- const { container } = renderComponent({
556
- ...defaultProps,
557
- tags: tagsWithUnsubscribe,
558
- });
559
-
560
- // The TagList should receive filtered tags (without unsubscribe)
561
- expect(container.querySelector('#bee-plugin-container')).toBeInTheDocument();
562
- expect(screen.getByTestId('tag-list')).toBeInTheDocument();
563
- });
564
-
565
- it('should handle empty tags array', () => {
566
- const { container } = renderComponent({
567
- ...defaultProps,
568
- tags: [],
569
- });
570
-
571
- expect(container.querySelector('#bee-plugin-container')).toBeInTheDocument();
572
- expect(screen.getByTestId('tag-list')).toBeInTheDocument();
573
- });
574
-
575
- it('should handle undefined tags', () => {
576
- const { container } = renderComponent({
577
- ...defaultProps,
578
- tags: undefined,
579
- });
580
-
581
- expect(container.querySelector('#bee-plugin-container')).toBeInTheDocument();
582
- expect(screen.getByTestId('tag-list')).toBeInTheDocument();
583
- });
584
- });
585
-
586
- describe('Error Handling', () => {
587
- it('should handle BeePlugin creation errors gracefully', async () => {
588
- const consoleSpy = jest.spyOn(console, 'error').mockImplementation(() => {});
589
- const mockCreateWithError = jest.fn((tokenData, config, callback) => {
590
- // Simulate error by not calling the callback
591
- // This tests the case where BeePlugin fails to initialize
592
- });
593
-
594
- const originalBeePlugin = global.window.BeePlugin;
595
- global.window.BeePlugin = { create: mockCreateWithError };
596
-
597
- expect(() => {
598
- renderComponent(defaultProps);
599
- }).not.toThrow();
600
-
601
- // Restore original BeePlugin
602
- global.window.BeePlugin = originalBeePlugin;
603
- consoleSpy.mockRestore();
604
- });
605
-
606
- });
607
-
608
- describe('Integration with Parent Components', () => {
609
- it('should pass all TagList props correctly', () => {
610
- const { container } = renderComponent(defaultProps);
611
-
612
- expect(container.querySelector('#bee-plugin-container')).toBeInTheDocument();
613
- const tagList = screen.getByTestId('tag-list');
614
- expect(tagList).toBeInTheDocument();
615
-
616
- // Verify TagList modal props are configured correctly
617
- expect(screen.queryByTestId('tag-list-modal')).not.toBeInTheDocument();
618
- });
619
-
620
- it('should call onContextChange when provided', () => {
621
- const { container } = renderComponent(defaultProps);
622
-
623
- expect(defaultProps.onContextChange).toBeDefined();
624
- expect(container.querySelector('#bee-plugin-container')).toBeInTheDocument();
625
- expect(screen.getByTestId('tag-list')).toBeInTheDocument();
626
- });
627
- });
628
- });