@capillarytech/creatives-library 9.1.7 → 9.1.8-alpha.sprint-cap-214249.38
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/index.js +0 -13
- package/package.json +1 -1
- package/services/getSchema.js +1 -4
- package/services/tests/getSchema.test.js +2 -2
- package/utils/common.js +0 -6
- package/utils/createMobilePushPayload.js +47 -33
- package/utils/tests/createMobilePushPayload.test.js +102 -8
- package/v2Components/CapMpushCTA/index.js +10 -9
- package/v2Components/CapMpushCTA/index.scss +29 -3
- package/v2Components/CapMpushCTA/tests/index.test.js +89 -0
- package/v2Components/CommonTestAndPreview/UnifiedPreview/MobilePushPreviewContent.js +26 -13
- package/v2Components/CommonTestAndPreview/UnifiedPreview/_unifiedPreview.scss +13 -1
- package/v2Components/CommonTestAndPreview/constants.js +2 -0
- package/v2Components/CommonTestAndPreview/index.js +49 -11
- package/v2Components/CommonTestAndPreview/tests/UnifiedPreview/MobilePushPreviewContent.test.js +79 -5
- package/v2Components/CommonTestAndPreview/tests/index.test.js +86 -0
- package/v2Components/FormBuilder/Functional/tests/mpush.crossFlowParity.test.js +1 -1
- package/v2Components/FormBuilder/Functional/tests/mpush.shellEvents.test.js +1 -1
- package/v2Components/FormBuilder/Functional/tests/mpush.singlePlatform.test.js +1 -1
- package/v2Components/FormBuilder/tests/mpush.characterization.test.js +2 -2
- package/v2Components/TemplatePreview/_templatePreview.scss +12 -2
- package/v2Components/TemplatePreview/index.js +30 -17
- package/v2Components/TemplatePreview/tests/index.test.js +61 -0
- package/v2Containers/Cap/index.js +0 -3
- package/v2Containers/CreativesContainer/SlideBoxContent.js +70 -151
- package/v2Containers/CreativesContainer/index.js +3 -6
- package/v2Containers/CreativesContainer/tests/SlideBoxContent.test.js +29 -0
- package/v2Containers/MobilePushNew/components/CtaButtons.js +52 -47
- package/v2Containers/MobilePushNew/components/MediaUploaders.js +207 -192
- package/v2Containers/MobilePushNew/components/PlatformContentFields.js +116 -121
- package/v2Containers/MobilePushNew/components/tests/CtaButtons.test.js +30 -208
- package/v2Containers/MobilePushNew/components/tests/MediaUploaders.test.js +316 -72
- package/v2Containers/MobilePushNew/components/tests/PlatformContentFields.test.js +45 -16
- package/v2Containers/MobilePushNew/constants.js +5 -0
- package/v2Containers/MobilePushNew/hooks/tests/usePlatformSync.test.js +63 -1
- package/v2Containers/MobilePushNew/hooks/tests/useUpload.test.js +52 -0
- package/v2Containers/MobilePushNew/hooks/usePlatformSync.js +38 -1
- package/v2Containers/MobilePushNew/hooks/useUpload.js +29 -39
- package/v2Containers/MobilePushNew/index.js +453 -188
- package/v2Containers/MobilePushNew/index.scss +188 -4
- package/v2Containers/MobilePushNew/messages.js +86 -6
- package/v2Containers/MobilePushNew/tests/index.test.js +450 -1
- package/v2Containers/MobilePushNew/tests/utils.test.js +25 -0
- package/v2Containers/MobilePushNew/utils.js +8 -0
- package/v2Containers/Templates/_templates.scss +10 -2
- package/v2Containers/Templates/index.js +84 -90
- package/v2Containers/Templates/tests/index.test.js +68 -0
- package/v2Components/FormBuilder/Functional/tests/manual.typingPerf.test.js +0 -135
- package/v2Components/FormBuilder/Functional/tests/mpush.ctaFlows.parity.test.js +0 -320
- package/v2Components/FormBuilder/Functional/tests/mpush.editContainer.parity.test.js +0 -148
- package/v2Components/FormBuilder/Functional/tests/mpush.libraryValidity.parity.test.js +0 -152
- package/v2Containers/MobilePush/Create/_mobilePushCreate.scss +0 -70
- package/v2Containers/MobilePush/Create/actions.js +0 -52
- package/v2Containers/MobilePush/Create/constants.js +0 -26
- package/v2Containers/MobilePush/Create/index.js +0 -2149
- package/v2Containers/MobilePush/Create/messages.js +0 -349
- package/v2Containers/MobilePush/Create/reducer.js +0 -72
- package/v2Containers/MobilePush/Create/sagas.js +0 -79
- package/v2Containers/MobilePush/Create/selectors.js +0 -29
- package/v2Containers/MobilePush/Create/test/contentValidity.test.js +0 -154
- package/v2Containers/MobilePush/Create/test/saga.test.js +0 -19
- package/v2Containers/MobilePush/Create/test/stayOpenOnSave.test.js +0 -80
- package/v2Containers/MobilePush/Edit/_mobilePushCreate.scss +0 -65
- package/v2Containers/MobilePush/Edit/actions.js +0 -94
- package/v2Containers/MobilePush/Edit/constants.js +0 -37
- package/v2Containers/MobilePush/Edit/index.js +0 -2407
- package/v2Containers/MobilePush/Edit/messages.js +0 -341
- package/v2Containers/MobilePush/Edit/reducer.js +0 -113
- package/v2Containers/MobilePush/Edit/sagas.js +0 -113
- package/v2Containers/MobilePush/Edit/selectors.js +0 -33
- package/v2Containers/MobilePush/Edit/test/contentValidity.test.js +0 -149
- package/v2Containers/MobilePush/Edit/test/saga.test.js +0 -255
- package/v2Containers/MobilePush/Edit/test/stayOpenOnSave.test.js +0 -60
- package/v2Containers/MobilePush/commonMethods.js +0 -333
- package/v2Containers/MobilePush/eventsMap.js +0 -130
- package/v2Containers/MobilePush/tests/commonMethods.test.js +0 -401
- package/v2Containers/MobilepushWrapper/_mobilepushWrapper.scss +0 -22
- package/v2Containers/MobilepushWrapper/index.js +0 -178
- package/v2Containers/MobilepushWrapper/messages.js +0 -29
- /package/{v2Containers/MobilePush/initialSchema.js → v2Components/FormBuilder/Functional/tests/fixtures/mpushInitialSchema.js} +0 -0
|
@@ -8,7 +8,6 @@ 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";
|
|
12
11
|
import CapLabel from "@capillarytech/cap-ui-library/CapLabel";
|
|
13
12
|
import CapInfoNote from "@capillarytech/cap-ui-library/CapInfoNote";
|
|
14
13
|
import TagList from "../../TagList";
|
|
@@ -16,10 +15,10 @@ import {
|
|
|
16
15
|
ANDROID,
|
|
17
16
|
IOS,
|
|
18
17
|
MEDIA_TYPES_OPTIONS,
|
|
19
|
-
LINK_TYPE_OPTIONS,
|
|
20
18
|
DEEP_LINK,
|
|
21
19
|
EXTERNAL_LINK,
|
|
22
20
|
CAROUSEL,
|
|
21
|
+
TAP_ACTION_APP,
|
|
23
22
|
} from "../constants";
|
|
24
23
|
import messages from "../messages";
|
|
25
24
|
import MediaUploaders from "./MediaUploaders";
|
|
@@ -56,8 +55,7 @@ const PlatformContentFields = ({
|
|
|
56
55
|
handleTitleChange,
|
|
57
56
|
handleMessageChange,
|
|
58
57
|
handleMediaTypeChange,
|
|
59
|
-
|
|
60
|
-
handleLinkTypeChange,
|
|
58
|
+
handleTapActionChange,
|
|
61
59
|
handleDeepLinkChange,
|
|
62
60
|
handleDeepLinkKeysChange,
|
|
63
61
|
handleExternalLinkChange,
|
|
@@ -120,14 +118,17 @@ const PlatformContentFields = ({
|
|
|
120
118
|
[handleMediaTypeChange, deviceType]
|
|
121
119
|
);
|
|
122
120
|
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
121
|
+
// "When tapped, open": App when there is no tap action, else the link type
|
|
122
|
+
const tapAction = content?.actionOnClick ? (content?.linkType || DEEP_LINK) : TAP_ACTION_APP;
|
|
123
|
+
const tapActionOptions = [
|
|
124
|
+
{ label: formatMessage(messages.tapActionApp), value: TAP_ACTION_APP },
|
|
125
|
+
{ label: formatMessage(messages.tapActionDeepLink), value: DEEP_LINK },
|
|
126
|
+
{ label: formatMessage(messages.tapActionExternalLink), value: EXTERNAL_LINK },
|
|
127
|
+
];
|
|
127
128
|
|
|
128
|
-
const
|
|
129
|
-
(value) =>
|
|
130
|
-
[
|
|
129
|
+
const onTapActionChange = useCallback(
|
|
130
|
+
(value) => handleTapActionChange(value),
|
|
131
|
+
[handleTapActionChange]
|
|
131
132
|
);
|
|
132
133
|
|
|
133
134
|
const onDeepLinkChange = useCallback((value) => handleDeepLinkChange(value), [
|
|
@@ -253,135 +254,129 @@ const PlatformContentFields = ({
|
|
|
253
254
|
<>
|
|
254
255
|
<CapDivider />
|
|
255
256
|
<CapRow useLegacy className="creatives-mpush-actions">
|
|
256
|
-
|
|
257
|
+
{/* Heading with "(Optional)" on the same line */}
|
|
258
|
+
<CapRow type="flex" align="middle" noWrap className="mpush-section-heading">
|
|
257
259
|
<CapHeading type="h3" className="mpush-actions">
|
|
258
|
-
<FormattedMessage {...messages.
|
|
260
|
+
<FormattedMessage {...messages.notificationTap} />
|
|
259
261
|
</CapHeading>
|
|
260
262
|
<CapLabel className="optional-text">
|
|
261
263
|
<FormattedMessage {...messages.optionalText} />
|
|
262
264
|
</CapLabel>
|
|
263
265
|
</CapRow>
|
|
264
|
-
<
|
|
265
|
-
|
|
266
|
-
|
|
267
|
-
|
|
268
|
-
>
|
|
269
|
-
<
|
|
270
|
-
|
|
271
|
-
|
|
272
|
-
|
|
273
|
-
<
|
|
274
|
-
|
|
275
|
-
|
|
276
|
-
|
|
277
|
-
|
|
278
|
-
|
|
279
|
-
|
|
280
|
-
|
|
266
|
+
<CapLabel className="mpush-tap-description">
|
|
267
|
+
<FormattedMessage {...messages.notificationTapDescription} />
|
|
268
|
+
</CapLabel>
|
|
269
|
+
{/* Dropdown (30%) with its link field filling the rest */}
|
|
270
|
+
<CapRow type="flex" noWrap gap={16} className="mpush-tap-row">
|
|
271
|
+
<CapColumn flex="0 0 30%" className="mpush-tap-action">
|
|
272
|
+
<CapHeading type="h4" className="mpush-tap-label">
|
|
273
|
+
<FormattedMessage {...messages.whenTappedOpen} />
|
|
274
|
+
</CapHeading>
|
|
275
|
+
<CapSelect.CapCustomSelect
|
|
276
|
+
id={`mobile-push-tap-action-${deviceType}`}
|
|
277
|
+
width="100%"
|
|
278
|
+
options={tapActionOptions}
|
|
279
|
+
value={tapAction}
|
|
280
|
+
onChange={onTapActionChange}
|
|
281
|
+
/>
|
|
282
|
+
</CapColumn>
|
|
283
|
+
{tapAction === DEEP_LINK && (
|
|
284
|
+
<CapColumn flex="1 1 0" className="mpush-tap-link">
|
|
285
|
+
<CapHeading type="h4" className="mpush-tap-label">
|
|
286
|
+
<FormattedMessage {...messages.tapActionDeepLink} />
|
|
281
287
|
</CapHeading>
|
|
282
288
|
<CapSelect.CapCustomSelect
|
|
283
|
-
|
|
284
|
-
|
|
285
|
-
|
|
286
|
-
|
|
289
|
+
width="100%"
|
|
290
|
+
options={(() => {
|
|
291
|
+
const options = [...(deepLink || [])];
|
|
292
|
+
// If the current value is not in the options, add it
|
|
293
|
+
if (deepLinkValue && !options.find((opt) => opt.value === deepLinkValue)) {
|
|
294
|
+
options.push({
|
|
295
|
+
value: deepLinkValue,
|
|
296
|
+
label: deepLinkValue,
|
|
297
|
+
});
|
|
298
|
+
}
|
|
299
|
+
return options;
|
|
300
|
+
})()}
|
|
301
|
+
value={deepLinkValue}
|
|
302
|
+
onChange={onDeepLinkChange}
|
|
303
|
+
key="mobile-push-deep-link-type"
|
|
287
304
|
selectPlaceholder={formatMessage(messages.selectDeepLink)}
|
|
288
305
|
/>
|
|
289
|
-
|
|
290
|
-
|
|
291
|
-
|
|
292
|
-
|
|
293
|
-
{formatMessage(messages.deepLink)}
|
|
294
|
-
</CapHeading>
|
|
295
|
-
<CapSelect.CapCustomSelect
|
|
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" }}
|
|
312
|
-
/>
|
|
313
|
-
</CapColumn>
|
|
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)}
|
|
306
|
+
{deepLinkValue && (deepLinkKeysFromSelectionArray?.length > 0 || deepLinkKeysArray?.length > 0) && (
|
|
307
|
+
<CapRow className="mpush-tap-deep-link-keys">
|
|
308
|
+
<CapHeading type="h4" className="deep-link-keys-heading">
|
|
309
|
+
{formatMessage(messages.deepLinkKeys)}
|
|
320
310
|
</CapHeading>
|
|
321
|
-
<
|
|
322
|
-
|
|
323
|
-
|
|
324
|
-
|
|
325
|
-
|
|
326
|
-
|
|
327
|
-
|
|
328
|
-
|
|
329
|
-
|
|
330
|
-
|
|
331
|
-
|
|
332
|
-
|
|
333
|
-
|
|
334
|
-
|
|
335
|
-
}
|
|
311
|
+
<CapLabel type="label2" className="deep-link-keys-value">
|
|
312
|
+
{(() => {
|
|
313
|
+
if (deepLinkKeysFromSelectionArray?.length > 0) {
|
|
314
|
+
return deepLinkKeysFromSelectionArray?.join(', ');
|
|
315
|
+
}
|
|
316
|
+
if (deepLinkKeysArray?.length > 0) {
|
|
317
|
+
return deepLinkKeysArray?.join(', ');
|
|
318
|
+
}
|
|
319
|
+
return '';
|
|
320
|
+
})()}
|
|
321
|
+
</CapLabel>
|
|
322
|
+
<CapInput
|
|
323
|
+
id="mobile-push-deep-link-keys-input"
|
|
324
|
+
onChange={onDeepLinkKeysChange}
|
|
325
|
+
placeholder={formatMessage(messages.deepLinkKeysPlaceholder, { key: deepLinkKeysFromSelectionArray?.join(', ') })}
|
|
326
|
+
value={Array.isArray(deepLinkKeysValue) ? deepLinkKeysValue?.join(', ') : (deepLinkKeysValue || "")}
|
|
327
|
+
size="default"
|
|
328
|
+
style={{ marginTop: "10px" }}
|
|
329
|
+
error={errors?.deepLinkKeys}
|
|
336
330
|
/>
|
|
337
331
|
</CapRow>
|
|
338
|
-
|
|
339
|
-
|
|
340
|
-
|
|
341
|
-
|
|
342
|
-
|
|
343
|
-
|
|
344
|
-
|
|
345
|
-
|
|
346
|
-
|
|
347
|
-
|
|
348
|
-
|
|
349
|
-
|
|
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(', ');
|
|
332
|
+
)}
|
|
333
|
+
</CapColumn>
|
|
334
|
+
)}
|
|
335
|
+
{tapAction === EXTERNAL_LINK && (
|
|
336
|
+
<CapColumn flex="1 1 0" className="mpush-tap-link">
|
|
337
|
+
<CapRow type="flex" align="middle" justify="space-between" noWrap className="mpush-tap-link-header">
|
|
338
|
+
<CapHeading type="h4" className="mpush-tap-label">
|
|
339
|
+
<FormattedMessage {...messages.url} />
|
|
340
|
+
</CapHeading>
|
|
341
|
+
<TagList
|
|
342
|
+
moduleFilterEnabled={
|
|
343
|
+
location?.query?.type !== "embedded"
|
|
367
344
|
}
|
|
368
|
-
|
|
369
|
-
|
|
345
|
+
label={formatMessage(messages.addLabels)}
|
|
346
|
+
onTagSelect={onButtonTagSelect}
|
|
347
|
+
onContextChange={handleOnTagsContextChange}
|
|
348
|
+
location={location}
|
|
349
|
+
tags={tags}
|
|
350
|
+
injectedTags={injectedTags}
|
|
351
|
+
selectedOfferDetails={selectedOfferDetails}
|
|
352
|
+
disabled={restrictPersonalization}
|
|
353
|
+
disableTooltipMsg={
|
|
354
|
+
restrictPersonalization ? formatMessage(messages.personalizationNotSupportedAnonymous) : undefined
|
|
370
355
|
}
|
|
371
|
-
|
|
372
|
-
|
|
373
|
-
</CapLabel>
|
|
356
|
+
/>
|
|
357
|
+
</CapRow>
|
|
374
358
|
<CapInput
|
|
375
|
-
id="mobile-push-
|
|
376
|
-
onChange={
|
|
377
|
-
placeholder={formatMessage(messages.
|
|
378
|
-
value={
|
|
359
|
+
id="mobile-push-external-link-input"
|
|
360
|
+
onChange={onExternalLinkChange}
|
|
361
|
+
placeholder={formatMessage(messages.enterUrl)}
|
|
362
|
+
value={externalLinkValue}
|
|
379
363
|
size="default"
|
|
380
|
-
|
|
381
|
-
|
|
364
|
+
isRequired
|
|
365
|
+
errorMessage={
|
|
366
|
+
errors.externalLink && (
|
|
367
|
+
<CapError className="mobile-push-external-link-error">
|
|
368
|
+
{errors.externalLink}
|
|
369
|
+
</CapError>
|
|
370
|
+
)
|
|
371
|
+
}
|
|
382
372
|
/>
|
|
383
373
|
</CapColumn>
|
|
384
|
-
|
|
374
|
+
)}
|
|
375
|
+
</CapRow>
|
|
376
|
+
{tapAction === TAP_ACTION_APP && (
|
|
377
|
+
<CapLabel className="mpush-tap-description mpush-tap-help">
|
|
378
|
+
<FormattedMessage {...messages.tapActionAppHelp} />
|
|
379
|
+
</CapLabel>
|
|
385
380
|
)}
|
|
386
381
|
</CapRow>
|
|
387
382
|
<CtaButtons {...ctaButtonProps} />
|
|
@@ -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,
|
|
10
|
+
import { PRIMARY, DEEP_LINK } from '../../constants';
|
|
11
11
|
|
|
12
12
|
// Mock the UI components
|
|
13
13
|
jest.mock('@capillarytech/cap-ui-library/CapRow', () =>
|
|
@@ -82,6 +82,10 @@ jest.mock('../../messages', () => ({
|
|
|
82
82
|
id: 'buttons',
|
|
83
83
|
defaultMessage: 'Buttons',
|
|
84
84
|
},
|
|
85
|
+
optionalText: {
|
|
86
|
+
id: 'optional.text',
|
|
87
|
+
defaultMessage: '(Optional)',
|
|
88
|
+
},
|
|
85
89
|
addPrimaryButton: {
|
|
86
90
|
id: 'add.primary.button',
|
|
87
91
|
defaultMessage: 'Add primary button',
|
|
@@ -128,7 +132,7 @@ describe('CtaButtons', () => {
|
|
|
128
132
|
describe('Initial Rendering', () => {
|
|
129
133
|
it('should render the component with default props', () => {
|
|
130
134
|
renderComponent();
|
|
131
|
-
expect(screen.
|
|
135
|
+
expect(screen.getAllByTestId('cap-row').length).toBeGreaterThan(0);
|
|
132
136
|
expect(screen.getByText('Buttons')).toBeInTheDocument();
|
|
133
137
|
});
|
|
134
138
|
|
|
@@ -221,114 +225,31 @@ describe('CtaButtons', () => {
|
|
|
221
225
|
});
|
|
222
226
|
});
|
|
223
227
|
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
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
|
|
228
|
+
// Secondary button is commented out until backend support lands
|
|
229
|
+
describe('Secondary Button (hidden)', () => {
|
|
230
|
+
it('does not render add secondary button even when the primary button is saved', () => {
|
|
231
|
+
renderComponent({
|
|
232
|
+
primaryButton: true,
|
|
233
|
+
ctaData: [{ index: 0, text: 'Primary Button', isSaved: true }],
|
|
257
234
|
});
|
|
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
|
-
});
|
|
270
235
|
|
|
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
|
|
285
236
|
expect(screen.queryByTestId('add-secondary-button')).not.toBeInTheDocument();
|
|
237
|
+
expect(screen.queryByText('Add secondary button')).not.toBeInTheDocument();
|
|
286
238
|
});
|
|
287
239
|
|
|
288
|
-
it('
|
|
289
|
-
|
|
290
|
-
|
|
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,
|
|
240
|
+
it('does not render a secondary CTA form for a template that already has one', () => {
|
|
241
|
+
renderComponent({
|
|
242
|
+
primaryButton: true,
|
|
298
243
|
secondaryButton: true,
|
|
299
|
-
|
|
300
|
-
|
|
244
|
+
ctaData: [
|
|
245
|
+
{ index: 0, text: 'Primary Button', isSaved: true },
|
|
246
|
+
{ index: 1, text: 'Secondary Button', ctaType: 'SECONDARY', isSaved: true },
|
|
247
|
+
],
|
|
301
248
|
});
|
|
302
|
-
|
|
303
|
-
// Should not render add button when secondaryButton is true and button exists
|
|
304
|
-
expect(screen.queryByTestId('add-secondary-button')).not.toBeInTheDocument();
|
|
305
|
-
});
|
|
306
249
|
|
|
307
|
-
|
|
308
|
-
|
|
309
|
-
|
|
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');
|
|
250
|
+
const ctas = screen.getAllByTestId('cap-mpush-cta');
|
|
251
|
+
expect(ctas).toHaveLength(1);
|
|
252
|
+
expect(ctas[0]).toHaveAttribute('data-button-type', 'PRIMARY');
|
|
332
253
|
});
|
|
333
254
|
});
|
|
334
255
|
|
|
@@ -379,12 +300,18 @@ describe('CtaButtons', () => {
|
|
|
379
300
|
it('should render proper component structure', () => {
|
|
380
301
|
renderComponent();
|
|
381
302
|
|
|
382
|
-
expect(screen.
|
|
303
|
+
expect(screen.getAllByTestId('cap-row')).toHaveLength(2);
|
|
383
304
|
expect(screen.getByTestId('cap-heading')).toBeInTheDocument();
|
|
384
305
|
expect(screen.getByTestId('cap-icon')).toBeInTheDocument();
|
|
385
306
|
expect(screen.getByTestId('cap-icon')).toHaveAttribute('data-icon-type', 'plus');
|
|
386
307
|
});
|
|
387
308
|
|
|
309
|
+
it('should render (Optional) beside the Buttons heading', () => {
|
|
310
|
+
renderComponent();
|
|
311
|
+
|
|
312
|
+
expect(screen.getByText('(Optional)')).toBeInTheDocument();
|
|
313
|
+
});
|
|
314
|
+
|
|
388
315
|
it('should render heading with correct type', () => {
|
|
389
316
|
renderComponent();
|
|
390
317
|
|
|
@@ -417,44 +344,6 @@ describe('CtaButtons', () => {
|
|
|
417
344
|
expect(updateHandler).not.toHaveBeenCalled();
|
|
418
345
|
});
|
|
419
346
|
|
|
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
|
-
|
|
458
347
|
it('should handle early return in handleAddPrimary when primaryButton and showPrimaryCTA are true', () => {
|
|
459
348
|
const updateHandler = jest.fn();
|
|
460
349
|
const setPrimaryButton = jest.fn();
|
|
@@ -494,72 +383,5 @@ describe('CtaButtons', () => {
|
|
|
494
383
|
expect(setPrimaryButton).not.toHaveBeenCalled();
|
|
495
384
|
}
|
|
496
385
|
});
|
|
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
|
-
});
|
|
564
386
|
});
|
|
565
387
|
});
|