@capillarytech/creatives-library 8.0.255-alpha.4 → 8.0.256

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 (164) hide show
  1. package/constants/unified.js +0 -1
  2. package/package.json +1 -1
  3. package/services/api.js +0 -5
  4. package/translations/en.json +3 -4
  5. package/utils/common.js +0 -6
  6. package/utils/tests/transformerUtils.test.js +0 -297
  7. package/utils/transformerUtils.js +0 -40
  8. package/v2Components/CapImageUpload/constants.js +0 -2
  9. package/v2Components/CapImageUpload/index.js +16 -65
  10. package/v2Components/CapImageUpload/index.scss +1 -4
  11. package/v2Components/CapImageUpload/messages.js +1 -5
  12. package/v2Components/CommonTestAndPreview/UnifiedPreview/InAppPreviewContent.js +3 -3
  13. package/v2Components/CommonTestAndPreview/UnifiedPreview/RcsPreviewContent.js +3 -3
  14. package/v2Components/CommonTestAndPreview/UnifiedPreview/SmsPreviewContent.js +3 -3
  15. package/v2Components/CommonTestAndPreview/UnifiedPreview/ViberPreviewContent.js +3 -3
  16. package/v2Components/CommonTestAndPreview/UnifiedPreview/WhatsAppPreviewContent.js +1 -1
  17. package/v2Components/CommonTestAndPreview/UnifiedPreview/_unifiedPreview.scss +37 -6
  18. package/v2Components/CommonTestAndPreview/_commonTestAndPreview.scss +0 -2
  19. package/v2Components/TemplatePreview/_templatePreview.scss +1 -2
  20. package/v2Components/TestAndPreviewSlidebox/_testAndPreviewSlidebox.scss +0 -1
  21. package/v2Containers/App/constants.js +0 -5
  22. package/v2Containers/Cap/tests/__snapshots__/index.test.js.snap +3 -4
  23. package/v2Containers/CreativesContainer/SlideBoxContent.js +2 -57
  24. package/v2Containers/CreativesContainer/SlideBoxHeader.js +0 -1
  25. package/v2Containers/CreativesContainer/constants.js +0 -3
  26. package/v2Containers/CreativesContainer/index.js +0 -168
  27. package/v2Containers/CreativesContainer/messages.js +0 -4
  28. package/v2Containers/CreativesContainer/tests/SlideBoxContent.test.js +0 -210
  29. package/v2Containers/CreativesContainer/tests/__snapshots__/SlideBoxContent.test.js.snap +0 -304
  30. package/v2Containers/Line/Container/ImageCarousel/tests/__snapshots__/content.test.js.snap +12 -36
  31. package/v2Containers/Line/Container/ImageCarousel/tests/__snapshots__/index.test.js.snap +6 -8
  32. package/v2Containers/Line/Container/Wrapper/tests/__snapshots__/index.test.js.snap +75 -100
  33. package/v2Containers/Line/Container/tests/__snapshots__/index.test.js.snap +54 -72
  34. package/v2Containers/Rcs/tests/__snapshots__/index.test.js.snap +214 -286
  35. package/v2Containers/SmsTrai/Create/tests/__snapshots__/index.test.js.snap +12 -16
  36. package/v2Containers/SmsTrai/Edit/tests/__snapshots__/index.test.js.snap +48 -60
  37. package/v2Containers/Templates/ChannelTypeIllustration.js +1 -13
  38. package/v2Containers/Templates/_templates.scss +0 -205
  39. package/v2Containers/Templates/actions.js +1 -2
  40. package/v2Containers/Templates/constants.js +0 -1
  41. package/v2Containers/Templates/index.js +34 -274
  42. package/v2Containers/Templates/messages.js +0 -24
  43. package/v2Containers/Templates/reducer.js +0 -2
  44. package/v2Containers/Templates/tests/index.test.js +0 -10
  45. package/v2Containers/TemplatesV2/index.js +7 -15
  46. package/v2Containers/TemplatesV2/messages.js +0 -4
  47. package/v2Containers/Whatsapp/index.js +1 -1
  48. package/v2Containers/Whatsapp/tests/__snapshots__/index.test.js.snap +870 -1442
  49. package/utils/imageUrlUpload.js +0 -141
  50. package/v2Components/CapImageUrlUpload/constants.js +0 -26
  51. package/v2Components/CapImageUrlUpload/index.js +0 -365
  52. package/v2Components/CapImageUrlUpload/index.scss +0 -35
  53. package/v2Components/CapImageUrlUpload/messages.js +0 -47
  54. package/v2Containers/WebPush/Create/components/BrandIconSection.js +0 -108
  55. package/v2Containers/WebPush/Create/components/ButtonForm.js +0 -172
  56. package/v2Containers/WebPush/Create/components/ButtonItem.js +0 -101
  57. package/v2Containers/WebPush/Create/components/ButtonList.js +0 -145
  58. package/v2Containers/WebPush/Create/components/ButtonsLinksSection.js +0 -164
  59. package/v2Containers/WebPush/Create/components/ButtonsLinksSection.test.js +0 -463
  60. package/v2Containers/WebPush/Create/components/FormActions.js +0 -54
  61. package/v2Containers/WebPush/Create/components/FormActions.test.js +0 -163
  62. package/v2Containers/WebPush/Create/components/MediaSection.js +0 -142
  63. package/v2Containers/WebPush/Create/components/MediaSection.test.js +0 -341
  64. package/v2Containers/WebPush/Create/components/MessageSection.js +0 -103
  65. package/v2Containers/WebPush/Create/components/MessageSection.test.js +0 -268
  66. package/v2Containers/WebPush/Create/components/NotificationTitleSection.js +0 -87
  67. package/v2Containers/WebPush/Create/components/NotificationTitleSection.test.js +0 -210
  68. package/v2Containers/WebPush/Create/components/TemplateNameSection.js +0 -54
  69. package/v2Containers/WebPush/Create/components/TemplateNameSection.test.js +0 -143
  70. package/v2Containers/WebPush/Create/components/__snapshots__/ButtonsLinksSection.test.js.snap +0 -86
  71. package/v2Containers/WebPush/Create/components/__snapshots__/FormActions.test.js.snap +0 -16
  72. package/v2Containers/WebPush/Create/components/__snapshots__/MediaSection.test.js.snap +0 -41
  73. package/v2Containers/WebPush/Create/components/__snapshots__/MessageSection.test.js.snap +0 -54
  74. package/v2Containers/WebPush/Create/components/__snapshots__/NotificationTitleSection.test.js.snap +0 -37
  75. package/v2Containers/WebPush/Create/components/__snapshots__/TemplateNameSection.test.js.snap +0 -21
  76. package/v2Containers/WebPush/Create/components/_buttons.scss +0 -246
  77. package/v2Containers/WebPush/Create/components/tests/ButtonForm.test.js +0 -554
  78. package/v2Containers/WebPush/Create/components/tests/ButtonItem.test.js +0 -607
  79. package/v2Containers/WebPush/Create/components/tests/ButtonList.test.js +0 -633
  80. package/v2Containers/WebPush/Create/components/tests/__snapshots__/ButtonForm.test.js.snap +0 -666
  81. package/v2Containers/WebPush/Create/components/tests/__snapshots__/ButtonItem.test.js.snap +0 -74
  82. package/v2Containers/WebPush/Create/components/tests/__snapshots__/ButtonList.test.js.snap +0 -78
  83. package/v2Containers/WebPush/Create/hooks/useButtonManagement.js +0 -138
  84. package/v2Containers/WebPush/Create/hooks/useButtonManagement.test.js +0 -406
  85. package/v2Containers/WebPush/Create/hooks/useCharacterCount.js +0 -30
  86. package/v2Containers/WebPush/Create/hooks/useCharacterCount.test.js +0 -151
  87. package/v2Containers/WebPush/Create/hooks/useImageUpload.js +0 -104
  88. package/v2Containers/WebPush/Create/hooks/useImageUpload.test.js +0 -538
  89. package/v2Containers/WebPush/Create/hooks/useTagManagement.js +0 -122
  90. package/v2Containers/WebPush/Create/hooks/useTagManagement.test.js +0 -633
  91. package/v2Containers/WebPush/Create/index.js +0 -1148
  92. package/v2Containers/WebPush/Create/index.scss +0 -134
  93. package/v2Containers/WebPush/Create/messages.js +0 -203
  94. package/v2Containers/WebPush/Create/preview/DevicePreviewContent.js +0 -228
  95. package/v2Containers/WebPush/Create/preview/NotificationContainer.js +0 -294
  96. package/v2Containers/WebPush/Create/preview/PreviewContent.js +0 -90
  97. package/v2Containers/WebPush/Create/preview/PreviewControls.js +0 -305
  98. package/v2Containers/WebPush/Create/preview/PreviewDisclaimer.js +0 -23
  99. package/v2Containers/WebPush/Create/preview/WebPushPreview.js +0 -155
  100. package/v2Containers/WebPush/Create/preview/assets/Light.svg +0 -53
  101. package/v2Containers/WebPush/Create/preview/assets/Top.svg +0 -5
  102. package/v2Containers/WebPush/Create/preview/assets/android-arrow-down.svg +0 -9
  103. package/v2Containers/WebPush/Create/preview/assets/android-arrow-up.svg +0 -9
  104. package/v2Containers/WebPush/Create/preview/assets/chrome-icon.png +0 -0
  105. package/v2Containers/WebPush/Create/preview/assets/edge-icon.png +0 -0
  106. package/v2Containers/WebPush/Create/preview/assets/firefox-icon.svg +0 -106
  107. package/v2Containers/WebPush/Create/preview/assets/iOS.svg +0 -26
  108. package/v2Containers/WebPush/Create/preview/assets/macos-arrow-down-icon.svg +0 -9
  109. package/v2Containers/WebPush/Create/preview/assets/macos-triple-dot-icon.svg +0 -9
  110. package/v2Containers/WebPush/Create/preview/assets/opera-icon.svg +0 -18
  111. package/v2Containers/WebPush/Create/preview/assets/safari-icon.svg +0 -29
  112. package/v2Containers/WebPush/Create/preview/assets/windows-close-icon.svg +0 -9
  113. package/v2Containers/WebPush/Create/preview/assets/windows-triple-dot-icon.svg +0 -9
  114. package/v2Containers/WebPush/Create/preview/components/AndroidMobileChromeHeader.js +0 -47
  115. package/v2Containers/WebPush/Create/preview/components/AndroidMobileExpanded.js +0 -141
  116. package/v2Containers/WebPush/Create/preview/components/IOSHeader.js +0 -45
  117. package/v2Containers/WebPush/Create/preview/components/NotificationExpandedContent.js +0 -68
  118. package/v2Containers/WebPush/Create/preview/components/NotificationHeader.js +0 -61
  119. package/v2Containers/WebPush/Create/preview/components/WindowsChromeExpanded.js +0 -99
  120. package/v2Containers/WebPush/Create/preview/components/tests/AndroidMobileExpanded.test.js +0 -733
  121. package/v2Containers/WebPush/Create/preview/components/tests/WindowsChromeExpanded.test.js +0 -571
  122. package/v2Containers/WebPush/Create/preview/components/tests/__snapshots__/AndroidMobileExpanded.test.js.snap +0 -81
  123. package/v2Containers/WebPush/Create/preview/components/tests/__snapshots__/WindowsChromeExpanded.test.js.snap +0 -81
  124. package/v2Containers/WebPush/Create/preview/config/notificationMappings.js +0 -50
  125. package/v2Containers/WebPush/Create/preview/constants.js +0 -637
  126. package/v2Containers/WebPush/Create/preview/notification-container.scss +0 -79
  127. package/v2Containers/WebPush/Create/preview/preview.scss +0 -351
  128. package/v2Containers/WebPush/Create/preview/styles/_android-mobile-chrome.scss +0 -370
  129. package/v2Containers/WebPush/Create/preview/styles/_android-mobile-edge.scss +0 -12
  130. package/v2Containers/WebPush/Create/preview/styles/_android-mobile-firefox.scss +0 -12
  131. package/v2Containers/WebPush/Create/preview/styles/_android-mobile-opera.scss +0 -12
  132. package/v2Containers/WebPush/Create/preview/styles/_android-tablet-chrome.scss +0 -47
  133. package/v2Containers/WebPush/Create/preview/styles/_android-tablet-edge.scss +0 -11
  134. package/v2Containers/WebPush/Create/preview/styles/_android-tablet-firefox.scss +0 -11
  135. package/v2Containers/WebPush/Create/preview/styles/_android-tablet-opera.scss +0 -11
  136. package/v2Containers/WebPush/Create/preview/styles/_base.scss +0 -207
  137. package/v2Containers/WebPush/Create/preview/styles/_ios.scss +0 -153
  138. package/v2Containers/WebPush/Create/preview/styles/_ipados.scss +0 -107
  139. package/v2Containers/WebPush/Create/preview/styles/_macos-chrome.scss +0 -101
  140. package/v2Containers/WebPush/Create/preview/styles/_windows-chrome.scss +0 -229
  141. package/v2Containers/WebPush/Create/preview/tests/DevicePreviewContent.test.js +0 -909
  142. package/v2Containers/WebPush/Create/preview/tests/NotificationContainer.test.js +0 -1081
  143. package/v2Containers/WebPush/Create/preview/tests/PreviewControls.test.js +0 -723
  144. package/v2Containers/WebPush/Create/preview/tests/WebPushPreview.test.js +0 -1327
  145. package/v2Containers/WebPush/Create/preview/tests/__snapshots__/DevicePreviewContent.test.js.snap +0 -131
  146. package/v2Containers/WebPush/Create/preview/tests/__snapshots__/NotificationContainer.test.js.snap +0 -112
  147. package/v2Containers/WebPush/Create/preview/tests/__snapshots__/PreviewControls.test.js.snap +0 -144
  148. package/v2Containers/WebPush/Create/preview/tests/__snapshots__/WebPushPreview.test.js.snap +0 -129
  149. package/v2Containers/WebPush/Create/utils/payloadBuilder.js +0 -96
  150. package/v2Containers/WebPush/Create/utils/payloadBuilder.test.js +0 -396
  151. package/v2Containers/WebPush/Create/utils/previewUtils.js +0 -89
  152. package/v2Containers/WebPush/Create/utils/urlValidation.js +0 -115
  153. package/v2Containers/WebPush/Create/utils/urlValidation.test.js +0 -449
  154. package/v2Containers/WebPush/Create/utils/validation.js +0 -75
  155. package/v2Containers/WebPush/Create/utils/validation.test.js +0 -283
  156. package/v2Containers/WebPush/actions.js +0 -60
  157. package/v2Containers/WebPush/constants.js +0 -132
  158. package/v2Containers/WebPush/index.js +0 -2
  159. package/v2Containers/WebPush/reducer.js +0 -104
  160. package/v2Containers/WebPush/sagas.js +0 -119
  161. package/v2Containers/WebPush/selectors.js +0 -65
  162. package/v2Containers/WebPush/tests/reducer.test.js +0 -863
  163. package/v2Containers/WebPush/tests/sagas.test.js +0 -566
  164. package/v2Containers/WebPush/tests/selectors.test.js +0 -960
