@capillarytech/creatives-library 9.2.0 → 9.2.1-alpha.sprint-cap-214249.42
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/constants/unified.js +0 -1
- package/package.json +1 -1
- package/utils/common.js +0 -6
- package/utils/createMobilePushPayload.js +56 -51
- package/utils/tests/createMobilePushPayload.test.js +162 -10
- package/v2Components/CapMpushCTA/index.js +47 -57
- package/v2Components/CapMpushCTA/index.scss +43 -5
- package/v2Components/CapMpushCTA/tests/index.test.js +150 -0
- package/v2Components/CommonTestAndPreview/UnifiedPreview/MobilePushPreviewContent.js +11 -8
- package/v2Components/CommonTestAndPreview/UnifiedPreview/_unifiedPreview.scss +13 -1
- package/v2Components/CommonTestAndPreview/constants.js +2 -0
- package/v2Components/CommonTestAndPreview/index.js +48 -10
- package/v2Components/CommonTestAndPreview/tests/UnifiedPreview/MobilePushPreviewContent.test.js +83 -5
- package/v2Components/CommonTestAndPreview/tests/index.test.js +86 -0
- package/v2Components/TemplatePreview/_templatePreview.scss +12 -2
- package/v2Components/TemplatePreview/index.js +14 -12
- package/v2Components/TemplatePreview/tests/index.test.js +69 -0
- package/v2Containers/CreativesContainer/SlideBoxContent.js +4 -6
- package/v2Containers/CreativesContainer/index.js +2 -1
- package/v2Containers/CreativesContainer/tests/SlideBoxContent.test.js +43 -0
- package/v2Containers/MobilePushNew/components/CtaButtons.js +52 -47
- package/v2Containers/MobilePushNew/components/MediaUploaders.js +314 -222
- package/v2Containers/MobilePushNew/components/PlatformContentFields.js +161 -130
- package/v2Containers/MobilePushNew/components/TapLinkActions.js +76 -0
- package/v2Containers/MobilePushNew/components/tests/CtaButtons.test.js +30 -208
- package/v2Containers/MobilePushNew/components/tests/MediaUploaders.test.js +484 -123
- package/v2Containers/MobilePushNew/components/tests/PlatformContentFields.test.js +152 -46
- package/v2Containers/MobilePushNew/constants.js +12 -0
- package/v2Containers/MobilePushNew/hooks/tests/usePlatformSync.test.js +63 -1
- package/v2Containers/MobilePushNew/hooks/tests/useUpload.test.js +78 -0
- package/v2Containers/MobilePushNew/hooks/usePlatformSync.js +40 -1
- package/v2Containers/MobilePushNew/hooks/useUpload.js +42 -46
- package/v2Containers/MobilePushNew/index.js +503 -273
- package/v2Containers/MobilePushNew/index.scss +215 -4
- package/v2Containers/MobilePushNew/messages.js +106 -6
- package/v2Containers/MobilePushNew/tests/index.test.js +482 -1
- package/v2Containers/MobilePushNew/tests/utils.test.js +122 -0
- package/v2Containers/MobilePushNew/utils.js +107 -0
- package/v2Containers/Templates/_templates.scss +10 -2
- package/v2Containers/Templates/index.js +83 -81
- package/v2Containers/Templates/tests/index.test.js +68 -0
package/constants/unified.js
CHANGED
|
@@ -46,7 +46,6 @@ export const HOSPITALITY_BASED_SCOPE = 'HOSPITALITY_BASED_SCOPE';
|
|
|
46
46
|
export const REGISTRATION_CUSTOM_FIELD = 'Registration custom fields';
|
|
47
47
|
export const GIFT_CARDS = 'GIFT_CARDS';
|
|
48
48
|
export const PROMO_ENGINE = 'PROMO_ENGINE';
|
|
49
|
-
export const ENABLE_NEW_MPUSH = 'ENABLE_NEW_MPUSH';
|
|
50
49
|
export const ENABLE_NEW_EDITOR_FLOW_INAPP = 'ENABLE_NEW_EDITOR_FLOW_INAPP';
|
|
51
50
|
// Per-channel flags for the FormBuilder V3 migration. Each routes its channel to
|
|
52
51
|
// the new functional FormBuilder; later channels get their own flags (…_EMAIL).
|
package/package.json
CHANGED
package/utils/common.js
CHANGED
|
@@ -24,7 +24,6 @@ import {
|
|
|
24
24
|
ENABLE_WECHAT,
|
|
25
25
|
ENABLE_WEBPUSH,
|
|
26
26
|
SUPPORT_CK_EDITOR,
|
|
27
|
-
ENABLE_NEW_MPUSH,
|
|
28
27
|
ENABLE_NEW_EDITOR_FLOW_INAPP,
|
|
29
28
|
ENABLE_NEW_FORMBUILDER_SMS,
|
|
30
29
|
ENABLE_NEW_FORMBUILDER_MPUSH,
|
|
@@ -144,11 +143,6 @@ export const isEmailUnsubscribeTagOptional = Auth.hasFeatureAccess.bind(
|
|
|
144
143
|
EMAIL_UNSUBSCRIBE_TAG_MANDATORY,
|
|
145
144
|
);
|
|
146
145
|
|
|
147
|
-
export const hasNewMobilePushFeatureEnabled = Auth.hasFeatureAccess.bind(
|
|
148
|
-
null,
|
|
149
|
-
ENABLE_NEW_MPUSH,
|
|
150
|
-
);
|
|
151
|
-
|
|
152
146
|
export const hasNewEditorFlowInAppEnabled = Auth.hasFeatureAccess.bind(
|
|
153
147
|
null,
|
|
154
148
|
ENABLE_NEW_EDITOR_FLOW_INAPP,
|
|
@@ -11,6 +11,7 @@ import {
|
|
|
11
11
|
TEXT,
|
|
12
12
|
} from "../v2Containers/MobilePushNew/constants";
|
|
13
13
|
import messages from '../v2Containers/MobilePushNew/messages';
|
|
14
|
+
import { appendDeepLinkParams } from '../v2Containers/MobilePushNew/utils';
|
|
14
15
|
|
|
15
16
|
/**
|
|
16
17
|
* Constructs the payload for Mobile Push, supporting both legacy and rich media as per backend contract.
|
|
@@ -27,6 +28,7 @@ import messages from '../v2Containers/MobilePushNew/messages';
|
|
|
27
28
|
* @param {Object} params.accountData - Account data for the payload
|
|
28
29
|
* @param {boolean} params.sameContent - Whether content is shared between platforms
|
|
29
30
|
* @param {Object} params.options - Additional options
|
|
31
|
+
* @param {string} [params.options.skipPlatform] - ANDROID or IOS: leave out a supported platform the user chose not to configure
|
|
30
32
|
* @param {Object} params.intl - Internationalization object for messages
|
|
31
33
|
*/
|
|
32
34
|
const createMobilePushPayload = ({
|
|
@@ -41,8 +43,8 @@ const createMobilePushPayload = ({
|
|
|
41
43
|
intl,
|
|
42
44
|
}) => {
|
|
43
45
|
// Platform support checks must be at the top
|
|
44
|
-
const isAndroidSupported = accountData?.configs?.android === '1';
|
|
45
|
-
const isIosSupported = accountData?.configs?.ios === '1';
|
|
46
|
+
const isAndroidSupported = accountData?.configs?.android === '1' && options?.skipPlatform !== ANDROID;
|
|
47
|
+
const isIosSupported = accountData?.configs?.ios === '1' && options?.skipPlatform !== IOS;
|
|
46
48
|
|
|
47
49
|
const {
|
|
48
50
|
accountId: accountIdFromAccountData, id, licenseCode: licenseCodeFromAccountData, sourceAccountIdentifier, sourceType: sourceTypeFromAccountData, sourceTypeName,
|
|
@@ -121,6 +123,47 @@ const createMobilePushPayload = ({
|
|
|
121
123
|
return payload;
|
|
122
124
|
};
|
|
123
125
|
|
|
126
|
+
/**
|
|
127
|
+
* Carousel cards as Save sends them (also used by the Test & Preview payload)
|
|
128
|
+
* @param {Array} carouselData - Editor carousel cards
|
|
129
|
+
* @returns {Array} Cards with deep link keys appended to button links
|
|
130
|
+
*/
|
|
131
|
+
export function buildCarouselCards(carouselData = []) {
|
|
132
|
+
return (carouselData || []).map((card) => {
|
|
133
|
+
const {
|
|
134
|
+
mediaType,
|
|
135
|
+
imageUrl,
|
|
136
|
+
videoSrc,
|
|
137
|
+
videoPreviewImg,
|
|
138
|
+
buttons,
|
|
139
|
+
} = card || {};
|
|
140
|
+
|
|
141
|
+
return {
|
|
142
|
+
mediaType: mediaType || IMAGE.toLowerCase(),
|
|
143
|
+
imageUrl: imageUrl || '',
|
|
144
|
+
videoSrc: videoSrc || '',
|
|
145
|
+
// Thumbnail, so the phone preview can show the video card when editing
|
|
146
|
+
...(videoPreviewImg && { videoPreviewImg }),
|
|
147
|
+
buttons: buttons ? buttons.map((button) => {
|
|
148
|
+
if (!button) return button;
|
|
149
|
+
// isSaved is the editor's own Save state; it doesn't go to the backend
|
|
150
|
+
const { isSaved, ...buttonData } = button;
|
|
151
|
+
const { linkType: buttonLinkType, deepLinkKeys, deepLinkValue: buttonDeepLinkValue } = buttonData;
|
|
152
|
+
if (buttonLinkType === DEEP_LINK && deepLinkKeys && buttonDeepLinkValue) {
|
|
153
|
+
const deepLinkKeysArray = Array.isArray(deepLinkKeys) ? deepLinkKeys : [deepLinkKeys];
|
|
154
|
+
const updatedDeepLinkValue = appendDeepLinkKeysToUrl(buttonDeepLinkValue, deepLinkKeysArray);
|
|
155
|
+
|
|
156
|
+
return {
|
|
157
|
+
...buttonData,
|
|
158
|
+
deepLinkValue: updatedDeepLinkValue,
|
|
159
|
+
};
|
|
160
|
+
}
|
|
161
|
+
return buttonData;
|
|
162
|
+
}) : [],
|
|
163
|
+
};
|
|
164
|
+
});
|
|
165
|
+
}
|
|
166
|
+
|
|
124
167
|
/**
|
|
125
168
|
* Builds platform-specific content for the payload
|
|
126
169
|
* @param {Object} content - Platform content (Android/iOS)
|
|
@@ -129,7 +172,7 @@ const createMobilePushPayload = ({
|
|
|
129
172
|
* @param {string} platform - Platform (ANDROID/IOS)
|
|
130
173
|
* @returns {Object} Platform-specific content
|
|
131
174
|
*/
|
|
132
|
-
function buildPlatformContent(content, imageSrc, mpushVideoSrcAndPreview, platform) {
|
|
175
|
+
export function buildPlatformContent(content, imageSrc, mpushVideoSrcAndPreview, platform) {
|
|
133
176
|
const {
|
|
134
177
|
title = '',
|
|
135
178
|
message = '',
|
|
@@ -153,13 +196,7 @@ function buildPlatformContent(content, imageSrc, mpushVideoSrcAndPreview, platfo
|
|
|
153
196
|
let finalDeepLinkValue = deepLinkValue;
|
|
154
197
|
|
|
155
198
|
if (linkType === DEEP_LINK && deepLinkKeysValue?.length > 0) {
|
|
156
|
-
|
|
157
|
-
const urlHasKeys = deepLinkKeysValue?.some((key) => deepLinkValue?.includes(`${key}=${key}`));
|
|
158
|
-
|
|
159
|
-
// Only append keys if they're not already in the URL
|
|
160
|
-
if (!urlHasKeys) {
|
|
161
|
-
finalDeepLinkValue = appendDeepLinkKeysToUrl(deepLinkValue, deepLinkKeysValue);
|
|
162
|
-
}
|
|
199
|
+
finalDeepLinkValue = appendDeepLinkKeysToUrl(deepLinkValue, deepLinkKeysValue);
|
|
163
200
|
}
|
|
164
201
|
|
|
165
202
|
platformContent.cta = {
|
|
@@ -184,7 +221,8 @@ function buildPlatformContent(content, imageSrc, mpushVideoSrcAndPreview, platfo
|
|
|
184
221
|
platformContent.expandableDetails.style = VIDEO;
|
|
185
222
|
platformContent.expandableDetails.message = message;
|
|
186
223
|
platformContent.expandableDetails.media = [{
|
|
187
|
-
|
|
224
|
+
// This platform's own video; mpushVideoSrcAndPreview is shared by both tabs
|
|
225
|
+
url: content?.videoSrc || content?.mediaList?.[0]?.url || '',
|
|
188
226
|
text: content?.mediaList?.[0]?.text || '',
|
|
189
227
|
type: VIDEO,
|
|
190
228
|
}];
|
|
@@ -201,11 +239,11 @@ function buildPlatformContent(content, imageSrc, mpushVideoSrcAndPreview, platfo
|
|
|
201
239
|
type: type.toLowerCase(),
|
|
202
240
|
}];
|
|
203
241
|
} else {
|
|
204
|
-
//
|
|
242
|
+
// No mediaList: use this platform's own GIF
|
|
205
243
|
platformContent.expandableDetails.style = GIF;
|
|
206
244
|
platformContent.expandableDetails.message = message;
|
|
207
245
|
platformContent.expandableDetails.media = [{
|
|
208
|
-
url:
|
|
246
|
+
url: content?.videoSrc || '',
|
|
209
247
|
text: '',
|
|
210
248
|
type: GIF, // Backend expects GIF type for GIFs
|
|
211
249
|
}];
|
|
@@ -218,33 +256,7 @@ function buildPlatformContent(content, imageSrc, mpushVideoSrcAndPreview, platfo
|
|
|
218
256
|
|
|
219
257
|
// Handle carouselData
|
|
220
258
|
if (content?.carouselData?.length > 0) {
|
|
221
|
-
platformContent.expandableDetails.carouselData = content.carouselData
|
|
222
|
-
const {
|
|
223
|
-
mediaType,
|
|
224
|
-
imageUrl,
|
|
225
|
-
videoSrc,
|
|
226
|
-
buttons,
|
|
227
|
-
} = card || {};
|
|
228
|
-
|
|
229
|
-
return {
|
|
230
|
-
mediaType: mediaType || IMAGE.toLowerCase(),
|
|
231
|
-
imageUrl: imageUrl || '',
|
|
232
|
-
videoSrc: videoSrc || '',
|
|
233
|
-
buttons: buttons ? buttons.map((button) => {
|
|
234
|
-
const { linkType: buttonLinkType, deepLinkKeys, deepLinkValue: buttonDeepLinkValue } = button || {};
|
|
235
|
-
if (buttonLinkType === DEEP_LINK && deepLinkKeys && buttonDeepLinkValue) {
|
|
236
|
-
const deepLinkKeysArray = Array.isArray(deepLinkKeys) ? deepLinkKeys : [deepLinkKeys];
|
|
237
|
-
const updatedDeepLinkValue = appendDeepLinkKeysToUrl(buttonDeepLinkValue, deepLinkKeysArray);
|
|
238
|
-
|
|
239
|
-
return {
|
|
240
|
-
...button,
|
|
241
|
-
deepLinkValue: updatedDeepLinkValue,
|
|
242
|
-
};
|
|
243
|
-
}
|
|
244
|
-
return button;
|
|
245
|
-
}) : [],
|
|
246
|
-
};
|
|
247
|
-
});
|
|
259
|
+
platformContent.expandableDetails.carouselData = buildCarouselCards(content.carouselData);
|
|
248
260
|
}
|
|
249
261
|
|
|
250
262
|
// Handle mediaList
|
|
@@ -305,21 +317,14 @@ function buildCustomFields(content) {
|
|
|
305
317
|
}
|
|
306
318
|
|
|
307
319
|
/**
|
|
308
|
-
* Appends deep link
|
|
320
|
+
* Appends deep link params to URL
|
|
309
321
|
* @param {string} url - Base URL
|
|
310
|
-
* @param {Array} keys -
|
|
311
|
-
* @returns {string} URL with
|
|
322
|
+
* @param {Array} keys - "key=value" entries (an old entry without "=" means key=key)
|
|
323
|
+
* @returns {string} URL with the params
|
|
312
324
|
*/
|
|
313
325
|
export function appendDeepLinkKeysToUrl(url, keys) {
|
|
314
326
|
if (!url || !keys || !Array.isArray(keys) || keys?.length === 0) return url;
|
|
315
|
-
|
|
316
|
-
const separator = url.includes('?') ? '&' : '?';
|
|
317
|
-
const validKeys = keys.filter((key) => typeof key === 'string' && key?.length > 0);
|
|
318
|
-
if (validKeys?.length === 0) return url;
|
|
319
|
-
|
|
320
|
-
const keyParams = validKeys.map((key) => `${key}=${key}`).join('&');
|
|
321
|
-
|
|
322
|
-
return `${url}${separator}${keyParams}`;
|
|
327
|
+
return appendDeepLinkParams(url, keys);
|
|
323
328
|
}
|
|
324
329
|
|
|
325
330
|
export default createMobilePushPayload;
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { IntlProvider } from 'react-intl';
|
|
2
|
-
import createMobilePushPayload from '../createMobilePushPayload';
|
|
2
|
+
import createMobilePushPayload, { buildCarouselCards } from '../createMobilePushPayload';
|
|
3
3
|
import messages from '../../v2Containers/MobilePushNew/messages';
|
|
4
4
|
|
|
5
5
|
// Create a mock intl object
|
|
@@ -48,6 +48,7 @@ jest.mock('../createMobilePushPayload', () => {
|
|
|
48
48
|
__esModule: true,
|
|
49
49
|
default: mockCreateMobilePushPayload,
|
|
50
50
|
appendDeepLinkKeysToUrl: originalModule.appendDeepLinkKeysToUrl,
|
|
51
|
+
buildCarouselCards: originalModule.buildCarouselCards,
|
|
51
52
|
};
|
|
52
53
|
});
|
|
53
54
|
|
|
@@ -261,6 +262,21 @@ describe('createMobilePushPayload', () => {
|
|
|
261
262
|
accountData: unsupportedAccountData,
|
|
262
263
|
})).not.toThrow();
|
|
263
264
|
});
|
|
265
|
+
|
|
266
|
+
it.each([
|
|
267
|
+
['IOS', 'ANDROID', { androidContent: { title: 'Title', message: 'Message' }, iosContent: { title: '', message: '' } }],
|
|
268
|
+
['ANDROID', 'IOS', { androidContent: { title: '', message: '' }, iosContent: { title: 'Title', message: 'Message' } }],
|
|
269
|
+
])('leaves out a supported platform passed as skipPlatform (%s)', (skipPlatform, keptPlatform, content) => {
|
|
270
|
+
const result = callWithIntl({
|
|
271
|
+
templateName: 'Test',
|
|
272
|
+
...content,
|
|
273
|
+
accountData: mockAccountData,
|
|
274
|
+
options: { skipPlatform },
|
|
275
|
+
});
|
|
276
|
+
|
|
277
|
+
expect(result.versions.base[skipPlatform]).toBeUndefined();
|
|
278
|
+
expect(result.versions.base[keptPlatform]).toBeDefined();
|
|
279
|
+
});
|
|
264
280
|
});
|
|
265
281
|
|
|
266
282
|
// Account Data Validation Tests
|
|
@@ -335,33 +351,67 @@ describe('createMobilePushPayload', () => {
|
|
|
335
351
|
expect(result.versions.base.ANDROID.expandableDetails.image).toBe('test-image.jpg');
|
|
336
352
|
});
|
|
337
353
|
|
|
338
|
-
it('should handle VIDEO media type with
|
|
354
|
+
it('should handle VIDEO media type with the platform videoSrc', () => {
|
|
339
355
|
const result = callWithIntl({
|
|
340
356
|
templateName: 'Test',
|
|
341
357
|
androidContent: {
|
|
342
358
|
title: 'Title',
|
|
343
359
|
message: 'Message',
|
|
344
360
|
mediaType: 'VIDEO',
|
|
361
|
+
videoSrc: 'test-video.mp4',
|
|
345
362
|
},
|
|
346
363
|
iosContent: { title: 'Title', message: 'Message' },
|
|
347
364
|
accountData: mockAccountData,
|
|
348
|
-
|
|
365
|
+
// The shared slot is ignored; it can hold the other tab's video
|
|
366
|
+
mpushVideoSrcAndPreview: { mpushVideoSrc: 'other-tab.mp4' },
|
|
349
367
|
});
|
|
350
368
|
expect(result.versions.base.ANDROID.expandableDetails.media[0].url).toBe('test-video.mp4');
|
|
351
369
|
expect(result.versions.base.ANDROID.expandableDetails.media[0].type).toBe('VIDEO');
|
|
352
370
|
});
|
|
353
371
|
|
|
354
|
-
it('should
|
|
372
|
+
it('should fall back to mediaList for a VIDEO with no videoSrc', () => {
|
|
373
|
+
const result = callWithIntl({
|
|
374
|
+
templateName: 'Test',
|
|
375
|
+
androidContent: {
|
|
376
|
+
title: 'Title',
|
|
377
|
+
message: 'Message',
|
|
378
|
+
mediaType: 'VIDEO',
|
|
379
|
+
mediaList: [{ url: 'saved.mp4', text: 'Saved' }],
|
|
380
|
+
},
|
|
381
|
+
iosContent: { title: 'Title', message: 'Message' },
|
|
382
|
+
accountData: mockAccountData,
|
|
383
|
+
});
|
|
384
|
+
expect(result.versions.base.ANDROID.expandableDetails.media[0]).toEqual({ url: 'saved.mp4', text: 'Saved', type: 'VIDEO' });
|
|
385
|
+
});
|
|
386
|
+
|
|
387
|
+
it('saves each platform its own video', () => {
|
|
388
|
+
const result = callWithIntl({
|
|
389
|
+
templateName: 'Test',
|
|
390
|
+
androidContent: {
|
|
391
|
+
title: 'Title', message: 'Message', mediaType: 'VIDEO', videoSrc: 'a.mp4',
|
|
392
|
+
},
|
|
393
|
+
iosContent: {
|
|
394
|
+
title: 'Title', message: 'Message', mediaType: 'VIDEO', videoSrc: 'b.mp4',
|
|
395
|
+
},
|
|
396
|
+
accountData: mockAccountData,
|
|
397
|
+
mpushVideoSrcAndPreview: { mpushVideoSrc: 'b.mp4' },
|
|
398
|
+
});
|
|
399
|
+
expect(result.versions.base.ANDROID.expandableDetails.media[0].url).toBe('a.mp4');
|
|
400
|
+
expect(result.versions.base.IOS.expandableDetails.media[0].url).toBe('b.mp4');
|
|
401
|
+
});
|
|
402
|
+
|
|
403
|
+
it('should handle GIF media type with the platform videoSrc', () => {
|
|
355
404
|
const result = callWithIntl({
|
|
356
405
|
templateName: 'Test',
|
|
357
406
|
androidContent: {
|
|
358
407
|
title: 'Title',
|
|
359
408
|
message: 'Message',
|
|
360
409
|
mediaType: 'GIF',
|
|
410
|
+
videoSrc: 'test-gif.gif',
|
|
361
411
|
},
|
|
362
412
|
iosContent: { title: 'Title', message: 'Message' },
|
|
363
413
|
accountData: mockAccountData,
|
|
364
|
-
mpushVideoSrcAndPreview: { mpushVideoSrc: '
|
|
414
|
+
mpushVideoSrcAndPreview: { mpushVideoSrc: 'other-tab.gif' },
|
|
365
415
|
});
|
|
366
416
|
expect(result.versions.base.ANDROID.expandableDetails.media[0].url).toBe('test-gif.gif');
|
|
367
417
|
expect(result.versions.base.ANDROID.expandableDetails.media[0].type).toBe('GIF');
|
|
@@ -611,7 +661,7 @@ describe('createMobilePushPayload', () => {
|
|
|
611
661
|
});
|
|
612
662
|
});
|
|
613
663
|
|
|
614
|
-
it('should
|
|
664
|
+
it('should add the missing key when URL contains some keys but not all', () => {
|
|
615
665
|
const result = callWithIntl({
|
|
616
666
|
templateName: 'Test',
|
|
617
667
|
androidContent: {
|
|
@@ -627,10 +677,47 @@ describe('createMobilePushPayload', () => {
|
|
|
627
677
|
});
|
|
628
678
|
expect(result.versions.base.ANDROID.cta).toEqual({
|
|
629
679
|
type: 'DEEP_LINK',
|
|
630
|
-
actionLink: 'app://deep-link?key1=key1',
|
|
680
|
+
actionLink: 'app://deep-link?key1=key1&key2=key2',
|
|
631
681
|
});
|
|
632
682
|
});
|
|
633
683
|
|
|
684
|
+
it('should send the configured key with the typed value', () => {
|
|
685
|
+
const result = callWithIntl({
|
|
686
|
+
templateName: 'Test',
|
|
687
|
+
androidContent: {
|
|
688
|
+
title: 'Title',
|
|
689
|
+
message: 'Message',
|
|
690
|
+
actionOnClick: true,
|
|
691
|
+
linkType: 'DEEP_LINK',
|
|
692
|
+
deepLinkValue: 'https://www.youtube.com/',
|
|
693
|
+
deepLinkKeysValue: ['testing_purpose=androidDeeplink'],
|
|
694
|
+
},
|
|
695
|
+
iosContent: { title: 'Title', message: 'Message' },
|
|
696
|
+
accountData: mockAccountData,
|
|
697
|
+
});
|
|
698
|
+
expect(result.versions.base.ANDROID.cta).toEqual({
|
|
699
|
+
type: 'DEEP_LINK',
|
|
700
|
+
actionLink: 'https://www.youtube.com/?testing_purpose=androidDeeplink',
|
|
701
|
+
});
|
|
702
|
+
});
|
|
703
|
+
|
|
704
|
+
it('should replace a saved value instead of adding the key twice', () => {
|
|
705
|
+
const result = callWithIntl({
|
|
706
|
+
templateName: 'Test',
|
|
707
|
+
androidContent: {
|
|
708
|
+
title: 'Title',
|
|
709
|
+
message: 'Message',
|
|
710
|
+
actionOnClick: true,
|
|
711
|
+
linkType: 'DEEP_LINK',
|
|
712
|
+
deepLinkValue: 'app://home?src=push&id=5',
|
|
713
|
+
deepLinkKeysValue: ['id=7'],
|
|
714
|
+
},
|
|
715
|
+
iosContent: { title: 'Title', message: 'Message' },
|
|
716
|
+
accountData: mockAccountData,
|
|
717
|
+
});
|
|
718
|
+
expect(result.versions.base.ANDROID.cta.actionLink).toBe('app://home?src=push&id=7');
|
|
719
|
+
});
|
|
720
|
+
|
|
634
721
|
it('should handle deep link CTA with empty deepLinkKeysValue', () => {
|
|
635
722
|
const result = callWithIntl({
|
|
636
723
|
templateName: 'Test',
|
|
@@ -860,13 +947,12 @@ describe('createMobilePushPayload', () => {
|
|
|
860
947
|
title: 'Title',
|
|
861
948
|
message: 'Message',
|
|
862
949
|
mediaType: 'GIF',
|
|
950
|
+
videoSrc: 'test-gif.gif',
|
|
863
951
|
},
|
|
864
952
|
iosContent: { title: 'Title', message: 'Message' },
|
|
865
953
|
accountData: mockAccountData,
|
|
866
|
-
mpushVideoSrcAndPreview: { mpushVideoSrc: 'test-gif.gif' },
|
|
867
954
|
});
|
|
868
|
-
|
|
869
|
-
expect(result.versions.base.ANDROID.expandableDetails.media[0].type).toBe('GIF');
|
|
955
|
+
expect(result.versions.base.ANDROID.expandableDetails.media[0]).toEqual({ url: 'test-gif.gif', text: '', type: 'GIF' });
|
|
870
956
|
});
|
|
871
957
|
|
|
872
958
|
it('should handle options with custom mode', () => {
|
|
@@ -1322,3 +1408,69 @@ describe('createMobilePushPayload', () => {
|
|
|
1322
1408
|
});
|
|
1323
1409
|
});
|
|
1324
1410
|
});
|
|
1411
|
+
|
|
1412
|
+
describe('buildCarouselCards', () => {
|
|
1413
|
+
it.each([
|
|
1414
|
+
['no argument', undefined],
|
|
1415
|
+
['null', null],
|
|
1416
|
+
['an empty array', []],
|
|
1417
|
+
])('returns [] for %s', (_label, input) => {
|
|
1418
|
+
expect(buildCarouselCards(input)).toEqual([]);
|
|
1419
|
+
});
|
|
1420
|
+
|
|
1421
|
+
it('fills defaults for a missing card', () => {
|
|
1422
|
+
expect(buildCarouselCards([null])).toEqual([
|
|
1423
|
+
{ mediaType: 'image', imageUrl: '', videoSrc: '', buttons: [] },
|
|
1424
|
+
]);
|
|
1425
|
+
});
|
|
1426
|
+
|
|
1427
|
+
it('leaves the editor-only isSaved flag out of card buttons', () => {
|
|
1428
|
+
const [card] = buildCarouselCards([{
|
|
1429
|
+
mediaType: 'image',
|
|
1430
|
+
imageUrl: 'a.jpg',
|
|
1431
|
+
buttons: [{
|
|
1432
|
+
actionOnClick: true, linkType: 'EXTERNAL_LINK', externalLinkValue: 'https://a.com', isSaved: true,
|
|
1433
|
+
}],
|
|
1434
|
+
}]);
|
|
1435
|
+
expect(card.buttons[0]).toEqual({ actionOnClick: true, linkType: 'EXTERNAL_LINK', externalLinkValue: 'https://a.com' });
|
|
1436
|
+
});
|
|
1437
|
+
|
|
1438
|
+
it('keeps the video thumbnail only when there is one', () => {
|
|
1439
|
+
const [withThumb, withoutThumb] = buildCarouselCards([
|
|
1440
|
+
{ mediaType: 'video', videoSrc: 'a.mp4', videoPreviewImg: 'a.png' },
|
|
1441
|
+
{ mediaType: 'video', videoSrc: 'b.mp4', videoPreviewImg: '' },
|
|
1442
|
+
]);
|
|
1443
|
+
|
|
1444
|
+
expect(withThumb).toEqual({ mediaType: 'video', imageUrl: '', videoSrc: 'a.mp4', videoPreviewImg: 'a.png', buttons: [] });
|
|
1445
|
+
expect(withoutThumb).toEqual({ mediaType: 'video', imageUrl: '', videoSrc: 'b.mp4', buttons: [] });
|
|
1446
|
+
});
|
|
1447
|
+
|
|
1448
|
+
it('appends key=value deep link params to carousel buttons', () => {
|
|
1449
|
+
const [card] = buildCarouselCards([{
|
|
1450
|
+
mediaType: 'image',
|
|
1451
|
+
imageUrl: 'a.jpg',
|
|
1452
|
+
buttons: [{ linkType: 'DEEP_LINK', deepLinkValue: 'app://home', deepLinkKeys: ['id={{user_id}}'] }],
|
|
1453
|
+
}]);
|
|
1454
|
+
|
|
1455
|
+
expect(card.buttons[0].deepLinkValue).toBe('app://home?id={{user_id}}');
|
|
1456
|
+
});
|
|
1457
|
+
|
|
1458
|
+
it('appends deep link keys and leaves other buttons as they are', () => {
|
|
1459
|
+
const externalButton = { linkType: 'EXTERNAL_LINK', externalLinkValue: 'https://x.com' };
|
|
1460
|
+
const [card] = buildCarouselCards([{
|
|
1461
|
+
mediaType: 'image',
|
|
1462
|
+
imageUrl: 'a.jpg',
|
|
1463
|
+
buttons: [
|
|
1464
|
+
{ linkType: 'DEEP_LINK', deepLinkValue: 'app://home', deepLinkKeys: 'id' },
|
|
1465
|
+
externalButton,
|
|
1466
|
+
null,
|
|
1467
|
+
],
|
|
1468
|
+
}]);
|
|
1469
|
+
|
|
1470
|
+
expect(card.buttons).toEqual([
|
|
1471
|
+
{ linkType: 'DEEP_LINK', deepLinkValue: 'app://home?id=id', deepLinkKeys: 'id' },
|
|
1472
|
+
externalButton,
|
|
1473
|
+
null,
|
|
1474
|
+
]);
|
|
1475
|
+
});
|
|
1476
|
+
});
|
|
@@ -20,7 +20,9 @@ import {
|
|
|
20
20
|
isUrl,
|
|
21
21
|
isValidText,
|
|
22
22
|
} from "../../v2Containers/Line/Container/Wrapper/utils";
|
|
23
|
-
import {
|
|
23
|
+
import {
|
|
24
|
+
isDeepLink, getDeepLinkParamValue, setDeepLinkParamValue, hasAllDeepLinkParams,
|
|
25
|
+
} from "../../v2Containers/MobilePushNew/utils";
|
|
24
26
|
import {
|
|
25
27
|
BTN_MAX_LENGTH,
|
|
26
28
|
DEEP_LINK,
|
|
@@ -52,8 +54,9 @@ export const CapMpushCTA = (props) => {
|
|
|
52
54
|
const [urlError, setUrlError] = useState(false);
|
|
53
55
|
const [buttonError, setButtonError] = useState(false);
|
|
54
56
|
const [deepLinkKeysError, setDeepLinkKeysError] = useState(false);
|
|
55
|
-
|
|
56
|
-
const
|
|
57
|
+
// Read from ctaData so a copy from the other tab shows here too
|
|
58
|
+
const ctaDeepLinkValue = ctaData[0]?.url || "";
|
|
59
|
+
const ctaDeepLinkKeysValue = ctaData[0]?.deepLinkKeys || [];
|
|
57
60
|
const [localUrlValues, setLocalUrlValues] = useState({});
|
|
58
61
|
// Track which URLs have been manually cleared to prevent restoration
|
|
59
62
|
const clearedUrlsRef = useRef(new Set());
|
|
@@ -133,21 +136,16 @@ export const CapMpushCTA = (props) => {
|
|
|
133
136
|
// Mark this URL as manually cleared to prevent restoration
|
|
134
137
|
clearedUrlsRef.current.add(index);
|
|
135
138
|
|
|
136
|
-
// Clear the URL field when switching between link types
|
|
137
|
-
updateHelper('url', '', index);
|
|
138
|
-
|
|
139
139
|
// Immediately clear the local URL state for this button
|
|
140
140
|
setLocalUrlValues(prev => ({
|
|
141
141
|
...prev,
|
|
142
142
|
[index]: ''
|
|
143
143
|
}));
|
|
144
144
|
|
|
145
|
-
// Also clear the local deep link state
|
|
146
|
-
setCtaDeepLinkValue('');
|
|
147
145
|
// Clear any URL errors
|
|
148
146
|
setUrlError(false);
|
|
149
|
-
//
|
|
150
|
-
|
|
147
|
+
// One update: clear the URL and set the new type
|
|
148
|
+
updateHandler({ ...cloneDeep(ctaData[index]), url: '', urlType: value }, index);
|
|
151
149
|
};
|
|
152
150
|
|
|
153
151
|
const onUrlChange = ({ target }) => {
|
|
@@ -175,7 +173,6 @@ export const CapMpushCTA = (props) => {
|
|
|
175
173
|
};
|
|
176
174
|
|
|
177
175
|
const onDeepLinkSelect = (value, index) => {
|
|
178
|
-
setCtaDeepLinkValue(value);
|
|
179
176
|
let errorMessage = false;
|
|
180
177
|
if (!isDeepLink(value)) {
|
|
181
178
|
errorMessage = formatMessage(messages.ctaWebsiteUrlErrorMessage);
|
|
@@ -184,13 +181,10 @@ export const CapMpushCTA = (props) => {
|
|
|
184
181
|
updateHelper('url', value, index);
|
|
185
182
|
};
|
|
186
183
|
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
const
|
|
190
|
-
|
|
191
|
-
const keysArray = value?.split(',')?.map((key) => key?.trim())?.filter((key) => key?.length > 0);
|
|
192
|
-
setCtaDeepLinkKeysValue(keysArray);
|
|
193
|
-
setDeepLinkKeysError(keysArray.length === 0);
|
|
184
|
+
// Stores "key=value" for the configured key being typed into
|
|
185
|
+
const onDeepLinkKeysChange = (index, key, value) => {
|
|
186
|
+
const keysArray = setDeepLinkParamValue(deepLinkKeysArray, deepLinkKeysFromSelectionArray, key, value);
|
|
187
|
+
setDeepLinkKeysError(!hasAllDeepLinkParams(keysArray, deepLinkKeysFromSelectionArray));
|
|
194
188
|
updateHelper('deepLinkKeys', keysArray, index);
|
|
195
189
|
};
|
|
196
190
|
|
|
@@ -200,7 +194,7 @@ export const CapMpushCTA = (props) => {
|
|
|
200
194
|
return true;
|
|
201
195
|
} else if (urlType === DEEP_LINK && (ctaDeepLinkValue === "" || urlError)) {
|
|
202
196
|
return true;
|
|
203
|
-
} else if (urlType === DEEP_LINK && ctaDeepLinkValue && deepLinkKeysFromSelectionArray?.length > 0 && (!
|
|
197
|
+
} else if (urlType === DEEP_LINK && ctaDeepLinkValue && deepLinkKeysFromSelectionArray?.length > 0 && (!hasAllDeepLinkParams(deepLinkKeysArray, deepLinkKeysFromSelectionArray) || deepLinkKeysError)) {
|
|
204
198
|
return true;
|
|
205
199
|
} else if (urlType === EXTERNAL_URL && (url === "" || urlError)) {
|
|
206
200
|
return true;
|
|
@@ -235,9 +229,10 @@ export const CapMpushCTA = (props) => {
|
|
|
235
229
|
type="flex"
|
|
236
230
|
>
|
|
237
231
|
<CapColumn>
|
|
238
|
-
<CapRow className="mpush-cta-row">
|
|
232
|
+
<CapRow type="flex" align="middle" className="mpush-cta-row">
|
|
239
233
|
<CapColumn>
|
|
240
|
-
|
|
234
|
+
{/* Not "launch": its SVG mask id collides with other launch icons and renders a square */}
|
|
235
|
+
<CapIcon size="s" type="open-in-new" />
|
|
241
236
|
</CapColumn>
|
|
242
237
|
<CapColumn className="btn-text">
|
|
243
238
|
<CapLabel type="label2" className="mpush-saved-cta-button-text">
|
|
@@ -251,13 +246,11 @@ export const CapMpushCTA = (props) => {
|
|
|
251
246
|
<CapTag className="cta-type-label">{formatMessage(messages.urlDeepLink)}</CapTag>
|
|
252
247
|
: <CapTag className="cta-type-label">{formatMessage(messages.urlExternalLink)}</CapTag>}
|
|
253
248
|
</CapColumn>
|
|
254
|
-
<CapColumn>
|
|
255
|
-
{urlType === DEEP_LINK ? selectedDeepLink?.label :
|
|
256
|
-
</CapColumn>
|
|
257
|
-
<CapColumn>
|
|
249
|
+
<CapColumn className="mpush-saved-cta-link" title={cta?.url}>
|
|
250
|
+
{urlType === DEEP_LINK ? selectedDeepLink?.label : cta?.url}
|
|
258
251
|
</CapColumn>
|
|
259
252
|
<CapColumn>
|
|
260
|
-
<CapRow className="cta-action-grp">
|
|
253
|
+
<CapRow type="flex" align="middle" className="cta-action-grp">
|
|
261
254
|
<CapColumn
|
|
262
255
|
className="mpush-saved-cta-edit-icon"
|
|
263
256
|
onClick={() => isSavedCta(index, false)}
|
|
@@ -317,9 +310,35 @@ export const CapMpushCTA = (props) => {
|
|
|
317
310
|
onChange={(value) => onDeepLinkSelect(value, index)}
|
|
318
311
|
value={ctaDeepLinkValue}
|
|
319
312
|
/>
|
|
313
|
+
{/* Keys under the Deep link dropdown, as in Notification tap */}
|
|
314
|
+
{ctaDeepLinkValue && deepLinkKeysFromSelectionArray.length > 0 && (
|
|
315
|
+
<CapRow useLegacy className="mpush-cta-deep-link-keys">
|
|
316
|
+
<CapHeading type="h4">
|
|
317
|
+
{formatMessage(messages.deepLinkKeys)}
|
|
318
|
+
</CapHeading>
|
|
319
|
+
{deepLinkKeysFromSelectionArray.map((key, keyIndex) => (
|
|
320
|
+
<CapRow useLegacy key={key} className="mpush-deep-link-key">
|
|
321
|
+
<CapLabel type="label2" className="cta-deep-link-keys-value">
|
|
322
|
+
{key}
|
|
323
|
+
</CapLabel>
|
|
324
|
+
<CapInput
|
|
325
|
+
id={keyIndex === 0 ? "mpush-deep-link-keys" : `mpush-deep-link-keys-${keyIndex}`}
|
|
326
|
+
className="mpush-deep-link-keys"
|
|
327
|
+
onChange={({ target: { value } }) => onDeepLinkKeysChange(index, key, value)}
|
|
328
|
+
placeholder={formatMessage(messages.deepLinkKeysPlaceholder, { key })}
|
|
329
|
+
value={getDeepLinkParamValue(deepLinkKeysArray, key)}
|
|
330
|
+
data-index={index}
|
|
331
|
+
errorMessage={deepLinkKeysError && keyIndex === deepLinkKeysFromSelectionArray.length - 1 ? formatMessage(messages.deepLinkKeysRequired) : ""}
|
|
332
|
+
/>
|
|
333
|
+
</CapRow>
|
|
334
|
+
))}
|
|
335
|
+
</CapRow>
|
|
336
|
+
)}
|
|
320
337
|
</CapRow>
|
|
321
338
|
)}
|
|
322
339
|
{urlType === EXTERNAL_URL && (
|
|
340
|
+
// Wrapper lets the stylesheet size the label row to match "Type of link"
|
|
341
|
+
<CapRow className="mpush-cta-external-link-field">
|
|
323
342
|
<CapTagListWithInput
|
|
324
343
|
inputId="mpush-cta-external-link"
|
|
325
344
|
inputValue={localUrlValues[index] || ''}
|
|
@@ -329,8 +348,7 @@ export const CapMpushCTA = (props) => {
|
|
|
329
348
|
inputMaxLength={URL_MAX_LENGTH}
|
|
330
349
|
inputErrorMessage={urlError}
|
|
331
350
|
headingText={formatMessage(messages.urlExternalLink)}
|
|
332
|
-
headingStyle={{
|
|
333
|
-
containerStyle={{ width: '70%', marginTop: '-0.625rem' }}
|
|
351
|
+
headingStyle={{ whiteSpace: 'nowrap' }}
|
|
334
352
|
moduleFilterEnabled={location?.query?.type !== "embedded"}
|
|
335
353
|
onTagSelect={onButtonTagSelect}
|
|
336
354
|
onContextChange={handleOnTagsContextChange}
|
|
@@ -340,37 +358,9 @@ export const CapMpushCTA = (props) => {
|
|
|
340
358
|
selectedOfferDetails={selectedOfferDetails}
|
|
341
359
|
inputProps={{ 'data-index': index }}
|
|
342
360
|
/>
|
|
361
|
+
</CapRow>
|
|
343
362
|
)}
|
|
344
363
|
</CapColumn>
|
|
345
|
-
{urlType === DEEP_LINK && ctaDeepLinkValue && deepLinkKeysFromSelectionArray.length > 0 && (
|
|
346
|
-
<CapColumn>
|
|
347
|
-
<CapRow useLegacy style={{ marginTop: '10px' }}>
|
|
348
|
-
<CapHeading type="h4">
|
|
349
|
-
{formatMessage(messages.deepLinkKeys)}
|
|
350
|
-
</CapHeading>
|
|
351
|
-
<CapLabel type="label2" className="cta-deep-link-keys-value">
|
|
352
|
-
{(() => {
|
|
353
|
-
if (deepLinkKeysFromSelectionArray.length > 0) {
|
|
354
|
-
return deepLinkKeysFromSelectionArray.join(', ');
|
|
355
|
-
}
|
|
356
|
-
if (deepLinkKeysArray.length > 0) {
|
|
357
|
-
return deepLinkKeysArray.join(', ');
|
|
358
|
-
}
|
|
359
|
-
})()}
|
|
360
|
-
</CapLabel>
|
|
361
|
-
<CapInput
|
|
362
|
-
id="mpush-deep-link-keys"
|
|
363
|
-
className="mpush-deep-link-keys"
|
|
364
|
-
onChange={onDeepLinkKeysChange}
|
|
365
|
-
placeholder={formatMessage(messages.deepLinkKeysPlaceholder, { key: deepLinkKeysFromSelectionArray.join(', ') })}
|
|
366
|
-
value={Array.isArray(ctaDeepLinkKeysValue) ? ctaDeepLinkKeysValue.join(', ') : (ctaDeepLinkKeysValue || '')}
|
|
367
|
-
size="large"
|
|
368
|
-
data-index={index}
|
|
369
|
-
errorMessage={deepLinkKeysError ? formatMessage(messages.deepLinkKeysRequired) : ""}
|
|
370
|
-
/>
|
|
371
|
-
</CapRow>
|
|
372
|
-
</CapColumn>
|
|
373
|
-
)}
|
|
374
364
|
<CapColumn>
|
|
375
365
|
<CapRow useLegacy className="mpush-cta-save-delete-btn">
|
|
376
366
|
<CapTooltip
|