@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.
Files changed (89) hide show
  1. package/constants/unified.js +1 -3
  2. package/package.json +1 -1
  3. package/translations/en.json +0 -1
  4. package/translations/ja-JP.json +0 -1
  5. package/translations/zh.json +0 -1
  6. package/utils/common.js +6 -0
  7. package/utils/createMobilePushPayload.js +56 -50
  8. package/utils/tagValidations.js +4 -35
  9. package/utils/tests/createMobilePushPayload.test.js +168 -177
  10. package/utils/tests/tagValidations.test.js +0 -48
  11. package/v2Components/CapMpushCTA/index.js +57 -47
  12. package/v2Components/CapMpushCTA/index.scss +5 -43
  13. package/v2Components/CapTagList/index.js +7 -46
  14. package/v2Components/CapTagList/messages.js +0 -44
  15. package/v2Components/CapTagList/style.scss +1 -113
  16. package/v2Components/CommonTestAndPreview/UnifiedPreview/MobilePushPreviewContent.js +8 -11
  17. package/v2Components/CommonTestAndPreview/UnifiedPreview/_unifiedPreview.scss +1 -13
  18. package/v2Components/CommonTestAndPreview/constants.js +0 -2
  19. package/v2Components/CommonTestAndPreview/index.js +12 -51
  20. package/v2Components/CommonTestAndPreview/tests/UnifiedPreview/MobilePushPreviewContent.test.js +5 -83
  21. package/v2Components/CommonTestAndPreview/tests/index.test.js +0 -100
  22. package/v2Components/FormBuilder/Classic.js +14 -24
  23. package/v2Components/FormBuilder/Functional/channels/mobilepush/config.js +0 -1
  24. package/v2Components/FormBuilder/Functional/channels/mobilepush/getEditorErrorDescriptor.js +1 -1
  25. package/v2Components/FormBuilder/Functional/channels/mobilepush/tests/validate.test.js +0 -57
  26. package/v2Components/FormBuilder/Functional/channels/mobilepush/validate.js +4 -4
  27. package/v2Components/FormBuilder/Functional/channels/sms/getEditorErrorDescriptor.js +0 -3
  28. package/v2Components/FormBuilder/Functional/channels/sms/tests/getEditorErrorDescriptor.test.js +0 -5
  29. package/v2Components/FormBuilder/Functional/channels/sms/tests/validate.test.js +0 -6
  30. package/v2Components/FormBuilder/Functional/channels/sms/validate.js +1 -3
  31. package/v2Components/FormBuilder/Functional/renderers/mpushRenderers.js +0 -3
  32. package/v2Components/FormBuilder/Functional/tests/mpushRenderers.test.js +0 -22
  33. package/v2Components/MobilePushPreviewV2/index.js +9 -22
  34. package/v2Components/TemplatePreview/_templatePreview.scss +2 -18
  35. package/v2Components/TemplatePreview/index.js +18 -20
  36. package/v2Components/TemplatePreview/tests/index.test.js +0 -69
  37. package/v2Containers/Cap/messages.js +0 -4
  38. package/v2Containers/Cap/tests/__snapshots__/index.test.js.snap +0 -1
  39. package/v2Containers/CommunicationFlow/steps/ChannelSelectionStep/extractContentForPreview.js +2 -12
  40. package/v2Containers/CreativesContainer/SlideBoxContent.js +6 -4
  41. package/v2Containers/CreativesContainer/index.js +1 -2
  42. package/v2Containers/CreativesContainer/tests/SlideBoxContent.test.js +0 -43
  43. package/v2Containers/InApp/index.js +1 -4
  44. package/v2Containers/Line/Container/ImageCarousel/tests/__snapshots__/content.test.js.snap +0 -3
  45. package/v2Containers/Line/Container/ImageCarousel/tests/__snapshots__/index.test.js.snap +0 -2
  46. package/v2Containers/Line/Container/Text/index.js +1 -3
  47. package/v2Containers/Line/Container/Wrapper/tests/__snapshots__/index.test.js.snap +0 -16
  48. package/v2Containers/Line/Container/tests/__snapshots__/index.test.js.snap +0 -18
  49. package/v2Containers/MobilePushNew/components/CtaButtons.js +47 -52
  50. package/v2Containers/MobilePushNew/components/MediaUploaders.js +345 -105
  51. package/v2Containers/MobilePushNew/components/PlatformContentFields.js +105 -127
  52. package/v2Containers/MobilePushNew/components/tests/CtaButtons.test.js +208 -30
  53. package/v2Containers/MobilePushNew/components/tests/MediaUploaders.test.js +1484 -307
  54. package/v2Containers/MobilePushNew/components/tests/PlatformContentFields.test.js +59 -165
  55. package/v2Containers/MobilePushNew/constants.js +0 -12
  56. package/v2Containers/MobilePushNew/hooks/tests/usePlatformSync.test.js +1 -63
  57. package/v2Containers/MobilePushNew/hooks/tests/useUpload.test.js +0 -78
  58. package/v2Containers/MobilePushNew/hooks/usePlatformSync.js +1 -40
  59. package/v2Containers/MobilePushNew/hooks/useUpload.js +46 -42
  60. package/v2Containers/MobilePushNew/index.js +290 -502
  61. package/v2Containers/MobilePushNew/index.scss +4 -151
  62. package/v2Containers/MobilePushNew/messages.js +6 -106
  63. package/v2Containers/MobilePushNew/tests/index.test.js +1 -483
  64. package/v2Containers/MobilePushNew/tests/utils.test.js +0 -110
  65. package/v2Containers/MobilePushNew/utils.js +0 -83
  66. package/v2Containers/Rcs/index.js +1 -8
  67. package/v2Containers/Rcs/tests/__snapshots__/index.test.js.snap +0 -59
  68. package/v2Containers/SmsTrai/Create/tests/__snapshots__/index.test.js.snap +0 -4
  69. package/v2Containers/SmsTrai/Edit/index.js +5 -13
  70. package/v2Containers/SmsTrai/Edit/tests/__snapshots__/index.test.js.snap +0 -15
  71. package/v2Containers/Templates/_templates.scss +2 -10
  72. package/v2Containers/Templates/index.js +81 -86
  73. package/v2Containers/Templates/tests/index.test.js +0 -81
  74. package/v2Containers/Viber/index.js +1 -3
  75. package/v2Containers/WebPush/Create/utils/validation.js +0 -6
  76. package/v2Containers/WebPush/Create/utils/validation.test.js +0 -50
  77. package/v2Containers/Whatsapp/index.js +5 -9
  78. package/v2Containers/Whatsapp/tests/__snapshots__/index.test.js.snap +2 -2
  79. package/v2Containers/Zalo/index.js +1 -4
  80. package/v2Components/CapMpushCTA/tests/index.test.js +0 -150
  81. package/v2Components/CapTagList/TagFallbackPanel.js +0 -124
  82. package/v2Components/CapTagList/constants.js +0 -5
  83. package/v2Components/CapTagList/tests/TagFallback.test.js +0 -222
  84. package/v2Components/CapTagList/utils.js +0 -17
  85. package/v2Components/MobilePushPreviewV2/_mobilePushPreviewV2.scss +0 -7
  86. package/v2Components/MobilePushPreviewV2/tests/index.test.js +0 -55
  87. package/v2Components/TemplatePreview/_mobilePushPhone.scss +0 -72
  88. package/v2Containers/CommunicationFlow/steps/ChannelSelectionStep/Tests/extractContentForPreview.test.js +0 -45
  89. package/v2Containers/MobilePushNew/components/TapLinkActions.js +0 -76