@@ -1,1327 +0,0 @@
1
- import React from 'react';
2
- import { act } from 'react-dom/test-utils';
3
- import { mountWithIntl, shallowWithIntl } from '../../../../../helpers/intl-enzym-test-helpers';
4
- import WebPushPreview from '../WebPushPreview';
5
- import PreviewControls from '../PreviewControls';
6
- import PreviewContent from '../PreviewContent';
7
- import PreviewDisclaimer from '../PreviewDisclaimer';
8
- import DevicePreviewContent from '../DevicePreviewContent';
9
- import CapSlideBox from '@capillarytech/cap-ui-library/CapSlideBox';
10
- import CapButton from '@capillarytech/cap-ui-library/CapButton';
11
- import CapRow from '@capillarytech/cap-ui-library/CapRow';
12
- import CapColumn from '@capillarytech/cap-ui-library/CapColumn';
13
- import {
14
- OS_OPTIONS,
15
- DEFAULT_OS,
16
- DEFAULT_BROWSER,
17
- OS_MACOS,
18
- OS_WINDOWS,
19
- OS_IOS,
20
- OS_IPADOS,
21
- OS_ANDROID_MOBILE,
22
- OS_ANDROID_TABLET,
23
- BROWSER_CHROME,
24
- BROWSER_FIREFOX,
25
- BROWSER_EDGE,
26
- BROWSER_SAFARI,
27
- BROWSER_OPERA,
28
- } from '../constants';
29
- import { getBrowserOptionsForOS } from '../config/notificationMappings';
30
-
31
- // Mock CapSlideBox to control its behavior in tests
32
- jest.mock('@capillarytech/cap-ui-library/CapSlideBox', () => {
33
- const React = require('react');
34
- return function MockCapSlideBox({ show, handleClose, content, header, className, size }) {
35
- // Always render the component (even when show is false) so we can test it
36
- // But use display: none or similar to hide it when show is false
37
- return (
38
- <div
39
- className={`mock-cap-slidebox ${className || ''}`}
40
- data-size={size}
41
- data-testid={className === 'webpush-preview-slidebox' ? 'webpush-slidebox' : undefined}
42
- style={{ display: show ? 'block' : 'none' }}
43
- >
44
- <div className="mock-slidebox-header">{header}</div>
45
- <button className="mock-slidebox-close" onClick={handleClose} data-testid="close-slidebox">
46
- Close
47
- </button>
48
- {show && <div className="mock-slidebox-content">{content}</div>}
49
- </div>
50
- );
51
- };
52
- });
53
-
54
- describe('WebPushPreview', () => {
55
- const defaultProps = {
56
- notificationTitle: 'Test Notification Title',
57
- notificationBody: 'Test notification body text',
58
- url: 'https://www.example.com',
59
- imageSrc: 'https://example.com/image.jpg',
60
- brandIconSrc: 'https://example.com/icon.png',
61
- };
62
-
63
- beforeEach(() => {
64
- jest.clearAllMocks();
65
- });
66
-
67
- describe('Basic Rendering', () => {
68
- it('should render correctly with default props', () => {
69
- const wrapper = shallowWithIntl(<WebPushPreview {...defaultProps} />);
70
- expect(wrapper).toMatchSnapshot();
71
- });
72
-
73
- it('should render with minimal props', () => {
74
- const wrapper = mountWithIntl(<WebPushPreview />);
75
- expect(wrapper.exists()).toBe(true);
76
- });
77
-
78
- it('should render main container with correct class', () => {
79
- const wrapper = mountWithIntl(<WebPushPreview {...defaultProps} />);
80
- const container = wrapper.find('.webpush-preview-container').first();
81
- expect(container.exists()).toBe(true);
82
- expect(container.is(CapRow)).toBe(true);
83
- });
84
-
85
- it('should render PreviewControls component', () => {
86
- const wrapper = mountWithIntl(<WebPushPreview {...defaultProps} />);
87
- const previewControls = wrapper.find(PreviewControls);
88
- expect(previewControls.exists()).toBe(true);
89
- });
90
-
91
- it('should render PreviewContent component', () => {
92
- const wrapper = mountWithIntl(<WebPushPreview {...defaultProps} />);
93
- const previewContent = wrapper.find(PreviewContent);
94
- expect(previewContent.exists()).toBe(true);
95
- });
96
-
97
- it('should render PreviewDisclaimer component', () => {
98
- const wrapper = mountWithIntl(<WebPushPreview {...defaultProps} />);
99
- const previewDisclaimer = wrapper.find(PreviewDisclaimer);
100
- expect(previewDisclaimer.exists()).toBe(true);
101
- });
102
-
103
- it('should render "Preview in all devices" button', () => {
104
- const wrapper = mountWithIntl(<WebPushPreview {...defaultProps} />);
105
- const buttonRow = wrapper.find('.preview-all-devices-button');
106
- expect(buttonRow.exists()).toBe(true);
107
- const button = buttonRow.find(CapButton);
108
- expect(button.exists()).toBe(true);
109
- expect(button.hasClass('preview-all-devices-trigger')).toBe(true);
110
- });
111
-
112
- it('should render CapSlideBox component', () => {
113
- const wrapper = mountWithIntl(<WebPushPreview {...defaultProps} />);
114
- const allSlideBoxes = wrapper.find(CapSlideBox);
115
- let found = false;
116
- for (let i = 0; i < allSlideBoxes.length; i++) {
117
- if (allSlideBoxes.at(i).prop('className') === 'webpush-preview-slidebox') {
118
- found = true;
119
- break;
120
- }
121
- }
122
- expect(found).toBe(true);
123
- });
124
- });
125
-
126
- describe('Initial State', () => {
127
- it('should initialize with default OS', () => {
128
- const wrapper = mountWithIntl(<WebPushPreview {...defaultProps} />);
129
- const previewControls = wrapper.find(PreviewControls);
130
- expect(previewControls.prop('selectedOS')).toBe(DEFAULT_OS);
131
- });
132
-
133
- it('should initialize with default browser', () => {
134
- const wrapper = mountWithIntl(<WebPushPreview {...defaultProps} />);
135
- const previewControls = wrapper.find(PreviewControls);
136
- expect(previewControls.prop('selectedBrowser')).toBe(DEFAULT_BROWSER);
137
- });
138
-
139
- it('should initialize with slidebox closed', () => {
140
- const wrapper = mountWithIntl(<WebPushPreview {...defaultProps} />);
141
- const allSlideBoxes = wrapper.find(CapSlideBox);
142
- let showState = null;
143
- for (let i = 0; i < allSlideBoxes.length; i++) {
144
- if (allSlideBoxes.at(i).prop('className') === 'webpush-preview-slidebox') {
145
- showState = allSlideBoxes.at(i).prop('show');
146
- break;
147
- }
148
- }
149
- expect(showState).toBe(false);
150
- });
151
-
152
- it('should pass correct browser options for default OS', () => {
153
- const wrapper = mountWithIntl(<WebPushPreview {...defaultProps} />);
154
- const previewControls = wrapper.find(PreviewControls);
155
- const expectedBrowserOptions = getBrowserOptionsForOS(DEFAULT_OS);
156
- expect(previewControls.prop('browserOptions')).toEqual(expectedBrowserOptions);
157
- });
158
- });
159
-
160
- describe('PreviewControls Props', () => {
161
- it('should pass correct props to PreviewControls', () => {
162
- const wrapper = mountWithIntl(<WebPushPreview {...defaultProps} />);
163
- const previewControls = wrapper.find(PreviewControls);
164
-
165
- expect(previewControls.prop('selectedOS')).toBe(DEFAULT_OS);
166
- expect(previewControls.prop('selectedBrowser')).toBe(DEFAULT_BROWSER);
167
- expect(previewControls.prop('osOptions')).toBe(OS_OPTIONS);
168
- expect(previewControls.prop('layoutMode')).toBe('newRow');
169
- expect(previewControls.prop('showStateDropdown')).toBe(false);
170
-
171
- const expectedBrowserOptions = getBrowserOptionsForOS(DEFAULT_OS);
172
- expect(previewControls.prop('browserOptions')).toEqual(expectedBrowserOptions);
173
- });
174
-
175
- it('should pass onOSChange handler to PreviewControls', () => {
176
- const wrapper = mountWithIntl(<WebPushPreview {...defaultProps} />);
177
- const previewControls = wrapper.find(PreviewControls);
178
- expect(typeof previewControls.prop('onOSChange')).toBe('function');
179
- });
180
-
181
- it('should pass onBrowserChange handler to PreviewControls', () => {
182
- const wrapper = mountWithIntl(<WebPushPreview {...defaultProps} />);
183
- const previewControls = wrapper.find(PreviewControls);
184
- expect(typeof previewControls.prop('onBrowserChange')).toBe('function');
185
- });
186
- });
187
-
188
- describe('PreviewContent Props', () => {
189
- it('should pass correct props to PreviewContent', () => {
190
- const wrapper = mountWithIntl(<WebPushPreview {...defaultProps} />);
191
- const previewContent = wrapper.find(PreviewContent);
192
-
193
- expect(previewContent.prop('notificationTitle')).toBe(defaultProps.notificationTitle);
194
- expect(previewContent.prop('notificationBody')).toBe(defaultProps.notificationBody);
195
- expect(previewContent.prop('url')).toBe(defaultProps.url);
196
- expect(previewContent.prop('selectedOS')).toBe(DEFAULT_OS);
197
- expect(previewContent.prop('selectedBrowser')).toBe(DEFAULT_BROWSER);
198
- expect(previewContent.prop('notificationState')).toBe('Collapsed');
199
- expect(previewContent.prop('imageSrc')).toBe(defaultProps.imageSrc);
200
- expect(previewContent.prop('brandIconSrc')).toBe(defaultProps.brandIconSrc);
201
- });
202
-
203
- it('should pass updated OS to PreviewContent when OS changes', () => {
204
- const wrapper = mountWithIntl(<WebPushPreview {...defaultProps} />);
205
- const previewControls = wrapper.find(PreviewControls);
206
-
207
- act(() => {
208
- previewControls.prop('onOSChange')(OS_WINDOWS);
209
- });
210
- wrapper.update();
211
-
212
- const previewContent = wrapper.find(PreviewContent);
213
- expect(previewContent.prop('selectedOS')).toBe(OS_WINDOWS);
214
- });
215
-
216
- it('should pass updated browser to PreviewContent when browser changes', () => {
217
- const wrapper = mountWithIntl(<WebPushPreview {...defaultProps} />);
218
- const previewControls = wrapper.find(PreviewControls);
219
-
220
- act(() => {
221
- previewControls.prop('onBrowserChange')(BROWSER_FIREFOX);
222
- });
223
- wrapper.update();
224
-
225
- const previewContent = wrapper.find(PreviewContent);
226
- expect(previewContent.prop('selectedBrowser')).toBe(BROWSER_FIREFOX);
227
- });
228
- });
229
-
230
- describe('OS Change and Browser Reset', () => {
231
- it('should update OS when handleOSChange is called', () => {
232
- const wrapper = mountWithIntl(<WebPushPreview {...defaultProps} />);
233
- const previewControls = wrapper.find(PreviewControls);
234
-
235
- act(() => {
236
- previewControls.prop('onOSChange')(OS_WINDOWS);
237
- });
238
- wrapper.update();
239
-
240
- const updatedControls = wrapper.find(PreviewControls);
241
- expect(updatedControls.prop('selectedOS')).toBe(OS_WINDOWS);
242
- });
243
-
244
- it('should reset browser to first available option when OS changes', () => {
245
- const wrapper = mountWithIntl(<WebPushPreview {...defaultProps} />);
246
- const previewControls = wrapper.find(PreviewControls);
247
-
248
- // Start with macOS and Safari
249
- act(() => {
250
- previewControls.prop('onOSChange')(OS_MACOS);
251
- previewControls.prop('onBrowserChange')(BROWSER_SAFARI);
252
- });
253
- wrapper.update();
254
-
255
- expect(wrapper.find(PreviewControls).prop('selectedBrowser')).toBe(BROWSER_SAFARI);
256
-
257
- // Change to Windows (Safari not supported)
258
- act(() => {
259
- previewControls.prop('onOSChange')(OS_WINDOWS);
260
- });
261
- wrapper.update();
262
-
263
- // Browser should be reset to first available option for Windows
264
- const windowsBrowserOptions = getBrowserOptionsForOS(OS_WINDOWS);
265
- expect(wrapper.find(PreviewControls).prop('selectedBrowser')).toBe(windowsBrowserOptions[0].value);
266
- });
267
-
268
- it('should update browser options when OS changes', () => {
269
- const wrapper = mountWithIntl(<WebPushPreview {...defaultProps} />);
270
- const previewControls = wrapper.find(PreviewControls);
271
-
272
- // macOS should have all browsers including Safari
273
- act(() => {
274
- previewControls.prop('onOSChange')(OS_MACOS);
275
- });
276
- wrapper.update();
277
-
278
- let browserOptions = wrapper.find(PreviewControls).prop('browserOptions');
279
- expect(browserOptions.some(opt => opt.value === BROWSER_SAFARI)).toBe(true);
280
-
281
- // Windows should not have Safari
282
- act(() => {
283
- previewControls.prop('onOSChange')(OS_WINDOWS);
284
- });
285
- wrapper.update();
286
-
287
- browserOptions = wrapper.find(PreviewControls).prop('browserOptions');
288
- expect(browserOptions.some(opt => opt.value === BROWSER_SAFARI)).toBe(false);
289
- });
290
-
291
- it('should handle OS change for iOS', () => {
292
- const wrapper = mountWithIntl(<WebPushPreview {...defaultProps} />);
293
- const previewControls = wrapper.find(PreviewControls);
294
-
295
- act(() => {
296
- previewControls.prop('onOSChange')(OS_IOS);
297
- });
298
- wrapper.update();
299
-
300
- expect(wrapper.find(PreviewControls).prop('selectedOS')).toBe(OS_IOS);
301
- const browserOptions = wrapper.find(PreviewControls).prop('browserOptions');
302
- expect(browserOptions.some(opt => opt.value === BROWSER_SAFARI)).toBe(true);
303
- });
304
-
305
- it('should handle OS change for iPadOS', () => {
306
- const wrapper = mountWithIntl(<WebPushPreview {...defaultProps} />);
307
- const previewControls = wrapper.find(PreviewControls);
308
-
309
- act(() => {
310
- previewControls.prop('onOSChange')(OS_IPADOS);
311
- });
312
- wrapper.update();
313
-
314
- expect(wrapper.find(PreviewControls).prop('selectedOS')).toBe(OS_IPADOS);
315
- const browserOptions = wrapper.find(PreviewControls).prop('browserOptions');
316
- expect(browserOptions.some(opt => opt.value === BROWSER_SAFARI)).toBe(true);
317
- });
318
-
319
- it('should handle OS change for Android Mobile', () => {
320
- const wrapper = mountWithIntl(<WebPushPreview {...defaultProps} />);
321
- const previewControls = wrapper.find(PreviewControls);
322
-
323
- act(() => {
324
- previewControls.prop('onOSChange')(OS_ANDROID_MOBILE);
325
- });
326
- wrapper.update();
327
-
328
- expect(wrapper.find(PreviewControls).prop('selectedOS')).toBe(OS_ANDROID_MOBILE);
329
- const browserOptions = wrapper.find(PreviewControls).prop('browserOptions');
330
- expect(browserOptions.some(opt => opt.value === BROWSER_SAFARI)).toBe(false);
331
- });
332
-
333
- it('should handle OS change for Android Tablet', () => {
334
- const wrapper = mountWithIntl(<WebPushPreview {...defaultProps} />);
335
- const previewControls = wrapper.find(PreviewControls);
336
-
337
- act(() => {
338
- previewControls.prop('onOSChange')(OS_ANDROID_TABLET);
339
- });
340
- wrapper.update();
341
-
342
- expect(wrapper.find(PreviewControls).prop('selectedOS')).toBe(OS_ANDROID_TABLET);
343
- const browserOptions = wrapper.find(PreviewControls).prop('browserOptions');
344
- expect(browserOptions.some(opt => opt.value === BROWSER_SAFARI)).toBe(false);
345
- });
346
-
347
- it('should reset browser when OS changes and current browser is not available', () => {
348
- const wrapper = mountWithIntl(<WebPushPreview {...defaultProps} />);
349
- const previewControls = wrapper.find(PreviewControls);
350
-
351
- // Set to macOS with Safari
352
- act(() => {
353
- previewControls.prop('onOSChange')(OS_MACOS);
354
- previewControls.prop('onBrowserChange')(BROWSER_SAFARI);
355
- });
356
- wrapper.update();
357
-
358
- expect(wrapper.find(PreviewControls).prop('selectedBrowser')).toBe(BROWSER_SAFARI);
359
-
360
- // Change to Windows (Safari not available)
361
- act(() => {
362
- previewControls.prop('onOSChange')(OS_WINDOWS);
363
- });
364
- wrapper.update();
365
-
366
- // Should reset to first available browser (Chrome)
367
- const windowsBrowserOptions = getBrowserOptionsForOS(OS_WINDOWS);
368
- expect(wrapper.find(PreviewControls).prop('selectedBrowser')).toBe(windowsBrowserOptions[0].value);
369
- });
370
-
371
- it('should not reset browser when OS changes and current browser is still available', () => {
372
- const wrapper = mountWithIntl(<WebPushPreview {...defaultProps} />);
373
- const previewControls = wrapper.find(PreviewControls);
374
-
375
- // Set to macOS with Chrome
376
- act(() => {
377
- previewControls.prop('onOSChange')(OS_MACOS);
378
- previewControls.prop('onBrowserChange')(BROWSER_CHROME);
379
- });
380
- wrapper.update();
381
-
382
- expect(wrapper.find(PreviewControls).prop('selectedBrowser')).toBe(BROWSER_CHROME);
383
-
384
- // Change to Windows (Chrome is still available)
385
- act(() => {
386
- previewControls.prop('onOSChange')(OS_WINDOWS);
387
- });
388
- wrapper.update();
389
-
390
- // Browser should remain Chrome
391
- expect(wrapper.find(PreviewControls).prop('selectedBrowser')).toBe(BROWSER_CHROME);
392
- });
393
- });
394
-
395
- describe('Browser Change', () => {
396
- it('should update browser when handleBrowserChange is called', () => {
397
- const wrapper = mountWithIntl(<WebPushPreview {...defaultProps} />);
398
- const previewControls = wrapper.find(PreviewControls);
399
-
400
- act(() => {
401
- previewControls.prop('onBrowserChange')(BROWSER_FIREFOX);
402
- });
403
- wrapper.update();
404
-
405
- const updatedControls = wrapper.find(PreviewControls);
406
- expect(updatedControls.prop('selectedBrowser')).toBe(BROWSER_FIREFOX);
407
- });
408
-
409
- it('should handle browser change for Chrome', () => {
410
- const wrapper = mountWithIntl(<WebPushPreview {...defaultProps} />);
411
- const previewControls = wrapper.find(PreviewControls);
412
-
413
- act(() => {
414
- previewControls.prop('onBrowserChange')(BROWSER_CHROME);
415
- });
416
- wrapper.update();
417
-
418
- expect(wrapper.find(PreviewControls).prop('selectedBrowser')).toBe(BROWSER_CHROME);
419
- });
420
-
421
- it('should handle browser change for Firefox', () => {
422
- const wrapper = mountWithIntl(<WebPushPreview {...defaultProps} />);
423
- const previewControls = wrapper.find(PreviewControls);
424
-
425
- act(() => {
426
- previewControls.prop('onBrowserChange')(BROWSER_FIREFOX);
427
- });
428
- wrapper.update();
429
-
430
- expect(wrapper.find(PreviewControls).prop('selectedBrowser')).toBe(BROWSER_FIREFOX);
431
- });
432
-
433
- it('should handle browser change for Edge', () => {
434
- const wrapper = mountWithIntl(<WebPushPreview {...defaultProps} />);
435
- const previewControls = wrapper.find(PreviewControls);
436
-
437
- act(() => {
438
- previewControls.prop('onBrowserChange')(BROWSER_EDGE);
439
- });
440
- wrapper.update();
441
-
442
- expect(wrapper.find(PreviewControls).prop('selectedBrowser')).toBe(BROWSER_EDGE);
443
- });
444
-
445
- it('should handle browser change for Safari on macOS', () => {
446
- const wrapper = mountWithIntl(<WebPushPreview {...defaultProps} />);
447
- const previewControls = wrapper.find(PreviewControls);
448
-
449
- act(() => {
450
- previewControls.prop('onOSChange')(OS_MACOS);
451
- previewControls.prop('onBrowserChange')(BROWSER_SAFARI);
452
- });
453
- wrapper.update();
454
-
455
- expect(wrapper.find(PreviewControls).prop('selectedBrowser')).toBe(BROWSER_SAFARI);
456
- });
457
-
458
- it('should handle browser change for Opera', () => {
459
- const wrapper = mountWithIntl(<WebPushPreview {...defaultProps} />);
460
- const previewControls = wrapper.find(PreviewControls);
461
-
462
- act(() => {
463
- previewControls.prop('onBrowserChange')(BROWSER_OPERA);
464
- });
465
- wrapper.update();
466
-
467
- expect(wrapper.find(PreviewControls).prop('selectedBrowser')).toBe(BROWSER_OPERA);
468
- });
469
- });
470
-
471
- describe('Slidebox Toggle', () => {
472
- // Helper to get the actual CapSlideBox component props
473
- // Use .get(i) to get the actual React node instead of an Enzyme wrapper
474
- const getSlideBoxShowState = (wrapper) => {
475
- const allSlideBoxes = wrapper.find(CapSlideBox);
476
- for (let i = 0; i < allSlideBoxes.length; i++) {
477
- try {
478
- const reactNode = allSlideBoxes.get(i);
479
- if (reactNode && reactNode.props && reactNode.props.className === 'webpush-preview-slidebox') {
480
- return reactNode.props.show;
481
- }
482
- } catch (e) {
483
- continue;
484
- }
485
- }
486
- return null;
487
- };
488
-
489
- const getSlideBoxHandleClose = (wrapper) => {
490
- const allSlideBoxes = wrapper.find(CapSlideBox);
491
- for (let i = 0; i < allSlideBoxes.length; i++) {
492
- try {
493
- const reactNode = allSlideBoxes.get(i);
494
- if (reactNode && reactNode.props && reactNode.props.className === 'webpush-preview-slidebox') {
495
- return reactNode.props.handleClose;
496
- }
497
- } catch (e) {
498
- continue;
499
- }
500
- }
501
- return null;
502
- };
503
-
504
- const getSlideBoxProp = (wrapper, propName) => {
505
- const allSlideBoxes = wrapper.find(CapSlideBox);
506
- for (let i = 0; i < allSlideBoxes.length; i++) {
507
- try {
508
- const reactNode = allSlideBoxes.get(i);
509
- if (reactNode && reactNode.props && reactNode.props.className === 'webpush-preview-slidebox') {
510
- return reactNode.props[propName];
511
- }
512
- } catch (e) {
513
- continue;
514
- }
515
- }
516
- return null;
517
- };
518
-
519
- it('should open slidebox when button is clicked', () => {
520
- const wrapper = mountWithIntl(<WebPushPreview {...defaultProps} />);
521
- const button = wrapper.find('[data-test-id="webpush-preview-toggle"]').first();
522
-
523
- expect(getSlideBoxShowState(wrapper)).toBe(false);
524
-
525
- act(() => {
526
- button.prop('onClick')();
527
- });
528
- wrapper.update();
529
-
530
- expect(getSlideBoxShowState(wrapper)).toBe(true);
531
- });
532
-
533
- it('should close slidebox when handleClose is called', () => {
534
- const wrapper = mountWithIntl(<WebPushPreview {...defaultProps} />);
535
- const button = wrapper.find('[data-test-id="webpush-preview-toggle"]').first();
536
-
537
- // Open slidebox
538
- act(() => {
539
- button.prop('onClick')();
540
- });
541
- wrapper.update();
542
-
543
- expect(getSlideBoxShowState(wrapper)).toBe(true);
544
-
545
- // Close slidebox
546
- const handleClose = getSlideBoxHandleClose(wrapper);
547
- act(() => {
548
- handleClose();
549
- });
550
- wrapper.update();
551
-
552
- expect(getSlideBoxShowState(wrapper)).toBe(false);
553
- });
554
-
555
- it('should toggle slidebox multiple times', () => {
556
- const wrapper = mountWithIntl(<WebPushPreview {...defaultProps} />);
557
- const button = wrapper.find('[data-test-id="webpush-preview-toggle"]').first();
558
-
559
- // Open
560
- act(() => {
561
- button.prop('onClick')();
562
- });
563
- wrapper.update();
564
- expect(getSlideBoxShowState(wrapper)).toBe(true);
565
-
566
- // Close
567
- const handleClose = getSlideBoxHandleClose(wrapper);
568
- act(() => {
569
- handleClose();
570
- });
571
- wrapper.update();
572
- expect(getSlideBoxShowState(wrapper)).toBe(false);
573
-
574
- // Open again
575
- act(() => {
576
- button.prop('onClick')();
577
- });
578
- wrapper.update();
579
- expect(getSlideBoxShowState(wrapper)).toBe(true);
580
- });
581
-
582
- it('should pass correct props to CapSlideBox', () => {
583
- const wrapper = mountWithIntl(<WebPushPreview {...defaultProps} />);
584
-
585
- expect(getSlideBoxProp(wrapper, 'size')).toBe('size-xl');
586
- expect(getSlideBoxProp(wrapper, 'className')).toBe('webpush-preview-slidebox');
587
- expect(typeof getSlideBoxProp(wrapper, 'handleClose')).toBe('function');
588
- });
589
-
590
- it('should render DevicePreviewContent inside slidebox when open', () => {
591
- const wrapper = mountWithIntl(<WebPushPreview {...defaultProps} />);
592
- const button = wrapper.find('[data-test-id="webpush-preview-toggle"]').first();
593
-
594
- act(() => {
595
- button.prop('onClick')();
596
- });
597
- wrapper.update();
598
-
599
- const slideBoxContent = getSlideBoxProp(wrapper, 'content');
600
-
601
- // Check if the content is a DevicePreviewContent React element
602
- expect(slideBoxContent).toBeDefined();
603
- expect(slideBoxContent.type).toBe(DevicePreviewContent);
604
- });
605
-
606
- it('should pass correct props to DevicePreviewContent in slidebox', () => {
607
- const wrapper = mountWithIntl(<WebPushPreview {...defaultProps} />);
608
- const button = wrapper.find('[data-test-id="webpush-preview-toggle"]').first();
609
-
610
- act(() => {
611
- button.prop('onClick')();
612
- });
613
- wrapper.update();
614
-
615
- const slideBoxContent = getSlideBoxProp(wrapper, 'content');
616
-
617
- // Check the props directly on the React element
618
- expect(slideBoxContent.props.notificationTitle).toBe(defaultProps.notificationTitle);
619
- expect(slideBoxContent.props.notificationBody).toBe(defaultProps.notificationBody);
620
- expect(slideBoxContent.props.url).toBe(defaultProps.url);
621
- expect(slideBoxContent.props.imageSrc).toBe(defaultProps.imageSrc);
622
- expect(slideBoxContent.props.brandIconSrc).toBe(defaultProps.brandIconSrc);
623
- });
624
- });
625
-
626
- describe('Different OS/Browser Combinations', () => {
627
- const testCombinations = [
628
- { os: OS_MACOS, browser: BROWSER_CHROME },
629
- { os: OS_MACOS, browser: BROWSER_SAFARI },
630
- { os: OS_MACOS, browser: BROWSER_FIREFOX },
631
- { os: OS_WINDOWS, browser: BROWSER_CHROME },
632
- { os: OS_WINDOWS, browser: BROWSER_EDGE },
633
- { os: OS_IOS, browser: BROWSER_CHROME },
634
- { os: OS_IOS, browser: BROWSER_SAFARI },
635
- { os: OS_IPADOS, browser: BROWSER_CHROME },
636
- { os: OS_ANDROID_MOBILE, browser: BROWSER_CHROME },
637
- { os: OS_ANDROID_TABLET, browser: BROWSER_CHROME },
638
- ];
639
-
640
- testCombinations.forEach(({ os, browser }) => {
641
- it(`should handle ${os} + ${browser} combination`, () => {
642
- const wrapper = mountWithIntl(<WebPushPreview {...defaultProps} />);
643
- const previewControls = wrapper.find(PreviewControls);
644
-
645
- act(() => {
646
- previewControls.prop('onOSChange')(os);
647
- });
648
- wrapper.update();
649
-
650
- act(() => {
651
- previewControls.prop('onBrowserChange')(browser);
652
- });
653
- wrapper.update();
654
-
655
- const updatedControls = wrapper.find(PreviewControls);
656
- expect(updatedControls.prop('selectedOS')).toBe(os);
657
- expect(updatedControls.prop('selectedBrowser')).toBe(browser);
658
-
659
- const previewContent = wrapper.find(PreviewContent);
660
- expect(previewContent.prop('selectedOS')).toBe(os);
661
- expect(previewContent.prop('selectedBrowser')).toBe(browser);
662
- });
663
- });
664
- });
665
-
666
- describe('Props Updates', () => {
667
- it('should update PreviewContent when notificationTitle changes', () => {
668
- const wrapper = mountWithIntl(<WebPushPreview {...defaultProps} />);
669
-
670
- wrapper.setProps({ notificationTitle: 'New Title' });
671
- wrapper.update();
672
-
673
- const previewContent = wrapper.find(PreviewContent);
674
- expect(previewContent.prop('notificationTitle')).toBe('New Title');
675
- });
676
-
677
- it('should update PreviewContent when notificationBody changes', () => {
678
- const wrapper = mountWithIntl(<WebPushPreview {...defaultProps} />);
679
-
680
- wrapper.setProps({ notificationBody: 'New Body' });
681
- wrapper.update();
682
-
683
- const previewContent = wrapper.find(PreviewContent);
684
- expect(previewContent.prop('notificationBody')).toBe('New Body');
685
- });
686
-
687
- it('should update PreviewContent when url changes', () => {
688
- const wrapper = mountWithIntl(<WebPushPreview {...defaultProps} />);
689
-
690
- wrapper.setProps({ url: 'https://new-url.com' });
691
- wrapper.update();
692
-
693
- const previewContent = wrapper.find(PreviewContent);
694
- expect(previewContent.prop('url')).toBe('https://new-url.com');
695
- });
696
-
697
- it('should update PreviewContent when imageSrc changes', () => {
698
- const wrapper = mountWithIntl(<WebPushPreview {...defaultProps} />);
699
-
700
- wrapper.setProps({ imageSrc: 'https://new-image.jpg' });
701
- wrapper.update();
702
-
703
- const previewContent = wrapper.find(PreviewContent);
704
- expect(previewContent.prop('imageSrc')).toBe('https://new-image.jpg');
705
- });
706
-
707
- it('should update PreviewContent when brandIconSrc changes', () => {
708
- const wrapper = mountWithIntl(<WebPushPreview {...defaultProps} />);
709
-
710
- wrapper.setProps({ brandIconSrc: 'https://new-icon.png' });
711
- wrapper.update();
712
-
713
- const previewContent = wrapper.find(PreviewContent);
714
- expect(previewContent.prop('brandIconSrc')).toBe('https://new-icon.png');
715
- });
716
- });
717
-
718
- describe('Edge Cases', () => {
719
- it('should handle empty notificationTitle', () => {
720
- const wrapper = mountWithIntl(
721
- <WebPushPreview
722
- notificationTitle=""
723
- notificationBody={defaultProps.notificationBody}
724
- url={defaultProps.url}
725
- />
726
- );
727
- const previewContent = wrapper.find(PreviewContent);
728
- expect(previewContent.prop('notificationTitle')).toBe('');
729
- });
730
-
731
- it('should handle empty notificationBody', () => {
732
- const wrapper = mountWithIntl(
733
- <WebPushPreview
734
- notificationTitle={defaultProps.notificationTitle}
735
- notificationBody=""
736
- url={defaultProps.url}
737
- />
738
- );
739
- const previewContent = wrapper.find(PreviewContent);
740
- expect(previewContent.prop('notificationBody')).toBe('');
741
- });
742
-
743
- it('should handle empty url', () => {
744
- const wrapper = mountWithIntl(
745
- <WebPushPreview
746
- notificationTitle={defaultProps.notificationTitle}
747
- notificationBody={defaultProps.notificationBody}
748
- url=""
749
- />
750
- );
751
- const previewContent = wrapper.find(PreviewContent);
752
- expect(previewContent.prop('url')).toBe('');
753
- });
754
-
755
- it('should handle missing imageSrc and brandIconSrc', () => {
756
- const wrapper = mountWithIntl(
757
- <WebPushPreview
758
- notificationTitle={defaultProps.notificationTitle}
759
- notificationBody={defaultProps.notificationBody}
760
- url={defaultProps.url}
761
- />
762
- );
763
- const previewContent = wrapper.find(PreviewContent);
764
- expect(previewContent.prop('imageSrc')).toBe('');
765
- expect(previewContent.prop('brandIconSrc')).toBe('');
766
- });
767
-
768
- it('should handle rapid OS and browser changes', () => {
769
- const wrapper = mountWithIntl(<WebPushPreview {...defaultProps} />);
770
- const previewControls = wrapper.find(PreviewControls);
771
-
772
- act(() => {
773
- previewControls.prop('onOSChange')(OS_MACOS);
774
- previewControls.prop('onBrowserChange')(BROWSER_CHROME);
775
- });
776
- wrapper.update();
777
-
778
- act(() => {
779
- previewControls.prop('onOSChange')(OS_WINDOWS);
780
- previewControls.prop('onBrowserChange')(BROWSER_FIREFOX);
781
- });
782
- wrapper.update();
783
-
784
- act(() => {
785
- previewControls.prop('onOSChange')(OS_IOS);
786
- previewControls.prop('onBrowserChange')(BROWSER_SAFARI);
787
- });
788
- wrapper.update();
789
-
790
- const updatedControls = wrapper.find(PreviewControls);
791
- expect(updatedControls.prop('selectedOS')).toBe(OS_IOS);
792
- expect(updatedControls.prop('selectedBrowser')).toBe(BROWSER_SAFARI);
793
- });
794
-
795
- it('should handle browser options being empty array', () => {
796
- // This shouldn't happen in practice, but test the edge case
797
- const wrapper = mountWithIntl(<WebPushPreview {...defaultProps} />);
798
- const previewControls = wrapper.find(PreviewControls);
799
-
800
- // Change to an OS that might have empty options (shouldn't happen)
801
- act(() => {
802
- previewControls.prop('onOSChange')(OS_WINDOWS);
803
- });
804
- wrapper.update();
805
-
806
- const browserOptions = wrapper.find(PreviewControls).prop('browserOptions');
807
- expect(Array.isArray(browserOptions)).toBe(true);
808
- expect(browserOptions.length).toBeGreaterThan(0);
809
- });
810
- });
811
-
812
- describe('handleOpenPreviewSlideBox', () => {
813
- // Helper to get the slidebox show state
814
- const getSlideBoxShowState = (wrapper) => {
815
- const allSlideBoxes = wrapper.find(CapSlideBox);
816
- for (let i = 0; i < allSlideBoxes.length; i++) {
817
- try {
818
- const reactNode = allSlideBoxes.get(i);
819
- if (reactNode && reactNode.props && reactNode.props.className === 'webpush-preview-slidebox') {
820
- return reactNode.props.show;
821
- }
822
- } catch (e) {
823
- continue;
824
- }
825
- }
826
- return null;
827
- };
828
-
829
- it('should call onClickShowInAllDevices when provided', () => {
830
- const mockOnClickShowInAllDevices = jest.fn();
831
- const wrapper = mountWithIntl(
832
- <WebPushPreview
833
- {...defaultProps}
834
- onClickShowInAllDevices={mockOnClickShowInAllDevices}
835
- />
836
- );
837
- const button = wrapper.find('[data-test-id="webpush-preview-toggle"]').first();
838
-
839
- expect(mockOnClickShowInAllDevices).not.toHaveBeenCalled();
840
-
841
- act(() => {
842
- button.prop('onClick')();
843
- });
844
- wrapper.update();
845
-
846
- expect(mockOnClickShowInAllDevices).toHaveBeenCalledTimes(1);
847
- expect(mockOnClickShowInAllDevices).toHaveBeenCalledWith();
848
- });
849
-
850
- it('should not open slidebox when onClickShowInAllDevices is provided', () => {
851
- const mockOnClickShowInAllDevices = jest.fn();
852
- const wrapper = mountWithIntl(
853
- <WebPushPreview
854
- {...defaultProps}
855
- onClickShowInAllDevices={mockOnClickShowInAllDevices}
856
- />
857
- );
858
- const button = wrapper.find('[data-test-id="webpush-preview-toggle"]').first();
859
-
860
- expect(getSlideBoxShowState(wrapper)).toBe(false);
861
-
862
- act(() => {
863
- button.prop('onClick')();
864
- });
865
- wrapper.update();
866
-
867
- // Slidebox should remain closed when onClickShowInAllDevices is provided
868
- expect(getSlideBoxShowState(wrapper)).toBe(false);
869
- expect(mockOnClickShowInAllDevices).toHaveBeenCalledTimes(1);
870
- });
871
-
872
- it('should open slidebox when onClickShowInAllDevices is not provided', () => {
873
- const wrapper = mountWithIntl(<WebPushPreview {...defaultProps} />);
874
- const button = wrapper.find('[data-test-id="webpush-preview-toggle"]').first();
875
-
876
- expect(getSlideBoxShowState(wrapper)).toBe(false);
877
-
878
- act(() => {
879
- button.prop('onClick')();
880
- });
881
- wrapper.update();
882
-
883
- expect(getSlideBoxShowState(wrapper)).toBe(true);
884
- });
885
-
886
- it('should handle multiple calls when onClickShowInAllDevices is provided', () => {
887
- const mockOnClickShowInAllDevices = jest.fn();
888
- const wrapper = mountWithIntl(
889
- <WebPushPreview
890
- {...defaultProps}
891
- onClickShowInAllDevices={mockOnClickShowInAllDevices}
892
- />
893
- );
894
- const button = wrapper.find('[data-test-id="webpush-preview-toggle"]').first();
895
-
896
- act(() => {
897
- button.prop('onClick')();
898
- });
899
- wrapper.update();
900
-
901
- act(() => {
902
- button.prop('onClick')();
903
- });
904
- wrapper.update();
905
-
906
- act(() => {
907
- button.prop('onClick')();
908
- });
909
- wrapper.update();
910
-
911
- expect(mockOnClickShowInAllDevices).toHaveBeenCalledTimes(3);
912
- expect(getSlideBoxShowState(wrapper)).toBe(false);
913
- });
914
-
915
- it('should handle multiple calls when onClickShowInAllDevices is not provided', () => {
916
- const wrapper = mountWithIntl(<WebPushPreview {...defaultProps} />);
917
- const button = wrapper.find('[data-test-id="webpush-preview-toggle"]').first();
918
-
919
- // First call - should open
920
- act(() => {
921
- button.prop('onClick')();
922
- });
923
- wrapper.update();
924
- expect(getSlideBoxShowState(wrapper)).toBe(true);
925
-
926
- // Second call - should remain open (state doesn't change)
927
- act(() => {
928
- button.prop('onClick')();
929
- });
930
- wrapper.update();
931
- expect(getSlideBoxShowState(wrapper)).toBe(true);
932
-
933
- // Third call - should remain open
934
- act(() => {
935
- button.prop('onClick')();
936
- });
937
- wrapper.update();
938
- expect(getSlideBoxShowState(wrapper)).toBe(true);
939
- });
940
-
941
- it('should handle onClickShowInAllDevices being undefined', () => {
942
- const wrapper = mountWithIntl(
943
- <WebPushPreview
944
- {...defaultProps}
945
- onClickShowInAllDevices={undefined}
946
- />
947
- );
948
- const button = wrapper.find('[data-test-id="webpush-preview-toggle"]').first();
949
-
950
- expect(getSlideBoxShowState(wrapper)).toBe(false);
951
-
952
- act(() => {
953
- button.prop('onClick')();
954
- });
955
- wrapper.update();
956
-
957
- // Should open slidebox when prop is undefined
958
- expect(getSlideBoxShowState(wrapper)).toBe(true);
959
- });
960
-
961
- it('should handle onClickShowInAllDevices being null', () => {
962
- const wrapper = mountWithIntl(
963
- <WebPushPreview
964
- {...defaultProps}
965
- onClickShowInAllDevices={null}
966
- />
967
- );
968
- const button = wrapper.find('[data-test-id="webpush-preview-toggle"]').first();
969
-
970
- expect(getSlideBoxShowState(wrapper)).toBe(false);
971
-
972
- act(() => {
973
- button.prop('onClick')();
974
- });
975
- wrapper.update();
976
-
977
- // Should open slidebox when prop is null (falsy)
978
- expect(getSlideBoxShowState(wrapper)).toBe(true);
979
- });
980
-
981
- it('should handle onClickShowInAllDevices being an empty function', () => {
982
- const mockOnClickShowInAllDevices = jest.fn(() => {});
983
- const wrapper = mountWithIntl(
984
- <WebPushPreview
985
- {...defaultProps}
986
- onClickShowInAllDevices={mockOnClickShowInAllDevices}
987
- />
988
- );
989
- const button = wrapper.find('[data-test-id="webpush-preview-toggle"]').first();
990
-
991
- expect(getSlideBoxShowState(wrapper)).toBe(false);
992
-
993
- act(() => {
994
- button.prop('onClick')();
995
- });
996
- wrapper.update();
997
-
998
- expect(mockOnClickShowInAllDevices).toHaveBeenCalledTimes(1);
999
- expect(getSlideBoxShowState(wrapper)).toBe(false);
1000
- });
1001
-
1002
- it('should work correctly with slidebox close after opening without onClickShowInAllDevices', () => {
1003
- const wrapper = mountWithIntl(<WebPushPreview {...defaultProps} />);
1004
- const button = wrapper.find('[data-test-id="webpush-preview-toggle"]').first();
1005
-
1006
- // Open slidebox
1007
- act(() => {
1008
- button.prop('onClick')();
1009
- });
1010
- wrapper.update();
1011
- expect(getSlideBoxShowState(wrapper)).toBe(true);
1012
-
1013
- // Close slidebox
1014
- const allSlideBoxes = wrapper.find(CapSlideBox);
1015
- let handleClose = null;
1016
- for (let i = 0; i < allSlideBoxes.length; i++) {
1017
- try {
1018
- const reactNode = allSlideBoxes.get(i);
1019
- if (reactNode && reactNode.props && reactNode.props.className === 'webpush-preview-slidebox') {
1020
- handleClose = reactNode.props.handleClose;
1021
- break;
1022
- }
1023
- } catch (e) {
1024
- continue;
1025
- }
1026
- }
1027
-
1028
- act(() => {
1029
- handleClose();
1030
- });
1031
- wrapper.update();
1032
- expect(getSlideBoxShowState(wrapper)).toBe(false);
1033
-
1034
- // Open again
1035
- act(() => {
1036
- button.prop('onClick')();
1037
- });
1038
- wrapper.update();
1039
- expect(getSlideBoxShowState(wrapper)).toBe(true);
1040
- });
1041
-
1042
- it('should handle onClickShowInAllDevices that throws an error gracefully', () => {
1043
- const mockOnClickShowInAllDevices = jest.fn(() => {
1044
- throw new Error('Test error');
1045
- });
1046
- const consoleErrorSpy = jest.spyOn(console, 'error').mockImplementation(() => {});
1047
-
1048
- const wrapper = mountWithIntl(
1049
- <WebPushPreview
1050
- {...defaultProps}
1051
- onClickShowInAllDevices={mockOnClickShowInAllDevices}
1052
- />
1053
- );
1054
- const button = wrapper.find('[data-test-id="webpush-preview-toggle"]').first();
1055
-
1056
- expect(() => {
1057
- act(() => {
1058
- button.prop('onClick')();
1059
- });
1060
- }).toThrow('Test error');
1061
- wrapper.update();
1062
-
1063
- expect(mockOnClickShowInAllDevices).toHaveBeenCalledTimes(1);
1064
- expect(getSlideBoxShowState(wrapper)).toBe(false);
1065
-
1066
- consoleErrorSpy.mockRestore();
1067
- });
1068
-
1069
- it('should handle rapid clicks when onClickShowInAllDevices is provided', () => {
1070
- const mockOnClickShowInAllDevices = jest.fn();
1071
- const wrapper = mountWithIntl(
1072
- <WebPushPreview
1073
- {...defaultProps}
1074
- onClickShowInAllDevices={mockOnClickShowInAllDevices}
1075
- />
1076
- );
1077
- const button = wrapper.find('[data-test-id="webpush-preview-toggle"]').first();
1078
-
1079
- // Rapid clicks
1080
- act(() => {
1081
- button.prop('onClick')();
1082
- button.prop('onClick')();
1083
- button.prop('onClick')();
1084
- });
1085
- wrapper.update();
1086
-
1087
- expect(mockOnClickShowInAllDevices).toHaveBeenCalledTimes(3);
1088
- expect(getSlideBoxShowState(wrapper)).toBe(false);
1089
- });
1090
-
1091
- it('should handle rapid clicks when onClickShowInAllDevices is not provided', () => {
1092
- const wrapper = mountWithIntl(<WebPushPreview {...defaultProps} />);
1093
- const button = wrapper.find('[data-test-id="webpush-preview-toggle"]').first();
1094
-
1095
- // Rapid clicks
1096
- act(() => {
1097
- button.prop('onClick')();
1098
- button.prop('onClick')();
1099
- button.prop('onClick')();
1100
- });
1101
- wrapper.update();
1102
-
1103
- // Should be open after rapid clicks
1104
- expect(getSlideBoxShowState(wrapper)).toBe(true);
1105
- });
1106
-
1107
- it('should maintain correct behavior when props change from provided to not provided', () => {
1108
- const mockOnClickShowInAllDevices = jest.fn();
1109
- const wrapper = mountWithIntl(
1110
- <WebPushPreview
1111
- {...defaultProps}
1112
- onClickShowInAllDevices={mockOnClickShowInAllDevices}
1113
- />
1114
- );
1115
- const button = wrapper.find('[data-test-id="webpush-preview-toggle"]').first();
1116
-
1117
- // First call with onClickShowInAllDevices provided
1118
- act(() => {
1119
- button.prop('onClick')();
1120
- });
1121
- wrapper.update();
1122
- expect(mockOnClickShowInAllDevices).toHaveBeenCalledTimes(1);
1123
- expect(getSlideBoxShowState(wrapper)).toBe(false);
1124
-
1125
- // Remove onClickShowInAllDevices prop
1126
- act(() => {
1127
- wrapper.setProps({ onClickShowInAllDevices: undefined });
1128
- });
1129
- wrapper.update();
1130
-
1131
- // Get the button again after props change
1132
- const updatedButton = wrapper.find('[data-test-id="webpush-preview-toggle"]').first();
1133
-
1134
- // Second call without onClickShowInAllDevices
1135
- act(() => {
1136
- updatedButton.prop('onClick')();
1137
- });
1138
- wrapper.update();
1139
- // The mock should still have been called only once (from the first call)
1140
- expect(mockOnClickShowInAllDevices).toHaveBeenCalledTimes(1);
1141
- expect(getSlideBoxShowState(wrapper)).toBe(true); // Should open slidebox
1142
- });
1143
-
1144
- it('should maintain correct behavior when props change from not provided to provided', () => {
1145
- const wrapper = mountWithIntl(<WebPushPreview {...defaultProps} />);
1146
- const button = wrapper.find('[data-test-id="webpush-preview-toggle"]').first();
1147
-
1148
- // First call without onClickShowInAllDevices
1149
- act(() => {
1150
- button.prop('onClick')();
1151
- });
1152
- wrapper.update();
1153
- expect(getSlideBoxShowState(wrapper)).toBe(true);
1154
-
1155
- // Close slidebox
1156
- const allSlideBoxes = wrapper.find(CapSlideBox);
1157
- let handleClose = null;
1158
- for (let i = 0; i < allSlideBoxes.length; i++) {
1159
- try {
1160
- const reactNode = allSlideBoxes.get(i);
1161
- if (reactNode && reactNode.props && reactNode.props.className === 'webpush-preview-slidebox') {
1162
- handleClose = reactNode.props.handleClose;
1163
- break;
1164
- }
1165
- } catch (e) {
1166
- continue;
1167
- }
1168
- }
1169
-
1170
- act(() => {
1171
- handleClose();
1172
- });
1173
- wrapper.update();
1174
- expect(getSlideBoxShowState(wrapper)).toBe(false);
1175
-
1176
- // Add onClickShowInAllDevices prop
1177
- const mockOnClickShowInAllDevices = jest.fn();
1178
- act(() => {
1179
- wrapper.setProps({ onClickShowInAllDevices: mockOnClickShowInAllDevices });
1180
- });
1181
- wrapper.update();
1182
-
1183
- // Get the button again after props change
1184
- const updatedButton = wrapper.find('[data-test-id="webpush-preview-toggle"]').first();
1185
-
1186
- // Second call with onClickShowInAllDevices
1187
- act(() => {
1188
- updatedButton.prop('onClick')();
1189
- });
1190
- wrapper.update();
1191
- expect(mockOnClickShowInAllDevices).toHaveBeenCalledTimes(1);
1192
- expect(getSlideBoxShowState(wrapper)).toBe(false); // Should not open slidebox
1193
- });
1194
- });
1195
-
1196
- describe('Component Integration', () => {
1197
- it('should update all child components when OS changes', () => {
1198
- const wrapper = mountWithIntl(<WebPushPreview {...defaultProps} />);
1199
- const previewControls = wrapper.find(PreviewControls);
1200
-
1201
- act(() => {
1202
- previewControls.prop('onOSChange')(OS_WINDOWS);
1203
- });
1204
- wrapper.update();
1205
-
1206
- const updatedControls = wrapper.find(PreviewControls);
1207
- const previewContent = wrapper.find(PreviewContent);
1208
-
1209
- expect(updatedControls.prop('selectedOS')).toBe(OS_WINDOWS);
1210
- expect(previewContent.prop('selectedOS')).toBe(OS_WINDOWS);
1211
- });
1212
-
1213
- it('should update all child components when browser changes', () => {
1214
- const wrapper = mountWithIntl(<WebPushPreview {...defaultProps} />);
1215
- const previewControls = wrapper.find(PreviewControls);
1216
-
1217
- act(() => {
1218
- previewControls.prop('onBrowserChange')(BROWSER_FIREFOX);
1219
- });
1220
- wrapper.update();
1221
-
1222
- const updatedControls = wrapper.find(PreviewControls);
1223
- const previewContent = wrapper.find(PreviewContent);
1224
-
1225
- expect(updatedControls.prop('selectedBrowser')).toBe(BROWSER_FIREFOX);
1226
- expect(previewContent.prop('selectedBrowser')).toBe(BROWSER_FIREFOX);
1227
- });
1228
-
1229
- it('should maintain state consistency across components', () => {
1230
- const wrapper = mountWithIntl(<WebPushPreview {...defaultProps} />);
1231
- const previewControls = wrapper.find(PreviewControls);
1232
-
1233
- act(() => {
1234
- previewControls.prop('onOSChange')(OS_MACOS);
1235
- previewControls.prop('onBrowserChange')(BROWSER_SAFARI);
1236
- });
1237
- wrapper.update();
1238
-
1239
- const controls = wrapper.find(PreviewControls);
1240
- const content = wrapper.find(PreviewContent);
1241
-
1242
- expect(controls.prop('selectedOS')).toBe(content.prop('selectedOS'));
1243
- expect(controls.prop('selectedBrowser')).toBe(content.prop('selectedBrowser'));
1244
- });
1245
- });
1246
-
1247
- describe('Browser Options Filtering', () => {
1248
- it('should filter Safari from Windows browser options', () => {
1249
- const wrapper = mountWithIntl(<WebPushPreview {...defaultProps} />);
1250
- const previewControls = wrapper.find(PreviewControls);
1251
-
1252
- act(() => {
1253
- previewControls.prop('onOSChange')(OS_WINDOWS);
1254
- });
1255
- wrapper.update();
1256
-
1257
- const browserOptions = wrapper.find(PreviewControls).prop('browserOptions');
1258
- expect(browserOptions.some(opt => opt.value === BROWSER_SAFARI)).toBe(false);
1259
- });
1260
-
1261
- it('should include Safari in macOS browser options', () => {
1262
- const wrapper = mountWithIntl(<WebPushPreview {...defaultProps} />);
1263
- const previewControls = wrapper.find(PreviewControls);
1264
-
1265
- act(() => {
1266
- previewControls.prop('onOSChange')(OS_MACOS);
1267
- });
1268
- wrapper.update();
1269
-
1270
- const browserOptions = wrapper.find(PreviewControls).prop('browserOptions');
1271
- expect(browserOptions.some(opt => opt.value === BROWSER_SAFARI)).toBe(true);
1272
- });
1273
-
1274
- it('should include Safari in iOS browser options', () => {
1275
- const wrapper = mountWithIntl(<WebPushPreview {...defaultProps} />);
1276
- const previewControls = wrapper.find(PreviewControls);
1277
-
1278
- act(() => {
1279
- previewControls.prop('onOSChange')(OS_IOS);
1280
- });
1281
- wrapper.update();
1282
-
1283
- const browserOptions = wrapper.find(PreviewControls).prop('browserOptions');
1284
- expect(browserOptions.some(opt => opt.value === BROWSER_SAFARI)).toBe(true);
1285
- });
1286
-
1287
- it('should include Safari in iPadOS browser options', () => {
1288
- const wrapper = mountWithIntl(<WebPushPreview {...defaultProps} />);
1289
- const previewControls = wrapper.find(PreviewControls);
1290
-
1291
- act(() => {
1292
- previewControls.prop('onOSChange')(OS_IPADOS);
1293
- });
1294
- wrapper.update();
1295
-
1296
- const browserOptions = wrapper.find(PreviewControls).prop('browserOptions');
1297
- expect(browserOptions.some(opt => opt.value === BROWSER_SAFARI)).toBe(true);
1298
- });
1299
-
1300
- it('should exclude Safari from Android Mobile browser options', () => {
1301
- const wrapper = mountWithIntl(<WebPushPreview {...defaultProps} />);
1302
- const previewControls = wrapper.find(PreviewControls);
1303
-
1304
- act(() => {
1305
- previewControls.prop('onOSChange')(OS_ANDROID_MOBILE);
1306
- });
1307
- wrapper.update();
1308
-
1309
- const browserOptions = wrapper.find(PreviewControls).prop('browserOptions');
1310
- expect(browserOptions.some(opt => opt.value === BROWSER_SAFARI)).toBe(false);
1311
- });
1312
-
1313
- it('should exclude Safari from Android Tablet browser options', () => {
1314
- const wrapper = mountWithIntl(<WebPushPreview {...defaultProps} />);
1315
- const previewControls = wrapper.find(PreviewControls);
1316
-
1317
- act(() => {
1318
- previewControls.prop('onOSChange')(OS_ANDROID_TABLET);
1319
- });
1320
- wrapper.update();
1321
-
1322
- const browserOptions = wrapper.find(PreviewControls).prop('browserOptions');
1323
- expect(browserOptions.some(opt => opt.value === BROWSER_SAFARI)).toBe(false);
1324
- });
1325
- });
1326
- });
1327
-