@capillarytech/creatives-library 8.0.114-alpha.1 → 8.0.114

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 (37) hide show
  1. package/package.json +1 -1
  2. package/utils/commonUtils.js +3 -359
  3. package/utils/tagValidations.js +5 -20
  4. package/utils/tests/commonUtil.test.js +171 -474
  5. package/utils/tests/tagValidations.test.js +2 -89
  6. package/v2Components/ErrorInfoNote/index.js +46 -114
  7. package/v2Components/ErrorInfoNote/messages.js +0 -25
  8. package/v2Components/ErrorInfoNote/style.scss +1 -14
  9. package/v2Components/FormBuilder/index.js +127 -204
  10. package/v2Components/FormBuilder/messages.js +1 -1
  11. package/v2Containers/Cap/reducer.js +4 -4
  12. package/v2Containers/CreativesContainer/SlideBoxContent.js +3 -23
  13. package/v2Containers/CreativesContainer/SlideBoxFooter.js +1 -3
  14. package/v2Containers/CreativesContainer/constants.js +1 -4
  15. package/v2Containers/CreativesContainer/index.js +19 -44
  16. package/v2Containers/CreativesContainer/messages.js +0 -4
  17. package/v2Containers/CreativesContainer/tests/__snapshots__/index.test.js.snap +3 -21
  18. package/v2Containers/Ebill/index.js +3 -3
  19. package/v2Containers/EmailWrapper/components/EmailWrapperView.js +1 -1
  20. package/v2Containers/InApp/index.js +50 -123
  21. package/v2Containers/InApp/tests/index.test.js +1 -1
  22. package/v2Containers/InApp/tests/sagas.test.js +1 -1
  23. package/v2Containers/InApp/utils.js +0 -37
  24. package/v2Containers/MobilePush/Create/index.js +20 -24
  25. package/v2Containers/MobilePush/Edit/index.js +2 -6
  26. package/v2Containers/MobilepushWrapper/index.js +0 -2
  27. package/v2Containers/Sms/Create/index.js +0 -1
  28. package/v2Containers/Sms/Edit/index.js +0 -2
  29. package/v2Containers/SmsWrapper/index.js +0 -2
  30. package/v2Containers/Whatsapp/constants.js +1 -1
  31. package/v2Containers/Whatsapp/tests/__snapshots__/index.test.js.snap +57476 -0
  32. package/v2Containers/Whatsapp/tests/index.test.js +88 -0
  33. package/v2Components/ErrorInfoNote/ErrorTypeRenderer.js +0 -127
  34. package/v2Components/ErrorInfoNote/ErrorTypeRenderer.test.js +0 -147
  35. package/v2Components/ErrorInfoNote/utils.js +0 -38
  36. package/v2Components/ErrorInfoNote/utils.test.js +0 -156
  37. package/v2Containers/InApp/tests/utils.test.js +0 -41
@@ -7,6 +7,7 @@ import { mountWithIntl, shallowWithIntl } from '../../../../app/helpers/intl-enz
7
7
  import { Whatsapp } from '../index';
8
8
  import { mockData } from './mockData';
9
9
  import * as constants from '../constants';
10
+ import { mediaTypeOptions, WHATSAPP_CATEGORIES, HOST_GUPSHUP, HOST_TWILIO } from '../constants';
10
11
 
11
12
 
12
13
 
@@ -283,6 +284,38 @@ describe('Creatives Whatsapp test1/>', () => {
283
284
  renderedComponent.update();
284
285
  expect(renderedComponent).toMatchSnapshot();
285
286
  });
287
+ it("check for carousel render", () => {
288
+ renderHelper({}, true, accountData2);
289
+ renderedComponent
290
+ .find('CapSelect#select-whatsapp-category')
291
+ .props()
292
+ .onChange('MARKETING');
293
+ renderedComponent
294
+ .find('CapSelect#select-whatsapp-language')
295
+ .props()
296
+ .onChange('en');
297
+ expect(renderedComponent).toMatchSnapshot();
298
+ renderHelper({}, true, accountData3);
299
+ renderedComponent
300
+ .find('CapSelect#select-whatsapp-category')
301
+ .props()
302
+ .onChange('MARKETING');
303
+ renderedComponent
304
+ .find('CapSelect#select-whatsapp-language')
305
+ .props()
306
+ .onChange('en');
307
+ expect(renderedComponent).toMatchSnapshot();
308
+ renderHelper({}, true, accountData4);
309
+ renderedComponent
310
+ .find('CapSelect#select-whatsapp-category')
311
+ .props()
312
+ .onChange('MARKETING');
313
+ renderedComponent
314
+ .find('CapSelect#select-whatsapp-language')
315
+ .props()
316
+ .onChange('en');
317
+ expect(renderedComponent).toMatchSnapshot();
318
+ })
286
319
  });
