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

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 (23) hide show
  1. package/package.json +1 -1
  2. package/v2Components/CommonTestAndPreview/UnifiedPreview/PreviewHeader.js +0 -17
  3. package/v2Components/CommonTestAndPreview/UnifiedPreview/_unifiedPreview.scss +0 -70
  4. package/v2Components/CommonTestAndPreview/UnifiedPreview/index.js +5 -44
  5. package/v2Components/CommonTestAndPreview/constants.js +0 -2
  6. package/v2Components/CommonTestAndPreview/index.js +2 -51
  7. package/v2Components/CommonTestAndPreview/tests/UnifiedPreview/PreviewHeader.test.js +0 -159
  8. package/v2Components/CommonTestAndPreview/tests/UnifiedPreview/index.test.js +0 -255
  9. package/v2Components/CommonTestAndPreview/tests/constants.test.js +1 -2
  10. package/v2Components/CommonTestAndPreview/tests/index.test.js +0 -194
  11. package/v2Components/FormBuilder/index.js +162 -52
  12. package/v2Components/TestAndPreviewSlidebox/index.js +2 -2
  13. package/v2Containers/App/constants.js +0 -3
  14. package/v2Containers/CreativesContainer/index.js +60 -24
  15. package/v2Containers/Templates/index.js +2 -68
  16. package/v2Containers/WebPush/Create/index.js +8 -91
  17. package/v2Containers/WebPush/Create/index.scss +0 -7
  18. package/v2Components/CommonTestAndPreview/UnifiedPreview/WebPushPreviewContent.js +0 -169
  19. package/v2Components/CommonTestAndPreview/tests/UnifiedPreview/WebPushPreviewContent.test.js +0 -522
  20. package/v2Containers/App/tests/constants.test.js +0 -61
  21. package/v2Containers/Templates/tests/webpush.test.js +0 -375
  22. package/v2Containers/WebPush/Create/tests/getTemplateContent.test.js +0 -338
  23. package/v2Containers/WebPush/Create/tests/testAndPreviewIntegration.test.js +0 -325
