@capillarytech/creatives-library 9.1.8-alpha.sprint-cap-214249.39 → 9.2.0
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 +4 -0
- package/package.json +1 -1
- package/translations/en.json +1 -0
- package/translations/ja-JP.json +1 -0
- package/translations/zh.json +1 -0
- package/utils/common.js +6 -0
- package/utils/createMobilePushPayload.js +33 -50
- package/utils/tagValidations.js +35 -4
- package/utils/templateVarUtils.js +49 -0
- package/utils/tests/createMobilePushPayload.test.js +8 -113
- package/utils/tests/tagValidations.test.js +48 -0
- package/utils/tests/templateVarUtils.test.js +89 -0
- package/v2Components/CapMpushCTA/index.js +9 -10
- package/v2Components/CapMpushCTA/index.scss +3 -29
- package/v2Components/CapTagList/TagFallbackPanel.js +124 -0
- package/v2Components/CapTagList/constants.js +5 -0
- package/v2Components/CapTagList/index.js +46 -7
- package/v2Components/CapTagList/messages.js +44 -0
- package/v2Components/CapTagList/style.scss +113 -1
- package/v2Components/CapTagList/tests/TagFallback.test.js +222 -0
- package/v2Components/CapTagList/utils.js +17 -0
- package/v2Components/CommonTestAndPreview/UnifiedPreview/MobilePushPreviewContent.js +12 -20
- package/v2Components/CommonTestAndPreview/UnifiedPreview/_unifiedPreview.scss +1 -13
- package/v2Components/CommonTestAndPreview/constants.js +3 -2
- package/v2Components/CommonTestAndPreview/index.js +61 -61
- package/v2Components/CommonTestAndPreview/tests/UnifiedPreview/MobilePushPreviewContent.test.js +5 -81
- package/v2Components/CommonTestAndPreview/tests/index.test.js +0 -86
- package/v2Components/CommonTestAndPreview/tests/utils.test.js +102 -0
- package/v2Components/CommonTestAndPreview/utils.js +42 -3
- package/v2Components/FormBuilder/Classic.js +24 -14
- package/v2Components/FormBuilder/Functional/channels/mobilepush/config.js +1 -0
- package/v2Components/FormBuilder/Functional/channels/mobilepush/getEditorErrorDescriptor.js +1 -1
- package/v2Components/FormBuilder/Functional/channels/mobilepush/tests/validate.test.js +57 -0
- package/v2Components/FormBuilder/Functional/channels/mobilepush/validate.js +4 -4
- package/v2Components/FormBuilder/Functional/channels/sms/getEditorErrorDescriptor.js +3 -0
- package/v2Components/FormBuilder/Functional/channels/sms/tests/getEditorErrorDescriptor.test.js +5 -0
- package/v2Components/FormBuilder/Functional/channels/sms/tests/validate.test.js +6 -0
- package/v2Components/FormBuilder/Functional/channels/sms/validate.js +3 -1
- package/v2Components/FormBuilder/Functional/renderers/mpushRenderers.js +3 -0
- package/v2Components/FormBuilder/Functional/tests/mpushRenderers.test.js +22 -0
- package/v2Components/TemplatePreview/_templatePreview.scss +2 -12
- package/v2Components/TemplatePreview/index.js +16 -24
- package/v2Components/TemplatePreview/tests/index.test.js +0 -68
- package/v2Containers/Cap/messages.js +4 -0
- package/v2Containers/Cap/tests/__snapshots__/index.test.js.snap +1 -0
- package/v2Containers/CreativesContainer/SlideBoxContent.js +6 -4
- package/v2Containers/CreativesContainer/index.js +1 -2
- package/v2Containers/CreativesContainer/tests/SlideBoxContent.test.js +0 -43
- package/v2Containers/InApp/index.js +4 -1
- package/v2Containers/Line/Container/ImageCarousel/tests/__snapshots__/content.test.js.snap +3 -0
- package/v2Containers/Line/Container/ImageCarousel/tests/__snapshots__/index.test.js.snap +2 -0
- package/v2Containers/Line/Container/Text/index.js +3 -1
- package/v2Containers/Line/Container/Wrapper/tests/__snapshots__/index.test.js.snap +16 -0
- package/v2Containers/Line/Container/tests/__snapshots__/index.test.js.snap +18 -0
- package/v2Containers/MobilePushNew/components/CtaButtons.js +47 -52
- package/v2Containers/MobilePushNew/components/MediaUploaders.js +216 -297
- package/v2Containers/MobilePushNew/components/PlatformContentFields.js +125 -158
- package/v2Containers/MobilePushNew/components/tests/CtaButtons.test.js +208 -30
- package/v2Containers/MobilePushNew/components/tests/MediaUploaders.test.js +108 -464
- package/v2Containers/MobilePushNew/components/tests/PlatformContentFields.test.js +35 -106
- package/v2Containers/MobilePushNew/constants.js +0 -5
- package/v2Containers/MobilePushNew/hooks/tests/usePlatformSync.test.js +1 -63
- package/v2Containers/MobilePushNew/hooks/tests/useUpload.test.js +0 -52
- package/v2Containers/MobilePushNew/hooks/usePlatformSync.js +1 -40
- package/v2Containers/MobilePushNew/hooks/useUpload.js +39 -29
- package/v2Containers/MobilePushNew/index.js +239 -488
- package/v2Containers/MobilePushNew/index.scss +4 -205
- package/v2Containers/MobilePushNew/messages.js +6 -106
- package/v2Containers/MobilePushNew/tests/index.test.js +1 -469
- package/v2Containers/MobilePushNew/tests/utils.test.js +0 -70
- package/v2Containers/MobilePushNew/utils.js +0 -56
- package/v2Containers/Rcs/index.js +8 -1
- package/v2Containers/Rcs/tests/__snapshots__/index.test.js.snap +59 -0
- package/v2Containers/SmsTrai/Create/tests/__snapshots__/index.test.js.snap +4 -0
- package/v2Containers/SmsTrai/Edit/index.js +17 -7
- package/v2Containers/SmsTrai/Edit/tests/__snapshots__/index.test.js.snap +42 -0
- package/v2Containers/Templates/_templates.scss +2 -10
- package/v2Containers/Templates/index.js +81 -83
- package/v2Containers/Templates/tests/index.test.js +0 -68
- package/v2Containers/Viber/index.js +3 -1
- package/v2Containers/WebPush/Create/utils/validation.js +6 -0
- package/v2Containers/WebPush/Create/utils/validation.test.js +50 -0
- package/v2Containers/Whatsapp/index.js +9 -5
- package/v2Containers/Whatsapp/tests/__snapshots__/index.test.js.snap +2 -2
- package/v2Containers/Zalo/index.js +4 -1
- package/v2Components/CapMpushCTA/tests/index.test.js +0 -89
- package/v2Containers/MobilePushNew/components/TapLinkActions.js +0 -76
|
@@ -8,6 +8,7 @@ import CapHeading from "@capillarytech/cap-ui-library/CapHeading";
|
|
|
8
8
|
import CapError from "@capillarytech/cap-ui-library/CapError";
|
|
9
9
|
import CapDivider from "@capillarytech/cap-ui-library/CapDivider";
|
|
10
10
|
import CapSelect from "@capillarytech/cap-ui-library/CapSelect";
|
|
11
|
+
import CapCheckbox from "@capillarytech/cap-ui-library/CapCheckbox";
|
|
11
12
|
import CapLabel from "@capillarytech/cap-ui-library/CapLabel";
|
|
12
13
|
import CapInfoNote from "@capillarytech/cap-ui-library/CapInfoNote";
|
|
13
14
|
import TagList from "../../TagList";
|
|
@@ -15,15 +16,14 @@ import {
|
|
|
15
16
|
ANDROID,
|
|
16
17
|
IOS,
|
|
17
18
|
MEDIA_TYPES_OPTIONS,
|
|
19
|
+
LINK_TYPE_OPTIONS,
|
|
18
20
|
DEEP_LINK,
|
|
19
21
|
EXTERNAL_LINK,
|
|
20
22
|
CAROUSEL,
|
|
21
|
-
TAP_ACTION_APP,
|
|
22
23
|
} from "../constants";
|
|
23
24
|
import messages from "../messages";
|
|
24
25
|
import MediaUploaders from "./MediaUploaders";
|
|
25
26
|
import CtaButtons from "./CtaButtons";
|
|
26
|
-
import { SavedTapLink, TapLinkSaveDelete } from "./TapLinkActions";
|
|
27
27
|
import { hasPersonalizationTags } from "../../../utils/commonUtils";
|
|
28
28
|
|
|
29
29
|
const PlatformContentFields = ({
|
|
@@ -56,11 +56,11 @@ const PlatformContentFields = ({
|
|
|
56
56
|
handleTitleChange,
|
|
57
57
|
handleMessageChange,
|
|
58
58
|
handleMediaTypeChange,
|
|
59
|
-
|
|
59
|
+
handleActionOnClickChange,
|
|
60
|
+
handleLinkTypeChange,
|
|
60
61
|
handleDeepLinkChange,
|
|
61
62
|
handleDeepLinkKeysChange,
|
|
62
63
|
handleExternalLinkChange,
|
|
63
|
-
handleTapLinkSavedChange,
|
|
64
64
|
onTagSelect,
|
|
65
65
|
handleOnTagsContextChange,
|
|
66
66
|
} = handlers;
|
|
@@ -120,29 +120,15 @@ const PlatformContentFields = ({
|
|
|
120
120
|
[handleMediaTypeChange, deviceType]
|
|
121
121
|
);
|
|
122
122
|
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
{ label: formatMessage(messages.tapActionApp), value: TAP_ACTION_APP },
|
|
127
|
-
{ label: formatMessage(messages.tapActionDeepLink), value: DEEP_LINK },
|
|
128
|
-
{ label: formatMessage(messages.tapActionExternalLink), value: EXTERNAL_LINK },
|
|
129
|
-
];
|
|
130
|
-
|
|
131
|
-
const onTapActionChange = useCallback(
|
|
132
|
-
(value) => handleTapActionChange(value),
|
|
133
|
-
[handleTapActionChange]
|
|
123
|
+
const onActionOnClickChange = useCallback(
|
|
124
|
+
(e) => handleActionOnClickChange(deviceType, e.target.checked),
|
|
125
|
+
[handleActionOnClickChange, deviceType]
|
|
134
126
|
);
|
|
135
127
|
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|| (deepLinkKeysFromSelectionArray.length > 0 && deepLinkKeysArray.length === 0)
|
|
141
|
-
|| !!errors?.deepLink || !!errors?.deepLinkKeys)
|
|
142
|
-
: (!externalLinkValue?.trim() || !!errors?.externalLink);
|
|
143
|
-
const savedTapLinkText = tapAction === DEEP_LINK
|
|
144
|
-
? (selectedDeepLink?.label || deepLinkValue)
|
|
145
|
-
: externalLinkValue;
|
|
128
|
+
const onLinkTypeChange = useCallback(
|
|
129
|
+
(value) => handleLinkTypeChange(deviceType, value),
|
|
130
|
+
[handleLinkTypeChange, deviceType]
|
|
131
|
+
);
|
|
146
132
|
|
|
147
133
|
const onDeepLinkChange = useCallback((value) => handleDeepLinkChange(value), [
|
|
148
134
|
handleDeepLinkChange,
|
|
@@ -267,153 +253,135 @@ const PlatformContentFields = ({
|
|
|
267
253
|
<>
|
|
268
254
|
<CapDivider />
|
|
269
255
|
<CapRow useLegacy className="creatives-mpush-actions">
|
|
270
|
-
|
|
271
|
-
<CapRow type="flex" align="middle" noWrap className="mpush-section-heading">
|
|
256
|
+
<CapRow useLegacy className="mpush-actions-main">
|
|
272
257
|
<CapHeading type="h3" className="mpush-actions">
|
|
273
|
-
<FormattedMessage {...messages.
|
|
258
|
+
<FormattedMessage {...messages.buttonsAndLinks} />
|
|
274
259
|
</CapHeading>
|
|
275
260
|
<CapLabel className="optional-text">
|
|
276
261
|
<FormattedMessage {...messages.optionalText} />
|
|
277
262
|
</CapLabel>
|
|
278
263
|
</CapRow>
|
|
279
|
-
<
|
|
280
|
-
|
|
281
|
-
|
|
282
|
-
|
|
283
|
-
|
|
284
|
-
|
|
285
|
-
|
|
286
|
-
|
|
287
|
-
|
|
288
|
-
|
|
289
|
-
|
|
290
|
-
|
|
291
|
-
|
|
292
|
-
|
|
293
|
-
<
|
|
294
|
-
<
|
|
295
|
-
<
|
|
296
|
-
|
|
264
|
+
<CapCheckbox
|
|
265
|
+
checked={content.actionOnClick}
|
|
266
|
+
onChange={onActionOnClickChange}
|
|
267
|
+
className="action-on-click-checkbox"
|
|
268
|
+
>
|
|
269
|
+
<FormattedMessage {...messages.actionOnClickBody} />
|
|
270
|
+
</CapCheckbox>
|
|
271
|
+
<CapRow useLegacy>
|
|
272
|
+
<CapLabel className="action-description">
|
|
273
|
+
<FormattedMessage {...messages.actionDescription} />
|
|
274
|
+
</CapLabel>
|
|
275
|
+
</CapRow>
|
|
276
|
+
{content.actionOnClick && (
|
|
277
|
+
<CapRow style={{ display: "flex", justifyContent: "space-around" }}>
|
|
278
|
+
<CapColumn span={6}>
|
|
279
|
+
<CapHeading type="h4" className="buttons-heading">
|
|
280
|
+
<FormattedMessage {...messages.linkType} />
|
|
281
|
+
</CapHeading>
|
|
282
|
+
<CapSelect.CapCustomSelect
|
|
283
|
+
options={LINK_TYPE_OPTIONS}
|
|
284
|
+
value={content.linkType}
|
|
285
|
+
onChange={onLinkTypeChange}
|
|
286
|
+
key="mobile-push-link-type"
|
|
287
|
+
selectPlaceholder={formatMessage(messages.selectDeepLink)}
|
|
288
|
+
/>
|
|
289
|
+
</CapColumn>
|
|
290
|
+
{content.linkType === DEEP_LINK && (
|
|
291
|
+
<CapColumn span={14}>
|
|
292
|
+
<CapHeading type="h4" className="buttons-heading">
|
|
293
|
+
{formatMessage(messages.deepLink)}
|
|
297
294
|
</CapHeading>
|
|
298
295
|
<CapSelect.CapCustomSelect
|
|
299
|
-
|
|
300
|
-
|
|
301
|
-
|
|
302
|
-
|
|
303
|
-
|
|
296
|
+
options={(() => {
|
|
297
|
+
const options = [...(deepLink || [])];
|
|
298
|
+
// If the current value is not in the options, add it
|
|
299
|
+
if (deepLinkValue && !options.find((opt) => opt.value === deepLinkValue)) {
|
|
300
|
+
options.push({
|
|
301
|
+
value: deepLinkValue,
|
|
302
|
+
label: deepLinkValue,
|
|
303
|
+
});
|
|
304
|
+
}
|
|
305
|
+
return options;
|
|
306
|
+
})()}
|
|
307
|
+
value={deepLinkValue}
|
|
308
|
+
onChange={onDeepLinkChange}
|
|
309
|
+
key="mobile-push-deep-link-type"
|
|
310
|
+
placeholder={formatMessage(messages.selectDeepLink)}
|
|
311
|
+
style={{ marginTop: "10px" }}
|
|
304
312
|
/>
|
|
305
313
|
</CapColumn>
|
|
306
|
-
|
|
307
|
-
|
|
308
|
-
|
|
309
|
-
|
|
314
|
+
)}
|
|
315
|
+
{content.linkType === EXTERNAL_LINK && (
|
|
316
|
+
<CapColumn span={14}>
|
|
317
|
+
<CapRow style={{ display: "flex" }}>
|
|
318
|
+
<CapHeading type="h4" className="buttons-heading">
|
|
319
|
+
{formatMessage(messages.externalLink)}
|
|
310
320
|
</CapHeading>
|
|
311
|
-
<
|
|
312
|
-
|
|
313
|
-
|
|
314
|
-
|
|
315
|
-
|
|
316
|
-
|
|
317
|
-
|
|
318
|
-
|
|
319
|
-
|
|
320
|
-
|
|
321
|
-
|
|
322
|
-
|
|
323
|
-
|
|
324
|
-
|
|
325
|
-
onChange={onDeepLinkChange}
|
|
326
|
-
key="mobile-push-deep-link-type"
|
|
327
|
-
selectPlaceholder={formatMessage(messages.selectDeepLink)}
|
|
328
|
-
/>
|
|
329
|
-
{errors?.deepLink && (
|
|
330
|
-
<CapError className="mobile-push-deep-link-error">
|
|
331
|
-
{errors.deepLink}
|
|
332
|
-
</CapError>
|
|
333
|
-
)}
|
|
334
|
-
{deepLinkValue && (deepLinkKeysFromSelectionArray?.length > 0 || deepLinkKeysArray?.length > 0) && (
|
|
335
|
-
<CapRow className="mpush-tap-deep-link-keys">
|
|
336
|
-
<CapHeading type="h4" className="deep-link-keys-heading">
|
|
337
|
-
{formatMessage(messages.deepLinkKeys)}
|
|
338
|
-
</CapHeading>
|
|
339
|
-
<CapLabel type="label2" className="deep-link-keys-value">
|
|
340
|
-
{(() => {
|
|
341
|
-
if (deepLinkKeysFromSelectionArray?.length > 0) {
|
|
342
|
-
return deepLinkKeysFromSelectionArray?.join(', ');
|
|
343
|
-
}
|
|
344
|
-
if (deepLinkKeysArray?.length > 0) {
|
|
345
|
-
return deepLinkKeysArray?.join(', ');
|
|
346
|
-
}
|
|
347
|
-
return '';
|
|
348
|
-
})()}
|
|
349
|
-
</CapLabel>
|
|
350
|
-
<CapInput
|
|
351
|
-
id="mobile-push-deep-link-keys-input"
|
|
352
|
-
onChange={onDeepLinkKeysChange}
|
|
353
|
-
placeholder={formatMessage(messages.deepLinkKeysPlaceholder, { key: deepLinkKeysFromSelectionArray?.join(', ') })}
|
|
354
|
-
value={Array.isArray(deepLinkKeysValue) ? deepLinkKeysValue?.join(', ') : (deepLinkKeysValue || "")}
|
|
355
|
-
size="default"
|
|
356
|
-
style={{ marginTop: "10px" }}
|
|
357
|
-
error={errors?.deepLinkKeys}
|
|
358
|
-
/>
|
|
359
|
-
</CapRow>
|
|
360
|
-
)}
|
|
361
|
-
</CapColumn>
|
|
362
|
-
)}
|
|
363
|
-
{tapAction === EXTERNAL_LINK && (
|
|
364
|
-
<CapColumn flex="1 1 0" className="mpush-tap-link">
|
|
365
|
-
<CapRow type="flex" align="middle" justify="space-between" noWrap className="mpush-tap-link-header">
|
|
366
|
-
<CapHeading type="h4" className="mpush-tap-label">
|
|
367
|
-
<FormattedMessage {...messages.url} />
|
|
368
|
-
</CapHeading>
|
|
369
|
-
<TagList
|
|
370
|
-
moduleFilterEnabled={
|
|
371
|
-
location?.query?.type !== "embedded"
|
|
372
|
-
}
|
|
373
|
-
label={formatMessage(messages.addLabels)}
|
|
374
|
-
onTagSelect={onButtonTagSelect}
|
|
375
|
-
onContextChange={handleOnTagsContextChange}
|
|
376
|
-
location={location}
|
|
377
|
-
tags={tags}
|
|
378
|
-
injectedTags={injectedTags}
|
|
379
|
-
selectedOfferDetails={selectedOfferDetails}
|
|
380
|
-
disabled={restrictPersonalization}
|
|
381
|
-
disableTooltipMsg={
|
|
382
|
-
restrictPersonalization ? formatMessage(messages.personalizationNotSupportedAnonymous) : undefined
|
|
383
|
-
}
|
|
384
|
-
/>
|
|
385
|
-
</CapRow>
|
|
386
|
-
<CapInput
|
|
387
|
-
id="mobile-push-external-link-input"
|
|
388
|
-
onChange={onExternalLinkChange}
|
|
389
|
-
placeholder={formatMessage(messages.enterUrl)}
|
|
390
|
-
value={externalLinkValue}
|
|
391
|
-
size="default"
|
|
392
|
-
isRequired
|
|
393
|
-
errorMessage={
|
|
394
|
-
errors.externalLink && (
|
|
395
|
-
<CapError className="mobile-push-external-link-error">
|
|
396
|
-
{errors.externalLink}
|
|
397
|
-
</CapError>
|
|
398
|
-
)
|
|
321
|
+
<TagList
|
|
322
|
+
moduleFilterEnabled={
|
|
323
|
+
location?.query?.type !== "embedded"
|
|
324
|
+
}
|
|
325
|
+
label={formatMessage(messages.addLabels)}
|
|
326
|
+
onTagSelect={onButtonTagSelect}
|
|
327
|
+
onContextChange={handleOnTagsContextChange}
|
|
328
|
+
location={location}
|
|
329
|
+
tags={tags}
|
|
330
|
+
injectedTags={injectedTags}
|
|
331
|
+
selectedOfferDetails={selectedOfferDetails}
|
|
332
|
+
disabled={restrictPersonalization}
|
|
333
|
+
disableTooltipMsg={
|
|
334
|
+
restrictPersonalization ? formatMessage(messages.personalizationNotSupportedAnonymous) : undefined
|
|
399
335
|
}
|
|
400
336
|
/>
|
|
401
|
-
</
|
|
402
|
-
|
|
403
|
-
|
|
404
|
-
|
|
405
|
-
|
|
406
|
-
|
|
337
|
+
</CapRow>
|
|
338
|
+
<CapInput
|
|
339
|
+
id="mobile-push-external-link-input"
|
|
340
|
+
onChange={onExternalLinkChange}
|
|
341
|
+
placeholder={formatMessage(messages.enterExternalLink)}
|
|
342
|
+
value={externalLinkValue}
|
|
343
|
+
size="default"
|
|
344
|
+
isRequired
|
|
345
|
+
errorMessage={
|
|
346
|
+
errors.externalLink && (
|
|
347
|
+
<CapError className="mobile-push-external-link-error">
|
|
348
|
+
{errors.externalLink}
|
|
349
|
+
</CapError>
|
|
350
|
+
)
|
|
351
|
+
}
|
|
352
|
+
/>
|
|
353
|
+
</CapColumn>
|
|
354
|
+
)}
|
|
355
|
+
</CapRow>
|
|
356
|
+
)}
|
|
357
|
+
{content?.actionOnClick && content?.linkType === DEEP_LINK && deepLinkValue && (deepLinkKeysFromSelectionArray?.length > 0 || deepLinkKeysArray?.length > 0) && (
|
|
358
|
+
<CapRow style={{ marginTop: "10px", left: "6%", width: '115%'}}>
|
|
359
|
+
<CapColumn span={14}>
|
|
360
|
+
<CapHeading type="h4" className="deep-link-keys-heading">
|
|
361
|
+
{formatMessage(messages.deepLinkKeys)}
|
|
362
|
+
</CapHeading>
|
|
363
|
+
<CapLabel type="label2" className="deep-link-keys-value">
|
|
364
|
+
{(() => {
|
|
365
|
+
if (deepLinkKeysFromSelectionArray?.length > 0) {
|
|
366
|
+
return deepLinkKeysFromSelectionArray?.join(', ');
|
|
367
|
+
}
|
|
368
|
+
if (deepLinkKeysArray?.length > 0) {
|
|
369
|
+
return deepLinkKeysArray?.join(', ');
|
|
370
|
+
}
|
|
371
|
+
return '';
|
|
372
|
+
})()}
|
|
407
373
|
</CapLabel>
|
|
408
|
-
|
|
409
|
-
|
|
410
|
-
|
|
411
|
-
|
|
412
|
-
|
|
413
|
-
|
|
374
|
+
<CapInput
|
|
375
|
+
id="mobile-push-deep-link-keys-input"
|
|
376
|
+
onChange={onDeepLinkKeysChange}
|
|
377
|
+
placeholder={formatMessage(messages.deepLinkKeysPlaceholder, { key: deepLinkKeysFromSelectionArray?.join(', ')})}
|
|
378
|
+
value={Array.isArray(deepLinkKeysValue) ? deepLinkKeysValue?.join(', ') : (deepLinkKeysValue || "")}
|
|
379
|
+
size="default"
|
|
380
|
+
style={{ marginTop: "10px" }}
|
|
381
|
+
error={errors?.deepLinkKeys}
|
|
414
382
|
/>
|
|
415
|
-
|
|
416
|
-
|
|
383
|
+
</CapColumn>
|
|
384
|
+
</CapRow>
|
|
417
385
|
)}
|
|
418
386
|
</CapRow>
|
|
419
387
|
<CtaButtons {...ctaButtonProps} />
|
|
@@ -431,7 +399,6 @@ PlatformContentFields.propTypes = {
|
|
|
431
399
|
title: PropTypes.string,
|
|
432
400
|
message: PropTypes.string,
|
|
433
401
|
externalLink: PropTypes.string,
|
|
434
|
-
deepLink: PropTypes.string,
|
|
435
402
|
deepLinkKeys: PropTypes.string,
|
|
436
403
|
}).isRequired,
|
|
437
404
|
handlers: PropTypes.object.isRequired,
|
|
@@ -7,7 +7,7 @@ import { configureStore } from '@capillarytech/vulcan-react-sdk/utils';
|
|
|
7
7
|
import { initialReducer } from '../../../../initialReducer';
|
|
8
8
|
import history from '../../../../utils/history';
|
|
9
9
|
import CtaButtons from '../CtaButtons';
|
|
10
|
-
import { PRIMARY, DEEP_LINK } from '../../constants';
|
|
10
|
+
import { PRIMARY, SECONDARY, DEEP_LINK } from '../../constants';
|
|
11
11
|
|
|
12
12
|
// Mock the UI components
|
|
13
13
|
jest.mock('@capillarytech/cap-ui-library/CapRow', () =>
|
|
@@ -82,10 +82,6 @@ jest.mock('../../messages', () => ({
|
|
|
82
82
|
id: 'buttons',
|
|
83
83
|
defaultMessage: 'Buttons',
|
|
84
84
|
},
|
|
85
|
-
optionalText: {
|
|
86
|
-
id: 'optional.text',
|
|
87
|
-
defaultMessage: '(Optional)',
|
|
88
|
-
},
|
|
89
85
|
addPrimaryButton: {
|
|
90
86
|
id: 'add.primary.button',
|
|
91
87
|
defaultMessage: 'Add primary button',
|
|
@@ -132,7 +128,7 @@ describe('CtaButtons', () => {
|
|
|
132
128
|
describe('Initial Rendering', () => {
|
|
133
129
|
it('should render the component with default props', () => {
|
|
134
130
|
renderComponent();
|
|
135
|
-
expect(screen.
|
|
131
|
+
expect(screen.getByTestId('cap-row')).toBeInTheDocument();
|
|
136
132
|
expect(screen.getByText('Buttons')).toBeInTheDocument();
|
|
137
133
|
});
|
|
138
134
|
|
|
@@ -225,31 +221,114 @@ describe('CtaButtons', () => {
|
|
|
225
221
|
});
|
|
226
222
|
});
|
|
227
223
|
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
|
|
224
|
+
describe('Secondary Button Functionality', () => {
|
|
225
|
+
it('should render add secondary button when primary button is saved', () => {
|
|
226
|
+
const ctaData = [
|
|
227
|
+
{ index: 0, text: 'Primary Button', isSaved: true }
|
|
228
|
+
];
|
|
229
|
+
|
|
230
|
+
renderComponent({ ctaData });
|
|
231
|
+
|
|
232
|
+
expect(screen.getByTestId('add-secondary-button')).toBeInTheDocument();
|
|
233
|
+
expect(screen.getByText('Add secondary button')).toBeInTheDocument();
|
|
234
|
+
});
|
|
235
|
+
|
|
236
|
+
it('should not render add secondary button when primary button is not saved', () => {
|
|
237
|
+
const ctaData = [
|
|
238
|
+
{ index: 0, text: 'Primary Button', isSaved: false }
|
|
239
|
+
];
|
|
240
|
+
|
|
241
|
+
renderComponent({ ctaData });
|
|
242
|
+
|
|
243
|
+
expect(screen.queryByTestId('add-secondary-button')).not.toBeInTheDocument();
|
|
244
|
+
});
|
|
245
|
+
|
|
246
|
+
it('should handle adding secondary button', () => {
|
|
247
|
+
const setSecondaryButton = jest.fn();
|
|
248
|
+
const updateHandler = jest.fn();
|
|
249
|
+
const ctaData = [
|
|
250
|
+
{ index: 0, text: 'Primary Button', isSaved: true }
|
|
251
|
+
];
|
|
252
|
+
|
|
253
|
+
renderComponent({
|
|
254
|
+
ctaData,
|
|
255
|
+
setSecondaryButton,
|
|
256
|
+
updateHandler
|
|
234
257
|
});
|
|
258
|
+
|
|
259
|
+
// The secondary button should be disabled when primary button is saved
|
|
260
|
+
const secondaryButton = screen.getByTestId('add-secondary-button');
|
|
261
|
+
expect(secondaryButton).toBeDisabled();
|
|
262
|
+
|
|
263
|
+
// Since the button is disabled, clicking it should not trigger the handlers
|
|
264
|
+
fireEvent.click(secondaryButton);
|
|
265
|
+
|
|
266
|
+
// The handlers should not be called because the button is disabled
|
|
267
|
+
expect(updateHandler).not.toHaveBeenCalled();
|
|
268
|
+
expect(setSecondaryButton).not.toHaveBeenCalled();
|
|
269
|
+
});
|
|
235
270
|
|
|
271
|
+
it('should handle adding secondary button when primary button is not saved', () => {
|
|
272
|
+
const setSecondaryButton = jest.fn();
|
|
273
|
+
const updateHandler = jest.fn();
|
|
274
|
+
const ctaData = [
|
|
275
|
+
{ index: 0, text: 'Primary Button', isSaved: false }
|
|
276
|
+
];
|
|
277
|
+
|
|
278
|
+
renderComponent({
|
|
279
|
+
ctaData,
|
|
280
|
+
setSecondaryButton,
|
|
281
|
+
updateHandler
|
|
282
|
+
});
|
|
283
|
+
|
|
284
|
+
// The secondary button should not be rendered when primary button is not saved
|
|
236
285
|
expect(screen.queryByTestId('add-secondary-button')).not.toBeInTheDocument();
|
|
237
|
-
expect(screen.queryByText('Add secondary button')).not.toBeInTheDocument();
|
|
238
286
|
});
|
|
239
287
|
|
|
240
|
-
it('
|
|
241
|
-
|
|
242
|
-
|
|
288
|
+
it('should prevent multiple clicks when secondary button is already being added', () => {
|
|
289
|
+
const setSecondaryButton = jest.fn();
|
|
290
|
+
const updateHandler = jest.fn();
|
|
291
|
+
const ctaData = [
|
|
292
|
+
{ index: 0, text: 'Primary Button', isSaved: true },
|
|
293
|
+
{ index: 1, text: 'Secondary Button', ctaType: 'SECONDARY' }
|
|
294
|
+
];
|
|
295
|
+
|
|
296
|
+
renderComponent({
|
|
297
|
+
ctaData,
|
|
243
298
|
secondaryButton: true,
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
{ index: 1, text: 'Secondary Button', ctaType: 'SECONDARY', isSaved: true },
|
|
247
|
-
],
|
|
299
|
+
setSecondaryButton,
|
|
300
|
+
updateHandler
|
|
248
301
|
});
|
|
302
|
+
|
|
303
|
+
// Should not render add button when secondaryButton is true and button exists
|
|
304
|
+
expect(screen.queryByTestId('add-secondary-button')).not.toBeInTheDocument();
|
|
305
|
+
});
|
|
249
306
|
|
|
250
|
-
|
|
251
|
-
|
|
252
|
-
|
|
307
|
+
it('should not render add secondary button when secondary button is saved', () => {
|
|
308
|
+
const ctaData = [
|
|
309
|
+
{ index: 0, text: 'Primary Button', isSaved: true },
|
|
310
|
+
{ index: 1, text: 'Secondary Button', isSaved: true }
|
|
311
|
+
];
|
|
312
|
+
|
|
313
|
+
renderComponent({ ctaData });
|
|
314
|
+
|
|
315
|
+
expect(screen.queryByTestId('add-secondary-button')).not.toBeInTheDocument();
|
|
316
|
+
});
|
|
317
|
+
|
|
318
|
+
it('should show secondary CTA when secondary button is active and exists', () => {
|
|
319
|
+
const ctaData = [
|
|
320
|
+
{ index: 0, text: 'Primary Button', isSaved: true },
|
|
321
|
+
{ index: 1, text: 'Secondary Button', ctaType: 'SECONDARY' }
|
|
322
|
+
];
|
|
323
|
+
|
|
324
|
+
renderComponent({
|
|
325
|
+
secondaryButton: true,
|
|
326
|
+
ctaData
|
|
327
|
+
});
|
|
328
|
+
|
|
329
|
+
const secondaryCTA = screen.getByTestId('cap-mpush-cta');
|
|
330
|
+
expect(secondaryCTA).toBeInTheDocument();
|
|
331
|
+
expect(secondaryCTA).toHaveAttribute('data-button-type', 'SECONDARY');
|
|
253
332
|
});
|
|
254
333
|
});
|
|
255
334
|
|
|
@@ -300,18 +379,12 @@ describe('CtaButtons', () => {
|
|
|
300
379
|
it('should render proper component structure', () => {
|
|
301
380
|
renderComponent();
|
|
302
381
|
|
|
303
|
-
expect(screen.
|
|
382
|
+
expect(screen.getByTestId('cap-row')).toBeInTheDocument();
|
|
304
383
|
expect(screen.getByTestId('cap-heading')).toBeInTheDocument();
|
|
305
384
|
expect(screen.getByTestId('cap-icon')).toBeInTheDocument();
|
|
306
385
|
expect(screen.getByTestId('cap-icon')).toHaveAttribute('data-icon-type', 'plus');
|
|
307
386
|
});
|
|
308
387
|
|
|
309
|
-
it('should render (Optional) beside the Buttons heading', () => {
|
|
310
|
-
renderComponent();
|
|
311
|
-
|
|
312
|
-
expect(screen.getByText('(Optional)')).toBeInTheDocument();
|
|
313
|
-
});
|
|
314
|
-
|
|
315
388
|
it('should render heading with correct type', () => {
|
|
316
389
|
renderComponent();
|
|
317
390
|
|
|
@@ -344,6 +417,44 @@ describe('CtaButtons', () => {
|
|
|
344
417
|
expect(updateHandler).not.toHaveBeenCalled();
|
|
345
418
|
});
|
|
346
419
|
|
|
420
|
+
it('should handle early return when secondary button exists and showSecondaryCTA is true', () => {
|
|
421
|
+
const updateHandler = jest.fn();
|
|
422
|
+
const setSecondaryButton = jest.fn();
|
|
423
|
+
const ctaData = [
|
|
424
|
+
{ index: 0, text: 'Primary Button', isSaved: true },
|
|
425
|
+
{ index: 1, text: 'Secondary Button', ctaType: 'SECONDARY' }
|
|
426
|
+
];
|
|
427
|
+
|
|
428
|
+
renderComponent({
|
|
429
|
+
secondaryButton: true,
|
|
430
|
+
ctaData,
|
|
431
|
+
updateHandler,
|
|
432
|
+
setSecondaryButton
|
|
433
|
+
});
|
|
434
|
+
|
|
435
|
+
// Since secondaryButton is true and button exists, updateHandler should not be called
|
|
436
|
+
expect(updateHandler).not.toHaveBeenCalled();
|
|
437
|
+
});
|
|
438
|
+
|
|
439
|
+
it('should handle early return when shouldShowSecondaryCTA is true', () => {
|
|
440
|
+
const updateHandler = jest.fn();
|
|
441
|
+
const setSecondaryButton = jest.fn();
|
|
442
|
+
const ctaData = [
|
|
443
|
+
{ index: 0, text: 'Primary Button', isSaved: true },
|
|
444
|
+
{ index: 1, text: 'Secondary Button', ctaType: 'SECONDARY' }
|
|
445
|
+
];
|
|
446
|
+
|
|
447
|
+
renderComponent({
|
|
448
|
+
secondaryButton: true,
|
|
449
|
+
ctaData,
|
|
450
|
+
updateHandler,
|
|
451
|
+
setSecondaryButton
|
|
452
|
+
});
|
|
453
|
+
|
|
454
|
+
// Since shouldShowSecondaryCTA is true, updateHandler should not be called
|
|
455
|
+
expect(updateHandler).not.toHaveBeenCalled();
|
|
456
|
+
});
|
|
457
|
+
|
|
347
458
|
it('should handle early return in handleAddPrimary when primaryButton and showPrimaryCTA are true', () => {
|
|
348
459
|
const updateHandler = jest.fn();
|
|
349
460
|
const setPrimaryButton = jest.fn();
|
|
@@ -383,5 +494,72 @@ describe('CtaButtons', () => {
|
|
|
383
494
|
expect(setPrimaryButton).not.toHaveBeenCalled();
|
|
384
495
|
}
|
|
385
496
|
});
|
|
497
|
+
|
|
498
|
+
it('should handle early return in handleAddSecondary when secondaryButton and showSecondaryCTA are true', () => {
|
|
499
|
+
const updateHandler = jest.fn();
|
|
500
|
+
const setSecondaryButton = jest.fn();
|
|
501
|
+
const ctaData = [
|
|
502
|
+
{ index: 0, text: 'Primary Button', isSaved: true }
|
|
503
|
+
];
|
|
504
|
+
|
|
505
|
+
const { rerender } = renderComponent({
|
|
506
|
+
secondaryButton: true,
|
|
507
|
+
ctaData,
|
|
508
|
+
updateHandler,
|
|
509
|
+
setSecondaryButton
|
|
510
|
+
});
|
|
511
|
+
|
|
512
|
+
// First click to set showSecondaryCTA to true
|
|
513
|
+
const addButton = screen.getByTestId('add-secondary-button');
|
|
514
|
+
fireEvent.click(addButton);
|
|
515
|
+
|
|
516
|
+
// Clear the mock calls
|
|
517
|
+
updateHandler.mockClear();
|
|
518
|
+
setSecondaryButton.mockClear();
|
|
519
|
+
|
|
520
|
+
// Re-render with secondaryButton true and showSecondaryCTA true (from previous click)
|
|
521
|
+
rerender(
|
|
522
|
+
<Provider store={mockStore}>
|
|
523
|
+
<IntlProvider locale="en" messages={{}}>
|
|
524
|
+
<CtaButtons
|
|
525
|
+
{...defaultProps}
|
|
526
|
+
secondaryButton={true}
|
|
527
|
+
ctaData={ctaData}
|
|
528
|
+
updateHandler={updateHandler}
|
|
529
|
+
setSecondaryButton={setSecondaryButton}
|
|
530
|
+
/>
|
|
531
|
+
</IntlProvider>
|
|
532
|
+
</Provider>
|
|
533
|
+
);
|
|
534
|
+
|
|
535
|
+
// Try to click again - should hit early return
|
|
536
|
+
if (screen.queryByTestId('add-secondary-button')) {
|
|
537
|
+
fireEvent.click(screen.getByTestId('add-secondary-button'));
|
|
538
|
+
expect(updateHandler).not.toHaveBeenCalled();
|
|
539
|
+
expect(setSecondaryButton).not.toHaveBeenCalled();
|
|
540
|
+
}
|
|
541
|
+
});
|
|
542
|
+
|
|
543
|
+
it('should handle early return in handleAddSecondary when shouldShowSecondaryCTA is true', () => {
|
|
544
|
+
const updateHandler = jest.fn();
|
|
545
|
+
const setSecondaryButton = jest.fn();
|
|
546
|
+
const ctaData = [
|
|
547
|
+
{ index: 0, text: 'Primary Button', isSaved: true },
|
|
548
|
+
{ index: 1, text: 'Secondary Button', ctaType: 'SECONDARY' }
|
|
549
|
+
];
|
|
550
|
+
|
|
551
|
+
renderComponent({
|
|
552
|
+
secondaryButton: true,
|
|
553
|
+
ctaData,
|
|
554
|
+
updateHandler,
|
|
555
|
+
setSecondaryButton
|
|
556
|
+
});
|
|
557
|
+
|
|
558
|
+
// Since shouldShowSecondaryCTA is true (secondaryButton is true and button exists),
|
|
559
|
+
// the add button should not be rendered
|
|
560
|
+
expect(screen.queryByTestId('add-secondary-button')).not.toBeInTheDocument();
|
|
561
|
+
expect(updateHandler).not.toHaveBeenCalled();
|
|
562
|
+
expect(setSecondaryButton).not.toHaveBeenCalled();
|
|
563
|
+
});
|
|
386
564
|
});
|
|
387
565
|
});
|