@@ -24,9 +24,6 @@ jest.mock('../../../Cap/messages', () => ({
24
24
  unbalanacedCurlyBraces: {
25
25
  defaultMessage: 'Unbalanced curly braces',
26
26
  },
27
- unquotedTagDefaultValue: {
28
- defaultMessage: 'Default value must be within quotes',
29
- },
30
27
  }));
31
28
 
32
29
  import { validateTags } from '../../../../utils/tagValidations';
@@ -151,27 +148,6 @@ describe('validation', () => {
151
148
  });
152
149
  });
153
150
 
154
- it('should return default quote error when validateTags returns isDefaultQuoteError', () => {
155
- validateTags.mockReturnValue({ isBraceError: false, isDefaultQuoteError: true });
156
- const result = validateTitle('{{name | default: x}}', mockFormatMessage, mockMessages, false, {}, false);
157
- expect(result).toBe('Default value must be within quotes');
158
- expect(mockFormatMessage).toHaveBeenCalledWith(globalMessages.unquotedTagDefaultValue);
159
- });
160
-
161
- it('should prefer brace error over default quote error', () => {
162
- validateTags.mockReturnValue({ isBraceError: true, isDefaultQuoteError: true });
163
- const result = validateTitle('{{name', mockFormatMessage, mockMessages, false, {}, false);
164
- expect(result).toBe('Unbalanced curly braces');
165
- expect(mockFormatMessage).not.toHaveBeenCalledWith(globalMessages.unquotedTagDefaultValue);
166
- });
167
-
168
- it('should return empty when validateTags has no errors or returns null/undefined', () => {
169
- [{ isBraceError: false, isDefaultQuoteError: false }, null, undefined].forEach((response) => {
170
- validateTags.mockReturnValue(response);
171
- expect(validateTitle('Valid Title', mockFormatMessage, mockMessages, false, {}, false)).toBe('');
172
- });
173
- });
174
-
175
151
  it('should not run tag validation when validationConfig is null', () => {
176
152
  validateTags.mockClear();
177
153
  const result = validateTitle('Valid Title', mockFormatMessage, mockMessages, false, null);
@@ -290,32 +266,6 @@ describe('validation', () => {
290
266
  expect(mockFormatMessage).toHaveBeenCalledWith(globalMessages.unbalanacedCurlyBraces);
291
267
  });
292
268
 
293
- it('should return default quote error when validateTags returns isDefaultQuoteError', () => {
294
- validateTags.mockReturnValue({ isBraceError: false, isDefaultQuoteError: true });
295
- const result = validateMessageContent('{{name | default: x}}', mockFormatMessage, mockMessages, mockValidationConfig);
296
- expect(result).toBe('Default value must be within quotes');
297
- expect(mockFormatMessage).toHaveBeenCalledWith(globalMessages.unquotedTagDefaultValue);
298
- });
299
-
300
- it('should prefer brace error over default quote error', () => {
301
- validateTags.mockReturnValue({ isBraceError: true, isDefaultQuoteError: true });
302
- const result = validateMessageContent('{{name', mockFormatMessage, mockMessages, mockValidationConfig);
303
- expect(result).toBe('Unbalanced curly braces');
304
- expect(mockFormatMessage).not.toHaveBeenCalledWith(globalMessages.unquotedTagDefaultValue);
305
- });
306
-
307
- it('should return default quote error before personalization error', () => {
308
- validateTags.mockReturnValue({ isDefaultQuoteError: true });
309
- const result = validateMessageContent('{{first_name | default: x}}', mockFormatMessage, mockMessages, mockValidationConfig, false, true);
310
- expect(result).toBe('Default value must be within quotes');
311
- });
312
-
313
- it('should return empty when isDefaultQuoteError is false', () => {
314
- validateTags.mockReturnValue({ isBraceError: false, isDefaultQuoteError: false });
315
- const result = validateMessageContent('Valid message', mockFormatMessage, mockMessages, mockValidationConfig);
316
- expect(result).toBe('');
317
- });
318
-
319
269
  it('should pass validation config to validateTags', () => {
320
270
  const customConfig = {
321
271
  tagsParam: [{ id: 1, name: 'Tag1' }],
@@ -637,18 +637,17 @@ export const Whatsapp = (props) => {
637
637
  tagModule: getDefaultTags,
638
638
  isFullMode,
639
639
  }) || {};
640
- const hasTagSyntaxError = !!(validationResponse.isBraceError || validationResponse.isDefaultQuoteError);
641
640
  if (type === HEADER_TEXT) {
642
641
  headerTagValidationResponse = validationResponse;
643
- updateIsHeaderTagValidationError(hasTagSyntaxError);
642
+ updateIsHeaderTagValidationError(validationResponse.isBraceError);
644
643
  } else if (type === CAROUSEL_TEXT) {
645
644
  return [
646
- { fieldName: "carouselTagValidationErrMessage", value: hasTagSyntaxError ? validationResponse : {} },
647
- { fieldName: "carouselTagValidationErr", value: hasTagSyntaxError },
645
+ { fieldName: "carouselTagValidationErrMessage", value: validationResponse.isBraceError ? validationResponse : {} },
646
+ { fieldName: "carouselTagValidationErr", value: validationResponse.isBraceError },
648
647
  ];
649
648
  } else {
650
649
  tagValidationResponse = validationResponse;
651
- updateIsTagValidationError(hasTagSyntaxError);
650
+ updateIsTagValidationError(validationResponse.isBraceError);
652
651
  }
653
652
  }
654
653
  };
@@ -2838,13 +2837,10 @@ const isAuthenticationTemplate = isEqual(templateCategory, WHATSAPP_CATEGORIES.a
2838
2837
  } else {
2839
2838
  validationResponse = tagValidationResponse;
2840
2839
  }
2841
- const { isBraceError, isDefaultQuoteError } = validationResponse || {};
2840
+ const { isBraceError } = validationResponse || {};
2842
2841
  if (isBraceError) {
2843
2842
  return <CapError>{formatMessage(globalMessages.unbalanacedCurlyBraces)}</CapError>;
2844
2843
  }
2845
- if (isDefaultQuoteError) {
2846
- return <CapError>{formatMessage(globalMessages.unquotedTagDefaultValue)}</CapError>;
2847
- }
2848
2844
  return null;
2849
2845
  };
2850
2846
 
@@ -1,4 +1,4 @@
1
1
  [diffend] Oversized file quarantined before diffing.
2
2
  name: package/v2Containers/Whatsapp/tests/__snapshots__/index.test.js.snap
3
- size: 57312915 bytes
4
- sha256: 297ff99f24988ebb3e7289712381c4345e1104c2184c67094070a6bf65072c26
3
+ size: 57295127 bytes
4
+ sha256: 3ca4752bd0410b9d7f0e57070855228ef817cc04531f23794bf27e2647b4f7a2
@@ -281,13 +281,10 @@ export const Zalo = (props) => {
281
281
  tagModule: getDefaultTags,
282
282
  isFullMode,
283
283
  }) || {};