@@ -1,338 +0,0 @@
1
- /**
2
- * Unit tests for getTemplateContent logic used in WebPushCreate
3
- *
4
- * The getTemplateContent function (useCallback) transforms component state
5
- * into a structured content object for TestAndPreviewSlidebox.
6
- * Tested here as a pure function matching the exact implementation logic.
7
- */
8
-
9
- import {
10
- WEBPUSH_MEDIA_TYPES,
11
- BRAND_ICON_OPTIONS,
12
- ON_CLICK_BEHAVIOUR_OPTIONS,
13
- } from '../../constants';
14
-
15
- /**
16
- * Mirrors the getTemplateContent useCallback in WebPushCreate/index.js.
17
- * Keep in sync if the source function changes.
18
- */
19
- const getTemplateContent = ({
20
- notificationTitle = '',
21
- message = '',
22
- accountId = null,
23
- mediaType = WEBPUSH_MEDIA_TYPES.NONE,
24
- imageSrc = '',
25
- brandIconOption = BRAND_ICON_OPTIONS.DONT_SHOW,
26
- brandIconSrc = '',
27
- buttons = [],
28
- onClickBehaviour = ON_CLICK_BEHAVIOUR_OPTIONS.SITE_URL,
29
- redirectUrl = '',
30
- websiteLink = '',
31
- templateName = '',
32
- } = {}) => {
33
- let cta = null;
34
- if (onClickBehaviour === ON_CLICK_BEHAVIOUR_OPTIONS.REDIRECT_TO_URL && redirectUrl) {
35
- cta = { type: 'EXTERNAL_URL', actionLink: redirectUrl.trim() };
36
- } else if (onClickBehaviour === ON_CLICK_BEHAVIOUR_OPTIONS.SITE_URL && websiteLink) {
37
- cta = { type: 'SITE_URL', actionLink: websiteLink };
38
- }
39
-
40
- const hasImage = mediaType === WEBPUSH_MEDIA_TYPES.IMAGE && imageSrc;
41
- const hasCtas = buttons && buttons.length > 0;
42
- let expandableDetails = null;
43
- if (hasImage || hasCtas) {
44
- expandableDetails = {
45
- media: hasImage ? [{ url: imageSrc, type: 'IMAGE' }] : [],
46
- ctas: hasCtas
47
- ? buttons.map((btn) => ({
48
- type: 'EXTERNAL_URL',
49
- action: '',
50
- title: btn.text || '',
51
- actionLink: btn.url || '',
52
- }))
53
- : [],
54
- };
55
- }
56
-
57
- const iconImageUrl =
58
- brandIconOption !== BRAND_ICON_OPTIONS.DONT_SHOW && brandIconSrc ? brandIconSrc : undefined;
59
-
60
- return {
61
- channel: 'WEBPUSH',
62
- accountId,
63
- content: {
64
- title: notificationTitle || '',
65
- message: message || '',
66
- ...(iconImageUrl ? { iconImageUrl } : {}),
67
- ...(cta ? { cta } : {}),
68
- ...(expandableDetails ? { expandableDetails } : {}),
69
- },
70
- messageSubject: templateName || notificationTitle || '',
71
- offers: [],
72
- };
73
- };
74
-
75
- describe('getTemplateContent (WebPushCreate)', () => {
76
- describe('Basic structure', () => {
77
- it('should return channel WEBPUSH', () => {
78
- const result = getTemplateContent({ notificationTitle: 'T', message: 'M' });
79
- expect(result.channel).toBe('WEBPUSH');
80
- });
81
-
82
- it('should include accountId', () => {
83
- const result = getTemplateContent({ accountId: 'acc-123' });
84
- expect(result.accountId).toBe('acc-123');
85
- });
86
-
87
- it('should return null accountId when not provided', () => {
88
- const result = getTemplateContent({});
89
- expect(result.accountId).toBeNull();
90
- });
91
-
92
- it('should include title in content', () => {
93
- const result = getTemplateContent({ notificationTitle: 'Hello World' });
94
- expect(result.content.title).toBe('Hello World');
95
- });
96
-
97
- it('should include message in content', () => {
98
- const result = getTemplateContent({ message: 'Body text' });
99
- expect(result.content.message).toBe('Body text');
100
- });
101
-
102
- it('should default title to empty string', () => {
103
- const result = getTemplateContent({});
104
- expect(result.content.title).toBe('');
105
- });
106
-
107
- it('should default message to empty string', () => {
108
- const result = getTemplateContent({});
109
- expect(result.content.message).toBe('');
110
- });
111
-
112
- it('should include offers as empty array', () => {
113
- const result = getTemplateContent({});
114
- expect(result.offers).toEqual([]);
115
- });
116
- });
117
-
118
- describe('messageSubject', () => {
119
- it('should use templateName as messageSubject', () => {
120
- const result = getTemplateContent({ templateName: 'My Template', notificationTitle: 'T' });
121
- expect(result.messageSubject).toBe('My Template');
122
- });
123
-
124
- it('should fall back to notificationTitle when templateName is empty', () => {
125
- const result = getTemplateContent({ templateName: '', notificationTitle: 'Push Title' });
126
- expect(result.messageSubject).toBe('Push Title');
127
- });
128
-
129
- it('should be empty string when both templateName and notificationTitle are empty', () => {
130
- const result = getTemplateContent({ templateName: '', notificationTitle: '' });
131
- expect(result.messageSubject).toBe('');
132
- });
133
- });
134
-
135
- describe('CTA - REDIRECT_TO_URL', () => {
136
- it('should set EXTERNAL_URL cta when behaviour is REDIRECT_TO_URL with url', () => {
137
- const result = getTemplateContent({
138
- onClickBehaviour: ON_CLICK_BEHAVIOUR_OPTIONS.REDIRECT_TO_URL,
139
- redirectUrl: 'https://redirect.com',
140
- });
141
- expect(result.content.cta).toEqual({ type: 'EXTERNAL_URL', actionLink: 'https://redirect.com' });
142
- });
143
-
144
- it('should trim redirectUrl whitespace', () => {
145
- const result = getTemplateContent({
146
- onClickBehaviour: ON_CLICK_BEHAVIOUR_OPTIONS.REDIRECT_TO_URL,
147
- redirectUrl: ' https://redirect.com ',
148
- });
149
- expect(result.content.cta.actionLink).toBe('https://redirect.com');
150
- });
151
-
152
- it('should NOT set cta when REDIRECT_TO_URL but redirectUrl is empty', () => {
153
- const result = getTemplateContent({
154
- onClickBehaviour: ON_CLICK_BEHAVIOUR_OPTIONS.REDIRECT_TO_URL,
155
- redirectUrl: '',
156
- });
157
- expect(result.content.cta).toBeUndefined();
158
- });
159
- });
160
-
161
- describe('CTA - SITE_URL', () => {
162
- it('should set SITE_URL cta when behaviour is SITE_URL with websiteLink', () => {
163
- const result = getTemplateContent({
164
- onClickBehaviour: ON_CLICK_BEHAVIOUR_OPTIONS.SITE_URL,
165
- websiteLink: 'https://mysite.com',
166
- });
167
- expect(result.content.cta).toEqual({ type: 'SITE_URL', actionLink: 'https://mysite.com' });
168
- });
169
-
170
- it('should NOT set cta when SITE_URL but websiteLink is empty', () => {
171
- const result = getTemplateContent({
172
- onClickBehaviour: ON_CLICK_BEHAVIOUR_OPTIONS.SITE_URL,
173
- websiteLink: '',
174
- });
175
- expect(result.content.cta).toBeUndefined();
176
- });
177
-
178
- it('should NOT include cta key at all when no url configured', () => {
179
- const result = getTemplateContent({
180
- onClickBehaviour: ON_CLICK_BEHAVIOUR_OPTIONS.SITE_URL,
181
- websiteLink: '',
182
- redirectUrl: '',
183
- });
184
- expect(Object.keys(result.content)).not.toContain('cta');
185
- });
186
- });
187
-
188
- describe('expandableDetails - image', () => {
189
- it('should include image media when mediaType is IMAGE and imageSrc is set', () => {
190
- const result = getTemplateContent({
191
- mediaType: WEBPUSH_MEDIA_TYPES.IMAGE,
192
- imageSrc: 'https://example.com/img.jpg',
193
- });
194
- expect(result.content.expandableDetails).toBeDefined();
195
- expect(result.content.expandableDetails.media).toEqual([
196
- { url: 'https://example.com/img.jpg', type: 'IMAGE' },
197
- ]);
198
- });
199
-
200
- it('should NOT include expandableDetails when mediaType is NONE', () => {
201
- const result = getTemplateContent({
202
- mediaType: WEBPUSH_MEDIA_TYPES.NONE,
203
- imageSrc: 'https://example.com/img.jpg',
204
- });
205
- expect(result.content.expandableDetails).toBeUndefined();
206
- });
207
-
208
- it('should NOT include expandableDetails when imageSrc is empty even if mediaType is IMAGE', () => {
209
- const result = getTemplateContent({
210
- mediaType: WEBPUSH_MEDIA_TYPES.IMAGE,
211
- imageSrc: '',
212
- buttons: [],
213
- });
214
- expect(result.content.expandableDetails).toBeUndefined();
215
- });
216
- });
217
-
218
- describe('expandableDetails - buttons', () => {
219
- it('should include ctas when buttons are provided', () => {
220
- const result = getTemplateContent({
221
- buttons: [{ text: 'Click Me', url: 'https://click.com' }],
222
- });
223
- expect(result.content.expandableDetails).toBeDefined();
224
- expect(result.content.expandableDetails.ctas).toEqual([
225
- { type: 'EXTERNAL_URL', action: '', title: 'Click Me', actionLink: 'https://click.com' },
226
- ]);
227
- });
228
-
229
- it('should map multiple buttons to ctas', () => {
230
- const result = getTemplateContent({
231
- buttons: [
232
- { text: 'Btn1', url: 'https://a.com' },
233
- { text: 'Btn2', url: 'https://b.com' },
234
- ],
235
- });
236
- expect(result.content.expandableDetails.ctas).toHaveLength(2);
237
- });
238
-
239
- it('should handle button with empty text and url', () => {
240
- const result = getTemplateContent({
241
- buttons: [{ text: '', url: '' }],
242
- });
243
- expect(result.content.expandableDetails.ctas[0]).toEqual({
244
- type: 'EXTERNAL_URL',
245
- action: '',
246
- title: '',
247
- actionLink: '',
248
- });
249
- });
250
-
251
- it('should NOT include expandableDetails when buttons array is empty', () => {
252
- const result = getTemplateContent({ buttons: [] });
253
- expect(result.content.expandableDetails).toBeUndefined();
254
- });
255
- });
256
-
257
- describe('expandableDetails - image + buttons combined', () => {
258
- it('should include both media and ctas when image and buttons present', () => {
259
- const result = getTemplateContent({
260
- mediaType: WEBPUSH_MEDIA_TYPES.IMAGE,
261
- imageSrc: 'https://img.com/a.jpg',
262
- buttons: [{ text: 'Go', url: 'https://go.com' }],
263
- });
264
- expect(result.content.expandableDetails.media).toHaveLength(1);
265
- expect(result.content.expandableDetails.ctas).toHaveLength(1);
266
- });
267
- });
268
-
269
- describe('brandIcon (iconImageUrl)', () => {
270
- it('should include iconImageUrl when brandIconOption is not DONT_SHOW and brandIconSrc is set', () => {
271
- const result = getTemplateContent({
272
- brandIconOption: BRAND_ICON_OPTIONS.UPLOAD_IMAGE,
273
- brandIconSrc: 'https://example.com/brand.png',
274
- });
275
- expect(result.content.iconImageUrl).toBe('https://example.com/brand.png');
276
- });
277
-
278
- it('should NOT include iconImageUrl when brandIconOption is DONT_SHOW', () => {
279
- const result = getTemplateContent({
280
- brandIconOption: BRAND_ICON_OPTIONS.DONT_SHOW,
281
- brandIconSrc: 'https://example.com/brand.png',
282
- });
283
- expect(result.content.iconImageUrl).toBeUndefined();
284
- });
285
-
286
- it('should NOT include iconImageUrl when brandIconSrc is empty', () => {
287
- const result = getTemplateContent({
288
- brandIconOption: BRAND_ICON_OPTIONS.UPLOAD_IMAGE,
289
- brandIconSrc: '',
290
- });
291
- expect(result.content.iconImageUrl).toBeUndefined();
292
- });
293
-
294
- it('should NOT include iconImageUrl key when not applicable', () => {
295
- const result = getTemplateContent({
296
- brandIconOption: BRAND_ICON_OPTIONS.DONT_SHOW,
297
- brandIconSrc: '',
298
- });
299
- expect(Object.keys(result.content)).not.toContain('iconImageUrl');
300
- });
301
- });
302
-
303
- describe('Full payload with all fields', () => {
304
- it('should build complete payload with title, message, cta, expandableDetails, iconImageUrl', () => {
305
- const result = getTemplateContent({
306
- notificationTitle: 'Full Title',
307
- message: 'Full body',
308
- accountId: 'acc-full',
309
- templateName: 'Full Template',
310
- mediaType: WEBPUSH_MEDIA_TYPES.IMAGE,
311
- imageSrc: 'https://img.com/full.jpg',
312
- brandIconOption: BRAND_ICON_OPTIONS.UPLOAD_IMAGE,
313
- brandIconSrc: 'https://icon.com/full.png',
314
- buttons: [{ text: 'Action', url: 'https://action.com' }],
315
- onClickBehaviour: ON_CLICK_BEHAVIOUR_OPTIONS.REDIRECT_TO_URL,
316
- redirectUrl: 'https://redirect.com',
317
- websiteLink: '',
318
- });
319
-
320
- expect(result).toEqual({
321
- channel: 'WEBPUSH',
322
- accountId: 'acc-full',
323
- content: {
324
- title: 'Full Title',
325
- message: 'Full body',
326
- iconImageUrl: 'https://icon.com/full.png',
327
- cta: { type: 'EXTERNAL_URL', actionLink: 'https://redirect.com' },
328
- expandableDetails: {
329
- media: [{ url: 'https://img.com/full.jpg', type: 'IMAGE' }],
330
- ctas: [{ type: 'EXTERNAL_URL', action: '', title: 'Action', actionLink: 'https://action.com' }],
331
- },
332
- },
333
- messageSubject: 'Full Template',
334
- offers: [],
335
- });
336
- });
337
- });
338
- });
@@ -1,325 +0,0 @@
1
- /**
2
- * Integration tests for TestAndPreviewSlidebox in WebPushCreate
3
- *
4
- * Tests:
5
- * - Test & Preview button renders and opens the slidebox
6
- * - handleTestAndPreview sets showTestAndPreviewSlidebox=true
7
- * - handleCloseTestAndPreview sets showTestAndPreviewSlidebox=false
8
- * - TestAndPreviewSlidebox receives correct props (currentChannel, accountId, content)
9
- *
10
- * Note: all relative mock paths are resolved from THIS test file's location
11
- * (app/v2Containers/WebPush/Create/tests/), not from the component.
12
- */
13
-
14
- import React from 'react';
15
- import { render, screen, fireEvent } from '@testing-library/react';
16
- import '@testing-library/jest-dom';
17
- import { IntlProvider } from 'react-intl';
18
-
19
- // ── Infrastructure / HOC mocks ──────────────────────────────────────────────
20
- jest.mock('../../../../hoc/withCreatives', () => ({
21
- __esModule: true,
22
- default: ({ WrappedComponent }) => WrappedComponent,
23
- }));
24
-
25
- jest.mock('@capillarytech/vulcan-react-sdk/utils', () => ({
26
- injectReducer: () => (Component) => Component,
27
- injectSaga: () => (Component) => Component,
28
- }));
29
- jest.mock('@capillarytech/vulcan-react-sdk/utils/sagaInjectorTypes', () => ({
30
- DAEMON: 'DAEMON',
31
- }));
32
-
33
- // ── Redux slices (paths relative to this test file) ─────────────────────────
34
- jest.mock('../../../Templates/selectors', () => ({
35
- makeSelectTemplates: () => () => {},
36
- }));
37
- jest.mock('../../../Templates/actions', () => ({}));
38
- jest.mock('../../selectors', () => ({
39
- makeSelectWebPush: () => () => ({}),
40
- makeSelectCreateError: () => () => null,
41
- makeSelectCreateTemplateInProgress: () => () => false,
42
- makeSelectEditTemplateInProgress: () => () => false,
43
- makeSelectEditError: () => () => null,
44
- }));
45
- jest.mock('../../actions', () => ({}));
46
- jest.mock('../../reducer', () => () => ({}));
47
- jest.mock('../../sagas', () => ({}));
48
- jest.mock('../../../Templates/sagas', () => ({ v2TemplateSaga: {} }));
49
- jest.mock('../../../Cap/selectors', () => ({
50
- makeSelectMetaEntities: () => () => [],
51
- setInjectedTags: () => () => [],
52
- }));
53
- jest.mock('../../../CreativesContainer/constants', () => ({
54
- WEBPUSH: 'WEBPUSH',
55
- }));
56
- jest.mock('../../../CreativesContainer/messages', () => ({
57
- testAndPreview: { id: 'testAndPreview', defaultMessage: 'Test & Preview' },
58
- }));
59
- jest.mock('../../../../utils/common', () => ({
60
- isAiContentBotDisabled: () => false,
61
- }));
62
-
63
- // ── Form section components ──────────────────────────────────────────────────
64
- jest.mock('../components/TemplateNameSection', () => ({
65
- __esModule: true,
66
- default: () => <div data-testid="template-name-section" />,
67
- }));
68
- jest.mock('../components/NotificationTitleSection', () => ({
69
- __esModule: true,
70
- default: () => <div data-testid="notification-title-section" />,
71
- }));
72
- jest.mock('../components/MessageSection', () => ({
73
- __esModule: true,
74
- default: () => <div data-testid="message-section" />,
75
- }));
76
- jest.mock('../components/MediaSection', () => ({
77
- __esModule: true,
78
- default: () => <div data-testid="media-section" />,
79
- }));
80
- jest.mock('../components/BrandIconSection', () => ({
81
- __esModule: true,
82
- default: () => <div data-testid="brand-icon-section" />,
83
- }));
84
- jest.mock('../components/ButtonsLinksSection', () => ({
85
- __esModule: true,
86
- default: () => <div data-testid="buttons-links-section" />,
87
- }));
88
- jest.mock('../components/FormActions', () => ({
89
- __esModule: true,
90
- default: () => <div data-testid="form-actions" />,
91
- }));
92
- jest.mock('../preview/WebPushPreview', () => ({
93
- __esModule: true,
94
- default: () => <div data-testid="webpush-preview" />,
95
- }));
96
- jest.mock('../../../TagList', () => ({
97
- __esModule: true,
98
- default: () => <div data-testid="tag-list" />,
99
- }));
100
-
101
- // ── Hooks ────────────────────────────────────────────────────────────────────
102
- jest.mock('../hooks/useCharacterCount', () => ({
103
- useCharacterCount: () => ({ updateCharacterCount: jest.fn() }),
104
- }));
105
- jest.mock('../hooks/useButtonManagement', () => ({
106
- useButtonManagement: () => ({ buttons: [], setButtons: jest.fn() }),
107
- }));
108
- jest.mock('../hooks/useImageUpload', () => ({
109
- useImageUpload: () => ({
110
- imageSrc: '',
111
- imageUrl: '',
112
- isValidating: false,
113
- isUploading: false,
114
- setImageSrc: jest.fn(),
115
- setImageUrl: jest.fn(),
116
- }),
117
- }));
118
- jest.mock('../hooks/useTagManagement', () => ({
119
- useTagManagement: () => ({ tags: [], extractTags: jest.fn() }),
120
- }));
121
-
122
- // ── Capture TestAndPreviewSlidebox props ─────────────────────────────────────
123
- let capturedSlideboxProps = {};
124
- jest.mock('../../../../v2Components/TestAndPreviewSlidebox', () => ({
125
- __esModule: true,
126
- default: (props) => {
127
- capturedSlideboxProps = props;
128
- return (
129
- <div data-testid="test-and-preview-slidebox" data-show={props.show ? 'true' : 'false'}>
130
- {props.show && <div data-testid="slidebox-open">Slidebox Open</div>}
131
- <button data-testid="slidebox-close-btn" onClick={props.onClose}>
132
- Close
133
- </button>
134
- </div>
135
- );
136
- },
137
- }));
138
-
139
- // ── CapUI library ─────────────────────────────────────────────────────────────
140
- jest.mock('@capillarytech/cap-ui-library/CapRow', () => ({
141
- __esModule: true,
142
- default: ({ children, className }) => <div className={className}>{children}</div>,
143
- }));
144
- jest.mock('@capillarytech/cap-ui-library/CapColumn', () => ({
145
- __esModule: true,
146
- default: ({ children, className }) => <div className={className}>{children}</div>,
147
- }));
148
- jest.mock('@capillarytech/cap-ui-library/CapButton', () => ({
149
- __esModule: true,
150
- default: ({ children, onClick, className, type }) => (
151
- <button className={className} onClick={onClick} data-type={type}>
152
- {children}
153
- </button>
154
- ),
155
- }));
156
-
157
- // ── Import component AFTER mocks ─────────────────────────────────────────────
158
- // eslint-disable-next-line import/first
159
- import WebPushCreateDefault from '../index';
160
-
161
- const baseProps = {
162
- isFullMode: false,
163
- handleClose: jest.fn(),
164
- webPushActions: {
165
- createTemplate: jest.fn(),
166
- editTemplate: jest.fn(),
167
- uploadImage: jest.fn(),
168
- clearCreateError: jest.fn(),
169
- clearEditError: jest.fn(),
170
- clearCreateResponse: jest.fn(),
171
- clearEditResponse: jest.fn(),
172
- setSelectedAccount: jest.fn(),
173
- clearState: jest.fn(),
174
- },
175
- createTemplateInProgress: false,
176
- createTemplateError: null,
177
- editTemplateInProgress: false,
178
- editTemplateError: null,
179
- accountData: null,
180
- webPush: {},
181
- onCreateComplete: jest.fn(),
182
- getFormData: jest.fn(),
183
- isGetFormData: false,
184
- templateData: null,
185
- creativesMode: 'create',
186
- params: {},
187
- globalActions: { getMetaEntities: jest.fn() },
188
- location: { pathname: '/webpush', query: {}, search: '', state: {} },
189
- metaEntities: [],
190
- injectedTags: [],
191
- getDefaultTags: jest.fn(),
192
- supportedTags: [],
193
- forwardedTags: [],
194
- selectedOfferDetails: [],
195
- eventContextTags: [],
196
- waitEventContextTags: {},
197
- templateActions: {},
198
- Templates: { templates: [] },
199
- restrictPersonalization: false,
200
- };
201
-
202
- const TestWrapper = ({ children }) => (
203
- <IntlProvider locale="en" messages={{ testAndPreview: 'Test & Preview' }}>
204
- {children}
205
- </IntlProvider>
206
- );
207
-
208
- describe('WebPushCreate - Test & Preview integration', () => {
209
- beforeEach(() => {
210
- jest.clearAllMocks();
211
- capturedSlideboxProps = {};
212
- });
213
-
214
- it('should render the Test & Preview button', () => {
215
- render(
216
- <TestWrapper>
217
- <WebPushCreateDefault {...baseProps} />
218
- </TestWrapper>
219
- );
220
-
221
- expect(screen.getByText('Test & Preview')).toBeTruthy();
222
- });
223
-
224
- it('should render TestAndPreviewSlidebox with show=false initially', () => {
225
- render(
226
- <TestWrapper>
227
- <WebPushCreateDefault {...baseProps} />
228
- </TestWrapper>
229
- );
230
-
231
- const slidebox = screen.getByTestId('test-and-preview-slidebox');
232
- expect(slidebox.getAttribute('data-show')).toBe('false');
233
- });
234
-
235
- it('should open TestAndPreviewSlidebox when Test & Preview button is clicked', () => {
236
- render(
237
- <TestWrapper>
238
- <WebPushCreateDefault {...baseProps} />
239
- </TestWrapper>
240
- );
241
-
242
- fireEvent.click(screen.getByText('Test & Preview'));
243
-
244
- const slidebox = screen.getByTestId('test-and-preview-slidebox');
245
- expect(slidebox.getAttribute('data-show')).toBe('true');
246
- expect(screen.getByTestId('slidebox-open')).toBeTruthy();
247
- });
248
-
249
- it('should close TestAndPreviewSlidebox when onClose is called', () => {
250
- render(
251
- <TestWrapper>
252
- <WebPushCreateDefault {...baseProps} />
253
- </TestWrapper>
254
- );
255
-
256
- // Open it
257
- fireEvent.click(screen.getByText('Test & Preview'));
258
- expect(screen.getByTestId('test-and-preview-slidebox').getAttribute('data-show')).toBe('true');
259
-
260
- // Close it
261
- fireEvent.click(screen.getByTestId('slidebox-close-btn'));
262
- expect(screen.getByTestId('test-and-preview-slidebox').getAttribute('data-show')).toBe('false');
263
- });
264
-
265
- it('should pass currentChannel="WEBPUSH" to TestAndPreviewSlidebox', () => {
266
- render(
267
- <TestWrapper>
268
- <WebPushCreateDefault {...baseProps} />
269
- </TestWrapper>
270
- );
271
-
272
- expect(capturedSlideboxProps.currentChannel).toBe('WEBPUSH');
273
- });
274
-
275
- it('should pass null accountId when accountData is null', () => {
276
- render(
277
- <TestWrapper>
278
- <WebPushCreateDefault {...baseProps} accountData={null} />
279
- </TestWrapper>
280
- );
281
-
282
- expect(capturedSlideboxProps.accountId).toBeNull();
283
- });
284
-
285
- it('should pass content object with channel WEBPUSH to TestAndPreviewSlidebox', () => {
286
- render(
287
- <TestWrapper>
288
- <WebPushCreateDefault {...baseProps} />
289
- </TestWrapper>
290
- );
291
-
292
- expect(capturedSlideboxProps.content).toBeDefined();
293
- expect(capturedSlideboxProps.content.channel).toBe('WEBPUSH');
294
- });
295
-
296
- it('should pass content with offers array to TestAndPreviewSlidebox', () => {
297
- render(
298
- <TestWrapper>
299
- <WebPushCreateDefault {...baseProps} />
300
- </TestWrapper>
301
- );
302
-
303
- expect(capturedSlideboxProps.content.offers).toEqual([]);
304
- });
305
-
306
- it('should pass onClose handler to TestAndPreviewSlidebox', () => {
307
- render(
308
- <TestWrapper>
309
- <WebPushCreateDefault {...baseProps} />
310
- </TestWrapper>
311
- );
312
-
313
- expect(typeof capturedSlideboxProps.onClose).toBe('function');
314
- });
315
-
316
- it('should pass show=false to TestAndPreviewSlidebox before button click', () => {
317
- render(
318
- <TestWrapper>
319
- <WebPushCreateDefault {...baseProps} />
320
- </TestWrapper>
321
- );
322
-
323
- expect(capturedSlideboxProps.show).toBe(false);
324
- });
325
- });