@capillarytech/creatives-library 8.0.307-alpha.0 → 8.0.307-alpha.5

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 (70) hide show
  1. package/constants/unified.js +1 -3
  2. package/initialState.js +2 -0
  3. package/package.json +1 -1
  4. package/utils/common.js +8 -5
  5. package/utils/commonUtils.js +95 -36
  6. package/utils/tagValidations.js +231 -83
  7. package/utils/tests/commonUtil.test.js +124 -147
  8. package/utils/tests/tagValidations.test.js +388 -437
  9. package/v2Components/CapTagListWithInput/index.js +4 -0
  10. package/v2Components/CapWhatsappCTA/index.js +2 -0
  11. package/v2Components/ErrorInfoNote/index.js +5 -2
  12. package/v2Components/FormBuilder/index.js +218 -137
  13. package/v2Components/FormBuilder/messages.js +8 -0
  14. package/v2Components/HtmlEditor/HTMLEditor.js +10 -0
  15. package/v2Components/HtmlEditor/__tests__/HTMLEditor.apiErrors.test.js +1 -0
  16. package/v2Components/HtmlEditor/__tests__/HTMLEditor.test.js +15 -0
  17. package/v2Components/HtmlEditor/components/CodeEditorPane/index.js +5 -1
  18. package/v2Containers/BeeEditor/index.js +3 -0
  19. package/v2Containers/Cap/mockData.js +14 -0
  20. package/v2Containers/Cap/reducer.js +55 -3
  21. package/v2Containers/Cap/tests/reducer.test.js +102 -0
  22. package/v2Containers/CreativesContainer/SlideBoxContent.js +26 -5
  23. package/v2Containers/CreativesContainer/SlideBoxFooter.js +5 -13
  24. package/v2Containers/CreativesContainer/constants.js +0 -6
  25. package/v2Containers/CreativesContainer/index.js +10 -47
  26. package/v2Containers/Email/index.js +6 -1
  27. package/v2Containers/EmailWrapper/components/EmailHTMLEditor.js +79 -23
  28. package/v2Containers/EmailWrapper/components/EmailWrapperView.js +3 -0
  29. package/v2Containers/EmailWrapper/components/__tests__/EmailHTMLEditor.test.js +121 -20
  30. package/v2Containers/EmailWrapper/components/__tests__/EmailWrapperView.test.js +1 -0
  31. package/v2Containers/EmailWrapper/hooks/useEmailWrapper.js +3 -0
  32. package/v2Containers/EmailWrapper/index.js +4 -0
  33. package/v2Containers/EmailWrapper/tests/useEmailWrapper.edgeCases.test.js +1 -0
  34. package/v2Containers/EmailWrapper/tests/useEmailWrapper.test.js +1 -0
  35. package/v2Containers/FTP/index.js +51 -2
  36. package/v2Containers/FTP/messages.js +4 -0
  37. package/v2Containers/InApp/index.js +110 -35
  38. package/v2Containers/InApp/tests/index.test.js +6 -17
  39. package/v2Containers/InAppWrapper/hooks/__tests__/useInAppWrapper.test.js +1 -0
  40. package/v2Containers/InAppWrapper/hooks/useInAppWrapper.js +3 -0
  41. package/v2Containers/InAppWrapper/index.js +3 -0
  42. package/v2Containers/InappAdvance/index.js +115 -4
  43. package/v2Containers/InappAdvance/tests/index.test.js +0 -2
  44. package/v2Containers/Line/Container/Text/index.js +1 -0
  45. package/v2Containers/MobilePush/Create/index.js +21 -59
  46. package/v2Containers/MobilePush/Edit/index.js +22 -48
  47. package/v2Containers/MobilePushNew/index.js +33 -12
  48. package/v2Containers/MobilepushWrapper/index.js +3 -3
  49. package/v2Containers/Rcs/index.js +39 -12
  50. package/v2Containers/Sms/Create/index.js +5 -39
  51. package/v2Containers/Sms/Create/messages.js +0 -4
  52. package/v2Containers/Sms/Edit/index.js +5 -35
  53. package/v2Containers/Sms/commonMethods.js +6 -3
  54. package/v2Containers/SmsTrai/Edit/index.js +51 -11
  55. package/v2Containers/SmsTrai/Edit/tests/__snapshots__/index.test.js.snap +6 -6
  56. package/v2Containers/SmsWrapper/index.js +2 -2
  57. package/v2Containers/TagList/index.js +41 -2
  58. package/v2Containers/TagList/messages.js +4 -0
  59. package/v2Containers/TagList/tests/TagList.test.js +13 -1
  60. package/v2Containers/TagList/tests/mockdata.js +17 -0
  61. package/v2Containers/TemplatesV2/index.js +13 -28
  62. package/v2Containers/Viber/index.js +6 -0
  63. package/v2Containers/WebPush/Create/hooks/useTagManagement.js +5 -1
  64. package/v2Containers/WebPush/Create/hooks/useTagManagement.test.js +10 -0
  65. package/v2Containers/WebPush/Create/index.js +11 -3
  66. package/v2Containers/WebPush/Create/utils/validation.js +8 -17
  67. package/v2Containers/WebPush/Create/utils/validation.test.js +26 -44
  68. package/v2Containers/Whatsapp/index.js +23 -9
  69. package/v2Containers/Zalo/index.js +14 -3
  70. package/v2Containers/Sms/tests/commonMethods.test.js +0 -122