284
- const { isBraceError, isDefaultQuoteError } = tagValidationResponse;
284
+ const { isBraceError } = tagValidationResponse;
285
285
  if (isBraceError) {
286
286
  return formatMessage(globalMessages.unbalanacedCurlyBraces);
287
287
  }
288
- if (isDefaultQuoteError) {
289
- return formatMessage(globalMessages.unquotedTagDefaultValue);
290
- }
291
288
  return '';
292
289
  };
293
290
 
@@ -1,150 +0,0 @@
1
- import React from 'react';
2
- import { shallow } from 'enzyme';
3
- import CapIcon from '@capillarytech/cap-ui-library/CapIcon';
4
- import { CapMpushCTA } from '../index';
5
- import CapTagListWithInput from '../../CapTagListWithInput';
6
- import { DEEP_LINK, EXTERNAL_URL } from '../constants';
7
- import { PRIMARY } from '../../../v2Containers/MobilePushNew/constants';
8
-
9
- jest.mock('../../../v2Containers/TagList', () => () => null);
10
- jest.mock('../../CapTagListWithInput', () => () => null);
11
-
12
- const intl = { formatMessage: (msg) => msg?.defaultMessage || '' };
13
-
14
- const renderCta = (cta, extraProps = {}) => shallow(
15
- <CapMpushCTA
16
- intl={intl}
17
- ctaData={[{ index: 0, text: 'Shop', ...cta }]}
18
- buttonType={PRIMARY}
19
- updateHandler={jest.fn()}
20
- deleteHandler={jest.fn()}
21
- deepLink={[{ value: 'app://home', label: 'Home' }]}
22
- location={{ query: {} }}
23
- {...extraProps}
24
- />,
25
- );
26
-
27
- describe('CapMpushCTA', () => {
28
- describe('saved button card', () => {
29
- it('uses the mask-free "open-in-new" icon, not "launch"', () => {
30
- const wrapper = renderCta({ urlType: EXTERNAL_URL, url: 'https://google.com', isSaved: true });
31
- const iconTypes = wrapper.find(CapIcon).map((icon) => icon.prop('type'));
32
-
33
- expect(iconTypes).toContain('open-in-new');
34
- expect(iconTypes).not.toContain('launch');
35
- });
36
-
37
- it('shows the external URL in the link column with the URL as tooltip', () => {
38
- const wrapper = renderCta({ urlType: EXTERNAL_URL, url: 'https://google.com', isSaved: true });
39
- const link = wrapper.find('.mpush-saved-cta-link');
40
-
41
- expect(link.prop('children')).toBe('https://google.com');
42
- expect(link.prop('title')).toBe('https://google.com');
43
- expect(wrapper.find('.cta-type-label').prop('children')).toBe('External link');
44
- });
45
-
46
- it('shows the selected deep link label in the link column', () => {
47
- const wrapper = renderCta({ urlType: DEEP_LINK, url: 'app://home', isSaved: true });
48
-
49
- expect(wrapper.find('.mpush-saved-cta-link').prop('children')).toBe('Home');
50
- expect(wrapper.find('.cta-type-label').prop('children')).toBe('Deep link');
51
- });
52
-
53
- it('lays out the card rows horizontally with vertically centred items', () => {
54
- const wrapper = renderCta({ urlType: EXTERNAL_URL, url: 'https://google.com', isSaved: true });
55
-
56
- expect(wrapper.find('.mpush-cta-row').props()).toEqual(expect.objectContaining({ type: 'flex', align: 'middle' }));
57
- expect(wrapper.find('.cta-action-grp').props()).toEqual(expect.objectContaining({ type: 'flex', align: 'middle' }));
58
- });
59
-
60
- it('reopens the button for editing and deletes it from the card icons', () => {
61
- const updateHandler = jest.fn();
62
- const deleteHandler = jest.fn();
63
- const wrapper = renderCta(
64
- { urlType: EXTERNAL_URL, url: 'https://google.com', isSaved: true },
65
- { updateHandler, deleteHandler },
66
- );
67
-
68
- wrapper.find('.mpush-saved-cta-edit-icon').simulate('click');
69
- expect(updateHandler).toHaveBeenCalledWith(expect.objectContaining({ isSaved: false }), 0);
70
-
71
- wrapper.find('.cta-del-icon').simulate('click');
72
- expect(deleteHandler).toHaveBeenCalledWith(0);
73
- });
74
- });
75
-
76
- it('keeps the "External link" heading on one line in the edit form', () => {
77
- const wrapper = renderCta({ urlType: EXTERNAL_URL, url: '', isSaved: false });
78
-
79
- expect(wrapper.find(CapTagListWithInput).prop('headingStyle')).toEqual(
80
- expect.objectContaining({ whiteSpace: 'nowrap' }),
81
- );
82
- });
83
-
84
- it('wraps the External link field so its label row lines up with "Type of link"', () => {
85
- const wrapper = renderCta({ urlType: EXTERNAL_URL, url: '', isSaved: false });
86
-
87
- expect(wrapper.find('.mpush-cta-external-link-field').find(CapTagListWithInput).exists()).toBe(true);
88
- });
89
-
90
- describe('deep link keys', () => {
91
- const offerLink = [{ value: 'app://offer', label: 'Offer', keys: ['offerId', 'src'] }];
92
-
93
- it('shows one input per configured key with its saved value', () => {
94
- const wrapper = renderCta(
95
- { urlType: DEEP_LINK, url: 'app://offer', isSaved: false, deepLinkKeys: ['offerId=5'] },
96
- { deepLink: offerLink },
97
- );
98
-
99
- expect(wrapper.find({ id: 'mpush-deep-link-keys' }).prop('value')).toBe('5');
100
- expect(wrapper.find({ id: 'mpush-deep-link-keys-1' }).prop('value')).toBe('');
101
- });
102
-
103
- it('stores the configured key with the typed value', () => {
104
- const updateHandler = jest.fn();
105
- const wrapper = renderCta(
106
- { urlType: DEEP_LINK, url: 'app://offer', isSaved: false, deepLinkKeys: ['offerId=5'] },
107
- { deepLink: offerLink, updateHandler },
108
- );
109
-
110
- wrapper.find({ id: 'mpush-deep-link-keys-1' }).simulate('change', { target: { value: 'push' } });
111
- expect(updateHandler).toHaveBeenCalledWith(
112
- expect.objectContaining({ deepLinkKeys: ['offerId=5', 'src=push'] }),
113
- 0,
114
- );
115
- });
116
-
117
- it('shows a deep link copied in from the other tab after the form is open', () => {
118
- const wrapper = renderCta(
119
- { urlType: DEEP_LINK, url: '', isSaved: false },
120
- { deepLink: offerLink },
121
- );
122
- expect(wrapper.find({ id: 'mpush-deep-link-type' }).prop('value')).toBe('');
123
-
124
- wrapper.setProps({
125
- ctaData: [{
126
- index: 0, text: 'Shop', urlType: DEEP_LINK, url: 'app://offer', isSaved: false, deepLinkKeys: ['offerId=5'],
127
- }],
128
- });
129
-
130
- expect(wrapper.find({ id: 'mpush-deep-link-type' }).prop('value')).toBe('app://offer');
131
- expect(wrapper.find({ id: 'mpush-deep-link-keys' }).prop('value')).toBe('5');
132
- });
133
- });
134
-
135
- it('clears the url and sets the new type in one update on type change', () => {
136
- const updateHandler = jest.fn();
137
- const wrapper = renderCta(
138
- { urlType: DEEP_LINK, url: 'app://home', isSaved: false },
139
- { updateHandler },
140
- );
141
-
142
- wrapper.find({ id: 'mpush-cta-type' }).simulate('change', EXTERNAL_URL);
143
-
144
- expect(updateHandler).toHaveBeenCalledTimes(1);
145
- expect(updateHandler).toHaveBeenCalledWith(
146
- expect.objectContaining({ url: '', urlType: EXTERNAL_URL }),
147
- 0,
148
- );
149
- });
150
- });
@@ -1,124 +0,0 @@
1
- /**
2
- * TagFallbackPanel
3
- *
4
- * Shown in the tag list after a tag is clicked, to choose what is sent when the tag has no value.
5
- */
6
- import PropTypes from 'prop-types';
7
- import React from 'react';
8
- import CapButton from '@capillarytech/cap-ui-library/CapButton';
9
- import CapHeading from '@capillarytech/cap-ui-library/CapHeading';
10
- import CapIcon from '@capillarytech/cap-ui-library/CapIcon';
11
- import CapInput from '@capillarytech/cap-ui-library/CapInput';
12
- import CapLabel from '@capillarytech/cap-ui-library/CapLabel';
13
- import CapRadio from '@capillarytech/cap-ui-library/CapRadio';
14
- import CapRadioGroup from '@capillarytech/cap-ui-library/CapRadioGroup';
15
- import CapRow from '@capillarytech/cap-ui-library/CapRow';
16
- import { injectIntl, intlShape } from 'react-intl';
17
- import messages from './messages';
18
- import { FALLBACK_OPTIONS } from './constants';
19
- import { buildTagWithFallback, isValidFallbackValue } from './utils';
20
-
21
- export class TagFallbackPanel extends React.Component {
22
- constructor(props) {
23
- super(props);
24
- this.state = {
25
- option: FALLBACK_OPTIONS.NONE,
26
- fallbackValue: '',
27
- };
28
- }
29
-
30
- onOptionChange = (e) => {
31
- this.setState({ option: e.target.value });
32
- };
33
-
34
- onFallbackValueChange = (e) => {
35
- this.setState({ fallbackValue: e.target.value });
36
- };
37
-
38
- getTagValue = () => {
39
- const { option, fallbackValue } = this.state;
40
- return buildTagWithFallback(this.props.tagKey, option, fallbackValue);
41
- };
42
-
43
- copyTag = () => {
44
- navigator?.clipboard?.writeText(`{{${this.getTagValue()}}}`);
45
- };
46
-
47
- onInsert = () => {
48
- this.props.onInsert(this.getTagValue());
49
- };
50
-
51
- render() {
52
- const {
53
- intl: { formatMessage }, tagName, parentName, onBack,
54
- } = this.props;
55
- const { option, fallbackValue } = this.state;
56
- const isCustomValue = option === FALLBACK_OPTIONS.CUSTOM_VALUE;
57
- const isFallbackValueInvalid = isCustomValue && !isValidFallbackValue(fallbackValue);
58
- const isInsertDisabled = isCustomValue && (!fallbackValue.trim() || isFallbackValueInvalid);
59
-
60
- return (
61
- <CapRow className="tag-fallback-panel">
62
- <CapRow className="tag-fallback-header">
63
- <CapRow type="flex" align="middle" noWrap className="tag-fallback-title-row">
64
- <CapIcon
65
- type="back"
66
- size="m"
67
- className="tag-fallback-back"
68
- aria-label={formatMessage(messages.back)}
69
- onClick={onBack}
70
- />
71
- <CapHeading type="h4" className="tag-fallback-tag-name">{tagName}</CapHeading>
72
- </CapRow>
73
- {parentName ? <CapLabel type="label2" className="tag-fallback-group-name">{parentName}</CapLabel> : null}
74
- </CapRow>
75
- <CapRow className="tag-fallback-body">
76
- <CapHeading type="h4" className="tag-fallback-heading">{formatMessage(messages.fallbackBehaviour)}</CapHeading>
77
- <CapLabel type="label2" className="tag-fallback-subtext">{formatMessage(messages.fallbackBehaviourDesc)}</CapLabel>
78
- <CapRadioGroup className="tag-fallback-options" value={option} onChange={this.onOptionChange}>
79
- <CapRadio value={FALLBACK_OPTIONS.NONE}>{formatMessage(messages.dontSendMessage)}</CapRadio>
80
- <CapRadio value={FALLBACK_OPTIONS.NULL_VALUE}>{formatMessage(messages.sendWithNullValue)}</CapRadio>
81
- <CapRadio value={FALLBACK_OPTIONS.CUSTOM_VALUE}>{formatMessage(messages.fallbackValue)}</CapRadio>
82
- </CapRadioGroup>
83
- {isCustomValue && (
84
- <CapInput
85
- className="tag-fallback-input"
86
- value={fallbackValue}
87
- onChange={this.onFallbackValueChange}
88
- placeholder={formatMessage(messages.fallbackValuePlaceholder)}
89
- errorMessage={isFallbackValueInvalid ? formatMessage(messages.fallbackValueInvalid) : ''}
90
- size="default"
91
- />
92
- )}
93
- <CapLabel type="label2" className="tag-fallback-preview-label">{formatMessage(messages.addsToMessageAs)}</CapLabel>
94
- <CapRow type="flex" align="middle" noWrap className="tag-fallback-preview-row">
95
- <CapLabel className="tag-fallback-preview">{`{{${this.getTagValue()}}}`}</CapLabel>
96
- <CapIcon
97
- type="copy"
98
- size="m"
99
- className="tag-fallback-copy"
100
- aria-label={formatMessage(messages.copy)}
101
- onClick={this.copyTag}
102
- />
103
- </CapRow>
104
- </CapRow>
105
- <CapRow type="flex" justify="end" className="tag-fallback-footer">
106
- <CapButton type="primary" disabled={isInsertDisabled} onClick={this.onInsert}>
107
- {formatMessage(messages.insertTag)}
108
- </CapButton>
109
- </CapRow>
110
- </CapRow>
111
- );
112
- }
113
- }
114
-
115
- TagFallbackPanel.propTypes = {
116
- intl: intlShape.isRequired,
117
- tagKey: PropTypes.string.isRequired,
118
- tagName: PropTypes.node,
119
- parentName: PropTypes.node,
120
- onBack: PropTypes.func.isRequired,
121
- onInsert: PropTypes.func.isRequired,
122
- };
123
-
124
- export default injectIntl(TagFallbackPanel);
@@ -1,5 +0,0 @@
1
- export const FALLBACK_OPTIONS = {
2
- NONE: 'NONE',
3
- NULL_VALUE: 'NULL_VALUE',
4
- CUSTOM_VALUE: 'CUSTOM_VALUE',
5
- };
@@ -1,222 +0,0 @@
1
- import React from 'react';
2
- import { render, screen, fireEvent, act } from '@testing-library/react';
3
- import '@testing-library/jest-dom';
4
- import { IntlProvider } from 'react-intl';
5
- import TagFallbackPanel from '../TagFallbackPanel';
6
- import { CapTagList } from '../index';
7
- import { FALLBACK_OPTIONS } from '../constants';
8
- import { buildTagWithFallback, isValidFallbackValue } from '../utils';
9
-
10
- describe('buildTagWithFallback', () => {
11
- it('returns tag as it is for NONE', () => {
12
- expect(buildTagWithFallback('badge_description', FALLBACK_OPTIONS.NONE)).toBe('badge_description');
13
- });
14
-
15
- it('adds empty default for NULL_VALUE', () => {
16
- expect(buildTagWithFallback('badge_description', FALLBACK_OPTIONS.NULL_VALUE)).toBe("badge_description | default: ''");
17
- });
18
-
19
- it('adds trimmed fallback value for CUSTOM_VALUE', () => {
20
- expect(buildTagWithFallback('badge_description', FALLBACK_OPTIONS.CUSTOM_VALUE, ' Gold ')).toBe("badge_description | default: 'Gold'");
21
- });
22
-
23
- it('wraps value in double quotes when it has a single quote', () => {
24
- expect(buildTagWithFallback('name', FALLBACK_OPTIONS.CUSTOM_VALUE, "member's")).toBe('name | default: "member\'s"');
25
- });
26
- });
27
-
28
- describe('isValidFallbackValue', () => {
29
- it('rejects braces and values having both quote types', () => {
30
- expect(isValidFallbackValue('Gold')).toBe(true);
31
- expect(isValidFallbackValue("member's")).toBe(true);
32
- expect(isValidFallbackValue('a}b')).toBe(false);
33
- expect(isValidFallbackValue('{a')).toBe(false);
34
- expect(isValidFallbackValue(`it's "x"`)).toBe(false);
35
- });
36
-
37
- it('treats a missing value as valid (defaults to empty string)', () => {
38
- expect(isValidFallbackValue()).toBe(true);
39
- });
40
- });
41
-
42
- describe('TagFallbackPanel', () => {
43
- const renderPanel = (props = {}) => {
44
- const onInsert = jest.fn();
45
- const onBack = jest.fn();
46
- render(
47
- <IntlProvider locale="en">
48
- <TagFallbackPanel
49
- tagKey="badge_description"
50
- tagName="Badge description"
51
- parentName="Badge"
52
- onBack={onBack}
53
- onInsert={onInsert}
54
- {...props}
55
- />
56
- </IntlProvider>
57
- );
58
- return { onInsert, onBack };
59
- };
60
- const insertButton = () => screen.getByText('Insert tag').closest('button');
61
-
62
- it('shows tag and parent name with "Don’t send message" selected by default', () => {
63
- renderPanel();
64
- expect(screen.getByText('Badge description')).toBeInTheDocument();
65
- expect(screen.getByText('Badge')).toBeInTheDocument();
66
- expect(screen.getByLabelText('Don’t send message')).toBeChecked();
67
- expect(screen.getByText('{{badge_description}}')).toBeInTheDocument();
68
- });
69
-
70
- it('does not render the group name when parentName is not passed', () => {
71
- renderPanel({ parentName: undefined });
72
- expect(screen.getByText('Badge description')).toBeInTheDocument();
73
- expect(screen.queryByText('Badge')).toBeNull();
74
- expect(document.querySelector('.tag-fallback-group-name')).toBeNull();
75
- });
76
-
77
- it('does not throw on copy when clipboard is not available', () => {
78
- Object.assign(navigator, { clipboard: undefined });
79
- renderPanel();
80
- expect(() => fireEvent.click(screen.getByLabelText('Copy'))).not.toThrow();
81
- });
82
-
83
- it('inserts tag as it is by default', () => {
84
- const { onInsert } = renderPanel();
85
- fireEvent.click(insertButton());
86
- expect(onInsert).toHaveBeenCalledWith('badge_description');
87
- });
88
-
89
- it('inserts tag with empty default for "Send with null value"', () => {
90
- const { onInsert } = renderPanel();
91
- fireEvent.click(screen.getByLabelText('Send with null value'));
92
- expect(screen.getByText("{{badge_description | default: ''}}")).toBeInTheDocument();
93
- fireEvent.click(insertButton());
94
- expect(onInsert).toHaveBeenCalledWith("badge_description | default: ''");
95
- });
96
-
97
- it('inserts tag with entered fallback value', () => {
98
- const { onInsert } = renderPanel();
99
- fireEvent.click(screen.getByLabelText('Fallback value'));
100
- expect(insertButton()).toBeDisabled();
101
- fireEvent.change(screen.getByPlaceholderText('Enter fallback value'), { target: { value: 'Gold' } });
102
- expect(screen.getByText("{{badge_description | default: 'Gold'}}")).toBeInTheDocument();
103
- fireEvent.click(insertButton());
104
- expect(onInsert).toHaveBeenCalledWith("badge_description | default: 'Gold'");
105
- });
106
-
107
- it('disables insert for an invalid fallback value', () => {
108
- renderPanel();
109
- fireEvent.click(screen.getByLabelText('Fallback value'));
110
- fireEvent.change(screen.getByPlaceholderText('Enter fallback value'), { target: { value: '{bad}' } });
111
- expect(insertButton()).toBeDisabled();
112
- });
113
-
114
- it('copies the previewed tag on copy icon click', () => {
115
- const writeText = jest.fn();
116
- Object.assign(navigator, { clipboard: { writeText } });
117
- renderPanel();
118
- fireEvent.click(screen.getByLabelText('Send with null value'));
119
- fireEvent.click(screen.getByLabelText('Copy'));
120
- expect(writeText).toHaveBeenCalledWith("{{badge_description | default: ''}}");
121
- });
122
-
123
- it('calls onBack on back arrow click', () => {
124
- const { onBack } = renderPanel();
125
- fireEvent.click(screen.getByLabelText('Back'));
126
- expect(onBack).toHaveBeenCalled();
127
- });
128
- });
129
-
130
- describe('CapTagList fallback flow', () => {
131
- const getInstance = (props = {}) => {
132
- const instance = new CapTagList({
133
- tags: {},
134
- onSelect: jest.fn(),
135
- intl: { formatMessage: ({ defaultMessage }) => defaultMessage },
136
- disableTagsDetails: {},
137
- ...props,
138
- });
139
- instance.setState = (update) => {
140
- instance.state = { ...instance.state, ...(typeof update === 'function' ? update(instance.state) : update) };
141
- };
142
- return instance;
143
- };
144
- const leafInfo = (tagKey, extra = {}) => ({
145
- selectedNodes: [{ isLeaf: true, tagKey, tagName: 'Badge description', parentName: 'Badge', ...extra }],
146
- });
147
-
148
- it('opens the fallback panel instead of inserting on leaf click', () => {
149
- const instance = getInstance();
150
- const info = leafInfo('badge_description');
151
- instance.handleOnSelect(['Badge.badge_description'], info);
152
- expect(instance.props.onSelect).not.toHaveBeenCalled();
153
- expect(instance.state.selectedTag).toEqual({
154
- tagKey: 'badge_description', tagName: 'Badge description', parentName: 'Badge', info,
155
- });
156
- });
157
-
158
- it('keeps the dynamic expiry tag flow as it is', () => {
159
- const instance = getInstance();
160
- instance.handleOnSelect(['k'], leafInfo('dynamic_expiry_date_after_(N)_days.FORMAT_1'));
161
- expect(instance.state.selectedTag).toBeNull();
162
- expect(instance.state.showModal).toBe(true);
163
- });
164
-
165
- it('inserts built tag value and closes on insert', () => {
166
- const instance = getInstance();
167
- const info = leafInfo('badge_description');
168
- instance.handleOnSelect(['Badge.badge_description'], info);
169
- instance.handleFallbackInsert("badge_description | default: 'Gold'");
170
- expect(instance.props.onSelect).toHaveBeenCalledWith(["badge_description | default: 'Gold'"], info);
171
- expect(instance.state).toEqual(expect.objectContaining({ visible: false, selectedTag: null, selectedNodeKey: '' }));
172
- });
173
-
174
- it('goes back to the tag list and clears selection on back', () => {
175
- const instance = getInstance();
176
- instance.handleOnSelect(['Badge.badge_description'], leafInfo('badge_description'));
177
- instance.handleFallbackBack();
178
- expect(instance.state.selectedTag).toBeNull();
179
- expect(instance.state.selectedNodeKey).toBe('');
180
- });
181
-
182
- it('resets the fallback panel when popover closes', () => {
183
- const instance = getInstance();
184
- instance.handleOnSelect(['Badge.badge_description'], leafInfo('badge_description'));
185
- instance.togglePopoverVisibility(false);
186
- expect(instance.state.selectedTag).toBeNull();
187
- });
188
-
189
- it('keeps the searched text after going back from the fallback panel', () => {
190
- const intl = { formatMessage: ({ defaultMessage }) => defaultMessage, locale: 'en' };
191
- const ref = React.createRef();
192
- render(
193
- <IntlProvider locale="en">
194
- <CapTagList
195
- ref={ref}
196
- tags={{ Badge: { name: 'Badge', subtags: { badge_description: { name: 'Badge description', desc: 'Badge description' } } } }}
197
- onSelect={jest.fn()}
198
- intl={intl}
199
- disableTagsDetails={{}}
200
- hidePopover
201
- visibleTaglist
202
- />
203
- </IntlProvider>
204
- );
205
- fireEvent.change(screen.getByPlaceholderText('Search'), { target: { value: 'badge desc' } });
206
- // antd tree rows are not rendered in jsdom, so select the tag through the instance
207
- act(() => ref.current.handleOnSelect(['Badge.badge_description'], leafInfo('badge_description')));
208
- expect(screen.queryByPlaceholderText('Search')).toBeNull();
209
- fireEvent.click(screen.getByLabelText('Back'));
210
- expect(screen.getByPlaceholderText('Search')).toHaveValue('badge desc');
211
- });
212
-
213
- it('adds tag and parent names to leaf nodes', () => {
214
- const instance = getInstance();
215
- const list = instance.renderTags({
216
- Badge: { name: 'Badge', subtags: { badge_description: { name: 'Badge description', desc: 'Badge description' } } },
217
- });
218
- expect(list[0].children[0]).toEqual(expect.objectContaining({
219
- tagKey: 'badge_description', tagName: 'Badge description', parentName: 'Badge',
220
- }));
221
- });
222
- });
@@ -1,17 +0,0 @@
1
- import { FALLBACK_OPTIONS } from './constants';
2
-
3
- // { } would break tag braces; a value having both quote types cannot be wrapped in either.
4
- export const isValidFallbackValue = (value = '') => !/[{}]/.test(value) && !(value.includes("'") && value.includes('"'));
5
-
6
- // Builds tag value (without braces) for the fallback option, e.g. tag | default: 'value'.
7
- export const buildTagWithFallback = (tagKey, option, fallbackValue = '') => {
8
- if (option === FALLBACK_OPTIONS.NULL_VALUE) {
9
- return `${tagKey} | default: ''`;
10
- }
11
- if (option === FALLBACK_OPTIONS.CUSTOM_VALUE) {
12
- const value = fallbackValue.trim();
13
- const quote = value.includes("'") ? '"' : "'";
14
- return `${tagKey} | default: ${quote}${value}${quote}`;
15
- }
16
- return tagKey;
17
- };
@@ -1,7 +0,0 @@
1
- @import '../TemplatePreview/mobilePushPhone';
2
-
3
- // Saved-template preview (campaigns message summary, creatives template preview).
4
- // The extra .preview-container outranks TemplatePreview's own `.preview-container #mobilepush-preview` rule.
5
- .mobile-push-preview-v2 .preview-container #mobilepush-preview.shell-v2 {
6
- @include mobile-push-phone-shell;
7
- }