@capillarytech/creatives-library 8.0.126 → 8.0.127-alpha.1
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.
- package/containers/App/constants.js +1 -0
- package/index.html +3 -1
- package/package.json +1 -1
- package/services/api.js +4 -4
- package/tests/integration/TemplateCreation/TemplateCreation.integration.test.js +8 -3
- package/tests/integration/TemplateCreation/api-response.js +5 -0
- package/tests/integration/TemplateCreation/msw-handler.js +42 -63
- package/utils/common.js +7 -0
- package/utils/commonUtils.js +2 -6
- package/utils/createPayload.js +272 -0
- package/utils/tests/createPayload.test.js +761 -0
- package/v2Components/CapImageUpload/index.js +59 -46
- package/v2Components/CapInAppCTA/index.js +1 -0
- package/v2Components/CapMpushCTA/constants.js +25 -0
- package/v2Components/CapMpushCTA/index.js +332 -0
- package/v2Components/CapMpushCTA/index.scss +95 -0
- package/v2Components/CapMpushCTA/messages.js +89 -0
- package/v2Components/CapTagList/index.js +177 -120
- package/v2Components/CapVideoUpload/constants.js +3 -0
- package/v2Components/CapVideoUpload/index.js +167 -110
- package/v2Components/CapVideoUpload/messages.js +16 -0
- package/v2Components/Carousel/index.js +15 -13
- package/v2Components/CustomerSearchSection/index.js +12 -7
- package/v2Components/ErrorInfoNote/style.scss +1 -0
- package/v2Components/MobilePushPreviewV2/index.js +37 -5
- package/v2Components/TemplatePreview/_templatePreview.scss +114 -72
- package/v2Components/TemplatePreview/assets/images/Android _ With date and time.svg +29 -0
- package/v2Components/TemplatePreview/assets/images/android.svg +9 -0
- package/v2Components/TemplatePreview/assets/images/iOS _ With date and time.svg +26 -0
- package/v2Components/TemplatePreview/assets/images/ios.svg +9 -0
- package/v2Components/TemplatePreview/index.js +178 -50
- package/v2Components/TemplatePreview/messages.js +4 -0
- package/v2Components/TestAndPreviewSlidebox/CustomValuesEditor.js +169 -0
- package/v2Components/TestAndPreviewSlidebox/LeftPanelContent.js +95 -0
- package/v2Components/TestAndPreviewSlidebox/PreviewSection.js +69 -0
- package/v2Components/TestAndPreviewSlidebox/SendTestMessage.js +68 -0
- package/v2Components/TestAndPreviewSlidebox/index.js +67 -246
- package/v2Components/TestAndPreviewSlidebox/tests/CustomValuesEditor.test.js +425 -0
- package/v2Components/TestAndPreviewSlidebox/tests/LeftPanelContent.test.js +400 -0
- package/v2Components/TestAndPreviewSlidebox/tests/SendTestMessage.test.js +448 -0
- package/v2Containers/CreativesContainer/SlideBoxContent.js +9 -9
- package/v2Containers/CreativesContainer/index.js +191 -136
- package/v2Containers/Email/index.js +15 -2
- package/v2Containers/InApp/constants.js +1 -0
- package/v2Containers/InApp/index.js +13 -13
- package/v2Containers/MobilePush/Create/index.js +1 -0
- package/v2Containers/MobilePush/commonMethods.js +7 -14
- package/v2Containers/MobilePushNew/actions.js +116 -0
- package/v2Containers/MobilePushNew/components/CtaButtons.js +170 -0
- package/v2Containers/MobilePushNew/components/MediaUploaders.js +754 -0
- package/v2Containers/MobilePushNew/components/PlatformContentFields.js +279 -0
- package/v2Containers/MobilePushNew/components/index.js +5 -0
- package/v2Containers/MobilePushNew/components/tests/CtaButtons.test.js +779 -0
- package/v2Containers/MobilePushNew/components/tests/MediaUploaders.test.js +2114 -0
- package/v2Containers/MobilePushNew/components/tests/PlatformContentFields.test.js +343 -0
- package/v2Containers/MobilePushNew/constants.js +115 -0
- package/v2Containers/MobilePushNew/hooks/tests/usePlatformSync.test.js +1299 -0
- package/v2Containers/MobilePushNew/hooks/tests/useUpload.test.js +1223 -0
- package/v2Containers/MobilePushNew/hooks/usePlatformSync.js +246 -0
- package/v2Containers/MobilePushNew/hooks/useUpload.js +726 -0
- package/v2Containers/MobilePushNew/index.js +2280 -0
- package/v2Containers/MobilePushNew/index.scss +308 -0
- package/v2Containers/MobilePushNew/messages.js +226 -0
- package/v2Containers/MobilePushNew/reducer.js +160 -0
- package/v2Containers/MobilePushNew/sagas.js +198 -0
- package/v2Containers/MobilePushNew/selectors.js +55 -0
- package/v2Containers/MobilePushNew/tests/reducer.test.js +741 -0
- package/v2Containers/MobilePushNew/tests/sagas.test.js +863 -0
- package/v2Containers/MobilePushNew/tests/selectors.test.js +425 -0
- package/v2Containers/MobilePushNew/tests/utils.test.js +322 -0
- package/v2Containers/MobilePushNew/utils.js +33 -0
- package/v2Containers/Rcs/tests/__snapshots__/index.test.js.snap +5 -5
- package/v2Containers/TagList/index.js +56 -10
- package/v2Containers/Templates/_templates.scss +101 -1
- package/v2Containers/Templates/index.js +147 -35
- package/v2Containers/Templates/messages.js +8 -0
- package/v2Containers/Templates/sagas.js +2 -0
- package/v2Containers/Whatsapp/constants.js +1 -0
|
@@ -0,0 +1,1299 @@
|
|
|
1
|
+
import { renderHook, act } from '@testing-library/react';
|
|
2
|
+
import usePlatformSync from '../usePlatformSync';
|
|
3
|
+
import {
|
|
4
|
+
ANDROID, GIF, IMAGE, IOS, VIDEO,
|
|
5
|
+
} from '../../constants';
|
|
6
|
+
import { NONE } from '../../../Whatsapp/constants';
|
|
7
|
+
|
|
8
|
+
describe('usePlatformSync Hook', () => {
|
|
9
|
+
// Mock functions
|
|
10
|
+
const mockSetAndroidContent = jest.fn();
|
|
11
|
+
const mockSetIosContent = jest.fn();
|
|
12
|
+
const mockValidateTitle = jest.fn();
|
|
13
|
+
const mockValidateMessage = jest.fn();
|
|
14
|
+
const mockSetAndroidTitleError = jest.fn();
|
|
15
|
+
const mockSetAndroidMessageError = jest.fn();
|
|
16
|
+
const mockSetIosTitleError = jest.fn();
|
|
17
|
+
const mockSetIosMessageError = jest.fn();
|
|
18
|
+
const mockUpdateOnMpushImageReUpload = jest.fn();
|
|
19
|
+
const mockUpdateOnMpushVideoReUpload = jest.fn();
|
|
20
|
+
|
|
21
|
+
const defaultAndroidContent = {
|
|
22
|
+
title: 'Android Title',
|
|
23
|
+
message: 'Android Message',
|
|
24
|
+
mediaType: IMAGE,
|
|
25
|
+
buttons: [],
|
|
26
|
+
actionOnClick: false,
|
|
27
|
+
linkType: 'deep',
|
|
28
|
+
deepLinkValue: '',
|
|
29
|
+
externalLinkValue: '',
|
|
30
|
+
};
|
|
31
|
+
|
|
32
|
+
const defaultIosContent = {
|
|
33
|
+
title: 'iOS Title',
|
|
34
|
+
message: 'iOS Message',
|
|
35
|
+
mediaType: IMAGE,
|
|
36
|
+
buttons: [],
|
|
37
|
+
actionOnClick: false,
|
|
38
|
+
linkType: 'deep',
|
|
39
|
+
deepLinkValue: '',
|
|
40
|
+
externalLinkValue: '',
|
|
41
|
+
};
|
|
42
|
+
|
|
43
|
+
const defaultProps = {
|
|
44
|
+
setAndroidContent: mockSetAndroidContent,
|
|
45
|
+
setIosContent: mockSetIosContent,
|
|
46
|
+
validateTitle: mockValidateTitle,
|
|
47
|
+
validateMessage: mockValidateMessage,
|
|
48
|
+
setAndroidTitleError: mockSetAndroidTitleError,
|
|
49
|
+
setAndroidMessageError: mockSetAndroidMessageError,
|
|
50
|
+
setIosTitleError: mockSetIosTitleError,
|
|
51
|
+
setIosMessageError: mockSetIosMessageError,
|
|
52
|
+
androidContent: defaultAndroidContent,
|
|
53
|
+
iosContent: defaultIosContent,
|
|
54
|
+
updateOnMpushImageReUpload: mockUpdateOnMpushImageReUpload,
|
|
55
|
+
updateOnMpushVideoReUpload: mockUpdateOnMpushVideoReUpload,
|
|
56
|
+
};
|
|
57
|
+
|
|
58
|
+
beforeEach(() => {
|
|
59
|
+
jest.clearAllMocks();
|
|
60
|
+
mockValidateTitle.mockReturnValue('');
|
|
61
|
+
mockValidateMessage.mockReturnValue('');
|
|
62
|
+
|
|
63
|
+
// Make mock state setters actually execute functional updates
|
|
64
|
+
mockSetAndroidContent.mockImplementation((updater) => {
|
|
65
|
+
if (typeof updater === 'function') {
|
|
66
|
+
updater(defaultAndroidContent);
|
|
67
|
+
}
|
|
68
|
+
});
|
|
69
|
+
mockSetIosContent.mockImplementation((updater) => {
|
|
70
|
+
if (typeof updater === 'function') {
|
|
71
|
+
updater(defaultIosContent);
|
|
72
|
+
}
|
|
73
|
+
});
|
|
74
|
+
});
|
|
75
|
+
|
|
76
|
+
describe('Hook Initialization', () => {
|
|
77
|
+
it('should initialize with all handler functions', () => {
|
|
78
|
+
const { result } = renderHook(() => usePlatformSync(defaultProps));
|
|
79
|
+
|
|
80
|
+
expect(result.current.handleTitleChange).toBeDefined();
|
|
81
|
+
expect(result.current.handleMessageChange).toBeDefined();
|
|
82
|
+
expect(result.current.handleTagSelect).toBeDefined();
|
|
83
|
+
expect(result.current.handleMediaTypeChange).toBeDefined();
|
|
84
|
+
expect(result.current.handleButtonChange).toBeDefined();
|
|
85
|
+
expect(result.current.handleActionOnClickChange).toBeDefined();
|
|
86
|
+
expect(result.current.handleLinkTypeChange).toBeDefined();
|
|
87
|
+
});
|
|
88
|
+
});
|
|
89
|
+
|
|
90
|
+
describe('handleTitleChange', () => {
|
|
91
|
+
it('should update Android title when sync is disabled', () => {
|
|
92
|
+
const { result } = renderHook(() => usePlatformSync(defaultProps));
|
|
93
|
+
|
|
94
|
+
act(() => {
|
|
95
|
+
result.current.handleTitleChange(ANDROID, 'New Android Title');
|
|
96
|
+
});
|
|
97
|
+
|
|
98
|
+
expect(mockSetAndroidContent).toHaveBeenCalledWith(expect.objectContaining({
|
|
99
|
+
...defaultAndroidContent,
|
|
100
|
+
title: 'New Android Title',
|
|
101
|
+
}));
|
|
102
|
+
expect(mockSetAndroidTitleError).toHaveBeenCalledWith('');
|
|
103
|
+
expect(mockValidateTitle).toHaveBeenCalledWith('New Android Title');
|
|
104
|
+
expect(mockSetIosContent).not.toHaveBeenCalled();
|
|
105
|
+
});
|
|
106
|
+
|
|
107
|
+
it('should update iOS title when sync is disabled', () => {
|
|
108
|
+
const { result } = renderHook(() => usePlatformSync(defaultProps));
|
|
109
|
+
|
|
110
|
+
act(() => {
|
|
111
|
+
result.current.handleTitleChange(IOS, 'New iOS Title');
|
|
112
|
+
});
|
|
113
|
+
|
|
114
|
+
expect(mockSetIosContent).toHaveBeenCalledWith(expect.objectContaining({
|
|
115
|
+
...defaultIosContent,
|
|
116
|
+
title: 'New iOS Title',
|
|
117
|
+
}));
|
|
118
|
+
expect(mockSetIosTitleError).toHaveBeenCalledWith('');
|
|
119
|
+
expect(mockValidateTitle).toHaveBeenCalledWith('New iOS Title');
|
|
120
|
+
expect(mockSetAndroidContent).not.toHaveBeenCalled();
|
|
121
|
+
});
|
|
122
|
+
|
|
123
|
+
it('should sync title to iOS when changing Android title with sync enabled', () => {
|
|
124
|
+
const syncProps = { ...defaultProps, sameContent: true };
|
|
125
|
+
const { result } = renderHook(() => usePlatformSync(syncProps));
|
|
126
|
+
|
|
127
|
+
act(() => {
|
|
128
|
+
result.current.handleTitleChange(ANDROID, 'Synced Title');
|
|
129
|
+
});
|
|
130
|
+
|
|
131
|
+
expect(mockSetAndroidContent).toHaveBeenCalledWith(expect.objectContaining({
|
|
132
|
+
...defaultAndroidContent,
|
|
133
|
+
title: 'Synced Title',
|
|
134
|
+
}));
|
|
135
|
+
expect(mockSetIosContent).toHaveBeenCalledWith(expect.objectContaining({
|
|
136
|
+
title: 'Synced Title',
|
|
137
|
+
}));
|
|
138
|
+
expect(mockSetAndroidTitleError).toHaveBeenCalledWith('');
|
|
139
|
+
expect(mockSetIosTitleError).toHaveBeenCalledWith('');
|
|
140
|
+
});
|
|
141
|
+
|
|
142
|
+
it('should sync title to Android when changing iOS title with sync enabled', () => {
|
|
143
|
+
const syncProps = { ...defaultProps, sameContent: true };
|
|
144
|
+
const { result } = renderHook(() => usePlatformSync(syncProps));
|
|
145
|
+
|
|
146
|
+
act(() => {
|
|
147
|
+
result.current.handleTitleChange(IOS, 'Synced iOS Title');
|
|
148
|
+
});
|
|
149
|
+
|
|
150
|
+
expect(mockSetIosContent).toHaveBeenCalledWith(expect.objectContaining({
|
|
151
|
+
...defaultIosContent,
|
|
152
|
+
title: 'Synced iOS Title',
|
|
153
|
+
}));
|
|
154
|
+
expect(mockSetAndroidContent).toHaveBeenCalledWith(expect.objectContaining({
|
|
155
|
+
title: 'Synced iOS Title',
|
|
156
|
+
}));
|
|
157
|
+
expect(mockSetIosTitleError).toHaveBeenCalledWith('');
|
|
158
|
+
expect(mockSetAndroidTitleError).toHaveBeenCalledWith('');
|
|
159
|
+
});
|
|
160
|
+
|
|
161
|
+
it('should handle validation errors for title', () => {
|
|
162
|
+
mockValidateTitle.mockReturnValue('Title is required');
|
|
163
|
+
const { result } = renderHook(() => usePlatformSync(defaultProps));
|
|
164
|
+
|
|
165
|
+
act(() => {
|
|
166
|
+
result.current.handleTitleChange(ANDROID, '');
|
|
167
|
+
});
|
|
168
|
+
|
|
169
|
+
expect(mockSetAndroidTitleError).toHaveBeenCalledWith('Title is required');
|
|
170
|
+
});
|
|
171
|
+
});
|
|
172
|
+
|
|
173
|
+
describe('handleMessageChange', () => {
|
|
174
|
+
it('should update Android message when sync is disabled', () => {
|
|
175
|
+
const { result } = renderHook(() => usePlatformSync(defaultProps));
|
|
176
|
+
|
|
177
|
+
act(() => {
|
|
178
|
+
result.current.handleMessageChange(ANDROID, 'New Android Message');
|
|
179
|
+
});
|
|
180
|
+
|
|
181
|
+
expect(mockSetAndroidContent).toHaveBeenCalledWith(expect.objectContaining({
|
|
182
|
+
...defaultAndroidContent,
|
|
183
|
+
message: 'New Android Message',
|
|
184
|
+
}));
|
|
185
|
+
expect(mockSetAndroidMessageError).toHaveBeenCalledWith('');
|
|
186
|
+
expect(mockValidateMessage).toHaveBeenCalledWith('New Android Message');
|
|
187
|
+
expect(mockSetIosContent).not.toHaveBeenCalled();
|
|
188
|
+
});
|
|
189
|
+
|
|
190
|
+
it('should update iOS message when sync is disabled', () => {
|
|
191
|
+
const { result } = renderHook(() => usePlatformSync(defaultProps));
|
|
192
|
+
|
|
193
|
+
act(() => {
|
|
194
|
+
result.current.handleMessageChange(IOS, 'New iOS Message');
|
|
195
|
+
});
|
|
196
|
+
|
|
197
|
+
expect(mockSetIosContent).toHaveBeenCalledWith(expect.objectContaining({
|
|
198
|
+
...defaultIosContent,
|
|
199
|
+
message: 'New iOS Message',
|
|
200
|
+
}));
|
|
201
|
+
expect(mockSetIosMessageError).toHaveBeenCalledWith('');
|
|
202
|
+
expect(mockValidateMessage).toHaveBeenCalledWith('New iOS Message');
|
|
203
|
+
expect(mockSetAndroidContent).not.toHaveBeenCalled();
|
|
204
|
+
});
|
|
205
|
+
|
|
206
|
+
it('should sync message to iOS when changing Android message with sync enabled', () => {
|
|
207
|
+
const syncProps = { ...defaultProps, sameContent: true };
|
|
208
|
+
const { result } = renderHook(() => usePlatformSync(syncProps));
|
|
209
|
+
|
|
210
|
+
act(() => {
|
|
211
|
+
result.current.handleMessageChange(ANDROID, 'Synced Message');
|
|
212
|
+
});
|
|
213
|
+
|
|
214
|
+
expect(mockSetAndroidContent).toHaveBeenCalledWith(expect.objectContaining({
|
|
215
|
+
...defaultAndroidContent,
|
|
216
|
+
message: 'Synced Message',
|
|
217
|
+
}));
|
|
218
|
+
expect(mockSetIosContent).toHaveBeenCalledWith(expect.objectContaining({
|
|
219
|
+
message: 'Synced Message',
|
|
220
|
+
}));
|
|
221
|
+
expect(mockSetAndroidMessageError).toHaveBeenCalledWith('');
|
|
222
|
+
expect(mockSetIosMessageError).toHaveBeenCalledWith('');
|
|
223
|
+
});
|
|
224
|
+
|
|
225
|
+
it('should sync message to Android when changing iOS message with sync enabled', () => {
|
|
226
|
+
const syncProps = { ...defaultProps, sameContent: true };
|
|
227
|
+
const { result } = renderHook(() => usePlatformSync(syncProps));
|
|
228
|
+
|
|
229
|
+
act(() => {
|
|
230
|
+
result.current.handleMessageChange(IOS, 'Synced iOS Message');
|
|
231
|
+
});
|
|
232
|
+
|
|
233
|
+
expect(mockSetIosContent).toHaveBeenCalledWith(expect.objectContaining({
|
|
234
|
+
...defaultIosContent,
|
|
235
|
+
message: 'Synced iOS Message',
|
|
236
|
+
}));
|
|
237
|
+
expect(mockSetAndroidContent).toHaveBeenCalledWith(expect.objectContaining({
|
|
238
|
+
message: 'Synced iOS Message',
|
|
239
|
+
}));
|
|
240
|
+
expect(mockSetIosMessageError).toHaveBeenCalledWith('');
|
|
241
|
+
expect(mockSetAndroidMessageError).toHaveBeenCalledWith('');
|
|
242
|
+
});
|
|
243
|
+
|
|
244
|
+
it('should handle validation errors for message', () => {
|
|
245
|
+
mockValidateMessage.mockReturnValue('Message is required');
|
|
246
|
+
const { result } = renderHook(() => usePlatformSync(defaultProps));
|
|
247
|
+
|
|
248
|
+
act(() => {
|
|
249
|
+
result.current.handleMessageChange(ANDROID, '');
|
|
250
|
+
});
|
|
251
|
+
|
|
252
|
+
expect(mockSetAndroidMessageError).toHaveBeenCalledWith('Message is required');
|
|
253
|
+
});
|
|
254
|
+
});
|
|
255
|
+
|
|
256
|
+
describe('handleMediaTypeChange', () => {
|
|
257
|
+
describe('Android Platform', () => {
|
|
258
|
+
it('should update Android media type when sync is disabled', () => {
|
|
259
|
+
const { result } = renderHook(() => usePlatformSync(defaultProps));
|
|
260
|
+
|
|
261
|
+
act(() => {
|
|
262
|
+
result.current.handleMediaTypeChange(ANDROID, VIDEO);
|
|
263
|
+
});
|
|
264
|
+
|
|
265
|
+
expect(mockSetAndroidContent).toHaveBeenCalledWith(expect.objectContaining({
|
|
266
|
+
...defaultAndroidContent,
|
|
267
|
+
mediaType: VIDEO,
|
|
268
|
+
}));
|
|
269
|
+
expect(mockSetIosContent).not.toHaveBeenCalled();
|
|
270
|
+
});
|
|
271
|
+
|
|
272
|
+
it('should clear image data when switching from IMAGE to VIDEO on Android', () => {
|
|
273
|
+
const propsWithImageContent = {
|
|
274
|
+
...defaultProps,
|
|
275
|
+
androidContent: { ...defaultAndroidContent, mediaType: IMAGE },
|
|
276
|
+
};
|
|
277
|
+
|
|
278
|
+
mockSetAndroidContent.mockImplementation((updater) => {
|
|
279
|
+
if (typeof updater === 'function') {
|
|
280
|
+
updater(propsWithImageContent.androidContent);
|
|
281
|
+
}
|
|
282
|
+
});
|
|
283
|
+
|
|
284
|
+
const { result } = renderHook(() => usePlatformSync(propsWithImageContent));
|
|
285
|
+
|
|
286
|
+
act(() => {
|
|
287
|
+
result.current.handleMediaTypeChange(ANDROID, VIDEO);
|
|
288
|
+
});
|
|
289
|
+
|
|
290
|
+
expect(mockUpdateOnMpushImageReUpload).toHaveBeenCalled();
|
|
291
|
+
expect(mockUpdateOnMpushVideoReUpload).not.toHaveBeenCalled();
|
|
292
|
+
});
|
|
293
|
+
|
|
294
|
+
it('should clear image data when switching from IMAGE to GIF on Android', () => {
|
|
295
|
+
const propsWithImageContent = {
|
|
296
|
+
...defaultProps,
|
|
297
|
+
androidContent: { ...defaultAndroidContent, mediaType: IMAGE },
|
|
298
|
+
};
|
|
299
|
+
|
|
300
|
+
mockSetAndroidContent.mockImplementation((updater) => {
|
|
301
|
+
if (typeof updater === 'function') {
|
|
302
|
+
updater(propsWithImageContent.androidContent);
|
|
303
|
+
}
|
|
304
|
+
});
|
|
305
|
+
|
|
306
|
+
const { result } = renderHook(() => usePlatformSync(propsWithImageContent));
|
|
307
|
+
|
|
308
|
+
act(() => {
|
|
309
|
+
result.current.handleMediaTypeChange(ANDROID, GIF);
|
|
310
|
+
});
|
|
311
|
+
|
|
312
|
+
expect(mockUpdateOnMpushImageReUpload).toHaveBeenCalled();
|
|
313
|
+
expect(mockUpdateOnMpushVideoReUpload).not.toHaveBeenCalled();
|
|
314
|
+
});
|
|
315
|
+
|
|
316
|
+
it('should clear video data when switching from VIDEO to IMAGE on Android', () => {
|
|
317
|
+
const propsWithVideoContent = {
|
|
318
|
+
...defaultProps,
|
|
319
|
+
androidContent: { ...defaultAndroidContent, mediaType: VIDEO },
|
|
320
|
+
};
|
|
321
|
+
|
|
322
|
+
mockSetAndroidContent.mockImplementation((updater) => {
|
|
323
|
+
if (typeof updater === 'function') {
|
|
324
|
+
updater(propsWithVideoContent.androidContent);
|
|
325
|
+
}
|
|
326
|
+
});
|
|
327
|
+
|
|
328
|
+
const { result } = renderHook(() => usePlatformSync(propsWithVideoContent));
|
|
329
|
+
|
|
330
|
+
act(() => {
|
|
331
|
+
result.current.handleMediaTypeChange(ANDROID, IMAGE);
|
|
332
|
+
});
|
|
333
|
+
|
|
334
|
+
expect(mockUpdateOnMpushVideoReUpload).toHaveBeenCalled();
|
|
335
|
+
expect(mockUpdateOnMpushImageReUpload).not.toHaveBeenCalled();
|
|
336
|
+
});
|
|
337
|
+
|
|
338
|
+
it('should clear video data when switching from GIF to IMAGE on Android', () => {
|
|
339
|
+
const propsWithGifContent = {
|
|
340
|
+
...defaultProps,
|
|
341
|
+
androidContent: { ...defaultAndroidContent, mediaType: GIF },
|
|
342
|
+
};
|
|
343
|
+
|
|
344
|
+
mockSetAndroidContent.mockImplementation((updater) => {
|
|
345
|
+
if (typeof updater === 'function') {
|
|
346
|
+
updater(propsWithGifContent.androidContent);
|
|
347
|
+
}
|
|
348
|
+
});
|
|
349
|
+
|
|
350
|
+
const { result } = renderHook(() => usePlatformSync(propsWithGifContent));
|
|
351
|
+
|
|
352
|
+
act(() => {
|
|
353
|
+
result.current.handleMediaTypeChange(ANDROID, IMAGE);
|
|
354
|
+
});
|
|
355
|
+
|
|
356
|
+
expect(mockUpdateOnMpushVideoReUpload).toHaveBeenCalled();
|
|
357
|
+
expect(mockUpdateOnMpushImageReUpload).not.toHaveBeenCalled();
|
|
358
|
+
});
|
|
359
|
+
|
|
360
|
+
it('should clear video data when switching from VIDEO to GIF on Android (Line 151)', () => {
|
|
361
|
+
const propsWithVideoContent = {
|
|
362
|
+
...defaultProps,
|
|
363
|
+
androidContent: { ...defaultAndroidContent, mediaType: VIDEO },
|
|
364
|
+
};
|
|
365
|
+
|
|
366
|
+
mockSetAndroidContent.mockImplementation((updater) => {
|
|
367
|
+
if (typeof updater === 'function') {
|
|
368
|
+
updater(propsWithVideoContent.androidContent);
|
|
369
|
+
}
|
|
370
|
+
});
|
|
371
|
+
|
|
372
|
+
const { result } = renderHook(() => usePlatformSync(propsWithVideoContent));
|
|
373
|
+
|
|
374
|
+
act(() => {
|
|
375
|
+
result.current.handleMediaTypeChange(ANDROID, GIF);
|
|
376
|
+
});
|
|
377
|
+
|
|
378
|
+
expect(mockUpdateOnMpushVideoReUpload).toHaveBeenCalled();
|
|
379
|
+
expect(mockUpdateOnMpushImageReUpload).not.toHaveBeenCalled();
|
|
380
|
+
});
|
|
381
|
+
|
|
382
|
+
it('should clear video data when switching from GIF to VIDEO on Android (Line 151)', () => {
|
|
383
|
+
const propsWithGifContent = {
|
|
384
|
+
...defaultProps,
|
|
385
|
+
androidContent: { ...defaultAndroidContent, mediaType: GIF },
|
|
386
|
+
};
|
|
387
|
+
|
|
388
|
+
mockSetAndroidContent.mockImplementation((updater) => {
|
|
389
|
+
if (typeof updater === 'function') {
|
|
390
|
+
updater(propsWithGifContent.androidContent);
|
|
391
|
+
}
|
|
392
|
+
});
|
|
393
|
+
|
|
394
|
+
const { result } = renderHook(() => usePlatformSync(propsWithGifContent));
|
|
395
|
+
|
|
396
|
+
act(() => {
|
|
397
|
+
result.current.handleMediaTypeChange(ANDROID, VIDEO);
|
|
398
|
+
});
|
|
399
|
+
|
|
400
|
+
expect(mockUpdateOnMpushVideoReUpload).toHaveBeenCalled();
|
|
401
|
+
expect(mockUpdateOnMpushImageReUpload).not.toHaveBeenCalled();
|
|
402
|
+
});
|
|
403
|
+
|
|
404
|
+
it('should clear video data when switching from VIDEO to NONE on Android', () => {
|
|
405
|
+
const propsWithVideoContent = {
|
|
406
|
+
...defaultProps,
|
|
407
|
+
androidContent: { ...defaultAndroidContent, mediaType: VIDEO },
|
|
408
|
+
};
|
|
409
|
+
|
|
410
|
+
mockSetAndroidContent.mockImplementation((updater) => {
|
|
411
|
+
if (typeof updater === 'function') {
|
|
412
|
+
updater(propsWithVideoContent.androidContent);
|
|
413
|
+
}
|
|
414
|
+
});
|
|
415
|
+
|
|
416
|
+
const { result } = renderHook(() => usePlatformSync(propsWithVideoContent));
|
|
417
|
+
|
|
418
|
+
act(() => {
|
|
419
|
+
result.current.handleMediaTypeChange(ANDROID, NONE);
|
|
420
|
+
});
|
|
421
|
+
|
|
422
|
+
expect(mockUpdateOnMpushVideoReUpload).toHaveBeenCalled();
|
|
423
|
+
expect(mockUpdateOnMpushImageReUpload).not.toHaveBeenCalled();
|
|
424
|
+
});
|
|
425
|
+
|
|
426
|
+
it('should clear video data when switching from GIF to NONE on Android', () => {
|
|
427
|
+
const propsWithGifContent = {
|
|
428
|
+
...defaultProps,
|
|
429
|
+
androidContent: { ...defaultAndroidContent, mediaType: GIF },
|
|
430
|
+
};
|
|
431
|
+
|
|
432
|
+
mockSetAndroidContent.mockImplementation((updater) => {
|
|
433
|
+
if (typeof updater === 'function') {
|
|
434
|
+
updater(propsWithGifContent.androidContent);
|
|
435
|
+
}
|
|
436
|
+
});
|
|
437
|
+
|
|
438
|
+
const { result } = renderHook(() => usePlatformSync(propsWithGifContent));
|
|
439
|
+
|
|
440
|
+
act(() => {
|
|
441
|
+
result.current.handleMediaTypeChange(ANDROID, NONE);
|
|
442
|
+
});
|
|
443
|
+
|
|
444
|
+
expect(mockUpdateOnMpushVideoReUpload).toHaveBeenCalled();
|
|
445
|
+
expect(mockUpdateOnMpushImageReUpload).not.toHaveBeenCalled();
|
|
446
|
+
});
|
|
447
|
+
|
|
448
|
+
it('should not clear data when switching to same media type on Android', () => {
|
|
449
|
+
const propsWithVideoContent = {
|
|
450
|
+
...defaultProps,
|
|
451
|
+
androidContent: { ...defaultAndroidContent, mediaType: VIDEO },
|
|
452
|
+
};
|
|
453
|
+
|
|
454
|
+
mockSetAndroidContent.mockImplementation((updater) => {
|
|
455
|
+
if (typeof updater === 'function') {
|
|
456
|
+
updater(propsWithVideoContent.androidContent);
|
|
457
|
+
}
|
|
458
|
+
});
|
|
459
|
+
|
|
460
|
+
const { result } = renderHook(() => usePlatformSync(propsWithVideoContent));
|
|
461
|
+
|
|
462
|
+
act(() => {
|
|
463
|
+
result.current.handleMediaTypeChange(ANDROID, VIDEO);
|
|
464
|
+
});
|
|
465
|
+
|
|
466
|
+
expect(mockUpdateOnMpushVideoReUpload).not.toHaveBeenCalled();
|
|
467
|
+
expect(mockUpdateOnMpushImageReUpload).not.toHaveBeenCalled();
|
|
468
|
+
});
|
|
469
|
+
});
|
|
470
|
+
|
|
471
|
+
describe('iOS Platform', () => {
|
|
472
|
+
it('should update iOS media type when sync is disabled', () => {
|
|
473
|
+
const { result } = renderHook(() => usePlatformSync(defaultProps));
|
|
474
|
+
|
|
475
|
+
act(() => {
|
|
476
|
+
result.current.handleMediaTypeChange(IOS, VIDEO);
|
|
477
|
+
});
|
|
478
|
+
|
|
479
|
+
expect(mockSetIosContent).toHaveBeenCalledWith(expect.objectContaining({
|
|
480
|
+
...defaultIosContent,
|
|
481
|
+
mediaType: VIDEO,
|
|
482
|
+
}));
|
|
483
|
+
expect(mockSetAndroidContent).not.toHaveBeenCalled();
|
|
484
|
+
});
|
|
485
|
+
|
|
486
|
+
it('should clear image data when switching from IMAGE to VIDEO on iOS', () => {
|
|
487
|
+
const propsWithImageContent = {
|
|
488
|
+
...defaultProps,
|
|
489
|
+
iosContent: { ...defaultIosContent, mediaType: IMAGE },
|
|
490
|
+
};
|
|
491
|
+
|
|
492
|
+
mockSetIosContent.mockImplementation((updater) => {
|
|
493
|
+
if (typeof updater === 'function') {
|
|
494
|
+
updater(propsWithImageContent.iosContent);
|
|
495
|
+
}
|
|
496
|
+
});
|
|
497
|
+
|
|
498
|
+
const { result } = renderHook(() => usePlatformSync(propsWithImageContent));
|
|
499
|
+
|
|
500
|
+
act(() => {
|
|
501
|
+
result.current.handleMediaTypeChange(IOS, VIDEO);
|
|
502
|
+
});
|
|
503
|
+
|
|
504
|
+
expect(mockUpdateOnMpushImageReUpload).toHaveBeenCalled();
|
|
505
|
+
expect(mockUpdateOnMpushVideoReUpload).not.toHaveBeenCalled();
|
|
506
|
+
});
|
|
507
|
+
|
|
508
|
+
it('should clear image data when switching from IMAGE to GIF on iOS', () => {
|
|
509
|
+
const propsWithImageContent = {
|
|
510
|
+
...defaultProps,
|
|
511
|
+
iosContent: { ...defaultIosContent, mediaType: IMAGE },
|
|
512
|
+
};
|
|
513
|
+
|
|
514
|
+
mockSetIosContent.mockImplementation((updater) => {
|
|
515
|
+
if (typeof updater === 'function') {
|
|
516
|
+
updater(propsWithImageContent.iosContent);
|
|
517
|
+
}
|
|
518
|
+
});
|
|
519
|
+
|
|
520
|
+
const { result } = renderHook(() => usePlatformSync(propsWithImageContent));
|
|
521
|
+
|
|
522
|
+
act(() => {
|
|
523
|
+
result.current.handleMediaTypeChange(IOS, GIF);
|
|
524
|
+
});
|
|
525
|
+
|
|
526
|
+
expect(mockUpdateOnMpushImageReUpload).toHaveBeenCalled();
|
|
527
|
+
expect(mockUpdateOnMpushVideoReUpload).not.toHaveBeenCalled();
|
|
528
|
+
});
|
|
529
|
+
|
|
530
|
+
it('should clear video data when switching from VIDEO to IMAGE on iOS', () => {
|
|
531
|
+
const propsWithVideoContent = {
|
|
532
|
+
...defaultProps,
|
|
533
|
+
iosContent: { ...defaultIosContent, mediaType: VIDEO },
|
|
534
|
+
};
|
|
535
|
+
|
|
536
|
+
mockSetIosContent.mockImplementation((updater) => {
|
|
537
|
+
if (typeof updater === 'function') {
|
|
538
|
+
updater(propsWithVideoContent.iosContent);
|
|
539
|
+
}
|
|
540
|
+
});
|
|
541
|
+
|
|
542
|
+
const { result } = renderHook(() => usePlatformSync(propsWithVideoContent));
|
|
543
|
+
|
|
544
|
+
act(() => {
|
|
545
|
+
result.current.handleMediaTypeChange(IOS, IMAGE);
|
|
546
|
+
});
|
|
547
|
+
|
|
548
|
+
expect(mockUpdateOnMpushVideoReUpload).toHaveBeenCalled();
|
|
549
|
+
expect(mockUpdateOnMpushImageReUpload).not.toHaveBeenCalled();
|
|
550
|
+
});
|
|
551
|
+
|
|
552
|
+
it('should clear video data when switching from GIF to IMAGE on iOS', () => {
|
|
553
|
+
const propsWithGifContent = {
|
|
554
|
+
...defaultProps,
|
|
555
|
+
iosContent: { ...defaultIosContent, mediaType: GIF },
|
|
556
|
+
};
|
|
557
|
+
|
|
558
|
+
mockSetIosContent.mockImplementation((updater) => {
|
|
559
|
+
if (typeof updater === 'function') {
|
|
560
|
+
updater(propsWithGifContent.iosContent);
|
|
561
|
+
}
|
|
562
|
+
});
|
|
563
|
+
|
|
564
|
+
const { result } = renderHook(() => usePlatformSync(propsWithGifContent));
|
|
565
|
+
|
|
566
|
+
act(() => {
|
|
567
|
+
result.current.handleMediaTypeChange(IOS, IMAGE);
|
|
568
|
+
});
|
|
569
|
+
|
|
570
|
+
expect(mockUpdateOnMpushVideoReUpload).toHaveBeenCalled();
|
|
571
|
+
expect(mockUpdateOnMpushImageReUpload).not.toHaveBeenCalled();
|
|
572
|
+
});
|
|
573
|
+
|
|
574
|
+
it('should clear video data when switching from VIDEO to GIF on iOS (Line 151)', () => {
|
|
575
|
+
const propsWithVideoContent = {
|
|
576
|
+
...defaultProps,
|
|
577
|
+
iosContent: { ...defaultIosContent, mediaType: VIDEO },
|
|
578
|
+
};
|
|
579
|
+
|
|
580
|
+
mockSetIosContent.mockImplementation((updater) => {
|
|
581
|
+
if (typeof updater === 'function') {
|
|
582
|
+
updater(propsWithVideoContent.iosContent);
|
|
583
|
+
}
|
|
584
|
+
});
|
|
585
|
+
|
|
586
|
+
const { result } = renderHook(() => usePlatformSync(propsWithVideoContent));
|
|
587
|
+
|
|
588
|
+
act(() => {
|
|
589
|
+
result.current.handleMediaTypeChange(IOS, GIF);
|
|
590
|
+
});
|
|
591
|
+
|
|
592
|
+
expect(mockUpdateOnMpushVideoReUpload).toHaveBeenCalled();
|
|
593
|
+
expect(mockUpdateOnMpushImageReUpload).not.toHaveBeenCalled();
|
|
594
|
+
});
|
|
595
|
+
|
|
596
|
+
it('should clear video data when switching from GIF to VIDEO on iOS (Line 151)', () => {
|
|
597
|
+
const propsWithGifContent = {
|
|
598
|
+
...defaultProps,
|
|
599
|
+
iosContent: { ...defaultIosContent, mediaType: GIF },
|
|
600
|
+
};
|
|
601
|
+
|
|
602
|
+
mockSetIosContent.mockImplementation((updater) => {
|
|
603
|
+
if (typeof updater === 'function') {
|
|
604
|
+
updater(propsWithGifContent.iosContent);
|
|
605
|
+
}
|
|
606
|
+
});
|
|
607
|
+
|
|
608
|
+
const { result } = renderHook(() => usePlatformSync(propsWithGifContent));
|
|
609
|
+
|
|
610
|
+
act(() => {
|
|
611
|
+
result.current.handleMediaTypeChange(IOS, VIDEO);
|
|
612
|
+
});
|
|
613
|
+
|
|
614
|
+
expect(mockUpdateOnMpushVideoReUpload).toHaveBeenCalled();
|
|
615
|
+
expect(mockUpdateOnMpushImageReUpload).not.toHaveBeenCalled();
|
|
616
|
+
});
|
|
617
|
+
|
|
618
|
+
it('should not clear data when switching to same media type on iOS', () => {
|
|
619
|
+
const propsWithVideoContent = {
|
|
620
|
+
...defaultProps,
|
|
621
|
+
iosContent: { ...defaultIosContent, mediaType: VIDEO },
|
|
622
|
+
};
|
|
623
|
+
|
|
624
|
+
mockSetIosContent.mockImplementation((updater) => {
|
|
625
|
+
if (typeof updater === 'function') {
|
|
626
|
+
updater(propsWithVideoContent.iosContent);
|
|
627
|
+
}
|
|
628
|
+
});
|
|
629
|
+
|
|
630
|
+
const { result } = renderHook(() => usePlatformSync(propsWithVideoContent));
|
|
631
|
+
|
|
632
|
+
act(() => {
|
|
633
|
+
result.current.handleMediaTypeChange(IOS, VIDEO);
|
|
634
|
+
});
|
|
635
|
+
|
|
636
|
+
expect(mockUpdateOnMpushVideoReUpload).not.toHaveBeenCalled();
|
|
637
|
+
expect(mockUpdateOnMpushImageReUpload).not.toHaveBeenCalled();
|
|
638
|
+
});
|
|
639
|
+
});
|
|
640
|
+
|
|
641
|
+
describe('Sync Behavior', () => {
|
|
642
|
+
it('should sync media type to iOS when changing Android media type with sync enabled', () => {
|
|
643
|
+
const syncProps = { ...defaultProps, sameContent: true };
|
|
644
|
+
const { result } = renderHook(() => usePlatformSync(syncProps));
|
|
645
|
+
|
|
646
|
+
act(() => {
|
|
647
|
+
result.current.handleMediaTypeChange(ANDROID, VIDEO);
|
|
648
|
+
});
|
|
649
|
+
|
|
650
|
+
expect(mockSetAndroidContent).toHaveBeenCalledWith(expect.objectContaining({
|
|
651
|
+
mediaType: VIDEO,
|
|
652
|
+
}));
|
|
653
|
+
expect(mockSetIosContent).toHaveBeenCalledWith(expect.objectContaining({
|
|
654
|
+
mediaType: VIDEO,
|
|
655
|
+
}));
|
|
656
|
+
});
|
|
657
|
+
|
|
658
|
+
it('should sync media type to Android when changing iOS media type with sync enabled', () => {
|
|
659
|
+
const syncProps = { ...defaultProps, sameContent: true };
|
|
660
|
+
const { result } = renderHook(() => usePlatformSync(syncProps));
|
|
661
|
+
|
|
662
|
+
act(() => {
|
|
663
|
+
result.current.handleMediaTypeChange(IOS, GIF);
|
|
664
|
+
});
|
|
665
|
+
|
|
666
|
+
expect(mockSetIosContent).toHaveBeenCalledWith(expect.objectContaining({
|
|
667
|
+
mediaType: GIF,
|
|
668
|
+
}));
|
|
669
|
+
expect(mockSetAndroidContent).toHaveBeenCalledWith(expect.objectContaining({
|
|
670
|
+
mediaType: GIF,
|
|
671
|
+
}));
|
|
672
|
+
});
|
|
673
|
+
});
|
|
674
|
+
});
|
|
675
|
+
|
|
676
|
+
describe('handleTagSelect', () => {
|
|
677
|
+
it('should add tag to Android title when sync is disabled', () => {
|
|
678
|
+
const { result } = renderHook(() => usePlatformSync(defaultProps));
|
|
679
|
+
|
|
680
|
+
act(() => {
|
|
681
|
+
result.current.handleTagSelect(ANDROID, 'USER_NAME', true);
|
|
682
|
+
});
|
|
683
|
+
|
|
684
|
+
expect(mockSetAndroidContent).toHaveBeenCalledWith(expect.objectContaining({
|
|
685
|
+
title: 'Android Title{{USER_NAME}}',
|
|
686
|
+
}));
|
|
687
|
+
expect(mockSetAndroidTitleError).toHaveBeenCalledWith('');
|
|
688
|
+
expect(mockSetIosContent).not.toHaveBeenCalled();
|
|
689
|
+
});
|
|
690
|
+
|
|
691
|
+
it('should add tag to iOS title when sync is disabled', () => {
|
|
692
|
+
const { result } = renderHook(() => usePlatformSync(defaultProps));
|
|
693
|
+
|
|
694
|
+
act(() => {
|
|
695
|
+
result.current.handleTagSelect(IOS, 'USER_NAME', true);
|
|
696
|
+
});
|
|
697
|
+
|
|
698
|
+
expect(mockSetIosContent).toHaveBeenCalledWith(expect.objectContaining({
|
|
699
|
+
title: 'iOS Title{{USER_NAME}}',
|
|
700
|
+
}));
|
|
701
|
+
expect(mockSetIosTitleError).toHaveBeenCalledWith('');
|
|
702
|
+
expect(mockSetAndroidContent).not.toHaveBeenCalled();
|
|
703
|
+
});
|
|
704
|
+
|
|
705
|
+
it('should add tag to Android message when sync is disabled', () => {
|
|
706
|
+
const { result } = renderHook(() => usePlatformSync(defaultProps));
|
|
707
|
+
|
|
708
|
+
act(() => {
|
|
709
|
+
result.current.handleTagSelect(ANDROID, 'USER_NAME', false);
|
|
710
|
+
});
|
|
711
|
+
|
|
712
|
+
expect(mockSetAndroidContent).toHaveBeenCalledWith(expect.objectContaining({
|
|
713
|
+
message: 'Android Message{{USER_NAME}}',
|
|
714
|
+
}));
|
|
715
|
+
expect(mockSetAndroidMessageError).toHaveBeenCalledWith('');
|
|
716
|
+
expect(mockSetIosContent).not.toHaveBeenCalled();
|
|
717
|
+
});
|
|
718
|
+
|
|
719
|
+
it('should add tag to iOS message when sync is disabled', () => {
|
|
720
|
+
const { result } = renderHook(() => usePlatformSync(defaultProps));
|
|
721
|
+
|
|
722
|
+
act(() => {
|
|
723
|
+
result.current.handleTagSelect(IOS, 'USER_NAME', false);
|
|
724
|
+
});
|
|
725
|
+
|
|
726
|
+
expect(mockSetIosContent).toHaveBeenCalledWith(expect.objectContaining({
|
|
727
|
+
message: 'iOS Message{{USER_NAME}}',
|
|
728
|
+
}));
|
|
729
|
+
expect(mockSetIosMessageError).toHaveBeenCalledWith('');
|
|
730
|
+
expect(mockSetAndroidContent).not.toHaveBeenCalled();
|
|
731
|
+
});
|
|
732
|
+
|
|
733
|
+
it('should sync tag to iOS when adding to Android title with sync enabled', () => {
|
|
734
|
+
const syncProps = { ...defaultProps, sameContent: true };
|
|
735
|
+
const { result } = renderHook(() => usePlatformSync(syncProps));
|
|
736
|
+
|
|
737
|
+
act(() => {
|
|
738
|
+
result.current.handleTagSelect(ANDROID, 'USER_NAME', true);
|
|
739
|
+
});
|
|
740
|
+
|
|
741
|
+
expect(mockSetAndroidContent).toHaveBeenCalledWith(expect.objectContaining({
|
|
742
|
+
title: 'Android Title{{USER_NAME}}',
|
|
743
|
+
}));
|
|
744
|
+
expect(mockSetIosContent).toHaveBeenCalledWith(expect.objectContaining({
|
|
745
|
+
title: 'Android Title{{USER_NAME}}',
|
|
746
|
+
}));
|
|
747
|
+
});
|
|
748
|
+
|
|
749
|
+
it('should sync tag to Android when adding to iOS message with sync enabled', () => {
|
|
750
|
+
const syncProps = { ...defaultProps, sameContent: true };
|
|
751
|
+
const { result } = renderHook(() => usePlatformSync(syncProps));
|
|
752
|
+
|
|
753
|
+
act(() => {
|
|
754
|
+
result.current.handleTagSelect(IOS, 'USER_NAME', false);
|
|
755
|
+
});
|
|
756
|
+
|
|
757
|
+
expect(mockSetIosContent).toHaveBeenCalledWith(expect.objectContaining({
|
|
758
|
+
message: 'iOS Message{{USER_NAME}}',
|
|
759
|
+
}));
|
|
760
|
+
expect(mockSetAndroidContent).toHaveBeenCalledWith(expect.objectContaining({
|
|
761
|
+
message: 'iOS Message{{USER_NAME}}',
|
|
762
|
+
}));
|
|
763
|
+
});
|
|
764
|
+
});
|
|
765
|
+
|
|
766
|
+
describe('handleButtonChange', () => {
|
|
767
|
+
const testButtons = [
|
|
768
|
+
{
|
|
769
|
+
id: 1, text: 'Button 1', action: 'url', value: 'https://example.com',
|
|
770
|
+
},
|
|
771
|
+
{
|
|
772
|
+
id: 2, text: 'Button 2', action: 'deeplink', value: 'myapp://open',
|
|
773
|
+
},
|
|
774
|
+
];
|
|
775
|
+
|
|
776
|
+
it('should update Android buttons when sync is disabled', () => {
|
|
777
|
+
const { result } = renderHook(() => usePlatformSync(defaultProps));
|
|
778
|
+
|
|
779
|
+
act(() => {
|
|
780
|
+
result.current.handleButtonChange(ANDROID, testButtons);
|
|
781
|
+
});
|
|
782
|
+
|
|
783
|
+
expect(mockSetAndroidContent).toHaveBeenCalledWith(expect.objectContaining({
|
|
784
|
+
buttons: testButtons,
|
|
785
|
+
}));
|
|
786
|
+
expect(mockSetIosContent).not.toHaveBeenCalled();
|
|
787
|
+
});
|
|
788
|
+
|
|
789
|
+
it('should update iOS buttons when sync is disabled', () => {
|
|
790
|
+
const { result } = renderHook(() => usePlatformSync(defaultProps));
|
|
791
|
+
|
|
792
|
+
act(() => {
|
|
793
|
+
result.current.handleButtonChange(IOS, testButtons);
|
|
794
|
+
});
|
|
795
|
+
|
|
796
|
+
expect(mockSetIosContent).toHaveBeenCalledWith(expect.objectContaining({
|
|
797
|
+
buttons: testButtons,
|
|
798
|
+
}));
|
|
799
|
+
expect(mockSetAndroidContent).not.toHaveBeenCalled();
|
|
800
|
+
});
|
|
801
|
+
|
|
802
|
+
it('should sync buttons to iOS when changing Android buttons with sync enabled', () => {
|
|
803
|
+
const syncProps = { ...defaultProps, sameContent: true };
|
|
804
|
+
const { result } = renderHook(() => usePlatformSync(syncProps));
|
|
805
|
+
|
|
806
|
+
act(() => {
|
|
807
|
+
result.current.handleButtonChange(ANDROID, testButtons);
|
|
808
|
+
});
|
|
809
|
+
|
|
810
|
+
expect(mockSetAndroidContent).toHaveBeenCalledWith(expect.objectContaining({
|
|
811
|
+
buttons: testButtons,
|
|
812
|
+
}));
|
|
813
|
+
expect(mockSetIosContent).toHaveBeenCalledWith(expect.objectContaining({
|
|
814
|
+
buttons: expect.arrayContaining([
|
|
815
|
+
expect.objectContaining({ platform: IOS }),
|
|
816
|
+
expect.objectContaining({ platform: IOS }),
|
|
817
|
+
]),
|
|
818
|
+
}));
|
|
819
|
+
});
|
|
820
|
+
|
|
821
|
+
it('should sync buttons to Android when changing iOS buttons with sync enabled', () => {
|
|
822
|
+
const syncProps = { ...defaultProps, sameContent: true };
|
|
823
|
+
const { result } = renderHook(() => usePlatformSync(syncProps));
|
|
824
|
+
|
|
825
|
+
act(() => {
|
|
826
|
+
result.current.handleButtonChange(IOS, testButtons);
|
|
827
|
+
});
|
|
828
|
+
|
|
829
|
+
expect(mockSetIosContent).toHaveBeenCalledWith(expect.objectContaining({
|
|
830
|
+
buttons: testButtons,
|
|
831
|
+
}));
|
|
832
|
+
expect(mockSetAndroidContent).toHaveBeenCalledWith(expect.objectContaining({
|
|
833
|
+
buttons: expect.arrayContaining([
|
|
834
|
+
expect.objectContaining({ platform: ANDROID }),
|
|
835
|
+
expect.objectContaining({ platform: ANDROID }),
|
|
836
|
+
]),
|
|
837
|
+
}));
|
|
838
|
+
});
|
|
839
|
+
|
|
840
|
+
// Additional test cases for line 49 coverage - Array.isArray(sourceContent.buttons)
|
|
841
|
+
it('should handle non-array buttons during sync - null buttons (Line 49)', () => {
|
|
842
|
+
const syncProps = { ...defaultProps, sameContent: true };
|
|
843
|
+
const propsWithNullButtons = {
|
|
844
|
+
...syncProps,
|
|
845
|
+
androidContent: { ...defaultAndroidContent, buttons: null },
|
|
846
|
+
};
|
|
847
|
+
|
|
848
|
+
const { result } = renderHook(() => usePlatformSync(propsWithNullButtons));
|
|
849
|
+
|
|
850
|
+
act(() => {
|
|
851
|
+
result.current.handleTitleChange(ANDROID, 'Test Title');
|
|
852
|
+
});
|
|
853
|
+
|
|
854
|
+
// When syncing, if buttons is null, it should default to empty array
|
|
855
|
+
expect(mockSetIosContent).toHaveBeenCalledWith(expect.objectContaining({
|
|
856
|
+
title: 'Test Title',
|
|
857
|
+
buttons: [],
|
|
858
|
+
}));
|
|
859
|
+
});
|
|
860
|
+
|
|
861
|
+
it('should handle non-array buttons during sync - undefined buttons (Line 49)', () => {
|
|
862
|
+
const syncProps = { ...defaultProps, sameContent: true };
|
|
863
|
+
const propsWithUndefinedButtons = {
|
|
864
|
+
...syncProps,
|
|
865
|
+
androidContent: { ...defaultAndroidContent, buttons: undefined },
|
|
866
|
+
};
|
|
867
|
+
|
|
868
|
+
const { result } = renderHook(() => usePlatformSync(propsWithUndefinedButtons));
|
|
869
|
+
|
|
870
|
+
act(() => {
|
|
871
|
+
result.current.handleMessageChange(ANDROID, 'Test Message');
|
|
872
|
+
});
|
|
873
|
+
|
|
874
|
+
// When syncing, if buttons is undefined, it should default to empty array
|
|
875
|
+
expect(mockSetIosContent).toHaveBeenCalledWith(expect.objectContaining({
|
|
876
|
+
message: 'Test Message',
|
|
877
|
+
buttons: [],
|
|
878
|
+
}));
|
|
879
|
+
});
|
|
880
|
+
|
|
881
|
+
it('should handle non-array buttons during sync - string buttons (Line 49)', () => {
|
|
882
|
+
const syncProps = { ...defaultProps, sameContent: true };
|
|
883
|
+
const propsWithStringButtons = {
|
|
884
|
+
...syncProps,
|
|
885
|
+
androidContent: { ...defaultAndroidContent, buttons: 'invalid-buttons' },
|
|
886
|
+
};
|
|
887
|
+
|
|
888
|
+
const { result } = renderHook(() => usePlatformSync(propsWithStringButtons));
|
|
889
|
+
|
|
890
|
+
act(() => {
|
|
891
|
+
result.current.handleActionOnClickChange(ANDROID, true);
|
|
892
|
+
});
|
|
893
|
+
|
|
894
|
+
// When syncing, if buttons is not an array, it should default to empty array
|
|
895
|
+
expect(mockSetIosContent).toHaveBeenCalledWith(expect.objectContaining({
|
|
896
|
+
actionOnClick: true,
|
|
897
|
+
buttons: [],
|
|
898
|
+
}));
|
|
899
|
+
});
|
|
900
|
+
|
|
901
|
+
it('should handle non-array buttons during sync - object buttons (Line 49)', () => {
|
|
902
|
+
const syncProps = { ...defaultProps, sameContent: true };
|
|
903
|
+
const propsWithObjectButtons = {
|
|
904
|
+
...syncProps,
|
|
905
|
+
iosContent: { ...defaultIosContent, buttons: { invalid: 'object' } },
|
|
906
|
+
};
|
|
907
|
+
|
|
908
|
+
const { result } = renderHook(() => usePlatformSync(propsWithObjectButtons));
|
|
909
|
+
|
|
910
|
+
act(() => {
|
|
911
|
+
result.current.handleLinkTypeChange(IOS, 'external');
|
|
912
|
+
});
|
|
913
|
+
|
|
914
|
+
// When syncing, if buttons is not an array, it should default to empty array
|
|
915
|
+
expect(mockSetAndroidContent).toHaveBeenCalledWith(expect.objectContaining({
|
|
916
|
+
linkType: 'external',
|
|
917
|
+
buttons: [],
|
|
918
|
+
}));
|
|
919
|
+
});
|
|
920
|
+
});
|
|
921
|
+
|
|
922
|
+
describe('handleActionOnClickChange', () => {
|
|
923
|
+
it('should update Android actionOnClick when sync is disabled', () => {
|
|
924
|
+
const { result } = renderHook(() => usePlatformSync(defaultProps));
|
|
925
|
+
|
|
926
|
+
act(() => {
|
|
927
|
+
result.current.handleActionOnClickChange(ANDROID, true);
|
|
928
|
+
});
|
|
929
|
+
|
|
930
|
+
expect(mockSetAndroidContent).toHaveBeenCalledWith(expect.objectContaining({
|
|
931
|
+
actionOnClick: true,
|
|
932
|
+
}));
|
|
933
|
+
expect(mockSetIosContent).not.toHaveBeenCalled();
|
|
934
|
+
});
|
|
935
|
+
|
|
936
|
+
it('should update iOS actionOnClick when sync is disabled', () => {
|
|
937
|
+
const { result } = renderHook(() => usePlatformSync(defaultProps));
|
|
938
|
+
|
|
939
|
+
act(() => {
|
|
940
|
+
result.current.handleActionOnClickChange(IOS, true);
|
|
941
|
+
});
|
|
942
|
+
|
|
943
|
+
expect(mockSetIosContent).toHaveBeenCalledWith(expect.objectContaining({
|
|
944
|
+
actionOnClick: true,
|
|
945
|
+
}));
|
|
946
|
+
expect(mockSetAndroidContent).not.toHaveBeenCalled();
|
|
947
|
+
});
|
|
948
|
+
|
|
949
|
+
it('should sync actionOnClick to iOS when changing Android with sync enabled', () => {
|
|
950
|
+
const syncProps = { ...defaultProps, sameContent: true };
|
|
951
|
+
const { result } = renderHook(() => usePlatformSync(syncProps));
|
|
952
|
+
|
|
953
|
+
act(() => {
|
|
954
|
+
result.current.handleActionOnClickChange(ANDROID, true);
|
|
955
|
+
});
|
|
956
|
+
|
|
957
|
+
expect(mockSetAndroidContent).toHaveBeenCalledWith(expect.objectContaining({
|
|
958
|
+
actionOnClick: true,
|
|
959
|
+
}));
|
|
960
|
+
expect(mockSetIosContent).toHaveBeenCalledWith(expect.objectContaining({
|
|
961
|
+
actionOnClick: true,
|
|
962
|
+
}));
|
|
963
|
+
});
|
|
964
|
+
|
|
965
|
+
it('should sync actionOnClick to Android when changing iOS with sync enabled', () => {
|
|
966
|
+
const syncProps = { ...defaultProps, sameContent: true };
|
|
967
|
+
const { result } = renderHook(() => usePlatformSync(syncProps));
|
|
968
|
+
|
|
969
|
+
act(() => {
|
|
970
|
+
result.current.handleActionOnClickChange(IOS, false);
|
|
971
|
+
});
|
|
972
|
+
|
|
973
|
+
expect(mockSetIosContent).toHaveBeenCalledWith(expect.objectContaining({
|
|
974
|
+
actionOnClick: false,
|
|
975
|
+
}));
|
|
976
|
+
expect(mockSetAndroidContent).toHaveBeenCalledWith(expect.objectContaining({
|
|
977
|
+
actionOnClick: false,
|
|
978
|
+
}));
|
|
979
|
+
});
|
|
980
|
+
});
|
|
981
|
+
|
|
982
|
+
describe('handleLinkTypeChange', () => {
|
|
983
|
+
it('should update Android linkType when sync is disabled', () => {
|
|
984
|
+
const { result } = renderHook(() => usePlatformSync(defaultProps));
|
|
985
|
+
|
|
986
|
+
act(() => {
|
|
987
|
+
result.current.handleLinkTypeChange(ANDROID, 'external');
|
|
988
|
+
});
|
|
989
|
+
|
|
990
|
+
expect(mockSetAndroidContent).toHaveBeenCalledWith(expect.objectContaining({
|
|
991
|
+
linkType: 'external',
|
|
992
|
+
deepLinkValue: '',
|
|
993
|
+
externalLinkValue: '',
|
|
994
|
+
}));
|
|
995
|
+
expect(mockSetIosContent).not.toHaveBeenCalled();
|
|
996
|
+
});
|
|
997
|
+
|
|
998
|
+
it('should update iOS linkType when sync is disabled', () => {
|
|
999
|
+
const { result } = renderHook(() => usePlatformSync(defaultProps));
|
|
1000
|
+
|
|
1001
|
+
act(() => {
|
|
1002
|
+
result.current.handleLinkTypeChange(IOS, 'external');
|
|
1003
|
+
});
|
|
1004
|
+
|
|
1005
|
+
expect(mockSetIosContent).toHaveBeenCalledWith(expect.objectContaining({
|
|
1006
|
+
linkType: 'external',
|
|
1007
|
+
deepLinkValue: '',
|
|
1008
|
+
externalLinkValue: '',
|
|
1009
|
+
}));
|
|
1010
|
+
expect(mockSetAndroidContent).not.toHaveBeenCalled();
|
|
1011
|
+
});
|
|
1012
|
+
|
|
1013
|
+
it('should sync linkType to iOS when changing Android with sync enabled', () => {
|
|
1014
|
+
const syncProps = { ...defaultProps, sameContent: true };
|
|
1015
|
+
const { result } = renderHook(() => usePlatformSync(syncProps));
|
|
1016
|
+
|
|
1017
|
+
act(() => {
|
|
1018
|
+
result.current.handleLinkTypeChange(ANDROID, 'external');
|
|
1019
|
+
});
|
|
1020
|
+
|
|
1021
|
+
expect(mockSetAndroidContent).toHaveBeenCalledWith(expect.objectContaining({
|
|
1022
|
+
linkType: 'external',
|
|
1023
|
+
deepLinkValue: '',
|
|
1024
|
+
externalLinkValue: '',
|
|
1025
|
+
}));
|
|
1026
|
+
expect(mockSetIosContent).toHaveBeenCalledWith(expect.objectContaining({
|
|
1027
|
+
linkType: 'external',
|
|
1028
|
+
deepLinkValue: '',
|
|
1029
|
+
externalLinkValue: '',
|
|
1030
|
+
}));
|
|
1031
|
+
});
|
|
1032
|
+
|
|
1033
|
+
it('should sync linkType to Android when changing iOS with sync enabled', () => {
|
|
1034
|
+
const syncProps = { ...defaultProps, sameContent: true };
|
|
1035
|
+
const { result } = renderHook(() => usePlatformSync(syncProps));
|
|
1036
|
+
|
|
1037
|
+
act(() => {
|
|
1038
|
+
result.current.handleLinkTypeChange(IOS, 'deep');
|
|
1039
|
+
});
|
|
1040
|
+
|
|
1041
|
+
expect(mockSetIosContent).toHaveBeenCalledWith(expect.objectContaining({
|
|
1042
|
+
linkType: 'deep',
|
|
1043
|
+
deepLinkValue: '',
|
|
1044
|
+
externalLinkValue: '',
|
|
1045
|
+
}));
|
|
1046
|
+
expect(mockSetAndroidContent).toHaveBeenCalledWith(expect.objectContaining({
|
|
1047
|
+
linkType: 'deep',
|
|
1048
|
+
deepLinkValue: '',
|
|
1049
|
+
externalLinkValue: '',
|
|
1050
|
+
}));
|
|
1051
|
+
});
|
|
1052
|
+
|
|
1053
|
+
it('should clear link values when switching link types', () => {
|
|
1054
|
+
const propsWithLinkValues = {
|
|
1055
|
+
...defaultProps,
|
|
1056
|
+
androidContent: {
|
|
1057
|
+
...defaultAndroidContent,
|
|
1058
|
+
linkType: 'deep',
|
|
1059
|
+
deepLinkValue: 'myapp://deeplink',
|
|
1060
|
+
externalLinkValue: 'https://example.com',
|
|
1061
|
+
},
|
|
1062
|
+
};
|
|
1063
|
+
const { result } = renderHook(() => usePlatformSync(propsWithLinkValues));
|
|
1064
|
+
|
|
1065
|
+
act(() => {
|
|
1066
|
+
result.current.handleLinkTypeChange(ANDROID, 'external');
|
|
1067
|
+
});
|
|
1068
|
+
|
|
1069
|
+
expect(mockSetAndroidContent).toHaveBeenCalledWith(expect.objectContaining({
|
|
1070
|
+
linkType: 'external',
|
|
1071
|
+
deepLinkValue: '',
|
|
1072
|
+
externalLinkValue: '',
|
|
1073
|
+
}));
|
|
1074
|
+
});
|
|
1075
|
+
});
|
|
1076
|
+
|
|
1077
|
+
describe('Edge Cases', () => {
|
|
1078
|
+
it('should handle empty content gracefully', () => {
|
|
1079
|
+
const propsWithEmptyContent = {
|
|
1080
|
+
...defaultProps,
|
|
1081
|
+
androidContent: {},
|
|
1082
|
+
iosContent: {},
|
|
1083
|
+
};
|
|
1084
|
+
const { result } = renderHook(() => usePlatformSync(propsWithEmptyContent));
|
|
1085
|
+
|
|
1086
|
+
act(() => {
|
|
1087
|
+
result.current.handleTitleChange(ANDROID, 'Test Title');
|
|
1088
|
+
});
|
|
1089
|
+
|
|
1090
|
+
expect(mockSetAndroidContent).toHaveBeenCalledWith(expect.objectContaining({
|
|
1091
|
+
title: 'Test Title',
|
|
1092
|
+
}));
|
|
1093
|
+
expect(mockSetAndroidTitleError).toHaveBeenCalledWith('');
|
|
1094
|
+
});
|
|
1095
|
+
|
|
1096
|
+
it('should handle validation functions gracefully', () => {
|
|
1097
|
+
const propsWithValidation = {
|
|
1098
|
+
...defaultProps,
|
|
1099
|
+
validateTitle: jest.fn().mockReturnValue(''),
|
|
1100
|
+
validateMessage: jest.fn().mockReturnValue(''),
|
|
1101
|
+
};
|
|
1102
|
+
|
|
1103
|
+
const { result } = renderHook(() => usePlatformSync(propsWithValidation));
|
|
1104
|
+
|
|
1105
|
+
expect(() => {
|
|
1106
|
+
act(() => {
|
|
1107
|
+
result.current.handleTitleChange(ANDROID, 'Test Title');
|
|
1108
|
+
});
|
|
1109
|
+
}).not.toThrow();
|
|
1110
|
+
|
|
1111
|
+
expect(propsWithValidation.validateTitle).toHaveBeenCalledWith('Test Title');
|
|
1112
|
+
});
|
|
1113
|
+
|
|
1114
|
+
it('should handle undefined media type gracefully', () => {
|
|
1115
|
+
const propsWithUndefinedMediaType = {
|
|
1116
|
+
...defaultProps,
|
|
1117
|
+
androidContent: { ...defaultAndroidContent, mediaType: undefined },
|
|
1118
|
+
};
|
|
1119
|
+
const { result } = renderHook(() => usePlatformSync(propsWithUndefinedMediaType));
|
|
1120
|
+
|
|
1121
|
+
act(() => {
|
|
1122
|
+
result.current.handleMediaTypeChange(ANDROID, VIDEO);
|
|
1123
|
+
});
|
|
1124
|
+
|
|
1125
|
+
expect(mockSetAndroidContent).toHaveBeenCalledWith(expect.objectContaining({
|
|
1126
|
+
...defaultAndroidContent,
|
|
1127
|
+
mediaType: VIDEO,
|
|
1128
|
+
}));
|
|
1129
|
+
});
|
|
1130
|
+
|
|
1131
|
+
it('should handle button array with platform-specific properties', () => {
|
|
1132
|
+
const buttonsWithPlatform = [
|
|
1133
|
+
{ id: 1, text: 'Button 1', platform: ANDROID },
|
|
1134
|
+
{ id: 2, text: 'Button 2', platform: IOS },
|
|
1135
|
+
];
|
|
1136
|
+
const syncProps = { ...defaultProps, sameContent: true };
|
|
1137
|
+
const { result } = renderHook(() => usePlatformSync(syncProps));
|
|
1138
|
+
|
|
1139
|
+
act(() => {
|
|
1140
|
+
result.current.handleButtonChange(ANDROID, buttonsWithPlatform);
|
|
1141
|
+
});
|
|
1142
|
+
|
|
1143
|
+
expect(mockSetAndroidContent).toHaveBeenCalledWith(expect.objectContaining({
|
|
1144
|
+
buttons: buttonsWithPlatform,
|
|
1145
|
+
}));
|
|
1146
|
+
expect(mockSetIosContent).toHaveBeenCalledWith(expect.objectContaining({
|
|
1147
|
+
buttons: expect.arrayContaining([
|
|
1148
|
+
expect.objectContaining({ platform: IOS }),
|
|
1149
|
+
expect.objectContaining({ platform: IOS }),
|
|
1150
|
+
]),
|
|
1151
|
+
}));
|
|
1152
|
+
});
|
|
1153
|
+
});
|
|
1154
|
+
|
|
1155
|
+
// Additional test case for line 152 coverage - IMAGE to VIDEO/GIF transitions
|
|
1156
|
+
describe('Media Type Changes - Line 152 Coverage', () => {
|
|
1157
|
+
it('should clear image data when switching from IMAGE to VIDEO (Line 152 - Android)', () => {
|
|
1158
|
+
const propsWithImageContent = {
|
|
1159
|
+
...defaultProps,
|
|
1160
|
+
androidContent: { ...defaultAndroidContent, mediaType: IMAGE },
|
|
1161
|
+
};
|
|
1162
|
+
|
|
1163
|
+
mockSetAndroidContent.mockImplementation((updater) => {
|
|
1164
|
+
if (typeof updater === 'function') {
|
|
1165
|
+
updater(propsWithImageContent.androidContent);
|
|
1166
|
+
}
|
|
1167
|
+
});
|
|
1168
|
+
|
|
1169
|
+
const { result } = renderHook(() => usePlatformSync(propsWithImageContent));
|
|
1170
|
+
|
|
1171
|
+
act(() => {
|
|
1172
|
+
result.current.handleMediaTypeChange(ANDROID, VIDEO);
|
|
1173
|
+
});
|
|
1174
|
+
|
|
1175
|
+
expect(mockUpdateOnMpushImageReUpload).toHaveBeenCalled();
|
|
1176
|
+
expect(mockUpdateOnMpushVideoReUpload).not.toHaveBeenCalled();
|
|
1177
|
+
});
|
|
1178
|
+
|
|
1179
|
+
it('should clear image data when switching from IMAGE to GIF (Line 152 - Android)', () => {
|
|
1180
|
+
const propsWithImageContent = {
|
|
1181
|
+
...defaultProps,
|
|
1182
|
+
androidContent: { ...defaultAndroidContent, mediaType: IMAGE },
|
|
1183
|
+
};
|
|
1184
|
+
|
|
1185
|
+
mockSetAndroidContent.mockImplementation((updater) => {
|
|
1186
|
+
if (typeof updater === 'function') {
|
|
1187
|
+
updater(propsWithImageContent.androidContent);
|
|
1188
|
+
}
|
|
1189
|
+
});
|
|
1190
|
+
|
|
1191
|
+
const { result } = renderHook(() => usePlatformSync(propsWithImageContent));
|
|
1192
|
+
|
|
1193
|
+
act(() => {
|
|
1194
|
+
result.current.handleMediaTypeChange(ANDROID, GIF);
|
|
1195
|
+
});
|
|
1196
|
+
|
|
1197
|
+
expect(mockUpdateOnMpushImageReUpload).toHaveBeenCalled();
|
|
1198
|
+
expect(mockUpdateOnMpushVideoReUpload).not.toHaveBeenCalled();
|
|
1199
|
+
});
|
|
1200
|
+
|
|
1201
|
+
it('should clear image data when switching from IMAGE to VIDEO (Line 152 - iOS)', () => {
|
|
1202
|
+
const propsWithImageContent = {
|
|
1203
|
+
...defaultProps,
|
|
1204
|
+
iosContent: { ...defaultIosContent, mediaType: IMAGE },
|
|
1205
|
+
};
|
|
1206
|
+
|
|
1207
|
+
mockSetIosContent.mockImplementation((updater) => {
|
|
1208
|
+
if (typeof updater === 'function') {
|
|
1209
|
+
updater(propsWithImageContent.iosContent);
|
|
1210
|
+
}
|
|
1211
|
+
});
|
|
1212
|
+
|
|
1213
|
+
const { result } = renderHook(() => usePlatformSync(propsWithImageContent));
|
|
1214
|
+
|
|
1215
|
+
act(() => {
|
|
1216
|
+
result.current.handleMediaTypeChange(IOS, VIDEO);
|
|
1217
|
+
});
|
|
1218
|
+
|
|
1219
|
+
expect(mockUpdateOnMpushImageReUpload).toHaveBeenCalled();
|
|
1220
|
+
expect(mockUpdateOnMpushVideoReUpload).not.toHaveBeenCalled();
|
|
1221
|
+
});
|
|
1222
|
+
|
|
1223
|
+
it('should clear image data when switching from IMAGE to GIF (Line 152 - iOS)', () => {
|
|
1224
|
+
const propsWithImageContent = {
|
|
1225
|
+
...defaultProps,
|
|
1226
|
+
iosContent: { ...defaultIosContent, mediaType: IMAGE },
|
|
1227
|
+
};
|
|
1228
|
+
|
|
1229
|
+
mockSetIosContent.mockImplementation((updater) => {
|
|
1230
|
+
if (typeof updater === 'function') {
|
|
1231
|
+
updater(propsWithImageContent.iosContent);
|
|
1232
|
+
}
|
|
1233
|
+
});
|
|
1234
|
+
|
|
1235
|
+
const { result } = renderHook(() => usePlatformSync(propsWithImageContent));
|
|
1236
|
+
|
|
1237
|
+
act(() => {
|
|
1238
|
+
result.current.handleMediaTypeChange(IOS, GIF);
|
|
1239
|
+
});
|
|
1240
|
+
|
|
1241
|
+
expect(mockUpdateOnMpushImageReUpload).toHaveBeenCalled();
|
|
1242
|
+
expect(mockUpdateOnMpushVideoReUpload).not.toHaveBeenCalled();
|
|
1243
|
+
});
|
|
1244
|
+
|
|
1245
|
+
it('should clear image data when switching from IMAGE to VIDEO with sync enabled (Line 152)', () => {
|
|
1246
|
+
const syncProps = { ...defaultProps, sameContent: true };
|
|
1247
|
+
const propsWithImageContent = {
|
|
1248
|
+
...syncProps,
|
|
1249
|
+
androidContent: { ...defaultAndroidContent, mediaType: IMAGE },
|
|
1250
|
+
};
|
|
1251
|
+
|
|
1252
|
+
mockSetAndroidContent.mockImplementation((updater) => {
|
|
1253
|
+
if (typeof updater === 'function') {
|
|
1254
|
+
updater(propsWithImageContent.androidContent);
|
|
1255
|
+
}
|
|
1256
|
+
});
|
|
1257
|
+
|
|
1258
|
+
const { result } = renderHook(() => usePlatformSync(propsWithImageContent));
|
|
1259
|
+
|
|
1260
|
+
act(() => {
|
|
1261
|
+
result.current.handleMediaTypeChange(ANDROID, VIDEO);
|
|
1262
|
+
});
|
|
1263
|
+
|
|
1264
|
+
expect(mockUpdateOnMpushImageReUpload).toHaveBeenCalled();
|
|
1265
|
+
expect(mockUpdateOnMpushVideoReUpload).not.toHaveBeenCalled();
|
|
1266
|
+
// Should also sync to iOS
|
|
1267
|
+
expect(mockSetIosContent).toHaveBeenCalledWith(expect.objectContaining({
|
|
1268
|
+
mediaType: VIDEO,
|
|
1269
|
+
}));
|
|
1270
|
+
});
|
|
1271
|
+
|
|
1272
|
+
it('should clear image data when switching from IMAGE to GIF with sync enabled (Line 152)', () => {
|
|
1273
|
+
const syncProps = { ...defaultProps, sameContent: true };
|
|
1274
|
+
const propsWithImageContent = {
|
|
1275
|
+
...syncProps,
|
|
1276
|
+
iosContent: { ...defaultIosContent, mediaType: IMAGE },
|
|
1277
|
+
};
|
|
1278
|
+
|
|
1279
|
+
mockSetIosContent.mockImplementation((updater) => {
|
|
1280
|
+
if (typeof updater === 'function') {
|
|
1281
|
+
updater(propsWithImageContent.iosContent);
|
|
1282
|
+
}
|
|
1283
|
+
});
|
|
1284
|
+
|
|
1285
|
+
const { result } = renderHook(() => usePlatformSync(propsWithImageContent));
|
|
1286
|
+
|
|
1287
|
+
act(() => {
|
|
1288
|
+
result.current.handleMediaTypeChange(IOS, GIF);
|
|
1289
|
+
});
|
|
1290
|
+
|
|
1291
|
+
expect(mockUpdateOnMpushImageReUpload).toHaveBeenCalled();
|
|
1292
|
+
expect(mockUpdateOnMpushVideoReUpload).not.toHaveBeenCalled();
|
|
1293
|
+
// Should also sync to Android
|
|
1294
|
+
expect(mockSetAndroidContent).toHaveBeenCalledWith(expect.objectContaining({
|
|
1295
|
+
mediaType: GIF,
|
|
1296
|
+
}));
|
|
1297
|
+
});
|
|
1298
|
+
});
|
|
1299
|
+
});
|