@@ -83,6 +83,7 @@ const MemoizedTagList = memo(({
83
83
  injectedTags,
84
84
  selectedOfferDetails,
85
85
  eventContextTags,
86
+ waitEventContextTags,
86
87
  forwardedTags,
87
88
  onTagSelect,
88
89
  restrictPersonalization = false,
@@ -98,6 +99,7 @@ const MemoizedTagList = memo(({
98
99
  injectedTags={injectedTags}
99
100
  selectedOfferDetails={selectedOfferDetails}
100
101
  eventContextTags={eventContextTags}
102
+ waitEventContextTags={waitEventContextTags}
101
103
  forwardedTags={forwardedTags}
102
104
  onTagSelect={onTagSelect}
103
105
  restrictPersonalization={restrictPersonalization}
@@ -115,6 +117,7 @@ const MemoizedTagList = memo(({
115
117
  && prevProps.injectedTags === nextProps.injectedTags
116
118
  && prevProps.selectedOfferDetails === nextProps.selectedOfferDetails
117
119
  && prevProps.eventContextTags === nextProps.eventContextTags
120
+ && prevProps.waitEventContextTags === nextProps.waitEventContextTags
118
121
  && prevProps.forwardedTags === nextProps.forwardedTags
119
122
  && prevProps.onTagSelect === nextProps.onTagSelect
120
123
  && prevProps.restrictPersonalization === nextProps.restrictPersonalization
@@ -151,6 +154,7 @@ const WebPushCreate = ({
151
154
  forwardedTags,
152
155
  selectedOfferDetails = [],
153
156
  eventContextTags = [],
157
+ waitEventContextTags = {},
154
158
  templateActions: templateActionsProps,
155
159
  Templates,
156
160
  restrictPersonalization = false,
@@ -230,6 +234,7 @@ const WebPushCreate = ({
230
234
  supportedTags: memoizedSupportedTags,
231
235
  injectedTags,
232
236
  eventContextTags,
237
+ waitEventContextTags,
233
238
  });
234
239
  const { tags, handleOnTagsContextChange, validationConfig } = tagState;
235
240
  const { weCrmAccounts } = Templates;
@@ -295,8 +300,8 @@ const WebPushCreate = ({
295
300
  const validateTemplateName = useCallback((value) => validateTemplateNameUtil(value), []);
296
301
 
297
302
  const validateTitle = useCallback(
298
- (value) => validateTitleUtil(value, formatMessage, messages, restrictPersonalization, validationConfig, isFullMode),
299
- [formatMessage, restrictPersonalization, validationConfig, isFullMode],
303
+ (value) => validateTitleUtil(value, formatMessage, messages, restrictPersonalization),
304
+ [formatMessage, restrictPersonalization],
300
305
  );
301
306
 
302
307
  const validateUrl = useCallback(
@@ -835,12 +840,13 @@ const WebPushCreate = ({
835
840
  injectedTags,
836
841
  selectedOfferDetails,
837
842
  eventContextTags,
843
+ waitEventContextTags,
838
844
  forwardedTags,
839
845
  restrictPersonalization,
840
846
  disabled: restrictPersonalization,
841
847
  disableTooltipMsg: restrictPersonalization ? formatMessage(messages.personalizationNotSupportedAnonymous) : undefined,
842
848
  }),
843
- [tags, injectedTags, selectedOfferDetails, eventContextTags, forwardedTags, restrictPersonalization, formatMessage],
849
+ [tags, injectedTags, selectedOfferDetails, eventContextTags, waitEventContextTags, forwardedTags, restrictPersonalization, formatMessage],
844
850
  );
845
851
 
846
852
  // Memoized TagList components with optimized props
@@ -1080,6 +1086,7 @@ WebPushCreate.propTypes = {
1080
1086
  forwardedTags: PropTypes.object,
1081
1087
  selectedOfferDetails: PropTypes.array,
1082
1088
  eventContextTags: PropTypes.array,
1089
+ waitEventContextTags: PropTypes.object,
1083
1090
  templateActions: PropTypes.object,
1084
1091
  restrictPersonalization: PropTypes.bool,
1085
1092
  };
@@ -1108,6 +1115,7 @@ WebPushCreate.defaultProps = {
1108
1115
  forwardedTags: {},
1109
1116
  selectedOfferDetails: [],
1110
1117
  eventContextTags: [],
1118
+ waitEventContextTags: {},
1111
1119
  templateActions: {},
1112
1120
  Templates: {},
1113
1121
  restrictPersonalization: false,
@@ -11,34 +11,19 @@ import { hasPersonalizationTags } from '../../../../utils/commonUtils';
11
11
  export const validateTemplateName = (value) => !value || value.trim() === '';
12
12
 
13
13
  /**
14
- * Validates notification title (required and optional tag validation)
14
+ * Validates notification title
15
15
  * @param {string} value - The title value
16
16
  * @param {Function} formatMessage - i18n format message function
17
17
  * @param {Object} messages - Message definitions
18
- * @param {Object} [validationConfig] - Optional config for tag validation
19
- * @param {boolean} [isFullMode] - Optional; when set with validationConfig, runs tag validation
20
18
  * @returns {string} Error message if invalid, empty string if valid
21
19
  */
22
- export const validateTitle = (value, formatMessage, messages, restrictPersonalization, validationConfig, isFullMode) => {
20
+ export const validateTitle = (value, formatMessage, messages, restrictPersonalization) => {
23
21
  if (!value || value.trim() === '') {
24
22
  return formatMessage(messages.titleRequired);
25
23
  }
26
24
  if (restrictPersonalization && hasPersonalizationTags(value)) {
27
25
  return formatMessage(messages.personalizationTokensErrorMessage);
28
26
  }
29
-
30
- if (validationConfig != null) {
31
- const validationResponse = validateTags({
32
- content: value,
33
- ...validationConfig,
34
- isFullMode,
35
- }) || {};
36
-
37
- if (validationResponse?.isBraceError) {
38
- return formatMessage(globalMessages.unbalanacedCurlyBraces);
39
- }
40
- }
41
-
42
27
  return '';
43
28
  };
44
29
 
@@ -80,6 +65,12 @@ export const validateMessageContent = (value, formatMessage, messages, validatio
80
65
  isFullMode,
81
66
  }) || {};
82
67
 
68
+ if (validationResponse?.unsupportedTags?.length) {
69
+ return formatMessage(globalMessages.unsupportedTagsValidationError, {
70
+ unsupportedTags: validationResponse.unsupportedTags.join(', '),
71
+ });
72
+ }
73
+
83
74
  if (validationResponse?.isBraceError) {
84
75
  return formatMessage(globalMessages.unbalanacedCurlyBraces);
85
76
  }
@@ -127,40 +127,6 @@ describe('validation', () => {
127
127
  expect(result).toBe('Personalization tags are not supported for anonymous customers');
128
128
  expect(mockFormatMessage).toHaveBeenCalledWith(mockMessages.personalizationTokensErrorMessage);
129
129
  });
130
-
131
- it('should return brace error when validationConfig is provided and validateTags returns isBraceError', () => {
132
- const validationConfig = { tagsParam: [], location: {}, tagModule: '' };
133
- validateTags.mockReturnValue({ isBraceError: true });
134
- const result = validateTitle(
135
- 'Valid Title',
136
- mockFormatMessage,
137
- mockMessages,
138
- false,
139
- validationConfig,
140
- false
141
- );
142
- expect(result).toBe('Unbalanced curly braces');
143
- expect(mockFormatMessage).toHaveBeenCalledWith(globalMessages.unbalanacedCurlyBraces);
144
- expect(validateTags).toHaveBeenCalledWith({
145
- content: 'Valid Title',
146
- ...validationConfig,
147
- isFullMode: false,
148
- });
149
- });
150
-
151
- it('should not run tag validation when validationConfig is null', () => {
152
- validateTags.mockClear();
153
- const result = validateTitle('Valid Title', mockFormatMessage, mockMessages, false, null);
154
- expect(result).toBe('');
155
- expect(validateTags).not.toHaveBeenCalled();
156
- });
157
-
158
- it('should not run tag validation when validationConfig is undefined', () => {
159
- validateTags.mockClear();
160
- const result = validateTitle('Valid Title', mockFormatMessage, mockMessages, false, undefined);
161
- expect(result).toBe('');
162
- expect(validateTags).not.toHaveBeenCalled();
163
- });
164
130
  });
165
131
 
166
132
  describe('validateUrl', () => {
@@ -217,8 +183,11 @@ describe('validation', () => {
217
183
  describe('validateMessageContent', () => {
218
184
  const mockValidationConfig = {
219
185
  tagsParam: [],
186
+ injectedTagsParams: [],
220
187
  location: {},
221
188
  tagModule: '',
189
+ eventContextTags: [],
190
+ waitEventContextTags: {},
222
191
  };
223
192
 
224
193
  beforeEach(() => {
@@ -257,6 +226,17 @@ describe('validation', () => {
257
226
  });
258
227
  });
259
228
 
229
+ it('should return error message for unsupported tags', () => {
230
+ validateTags.mockReturnValue({
231
+ unsupportedTags: ['tag1', 'tag2'],
232
+ });
233
+ const result = validateMessageContent('Message with {tag1} and {tag2}', mockFormatMessage, mockMessages, mockValidationConfig);
234
+ expect(result).toBe('Unsupported tags: tag1, tag2');
235
+ expect(mockFormatMessage).toHaveBeenCalledWith(globalMessages.unsupportedTagsValidationError, {
236
+ unsupportedTags: 'tag1, tag2',
237
+ });
238
+ });
239
+
260
240
  it('should return error message for unbalanced curly braces', () => {
261
241
  validateTags.mockReturnValue({
262
242
  isBraceError: true,
@@ -266,11 +246,23 @@ describe('validation', () => {
266
246
  expect(mockFormatMessage).toHaveBeenCalledWith(globalMessages.unbalanacedCurlyBraces);
267
247
  });
268
248
 
249
+ it('should return error message for both unsupported tags and brace error (unsupported tags takes precedence)', () => {
250
+ validateTags.mockReturnValue({
251
+ unsupportedTags: ['tag1'],
252
+ isBraceError: true,
253
+ });
254
+ const result = validateMessageContent('Message with {tag1}', mockFormatMessage, mockMessages, mockValidationConfig);
255
+ expect(result).toBe('Unsupported tags: tag1');
256
+ });
257
+
269
258
  it('should pass validation config to validateTags', () => {
270
259
  const customConfig = {
271
260
  tagsParam: [{ id: 1, name: 'Tag1' }],
261
+ injectedTagsParams: [{ id: 2, name: 'Tag2' }],
272
262
  location: { query: { type: 'test' } },
273
263
  tagModule: 'custom',
264
+ eventContextTags: [{ id: 3, name: 'Tag3' }],
265
+ waitEventContextTags: {},
274
266
  };
275
267
  validateTags.mockReturnValue({});
276
268
  validateMessageContent('Valid message', mockFormatMessage, mockMessages, customConfig);
@@ -316,16 +308,6 @@ describe('validation', () => {
316
308
  expect(result).toBe('Personalization tags are not supported for anonymous customers');
317
309
  expect(mockFormatMessage).toHaveBeenCalledWith(mockMessages.personalizationTokensErrorMessage);
318
310
  });
319
-
320
- it('should pass isFullMode to validateTags when provided', () => {
321
- validateTags.mockReturnValue({});
322
- validateMessageContent('Valid message', mockFormatMessage, mockMessages, mockValidationConfig, true);
323
- expect(validateTags).toHaveBeenCalledWith({
324
- content: 'Valid message',
325
- ...mockValidationConfig,
326
- isFullMode: true,
327
- });
328
- });
329
311
  });
330
312
  });
331
313
 
@@ -182,6 +182,7 @@ export const Whatsapp = (props) => {
182
182
  selectedOfferDetails,
183
183
  currentOrgDetails,
184
184
  eventContextTags,
185
+ waitEventContextTags,
185
186
  metaDataStatus = "",
186
187
  showTestAndPreviewSlidebox: propsShowTestAndPreviewSlidebox,
187
188
  handleTestAndPreview: propsHandleTestAndPreview,
@@ -637,21 +638,23 @@ export const Whatsapp = (props) => {
637
638
  validateTags({
638
639
  content: contentData.join(""),
639
640
  tagsParam: tags,
641
+ injectedTagsParams: injectedTags,
640
642
  location,
641
643
  tagModule: getDefaultTags,
644
+ eventContextTags,
645
+ waitEventContextTags,
642
646
  isFullMode,
643
647
  }) || {};
648
+ const unsupportedTagsLengthCheck =
649
+ validationResponse?.unsupportedTags?.length > 0;
644
650
  if (type === HEADER_TEXT) {
645
651
  headerTagValidationResponse = validationResponse;
646
- updateIsHeaderTagValidationError(validationResponse.isBraceError);
652
+ updateIsHeaderTagValidationError(unsupportedTagsLengthCheck);
647
653
  } else if (type === CAROUSEL_TEXT) {
648
- return [
649
- { fieldName: "carouselTagValidationErrMessage", value: validationResponse.isBraceError ? validationResponse : {} },
650
- { fieldName: "carouselTagValidationErr", value: validationResponse.isBraceError },
651
- ];
654
+ return [{fieldName: "carouselTagValidationErrMessage", value: validationResponse}, {fieldName: "carouselTagValidationErr", value: unsupportedTagsLengthCheck}];
652
655
  } else {
653
656
  tagValidationResponse = validationResponse;
654
- updateIsTagValidationError(validationResponse.isBraceError);
657
+ updateIsTagValidationError(unsupportedTagsLengthCheck);
655
658
  }
656
659
  }
657
660
  };
@@ -955,6 +958,7 @@ const isAuthenticationTemplate = isEqual(templateCategory, WHATSAPP_CATEGORIES.a
955
958
  injectedTags={injectedTags || {}}
956
959
  selectedOfferDetails={selectedOfferDetails}
957
960
  eventContextTags={eventContextTags}
961
+ waitEventContextTags={waitEventContextTags}
958
962
  />
959
963
  )}
960
964
  </>
@@ -1956,6 +1960,7 @@ const isAuthenticationTemplate = isEqual(templateCategory, WHATSAPP_CATEGORIES.a
1956
1960
  injectedTags={injectedTags || {}}
1957
1961
  selectedOfferDetails={selectedOfferDetails}
1958
1962
  eventContextTags={eventContextTags}
1963
+ waitEventContextTags={waitEventContextTags}
1959
1964
  />
1960
1965
  )
1961
1966
  : !isAuthenticationTemplate && (
@@ -2681,11 +2686,18 @@ const isAuthenticationTemplate = isEqual(templateCategory, WHATSAPP_CATEGORIES.a
2681
2686
  } else {
2682
2687
  validationResponse = tagValidationResponse;
2683
2688
  }
2684
- const { isBraceError } = validationResponse || {};
2689
+ const { unsupportedTags = [], isBraceError } = validationResponse;
2690
+
2691
+ let tagError = "";
2692
+ if (unsupportedTags.length > 0) {
2693
+ tagError = formatMessage(globalMessages.unsupportedTagsValidationError, {
2694
+ unsupportedTags,
2695
+ });
2696
+ }
2685
2697
  if (isBraceError) {
2686
- return <CapError>{formatMessage(globalMessages.unbalanacedCurlyBraces)}</CapError>;
2698
+ tagError = formatMessage(globalMessages.unbalanacedCurlyBraces);
2687
2699
  }
2688
- return null;
2700
+ return <CapError>{tagError}</CapError>;
2689
2701
  };
2690
2702
 
2691
2703
  const editModeContent = () => (
@@ -2762,6 +2774,7 @@ const isAuthenticationTemplate = isEqual(templateCategory, WHATSAPP_CATEGORIES.a
2762
2774
  injectedTags={injectedTags || {}}
2763
2775
  selectedOfferDetails={selectedOfferDetails}
2764
2776
  eventContextTags={eventContextTags}
2777
+ waitEventContextTags={waitEventContextTags}
2765
2778
  />
2766
2779
  )
2767
2780
  }
@@ -2880,6 +2893,7 @@ const isAuthenticationTemplate = isEqual(templateCategory, WHATSAPP_CATEGORIES.a
2880
2893
  injectedTags={injectedTags || {}}
2881
2894
  selectedOfferDetails={selectedOfferDetails}
2882
2895
  eventContextTags={eventContextTags}
2896
+ waitEventContextTags={waitEventContextTags}
2883
2897
  />
2884
2898
  )}
2885
2899
  {isBtnTypeQuickReply && (
@@ -76,6 +76,7 @@ export const Zalo = (props) => {
76
76
  selectedOfferDetails,
77
77
  hostName: zaloHostName = '',
78
78
  eventContextTags,
79
+ waitEventContextTags,
79
80
  metaDataStatus = "",
80
81
  // TestAndPreviewSlidebox props
81
82
  showTestAndPreviewSlidebox: propsShowTestAndPreviewSlidebox,
@@ -270,15 +271,24 @@ export const Zalo = (props) => {
270
271
  validateTags({
271
272
  content: message,
272
273
  tagsParam: tags,
274
+ injectedTagsParams: injectedTags,
273
275
  location,
274
276
  tagModule: getDefaultTags,
277
+ eventContextTags,
278
+ waitEventContextTags,
275
279
  isFullMode,
276
280
  }) || {};
277
- const { isBraceError } = tagValidationResponse;
281
+ const { unsupportedTags = [], isBraceError } = tagValidationResponse;
282
+ let tagError = '';
283
+ if (unsupportedTags.length > 0) {
284
+ tagError = formatMessage(globalMessages.unsupportedTagsValidationError, {
285
+ unsupportedTags,
286
+ });
287
+ }
278
288
  if (isBraceError) {
279
- return formatMessage(globalMessages.unbalanacedCurlyBraces);
289
+ tagError = formatMessage(globalMessages.unbalanacedCurlyBraces);
280
290
  }
281
- return '';
291
+ return tagError;
282
292
  };
283
293
 
284
294
  //this function is used for checking errror validation in this it validate tags error and length error
@@ -519,6 +529,7 @@ export const Zalo = (props) => {
519
529
  injectedTags={injectedTags || {}}
520
530
  selectedOfferDetails={selectedOfferDetails}
521
531
  eventContextTags={eventContextTags}
532
+ waitEventContextTags={waitEventContextTags}
522
533
  />
523
534
  }
524
535
  />
@@ -1,122 +0,0 @@
1
- import CapNotification from '@capillarytech/cap-ui-library/CapNotification';
2
- import { showError } from '../commonMethods';
3
-
4
- jest.mock('@capillarytech/cap-ui-library/CapNotification', () => ({
5
- error: jest.fn(),
6
- }));
7
-
8
- jest.mock('../Create/messages', () => ({
9
- __esModule: true,
10
- default: {
11
- validationError: { defaultMessage: 'Validation error' },
12
- },
13
- }));
14
-
15
- describe('Sms commonMethods', () => {
16
- describe('showError', () => {
17
- beforeEach(() => {
18
- jest.clearAllMocks();
19
- });
20
-
21
- it('should call CapNotification.error when formData is not empty, isFormValid is false, and errorData has at least one true value', () => {
22
- const context = {
23
- props: {
24
- intl: { formatMessage: jest.fn((msg) => msg.defaultMessage || 'Validation error') },
25
- },
26
- state: {
27
- formData: { message: 'test' },
28
- isFormValid: false,
29
- errorData: [{ message: true }],
30
- },
31
- };
32
- showError.call(context);
33
- expect(CapNotification.error).toHaveBeenCalledWith({
34
- key: 'validation-error',
35
- message: 'Validation error',
36
- });
37
- });
38
-
39
- it('should not call CapNotification.error when formData is empty', () => {
40
- const context = {
41
- props: { intl: { formatMessage: jest.fn() } },
42
- state: {
43
- formData: {},
44
- isFormValid: false,
45
- errorData: [{ message: true }],
46
- },
47
- };
48
- showError.call(context);
49
- expect(CapNotification.error).not.toHaveBeenCalled();
50
- });
51
-
52
- it('should not call CapNotification.error when isFormValid is true', () => {
53
- const context = {
54
- props: { intl: { formatMessage: jest.fn() } },
55
- state: {
56
- formData: { message: 'test' },
57
- isFormValid: true,
58
- errorData: [{ message: true }],
59
- },
60
- };
61
- showError.call(context);
62
- expect(CapNotification.error).not.toHaveBeenCalled();
63
- });
64
-
65
- it('should not call CapNotification.error when no errorData entry has a true value', () => {
66
- const context = {
67
- props: { intl: { formatMessage: jest.fn() } },
68
- state: {
69
- formData: { message: 'test' },
70
- isFormValid: false,
71
- errorData: [{ message: false, title: false }],
72
- },
73
- };
74
- showError.call(context);
75
- expect(CapNotification.error).not.toHaveBeenCalled();
76
- });
77
-
78
- it('should not call CapNotification.error when errorData is empty', () => {
79
- const context = {
80
- props: { intl: { formatMessage: jest.fn() } },
81
- state: {
82
- formData: { message: 'test' },
83
- isFormValid: false,
84
- errorData: [],
85
- },
86
- };
87
- showError.call(context);
88
- expect(CapNotification.error).not.toHaveBeenCalled();
89
- });
90
-
91
- it('should not call CapNotification.error when errorData[0] is undefined', () => {
92
- const context = {
93
- props: { intl: { formatMessage: jest.fn() } },
94
- state: {
95
- formData: { message: 'test' },
96
- isFormValid: false,
97
- errorData: [],
98
- },
99
- };
100
- showError.call(context);
101
- expect(CapNotification.error).not.toHaveBeenCalled();
102
- });
103
-
104
- it('should call CapNotification.error when errorData[0] has multiple keys and one is true', () => {
105
- const context = {
106
- props: {
107
- intl: { formatMessage: jest.fn((msg) => msg.defaultMessage || 'Validation error') },
108
- },
109
- state: {
110
- formData: { message: 'hello' },
111
- isFormValid: false,
112
- errorData: [{ message: false, title: true }],
113
- },
114
- };
115
- showError.call(context);
116
- expect(CapNotification.error).toHaveBeenCalledWith({
117
- key: 'validation-error',
118
- message: 'Validation error',
119
- });
120
- });
121
- });
122
- });