287
320
 
288
321
  describe('Creatives Whatsapp test2/>', () => {
@@ -488,3 +521,58 @@ describe('Creatives Whatsapp test2/>', () => {
488
521
  expect(renderedComponent).toMatchSnapshot();
489
522
  });
490
523
  });
524
+
525
+ // --- UNIT TESTS FOR mediaTypeOptions ---
526
+ describe('mediaTypeOptions', () => {
527
+ it('should include CAROUSEL when category is MARKETING and host is HOST_GUPSHUP', () => {
528
+ const options = mediaTypeOptions({
529
+ host: HOST_GUPSHUP,
530
+ templateCategory: WHATSAPP_CATEGORIES.marketing,
531
+ });
532
+ const hasCarousel = options.some(
533
+ (opt) => Array.isArray(opt)
534
+ ? opt.some((o) => o.key === 'CAROUSEL')
535
+ : opt.key === 'CAROUSEL'
536
+ ) || options.flat().some((o) => o.key === 'CAROUSEL');
537
+ expect(hasCarousel).toBe(true);
538
+ });
539
+
540
+ it('should NOT include CAROUSEL when category is MARKETING and host is NOT HOST_GUPSHUP', () => {
541
+ const options = mediaTypeOptions({
542
+ host: 'karixwhatsappbulk',
543
+ templateCategory: WHATSAPP_CATEGORIES.marketing,
544
+ });
545
+ const hasCarousel = options.some(
546
+ (opt) => Array.isArray(opt)
547
+ ? opt.some((o) => o.key === 'CAROUSEL')
548
+ : opt.key === 'CAROUSEL'
549
+ ) || options.flat().some((o) => o.key === 'CAROUSEL');
550
+ expect(hasCarousel).toBe(false);
551
+ });
552
+
553
+ it('should NOT include CAROUSEL when category is NOT MARKETING and host is HOST_GUPSHUP', () => {
554
+ const options = mediaTypeOptions({
555
+ host: HOST_GUPSHUP,
556
+ templateCategory: WHATSAPP_CATEGORIES.utility,
557
+ });
558
+ const hasCarousel = options.some(
559
+ (opt) => Array.isArray(opt)
560
+ ? opt.some((o) => o.key === 'CAROUSEL')
561
+ : opt.key === 'CAROUSEL'
562
+ ) || options.flat().some((o) => o.key === 'CAROUSEL');
563
+ expect(hasCarousel).toBe(false);
564
+ });
565
+
566
+ it('should NOT include CAROUSEL when category is NOT MARKETING and host is NOT HOST_GUPSHUP', () => {
567
+ const options = mediaTypeOptions({
568
+ host: HOST_TWILIO,
569
+ templateCategory: WHATSAPP_CATEGORIES.utility,
570
+ });
571
+ const hasCarousel = options.some(
572
+ (opt) => Array.isArray(opt)
573
+ ? opt.some((o) => o.key === 'CAROUSEL')
574
+ : opt.key === 'CAROUSEL'
575
+ ) || options.flat().some((o) => o.key === 'CAROUSEL');
576
+ expect(hasCarousel).toBe(false);
577
+ });
578
+ });
@@ -1,127 +0,0 @@
1
- // app/v2Components/ErrorInfoNote/ErrorTypeRenderer.js
2
- import React from 'react';
3
- import PropTypes from 'prop-types';
4
- import CapDivider from "@capillarytech/cap-ui-library/CapDivider";
5
- import { getLiquidProps } from './utils';
6
-
7
- /**
8
- * Renders error sections for either generic (non-platform) or platform-specific (Android/iOS) errors.
9
- * - If `genericErrors` is provided, renders standard and liquid errors (if present) without platform labels.
10
- * - If `androidErrors`/`iosErrors` are provided, renders merged errors for each platform with platform labels and dividers.
11
- */
12
- const ErrorTypeRenderer = ({
13
- genericErrors,
14
- androidErrors,
15
- iosErrors,
16
- ErrorSectionComponent,
17
- }) => {
18
- // Render generic (non-platform) errors
19
- if (genericErrors) {
20
- const hasStandard = genericErrors?.standard?.errorsToShow?.length > 0;
21
- const hasLiquid = genericErrors?.liquid?.errorsToShow?.length > 0;
22
- if (!hasStandard && !hasLiquid) return null;
23
-
24
- const liquidGenericProps = {
25
- title: genericErrors?.liquid?.title,
26
- errors: genericErrors?.liquid?.errorsToShow,
27
- platformLabel: null,
28
- };
29
-
30
- return (
31
- <div className="error-container">
32
- {hasStandard && (
33
- <ErrorSectionComponent
34
- title={genericErrors?.standard?.title}
35
- errors={genericErrors?.standard?.errorsToShow}
36
- liquidError={false}
37
- platformLabel={null}
38
- />
39
- )}
40
- {hasStandard && hasLiquid && <CapDivider className="liquid-divider" />}
41
- {hasLiquid && (
42
- <ErrorSectionComponent
43
- {...liquidGenericProps}
44
- liquidError
45
- />
46
- )}
47
- </div>
48
- );
49
- }
50
-
51
- // Render platform-specific errors (Android/iOS)
52
- const hasAndroid = (androidErrors?.standard?.errorsToShow?.length || 0) > 0
53
- || (androidErrors?.liquid?.errorsToShow?.length || 0) > 0;
54
- const hasIos = (iosErrors?.standard?.errorsToShow?.length || 0) > 0
55
- || (iosErrors?.liquid?.errorsToShow?.length || 0) > 0;
56
-
57
- if (!hasAndroid && !hasIos) return null;
58
-
59
- const showPlatformLabels = !!androidErrors?.standard?.platformLabel || !!iosErrors?.standard?.platformLabel;
60
- const showTitle = hasAndroid && hasIos && showPlatformLabels;
61
- const liquidAndroidProps = getLiquidProps(androidErrors, true, showTitle, showPlatformLabels);
62
- const liquidIosProps = getLiquidProps(iosErrors, false, showTitle, showPlatformLabels);
63
-
64
- return (
65
- <div className="error-container">
66
- {hasAndroid && (
67
- <ErrorSectionComponent
68
- {...liquidAndroidProps}
69
- />
70
- )}
71
- {hasAndroid && hasIos && showPlatformLabels && (
72
- <CapDivider className="platform-divider" />
73
- )}
74
- {hasIos && (
75
- <ErrorSectionComponent
76
- {...liquidIosProps}
77
- />
78
- )}
79
- </div>
80
- );
81
- };
82
-
83
- ErrorTypeRenderer.propTypes = {
84
- genericErrors: PropTypes.shape({
85
- standard: PropTypes.shape({
86
- errorsToShow: PropTypes.array.isRequired,
87
- title: PropTypes.node.isRequired,
88
- }),
89
- liquid: PropTypes.shape({
90
- errorsToShow: PropTypes.array.isRequired,
91
- title: PropTypes.node.isRequired,
92
- }),
93
- }),
94
- androidErrors: PropTypes.shape({
95
- standard: PropTypes.shape({
96
- errorsToShow: PropTypes.array.isRequired,
97
- title: PropTypes.node.isRequired,
98
- platformLabel: PropTypes.string,
99
- }),
100
- liquid: PropTypes.shape({
101
- errorsToShow: PropTypes.array.isRequired,
102
- title: PropTypes.node.isRequired,
103
- platformLabel: PropTypes.string,
104
- }),
105
- }),
106
- iosErrors: PropTypes.shape({
107
- standard: PropTypes.shape({
108
- errorsToShow: PropTypes.array.isRequired,
109
- title: PropTypes.node.isRequired,
110
- platformLabel: PropTypes.string,
111
- }),
112
- liquid: PropTypes.shape({
113
- errorsToShow: PropTypes.array.isRequired,
114
- title: PropTypes.node.isRequired,
115
- platformLabel: PropTypes.string,
116
- }),
117
- }),
118
- ErrorSectionComponent: PropTypes.elementType.isRequired,
119
- };
120
-
121
- ErrorTypeRenderer.defaultProps = {
122
- genericErrors: null,
123
- androidErrors: null,
124
- iosErrors: null,
125
- };
126
-
127
- export default ErrorTypeRenderer;
@@ -1,147 +0,0 @@
1
- import React from 'react';
2
- import { render } from '@testing-library/react';
3
- import ErrorTypeRenderer from './ErrorTypeRenderer';
4
- import { ANDROID, IOS } from '../../v2Containers/CreativesContainer/constants';
5
-
6
- describe('ErrorTypeRenderer', () => { const ErrorSectionComponent = jest.fn(({
7
- title,
8
- errors,
9
- liquidError,
10
- platformLabel,
11
- }) => (
12
- <div data-testid="error-section">
13
- <span>{title}</span>
14
- <span>{errors && errors.join(',')}</span>
15
- <span>{liquidError ? 'liquid' : 'standard'}</span>
16
- <span>{platformLabel}</span>
17
- </div>
18
- ));
19
-
20
- afterEach(() => {
21
- ErrorSectionComponent.mockClear();
22
- });
23
-
24
- it('renders nothing if all errors are empty', () => {
25
- const { container } = render(
26
- <ErrorTypeRenderer
27
- genericErrors={{ standard: { errorsToShow: [], title: 'Standard' }, liquid: { errorsToShow: [], title: 'Liquid' } }}
28
- ErrorSectionComponent={ErrorSectionComponent}
29
- />
30
- );
31
- expect(container.firstChild).toBeNull();
32
- expect(ErrorSectionComponent).not.toHaveBeenCalled();
33
- });
34
-
35
- it('renders generic standard errors only', () => {
36
- render(
37
- <ErrorTypeRenderer
38
- genericErrors={{ standard: { errorsToShow: ['err1', 'err2'], title: 'Standard' }, liquid: { errorsToShow: [], title: 'Liquid' } }}
39
- ErrorSectionComponent={ErrorSectionComponent}
40
- />
41
- );
42
- expect(ErrorSectionComponent).toHaveBeenCalledWith(
43
- expect.objectContaining({
44
- title: 'Standard',
45
- errors: ['err1', 'err2'],
46
- liquidError: false,
47
- platformLabel: null,
48
- }),
49
- expect.anything()
50
- );
51
- });
52
-
53
- it('renders generic liquid errors only', () => {
54
- render(
55
- <ErrorTypeRenderer
56
- genericErrors={{ standard: { errorsToShow: [], title: 'Standard' }, liquid: { errorsToShow: ['l1'], title: 'Liquid' } }}
57
- ErrorSectionComponent={ErrorSectionComponent}
58
- />
59
- );
60
- expect(ErrorSectionComponent).toHaveBeenCalledWith(
61
- expect.objectContaining({
62
- title: 'Liquid',
63
- errors: ['l1'],
64
- liquidError: true,
65
- platformLabel: null,
66
- }),
67
- expect.anything()
68
- );
69
- });
70
-
71
- it('renders both generic standard and liquid errors', () => {
72
- render(
73
- <ErrorTypeRenderer
74
- genericErrors={{ standard: { errorsToShow: ['err1'], title: 'Standard' }, liquid: { errorsToShow: ['l1'], title: 'Liquid' } }}
75
- ErrorSectionComponent={ErrorSectionComponent}
76
- />
77
- );
78
- expect(ErrorSectionComponent).toHaveBeenCalledWith(
79
- expect.objectContaining({
80
- title: 'Standard',
81
- errors: ['err1'],
82
- liquidError: false,
83
- platformLabel: null,
84
- }),
85
- expect.anything()
86
- );
87
- expect(ErrorSectionComponent).toHaveBeenCalledWith(
88
- expect.objectContaining({
89
- title: 'Liquid',
90
- errors: ['l1'],
91
- liquidError: true,
92
- platformLabel: null,
93
- }),
94
- expect.anything()
95
- );
96
- });
97
-
98
- it('renders merged android errors with platform label', () => {
99
- render(
100
- <ErrorTypeRenderer
101
- androidErrors={{
102
- standard: { errorsToShow: ['a1'], title: 'Android Standard', platformLabel: ANDROID },
103
- liquid: { errorsToShow: ['al1'], title: 'Android Liquid', platformLabel: ANDROID },
104
- }}
105
- iosErrors={{
106
- standard: { errorsToShow: [], title: 'iOS Standard', platformLabel: IOS },
107
- liquid: { errorsToShow: [], title: 'iOS Liquid', platformLabel: IOS },
108
- }}
109
- ErrorSectionComponent={ErrorSectionComponent}
110
- />
111
- );
112
- expect(ErrorSectionComponent).toHaveBeenCalledWith(
113
- expect.objectContaining({
114
- title: false,
115
- errors: ['a1', 'al1'],
116
- liquidError: true,
117
- platformLabel: ANDROID,
118
- }),
119
- expect.anything()
120
- );
121
- });
122
-
123
- it('renders merged ios errors with platform label', () => {
124
- render(
125
- <ErrorTypeRenderer
126
- androidErrors={{
127
- standard: { errorsToShow: [], title: 'Android Standard', platformLabel: ANDROID },
128
- liquid: { errorsToShow: [], title: 'Android Liquid', platformLabel: ANDROID },
129
- }}
130
- iosErrors={{
131
- standard: { errorsToShow: ['i1'], title: 'iOS Standard', platformLabel: IOS },
132
- liquid: { errorsToShow: ['il1'], title: 'iOS Liquid', platformLabel: IOS },
133
- }}
134
- ErrorSectionComponent={ErrorSectionComponent}
135
- />
136
- );
137
- expect(ErrorSectionComponent).toHaveBeenCalledWith(
138
- expect.objectContaining({
139
- title: 'iOS Liquid',
140
- errors: ['i1', 'il1'],
141
- liquidError: true,
142
- platformLabel: IOS,
143
- }),
144
- expect.anything()
145
- );
146
- });
147
- });
@@ -1,38 +0,0 @@
1
- import React from 'react';
2
- import { FormattedMessage } from 'react-intl';
3
- import { ANDROID, GENERIC, IOS } from '../../v2Containers/CreativesContainer/constants';
4
-
5
- export const processErrors = (rawErrorData, errorType, platform, messages) => {
6
- let errorsToShow = [];
7
- let titleMsg = messages.standardErrorHeader;
8
- let platformLabel = null;
9
-
10
- const isObject = typeof rawErrorData === 'object' && rawErrorData !== null;
11
- const isNotArray = !Array.isArray(rawErrorData);
12
- const hasPlatformKeys = isObject && isNotArray && [ANDROID, IOS, GENERIC].some((key) => key in rawErrorData);
13
- if (hasPlatformKeys) {
14
- if (errorType === "liquid") {
15
- titleMsg = messages.dynamicErrorHeader;
16
- }
17
- errorsToShow = rawErrorData[platform] || [];
18
- platformLabel = platform; // Only set platform label for new structure
19
- } else if (Array.isArray(rawErrorData)) {
20
- errorsToShow = rawErrorData;
21
- if (errorType === "liquid") {
22
- titleMsg = messages.dynamicErrorHeader;
23
- }
24
- }
25
-
26
- const title = <FormattedMessage {...titleMsg} />;
27
- return { errorsToShow, title, platformLabel };
28
- };
29
-
30
- export const getLiquidProps = (errors, isAndroid,showTitle,showPlatformLabels) => ({
31
- title: (isAndroid ? showTitle : !showTitle) && errors?.liquid?.title,
32
- errors: [
33
- ...(errors?.standard?.errorsToShow || []),
34
- ...(errors?.liquid?.errorsToShow || []),
35
- ],
36
- liquidError: !!errors?.liquid?.errorsToShow?.length,
37
- platformLabel: showPlatformLabels ? (isAndroid ? ANDROID : IOS) : null,
38
- });
@@ -1,156 +0,0 @@
1
- import { processErrors, getLiquidProps } from './utils';
2
-
3
- const makeMessages = (overrides = {}) => ({
4
- standardErrorHeader: { id: 'standard', defaultMessage: 'Standard' },
5
- dynamicErrorHeader: { id: 'liquid', defaultMessage: 'Liquid' },
6
- ...overrides,
7
- });
8
-
9
- // Mock platform constants
10
- const ANDROID = 'ANDROID';
11
- const IOS = 'IOS';
12
-
13
- describe('processErrors', () => {
14
- it('returns empty errors if platform is not specified and input has GENERIC key', () => {
15
- const messages = makeMessages();
16
- const raw = { ANDROID: ['a1'], IOS: ['i1'], GENERIC: ['g1', 'g2'] };
17
- const result = processErrors(raw, 'standard', undefined, messages);
18
- expect(result.errorsToShow).toEqual([]);
19
- expect(result.platformLabel).toBeUndefined();
20
- });
21
-
22
- it('returns empty errors for object input with missing keys', () => {
23
- const messages = makeMessages();
24
- const raw = { ANDROID: [], IOS: [], GENERIC: [] };
25
- const result = processErrors(raw, 'standard', 'ANDROID', messages);
26
- expect(result.errorsToShow).toEqual([]);
27
- expect(result.platformLabel).toBe('ANDROID');
28
- });
29
-
30
- it('returns empty errors for null/undefined/empty input', () => {
31
- const messages = makeMessages();
32
- expect(processErrors(null, 'standard', undefined, messages).errorsToShow).toEqual([]);
33
- expect(processErrors(undefined, 'standard', undefined, messages).errorsToShow).toEqual([]);
34
- expect(processErrors([], 'standard', undefined, messages).errorsToShow).toEqual([]);
35
- });
36
-
37
- it('returns empty errors for object input with only GENERIC key', () => {
38
- const messages = makeMessages();
39
- const raw = { GENERIC: ['g1', 'g2'] };
40
- const result = processErrors(raw, 'standard', undefined, messages);
41
- expect(result.errorsToShow).toEqual([]);
42
- expect(result.platformLabel).toBeUndefined();
43
- });
44
-
45
- it('handles object input with only ANDROID/IOS keys', () => {
46
- const messages = makeMessages();
47
- const raw = { ANDROID: ['a1'], IOS: ['i1'] };
48
- const result = processErrors(raw, 'standard', 'ANDROID', messages);
49
- expect(result.errorsToShow).toEqual(['a1']);
50
- expect(result.platformLabel).toBe('ANDROID');
51
- });
52
-
53
- it('handles object input with no errors for currentTab', () => {
54
- const messages = makeMessages();
55
- const raw = { ANDROID: [], IOS: ['i1'] };
56
- const result = processErrors(raw, 'standard', 'ANDROID', messages);
57
- expect(result.errorsToShow).toEqual([]);
58
- expect(result.platformLabel).toBe('ANDROID');
59
- });
60
-
61
- it('returns undefined platformLabel for object input with no GENERIC key and no platform', () => {
62
- const messages = makeMessages();
63
- const raw = { ANDROID: ['a1'], IOS: ['i1'] };
64
- const result = processErrors(raw, 'standard', undefined, messages);
65
- expect(result.errorsToShow).toEqual([]);
66
- expect(result.platformLabel).toBeUndefined();
67
- });
68
-
69
- it('returns correct title and errors for array input with errorType liquid', () => {
70
- const messages = makeMessages();
71
- const result = processErrors(['liquidErr1', 'liquidErr2'], 'liquid', undefined, messages);
72
- expect(result.errorsToShow).toEqual(['liquidErr1', 'liquidErr2']);
73
- expect(result.title.props.id).toBe('liquid');
74
- expect(result.title.props.defaultMessage).toBe('Liquid');
75
- expect(result.platformLabel).toBeNull();
76
- });
77
-
78
- it('returns correct title and errors for object input with errorType liquid and platform', () => {
79
- const messages = makeMessages();
80
- const raw = { ANDROID: ['l1', 'l2'], IOS: ['l3'], GENERIC: ['lg1'] };
81
- const result = processErrors(raw, 'liquid', 'ANDROID', messages);
82
- expect(result.errorsToShow).toEqual(['l1', 'l2']);
83
- expect(result.title.props.id).toBe('liquid');
84
- expect(result.title.props.defaultMessage).toBe('Liquid');
85
- expect(result.platformLabel).toBe('ANDROID');
86
- });
87
-
88
- it('returns empty errors for object input with errorType liquid and no platform', () => {
89
- const messages = makeMessages();
90
- const raw = { ANDROID: ['l1'], IOS: ['l2'], GENERIC: ['lg1', 'lg2'] };
91
- const result = processErrors(raw, 'liquid', undefined, messages);
92
- expect(result.errorsToShow).toEqual([]);
93
- expect(result.title.props.id).toBe('liquid');
94
- expect(result.title.props.defaultMessage).toBe('Liquid');
95
- expect(result.platformLabel).toBeUndefined();
96
- });
97
- });
98
-
99
- describe('getLiquidProps', () => {
100
- const baseErrors = {
101
- standard: { errorsToShow: ['s1'] },
102
- liquid: { errorsToShow: ['l1'], title: 'Liquid Title' },
103
- };
104
-
105
- it('returns correct props for Android with showTitle true and showPlatformLabels true', () => {
106
- const result = getLiquidProps(baseErrors, true, true, true);
107
- expect(result).toEqual({
108
- title: 'Liquid Title',
109
- errors: ['s1', 'l1'],
110
- liquidError: true,
111
- platformLabel: ANDROID,
112
- });
113
- });
114
-
115
- it('returns correct props for iOS with showTitle false and showPlatformLabels true', () => {
116
- const result = getLiquidProps(baseErrors, false, false, true);
117
- expect(result).toEqual({
118
- title: 'Liquid Title',
119
- errors: ['s1', 'l1'],
120
- liquidError: true,
121
- platformLabel: IOS,
122
- });
123
- });
124
-
125
- it('returns null title if showTitle is false for Android', () => {
126
- const result = getLiquidProps(baseErrors, true, false, true);
127
- expect(result.title).toBeFalsy();
128
- });
129
-
130
- it('returns null title if showTitle is true for iOS', () => {
131
- const result = getLiquidProps(baseErrors, false, true, true);
132
- expect(result.title).toBeFalsy();
133
- });
134
-
135
- it('returns platformLabel null if showPlatformLabels is false', () => {
136
- const result = getLiquidProps(baseErrors, true, true, false);
137
- expect(result.platformLabel).toBeNull();
138
- });
139
-
140
- it('returns empty errors array if both errorsToShow are missing', () => {
141
- const result = getLiquidProps({}, true, true, true);
142
- expect(result.errors).toEqual([]);
143
- });
144
-
145
- it('liquidError is false if no liquid errors', () => {
146
- const result = getLiquidProps({ standard: { errorsToShow: ['s1'] } }, true, true, true);
147
- expect(result.liquidError).toBe(false);
148
- });
149
-
150
- it('handles undefined input gracefully', () => {
151
- const result = getLiquidProps(undefined, true, true, true);
152
- expect(result.errors).toEqual([]);
153
- expect(result.liquidError).toBe(false);
154
- expect(result.platformLabel).toBe(ANDROID);
155
- });
156
- });
@@ -1,41 +0,0 @@
1
- import { hasPlatformErrors } from "../utils";
2
-
3
- describe("hasPlatformErrors", () => {
4
- it("Happy case for hasPlatformErrors", () => {
5
- const result = hasPlatformErrors();
6
- expect(result).toBe(false);
7
- });
8
- it("returns false when called with no arguments", () => {
9
- expect(hasPlatformErrors()).toBe(false);
10
- });
11
-
12
- it("returns false when given null or undefined", () => {
13
- expect(hasPlatformErrors(null)).toBe(false);
14
- expect(hasPlatformErrors(undefined)).toBe(false);
15
- });
16
-
17
- it("returns false for empty error groups", () => {
18
- const emptyGroup = { ANDROID: [], IOS: [], GENERIC: [] };
19
- expect(hasPlatformErrors(emptyGroup)).toBe(false);
20
- });
21
-
22
- it("detects Android errors", () => {
23
- const data = { ANDROID: ["e1"], IOS: [], GENERIC: [] };
24
- expect(hasPlatformErrors(data)).toBe(true);
25
- });
26
-
27
- it("detects iOS errors", () => {
28
- const data = { ANDROID: [], IOS: ["e1"], GENERIC: [] };
29
- expect(hasPlatformErrors(data)).toBe(true);
30
- });
31
-
32
- it("detects generic errors", () => {
33
- const data = { ANDROID: [], IOS: [], GENERIC: ["e1"] };
34
- expect(hasPlatformErrors(data)).toBe(true);
35
- });
36
-
37
- it("detects mixed platform errors", () => {
38
- const data = { ANDROID: ["a"], IOS: ["i"], GENERIC: [] };
39
- expect(hasPlatformErrors(data)).toBe(true);
40
- });
41
- });