@capillarytech/creatives-library 9.2.2-alpha.sprint-cap-214249.44 → 9.2.2
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 +1 -3
- package/package.json +1 -1
- package/translations/en.json +0 -1
- package/translations/ja-JP.json +0 -1
- package/translations/zh.json +0 -1
- package/utils/common.js +6 -0
- package/utils/createMobilePushPayload.js +56 -50
- package/utils/tagValidations.js +4 -35
- package/utils/tests/createMobilePushPayload.test.js +168 -177
- package/utils/tests/tagValidations.test.js +0 -48
- package/v2Components/CapMpushCTA/index.js +57 -47
- package/v2Components/CapMpushCTA/index.scss +5 -43
- package/v2Components/CapTagList/index.js +7 -46
- package/v2Components/CapTagList/messages.js +0 -44
- package/v2Components/CapTagList/style.scss +1 -113
- package/v2Components/CommonTestAndPreview/UnifiedPreview/MobilePushPreviewContent.js +8 -11
- package/v2Components/CommonTestAndPreview/UnifiedPreview/_unifiedPreview.scss +1 -13
- package/v2Components/CommonTestAndPreview/constants.js +0 -2
- package/v2Components/CommonTestAndPreview/index.js +12 -51
- package/v2Components/CommonTestAndPreview/tests/UnifiedPreview/MobilePushPreviewContent.test.js +5 -83
- package/v2Components/CommonTestAndPreview/tests/index.test.js +0 -100
- package/v2Components/FormBuilder/Classic.js +14 -24
- package/v2Components/FormBuilder/Functional/channels/mobilepush/config.js +0 -1
- package/v2Components/FormBuilder/Functional/channels/mobilepush/getEditorErrorDescriptor.js +1 -1
- package/v2Components/FormBuilder/Functional/channels/mobilepush/tests/validate.test.js +0 -57
- package/v2Components/FormBuilder/Functional/channels/mobilepush/validate.js +4 -4
- package/v2Components/FormBuilder/Functional/channels/sms/getEditorErrorDescriptor.js +0 -3
- package/v2Components/FormBuilder/Functional/channels/sms/tests/getEditorErrorDescriptor.test.js +0 -5
- package/v2Components/FormBuilder/Functional/channels/sms/tests/validate.test.js +0 -6
- package/v2Components/FormBuilder/Functional/channels/sms/validate.js +1 -3
- package/v2Components/FormBuilder/Functional/renderers/mpushRenderers.js +0 -3
- package/v2Components/FormBuilder/Functional/tests/mpushRenderers.test.js +0 -22
- package/v2Components/MobilePushPreviewV2/index.js +9 -22
- package/v2Components/TemplatePreview/_templatePreview.scss +2 -18
- package/v2Components/TemplatePreview/index.js +18 -20
- package/v2Components/TemplatePreview/tests/index.test.js +0 -69
- package/v2Containers/Cap/messages.js +0 -4
- package/v2Containers/Cap/tests/__snapshots__/index.test.js.snap +0 -1
- package/v2Containers/CommunicationFlow/steps/ChannelSelectionStep/extractContentForPreview.js +2 -12
- 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 +1 -4
- package/v2Containers/Line/Container/ImageCarousel/tests/__snapshots__/content.test.js.snap +0 -3
- package/v2Containers/Line/Container/ImageCarousel/tests/__snapshots__/index.test.js.snap +0 -2
- package/v2Containers/Line/Container/Text/index.js +1 -3
- package/v2Containers/Line/Container/Wrapper/tests/__snapshots__/index.test.js.snap +0 -16
- package/v2Containers/Line/Container/tests/__snapshots__/index.test.js.snap +0 -18
- package/v2Containers/MobilePushNew/components/CtaButtons.js +47 -52
- package/v2Containers/MobilePushNew/components/MediaUploaders.js +345 -105
- package/v2Containers/MobilePushNew/components/PlatformContentFields.js +105 -127
- package/v2Containers/MobilePushNew/components/tests/CtaButtons.test.js +208 -30
- package/v2Containers/MobilePushNew/components/tests/MediaUploaders.test.js +1484 -307
- package/v2Containers/MobilePushNew/components/tests/PlatformContentFields.test.js +59 -165
- package/v2Containers/MobilePushNew/constants.js +0 -12
- package/v2Containers/MobilePushNew/hooks/tests/usePlatformSync.test.js +1 -63
- package/v2Containers/MobilePushNew/hooks/tests/useUpload.test.js +0 -78
- package/v2Containers/MobilePushNew/hooks/usePlatformSync.js +1 -40
- package/v2Containers/MobilePushNew/hooks/useUpload.js +46 -42
- package/v2Containers/MobilePushNew/index.js +290 -502
- package/v2Containers/MobilePushNew/index.scss +4 -151
- package/v2Containers/MobilePushNew/messages.js +6 -106
- package/v2Containers/MobilePushNew/tests/index.test.js +1 -483
- package/v2Containers/MobilePushNew/tests/utils.test.js +0 -110
- package/v2Containers/MobilePushNew/utils.js +0 -83
- package/v2Containers/Rcs/index.js +1 -8
- package/v2Containers/Rcs/tests/__snapshots__/index.test.js.snap +0 -59
- package/v2Containers/SmsTrai/Create/tests/__snapshots__/index.test.js.snap +0 -4
- package/v2Containers/SmsTrai/Edit/index.js +5 -13
- package/v2Containers/SmsTrai/Edit/tests/__snapshots__/index.test.js.snap +0 -15
- package/v2Containers/Templates/_templates.scss +2 -10
- package/v2Containers/Templates/index.js +81 -86
- package/v2Containers/Templates/tests/index.test.js +0 -81
- package/v2Containers/Viber/index.js +1 -3
- package/v2Containers/WebPush/Create/utils/validation.js +0 -6
- package/v2Containers/WebPush/Create/utils/validation.test.js +0 -50
- package/v2Containers/Whatsapp/index.js +5 -9
- package/v2Containers/Whatsapp/tests/__snapshots__/index.test.js.snap +2 -2
- package/v2Containers/Zalo/index.js +1 -4
- package/v2Components/CapMpushCTA/tests/index.test.js +0 -150
- package/v2Components/CapTagList/TagFallbackPanel.js +0 -124
- package/v2Components/CapTagList/constants.js +0 -5
- package/v2Components/CapTagList/tests/TagFallback.test.js +0 -222
- package/v2Components/CapTagList/utils.js +0 -17
- package/v2Components/MobilePushPreviewV2/_mobilePushPreviewV2.scss +0 -7
- package/v2Components/MobilePushPreviewV2/tests/index.test.js +0 -55
- package/v2Components/TemplatePreview/_mobilePushPhone.scss +0 -72
- package/v2Containers/CommunicationFlow/steps/ChannelSelectionStep/Tests/extractContentForPreview.test.js +0 -45
- 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,20 +16,15 @@ 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
|
-
TAP_ACTION_OPTIONS,
|
|
23
23
|
} from "../constants";
|
|
24
24
|
import messages from "../messages";
|
|
25
25
|
import MediaUploaders from "./MediaUploaders";
|
|
26
26
|
import CtaButtons from "./CtaButtons";
|
|
27
|
-
import { SavedTapLink, TapLinkSaveDelete } from "./TapLinkActions";
|
|
28
27
|
import { hasPersonalizationTags } from "../../../utils/commonUtils";
|
|
29
|
-
import {
|
|
30
|
-
getDeepLinkParamValue, setDeepLinkParamValue, hasAllDeepLinkParams, splitDeepLinkParam,
|
|
31
|
-
} from "../utils";
|
|
32
28
|
|
|
33
29
|
const PlatformContentFields = ({
|
|
34
30
|
deviceType,
|
|
@@ -60,11 +56,11 @@ const PlatformContentFields = ({
|
|
|
60
56
|
handleTitleChange,
|
|
61
57
|
handleMessageChange,
|
|
62
58
|
handleMediaTypeChange,
|
|
63
|
-
|
|
59
|
+
handleActionOnClickChange,
|
|
60
|
+
handleLinkTypeChange,
|
|
64
61
|
handleDeepLinkChange,
|
|
65
62
|
handleDeepLinkKeysChange,
|
|
66
63
|
handleExternalLinkChange,
|
|
67
|
-
handleTapLinkSavedChange,
|
|
68
64
|
onTagSelect,
|
|
69
65
|
handleOnTagsContextChange,
|
|
70
66
|
} = handlers;
|
|
@@ -102,10 +98,6 @@ const PlatformContentFields = ({
|
|
|
102
98
|
} else if (deepLinkKeysFromSelection) {
|
|
103
99
|
deepLinkKeysFromSelectionArray = [deepLinkKeysFromSelection];
|
|
104
100
|
}
|
|
105
|
-
// One input per configured key; the saved keys only while no option matches (options still loading)
|
|
106
|
-
const deepLinkInputKeys = selectedDeepLink
|
|
107
|
-
? deepLinkKeysFromSelectionArray
|
|
108
|
-
: deepLinkKeysArray.map((entry) => splitDeepLinkParam(entry)[0]);
|
|
109
101
|
|
|
110
102
|
const onTitleChange = useCallback(
|
|
111
103
|
({ target: { value } }) => {
|
|
@@ -128,36 +120,27 @@ const PlatformContentFields = ({
|
|
|
128
120
|
[handleMediaTypeChange, deviceType]
|
|
129
121
|
);
|
|
130
122
|
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
const onTapActionChange = useCallback(
|
|
136
|
-
(value) => handleTapActionChange(value),
|
|
137
|
-
[handleTapActionChange]
|
|
123
|
+
const onActionOnClickChange = useCallback(
|
|
124
|
+
(e) => handleActionOnClickChange(deviceType, e.target.checked),
|
|
125
|
+
[handleActionOnClickChange, deviceType]
|
|
138
126
|
);
|
|
139
127
|
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|| !hasAllDeepLinkParams(deepLinkKeysArray, deepLinkKeysFromSelectionArray)
|
|
145
|
-
|| !!errors?.deepLink || !!errors?.deepLinkKeys)
|
|
146
|
-
: (!externalLinkValue?.trim() || !!errors?.externalLink);
|
|
147
|
-
const savedTapLinkText = tapAction === DEEP_LINK
|
|
148
|
-
? (selectedDeepLink?.label || deepLinkValue)
|
|
149
|
-
: externalLinkValue;
|
|
128
|
+
const onLinkTypeChange = useCallback(
|
|
129
|
+
(value) => handleLinkTypeChange(deviceType, value),
|
|
130
|
+
[handleLinkTypeChange, deviceType]
|
|
131
|
+
);
|
|
150
132
|
|
|
151
133
|
const onDeepLinkChange = useCallback((value) => handleDeepLinkChange(value), [
|
|
152
134
|
handleDeepLinkChange,
|
|
153
135
|
]);
|
|
154
136
|
|
|
155
|
-
// Stores "key=value" for the configured key being typed into
|
|
156
137
|
const onDeepLinkKeysChange = useCallback(
|
|
157
|
-
(
|
|
158
|
-
|
|
138
|
+
({ target: { value } }) => {
|
|
139
|
+
// Parse comma-separated values into array
|
|
140
|
+
const keysArray = value?.split(',')?.map((key) => key?.trim())?.filter((key) => key?.length > 0);
|
|
141
|
+
handleDeepLinkKeysChange(keysArray);
|
|
159
142
|
},
|
|
160
|
-
[handleDeepLinkKeysChange
|
|
143
|
+
[handleDeepLinkKeysChange]
|
|
161
144
|
);
|
|
162
145
|
|
|
163
146
|
const onExternalLinkChange = useCallback(
|
|
@@ -248,7 +231,8 @@ const PlatformContentFields = ({
|
|
|
248
231
|
<CapHeading type="h3" className="mpush-media-type">
|
|
249
232
|
<FormattedMessage {...messages.mediaType} />
|
|
250
233
|
</CapHeading>
|
|
251
|
-
<CapSelect
|
|
234
|
+
<CapSelect.CapCustomSelect
|
|
235
|
+
width="100%"
|
|
252
236
|
className="margin-t-4"
|
|
253
237
|
options={MEDIA_TYPES_OPTIONS}
|
|
254
238
|
value={content.mediaType}
|
|
@@ -258,53 +242,57 @@ const PlatformContentFields = ({
|
|
|
258
242
|
mediaType={content.mediaType}
|
|
259
243
|
{...mediaUploaderProps}
|
|
260
244
|
formatMessage={formatMessage}
|
|
245
|
+
location={location}
|
|
246
|
+
tags={tags}
|
|
247
|
+
injectedTags={injectedTags}
|
|
248
|
+
selectedOfferDetails={selectedOfferDetails}
|
|
249
|
+
handleOnTagsContextChange={handleOnTagsContextChange}
|
|
261
250
|
/>
|
|
262
251
|
</CapRow>
|
|
263
|
-
{
|
|
264
|
-
|
|
265
|
-
|
|
266
|
-
|
|
267
|
-
|
|
268
|
-
|
|
269
|
-
|
|
270
|
-
|
|
271
|
-
|
|
272
|
-
|
|
273
|
-
|
|
274
|
-
</
|
|
275
|
-
|
|
276
|
-
|
|
277
|
-
|
|
278
|
-
|
|
279
|
-
|
|
280
|
-
|
|
281
|
-
|
|
282
|
-
|
|
283
|
-
|
|
284
|
-
|
|
285
|
-
|
|
286
|
-
|
|
287
|
-
|
|
288
|
-
|
|
289
|
-
|
|
290
|
-
|
|
291
|
-
|
|
292
|
-
<CapHeading type="h4" className="mpush-tap-label">
|
|
293
|
-
<FormattedMessage {...messages.whenTappedOpen} />
|
|
252
|
+
{content?.mediaType !== CAROUSEL && (
|
|
253
|
+
<>
|
|
254
|
+
<CapDivider />
|
|
255
|
+
<CapRow useLegacy className="creatives-mpush-actions">
|
|
256
|
+
<CapRow useLegacy className="mpush-actions-main">
|
|
257
|
+
<CapHeading type="h3" className="mpush-actions">
|
|
258
|
+
<FormattedMessage {...messages.buttonsAndLinks} />
|
|
259
|
+
</CapHeading>
|
|
260
|
+
<CapLabel className="optional-text">
|
|
261
|
+
<FormattedMessage {...messages.optionalText} />
|
|
262
|
+
</CapLabel>
|
|
263
|
+
</CapRow>
|
|
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} />
|
|
294
281
|
</CapHeading>
|
|
295
|
-
<CapSelect
|
|
296
|
-
|
|
297
|
-
|
|
298
|
-
|
|
299
|
-
|
|
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)}
|
|
300
288
|
/>
|
|
301
289
|
</CapColumn>
|
|
302
|
-
{
|
|
303
|
-
<CapColumn
|
|
304
|
-
<CapHeading type="h4" className="
|
|
305
|
-
|
|
290
|
+
{content.linkType === DEEP_LINK && (
|
|
291
|
+
<CapColumn span={14}>
|
|
292
|
+
<CapHeading type="h4" className="buttons-heading">
|
|
293
|
+
{formatMessage(messages.deepLink)}
|
|
306
294
|
</CapHeading>
|
|
307
|
-
<CapSelect
|
|
295
|
+
<CapSelect.CapCustomSelect
|
|
308
296
|
options={(() => {
|
|
309
297
|
const options = [...(deepLink || [])];
|
|
310
298
|
// If the current value is not in the options, add it
|
|
@@ -316,45 +304,19 @@ const PlatformContentFields = ({
|
|
|
316
304
|
}
|
|
317
305
|
return options;
|
|
318
306
|
})()}
|
|
319
|
-
value={deepLinkValue
|
|
307
|
+
value={deepLinkValue}
|
|
320
308
|
onChange={onDeepLinkChange}
|
|
321
309
|
key="mobile-push-deep-link-type"
|
|
322
310
|
placeholder={formatMessage(messages.selectDeepLink)}
|
|
311
|
+
style={{ marginTop: "10px" }}
|
|
323
312
|
/>
|
|
324
|
-
{errors?.deepLink && (
|
|
325
|
-
<CapError className="mobile-push-deep-link-error">
|
|
326
|
-
{errors.deepLink}
|
|
327
|
-
</CapError>
|
|
328
|
-
)}
|
|
329
|
-
{deepLinkValue && deepLinkInputKeys.length > 0 && (
|
|
330
|
-
<CapRow className="mpush-tap-deep-link-keys">
|
|
331
|
-
<CapHeading type="h4" className="deep-link-keys-heading">
|
|
332
|
-
{formatMessage(messages.deepLinkKeys)}
|
|
333
|
-
</CapHeading>
|
|
334
|
-
{deepLinkInputKeys.map((key, keyIndex) => (
|
|
335
|
-
<CapRow useLegacy key={key} className="mpush-deep-link-key">
|
|
336
|
-
<CapLabel type="label2" className="deep-link-keys-value">
|
|
337
|
-
{key}
|
|
338
|
-
</CapLabel>
|
|
339
|
-
<CapInput
|
|
340
|
-
id={keyIndex === 0 ? "mobile-push-deep-link-keys-input" : `mobile-push-deep-link-keys-input-${keyIndex}`}
|
|
341
|
-
onChange={({ target: { value } }) => onDeepLinkKeysChange(key, value)}
|
|
342
|
-
placeholder={formatMessage(messages.deepLinkKeysPlaceholder, { key })}
|
|
343
|
-
value={getDeepLinkParamValue(deepLinkKeysArray, key)}
|
|
344
|
-
size="default"
|
|
345
|
-
error={keyIndex === deepLinkInputKeys.length - 1 ? errors?.deepLinkKeys : undefined}
|
|
346
|
-
/>
|
|
347
|
-
</CapRow>
|
|
348
|
-
))}
|
|
349
|
-
</CapRow>
|
|
350
|
-
)}
|
|
351
313
|
</CapColumn>
|
|
352
314
|
)}
|
|
353
|
-
{
|
|
354
|
-
<CapColumn
|
|
355
|
-
<CapRow
|
|
356
|
-
<CapHeading type="h4" className="
|
|
357
|
-
|
|
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)}
|
|
358
320
|
</CapHeading>
|
|
359
321
|
<TagList
|
|
360
322
|
moduleFilterEnabled={
|
|
@@ -376,7 +338,7 @@ const PlatformContentFields = ({
|
|
|
376
338
|
<CapInput
|
|
377
339
|
id="mobile-push-external-link-input"
|
|
378
340
|
onChange={onExternalLinkChange}
|
|
379
|
-
placeholder={formatMessage(messages.
|
|
341
|
+
placeholder={formatMessage(messages.enterExternalLink)}
|
|
380
342
|
value={externalLinkValue}
|
|
381
343
|
size="default"
|
|
382
344
|
isRequired
|
|
@@ -391,23 +353,40 @@ const PlatformContentFields = ({
|
|
|
391
353
|
</CapColumn>
|
|
392
354
|
)}
|
|
393
355
|
</CapRow>
|
|
394
|
-
|
|
395
|
-
|
|
396
|
-
|
|
397
|
-
|
|
398
|
-
|
|
399
|
-
|
|
400
|
-
|
|
401
|
-
|
|
402
|
-
|
|
403
|
-
|
|
404
|
-
|
|
405
|
-
|
|
406
|
-
|
|
407
|
-
|
|
408
|
-
|
|
409
|
-
|
|
410
|
-
|
|
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
|
+
})()}
|
|
373
|
+
</CapLabel>
|
|
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}
|
|
382
|
+
/>
|
|
383
|
+
</CapColumn>
|
|
384
|
+
</CapRow>
|
|
385
|
+
)}
|
|
386
|
+
</CapRow>
|
|
387
|
+
<CtaButtons {...ctaButtonProps} />
|
|
388
|
+
</>
|
|
389
|
+
)}
|
|
411
390
|
</CapRow>
|
|
412
391
|
</>
|
|
413
392
|
);
|
|
@@ -420,7 +399,6 @@ PlatformContentFields.propTypes = {
|
|
|
420
399
|
title: PropTypes.string,
|
|
421
400
|
message: PropTypes.string,
|
|
422
401
|
externalLink: PropTypes.string,
|
|
423
|
-
deepLink: PropTypes.string,
|
|
424
402
|
deepLinkKeys: PropTypes.string,
|
|
425
403
|
}).isRequired,
|
|
426
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
|
});
|