@capillarytech/creatives-library 8.0.329 → 8.0.330
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 -14
- package/package.json +1 -1
- package/services/api.js +0 -17
- package/services/tests/api.test.js +0 -85
- package/utils/commonUtils.js +0 -10
- package/utils/tests/commonUtil.test.js +0 -169
- package/v2Components/CapTagList/index.js +0 -10
- package/v2Components/CommonTestAndPreview/CustomValuesEditor.js +49 -70
- package/v2Components/CommonTestAndPreview/DeliverySettings/DeliverySettings.scss +2 -8
- package/v2Components/CommonTestAndPreview/DeliverySettings/ModifyDeliverySettings.js +21 -207
- package/v2Components/CommonTestAndPreview/DeliverySettings/constants.js +0 -16
- package/v2Components/CommonTestAndPreview/DeliverySettings/index.js +10 -85
- package/v2Components/CommonTestAndPreview/DeliverySettings/messages.js +0 -30
- package/v2Components/CommonTestAndPreview/DeliverySettings/utils/parseSenderDetailsResponse.js +11 -79
- package/v2Components/CommonTestAndPreview/SendTestMessage.js +53 -87
- package/v2Components/CommonTestAndPreview/UnifiedPreview/_unifiedPreview.scss +1 -20
- package/v2Components/CommonTestAndPreview/UnifiedPreview/index.js +4 -133
- package/v2Components/CommonTestAndPreview/_commonTestAndPreview.scss +34 -145
- package/v2Components/CommonTestAndPreview/actions.js +0 -10
- package/v2Components/CommonTestAndPreview/constants.js +1 -53
- package/v2Components/CommonTestAndPreview/index.js +168 -1006
- package/v2Components/CommonTestAndPreview/messages.js +3 -147
- package/v2Components/CommonTestAndPreview/reducer.js +0 -10
- package/v2Components/CommonTestAndPreview/sagas.js +6 -15
- package/v2Components/CommonTestAndPreview/tests/CustomValuesEditor.test.js +286 -328
- package/v2Components/CommonTestAndPreview/tests/DeliverySettings/ModifyDeliverySettings.test.js +65 -231
- package/v2Components/CommonTestAndPreview/tests/DeliverySettings/index.test.js +5 -118
- package/v2Components/CommonTestAndPreview/tests/DeliverySettings/utils/parseSenderDetailsResponse.test.js +0 -341
- package/v2Components/CommonTestAndPreview/tests/SendTestMessage.test.js +24 -65
- package/v2Components/CommonTestAndPreview/tests/UnifiedPreview/index.test.js +1 -199
- package/v2Components/CommonTestAndPreview/tests/constants.test.js +1 -31
- package/v2Components/CommonTestAndPreview/tests/index.test.js +4 -168
- package/v2Components/CommonTestAndPreview/tests/reducer.test.js +0 -71
- package/v2Components/CommonTestAndPreview/tests/sagas.test.js +2 -2
- package/v2Components/CommonTestAndPreview/tests/selectors.test.js +0 -17
- package/v2Components/FormBuilder/index.js +1 -7
- package/v2Components/TestAndPreviewSlidebox/index.js +1 -8
- package/v2Components/TestAndPreviewSlidebox/sagas.js +4 -11
- package/v2Components/TestAndPreviewSlidebox/tests/saga.test.js +1 -3
- package/v2Containers/CreativesContainer/SlideBoxContent.js +4 -36
- package/v2Containers/CreativesContainer/SlideBoxFooter.js +1 -10
- package/v2Containers/CreativesContainer/SlideBoxHeader.js +4 -29
- package/v2Containers/CreativesContainer/constants.js +0 -9
- package/v2Containers/CreativesContainer/index.js +93 -286
- package/v2Containers/CreativesContainer/index.scss +1 -51
- package/v2Containers/CreativesContainer/tests/SlideBoxFooter.test.js +34 -78
- package/v2Containers/CreativesContainer/tests/SlideBoxHeader.test.js +16 -79
- package/v2Containers/CreativesContainer/tests/__snapshots__/SlideBoxContent.test.js.snap +0 -8
- package/v2Containers/CreativesContainer/tests/__snapshots__/SlideBoxHeader.test.js.snap +98 -357
- package/v2Containers/CreativesContainer/tests/__snapshots__/index.test.js.snap +10 -20
- package/v2Containers/CreativesContainer/tests/index.test.js +9 -71
- package/v2Containers/Rcs/constants.js +1 -34
- package/v2Containers/Rcs/index.js +884 -999
- package/v2Containers/Rcs/index.scss +6 -85
- package/v2Containers/Rcs/messages.js +1 -10
- package/v2Containers/Rcs/tests/__snapshots__/index.test.js.snap +2453 -41456
- package/v2Containers/Rcs/tests/__snapshots__/utils.test.js.snap +5 -0
- package/v2Containers/Rcs/tests/index.test.js +38 -41
- package/v2Containers/Rcs/tests/mockData.js +0 -38
- package/v2Containers/Rcs/tests/utils.test.js +1 -379
- package/v2Containers/Rcs/utils.js +10 -358
- package/v2Containers/Sms/Create/index.js +38 -100
- package/v2Containers/SmsTrai/Create/index.js +4 -9
- package/v2Containers/SmsTrai/Edit/constants.js +0 -2
- package/v2Containers/SmsTrai/Edit/index.js +128 -609
- package/v2Containers/SmsTrai/Edit/messages.js +4 -9
- package/v2Containers/SmsTrai/Edit/tests/__snapshots__/index.test.js.snap +2600 -4586
- package/v2Containers/SmsWrapper/index.js +8 -37
- package/v2Containers/TagList/index.js +0 -6
- package/v2Containers/Templates/_templates.scss +2 -63
- package/v2Containers/Templates/actions.js +0 -11
- package/v2Containers/Templates/constants.js +0 -2
- package/v2Containers/Templates/index.js +40 -90
- package/v2Containers/Templates/sagas.js +12 -57
- package/v2Containers/Templates/tests/__snapshots__/index.test.js.snap +1079 -1043
- package/v2Containers/Templates/tests/sagas.test.js +123 -193
- package/v2Containers/TemplatesV2/TemplatesV2.style.js +1 -72
- package/v2Containers/TemplatesV2/index.js +23 -86
- package/v2Containers/Whatsapp/index.js +20 -3
- package/v2Containers/Whatsapp/tests/__snapshots__/index.test.js.snap +4872 -5790
- package/utils/templateVarUtils.js +0 -172
- package/utils/tests/templateVarUtils.test.js +0 -160
- package/v2Components/CommonTestAndPreview/AddTestCustomer.js +0 -42
- package/v2Components/CommonTestAndPreview/CustomerCreationModal.js +0 -155
- package/v2Components/CommonTestAndPreview/ExistingCustomerModal.js +0 -93
- package/v2Components/CommonTestAndPreview/previewApiUtils.js +0 -59
- package/v2Components/CommonTestAndPreview/tests/AddTestCustomer.test.js +0 -66
- package/v2Components/CommonTestAndPreview/tests/CommonTestAndPreview.addTestCustomer.test.js +0 -648
- package/v2Components/CommonTestAndPreview/tests/CustomerCreationModal.test.js +0 -174
- package/v2Components/CommonTestAndPreview/tests/ExistingCustomerModal.test.js +0 -114
- package/v2Components/CommonTestAndPreview/tests/previewApiUtils.test.js +0 -67
- package/v2Components/SmsFallback/SmsFallbackLocalSelector.js +0 -87
- package/v2Components/SmsFallback/constants.js +0 -73
- package/v2Components/SmsFallback/index.js +0 -955
- package/v2Components/SmsFallback/index.scss +0 -265
- package/v2Components/SmsFallback/messages.js +0 -78
- package/v2Components/SmsFallback/smsFallbackUtils.js +0 -107
- package/v2Components/SmsFallback/tests/SmsFallbackLocalSelector.test.js +0 -50
- package/v2Components/SmsFallback/tests/rcsSmsFallback.acceptance.test.js +0 -147
- package/v2Components/SmsFallback/tests/smsFallbackHandlers.test.js +0 -304
- package/v2Components/SmsFallback/tests/smsFallbackUi.test.js +0 -197
- package/v2Components/SmsFallback/tests/smsFallbackUtils.test.js +0 -261
- package/v2Components/SmsFallback/tests/useLocalTemplateList.test.js +0 -422
- package/v2Components/SmsFallback/useLocalTemplateList.js +0 -92
- package/v2Components/VarSegmentMessageEditor/constants.js +0 -2
- package/v2Components/VarSegmentMessageEditor/index.js +0 -125
- package/v2Components/VarSegmentMessageEditor/index.scss +0 -46
- package/v2Containers/CreativesContainer/CreativesSlideBoxWrapper.js +0 -43
- package/v2Containers/CreativesContainer/embeddedSlideboxUtils.js +0 -67
- package/v2Containers/CreativesContainer/tests/SlideBoxContent.localTemplates.test.js +0 -90
- package/v2Containers/CreativesContainer/tests/embeddedSlideboxUtils.test.js +0 -258
- package/v2Containers/CreativesContainer/tests/useLocalTemplatesProp.test.js +0 -125
- package/v2Containers/Rcs/rcsLibraryHydrationUtils.js +0 -205
- package/v2Containers/Rcs/tests/rcsLibraryHydrationUtils.test.js +0 -251
- package/v2Containers/Sms/smsFormDataHelpers.js +0 -67
- package/v2Containers/Sms/tests/smsFormDataHelpers.test.js +0 -253
- package/v2Containers/SmsTrai/Edit/index.scss +0 -121
- package/v2Containers/Templates/TemplatesActionBar.js +0 -101
- package/v2Containers/Templates/tests/TemplatesActionBar.test.js +0 -120
- package/v2Containers/Templates/tests/smsTemplatesListApi.test.js +0 -180
- package/v2Containers/Templates/utils/smsTemplatesListApi.js +0 -79
- package/v2Containers/TemplatesV2/tests/TemplatesV2.localTemplates.test.js +0 -131
|
@@ -1,376 +1,334 @@
|
|
|
1
1
|
/**
|
|
2
|
+
* Tests for CustomValuesEditor component.
|
|
3
|
+
* Covers: loading state, values-missing warning, JSON view, tag table, discard/update buttons.
|
|
2
4
|
* @jest-environment jsdom
|
|
3
5
|
*/
|
|
6
|
+
|
|
4
7
|
import React from 'react';
|
|
5
8
|
import { render, screen, fireEvent } from '@testing-library/react';
|
|
6
|
-
import '@testing-library/jest-dom';
|
|
7
9
|
import { IntlProvider } from 'react-intl';
|
|
8
10
|
import PropTypes from 'prop-types';
|
|
9
|
-
import CustomValuesEditor from '../CustomValuesEditor';
|
|
10
11
|
|
|
11
|
-
jest.mock('@capillarytech/cap-ui-library/CapRow', () => {
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
}
|
|
16
|
-
|
|
17
|
-
jest.mock('@capillarytech/cap-ui-library/
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
}
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
}
|
|
32
|
-
|
|
33
|
-
}
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
}
|
|
44
|
-
|
|
45
|
-
}
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
placeholder: props?.placeholder,
|
|
53
|
-
onChange: props?.onChange,
|
|
54
|
-
});
|
|
55
|
-
};
|
|
56
|
-
});
|
|
57
|
-
jest.mock('@capillarytech/cap-ui-library/CapLabel', () => {
|
|
58
|
-
const React = require('react');
|
|
59
|
-
return function CapLabel(props) {
|
|
60
|
-
return React.createElement('div', { className: props?.className, 'data-testid': 'cap-label' }, props?.children);
|
|
61
|
-
};
|
|
62
|
-
});
|
|
12
|
+
jest.mock('@capillarytech/cap-ui-library/CapRow', () => ({ children, className }) => (
|
|
13
|
+
<div className={className}>{children}</div>
|
|
14
|
+
));
|
|
15
|
+
jest.mock('@capillarytech/cap-ui-library/CapSpin', () => ({ size }) => (
|
|
16
|
+
<div data-testid="cap-spin" data-size={size}>Loading...</div>
|
|
17
|
+
));
|
|
18
|
+
jest.mock('@capillarytech/cap-ui-library/CapSwitch', () => ({ checked, onChange }) => (
|
|
19
|
+
<button
|
|
20
|
+
type="button"
|
|
21
|
+
data-testid="cap-switch"
|
|
22
|
+
aria-checked={String(checked)}
|
|
23
|
+
onClick={() => onChange(!checked)}
|
|
24
|
+
>
|
|
25
|
+
Toggle
|
|
26
|
+
</button>
|
|
27
|
+
));
|
|
28
|
+
jest.mock('@capillarytech/cap-ui-library/CapButton', () => ({ children, onClick, disabled, loading, type: btnType, icon }) => (
|
|
29
|
+
<button
|
|
30
|
+
type="button"
|
|
31
|
+
data-testid="cap-button"
|
|
32
|
+
data-btntype={btnType}
|
|
33
|
+
data-icon={icon}
|
|
34
|
+
onClick={onClick}
|
|
35
|
+
disabled={!!(disabled || loading)}
|
|
36
|
+
>
|
|
37
|
+
{children}
|
|
38
|
+
</button>
|
|
39
|
+
));
|
|
40
|
+
jest.mock('@capillarytech/cap-ui-library/CapInput', () => ({ value, onChange, placeholder, isRequired, className }) => (
|
|
41
|
+
<input
|
|
42
|
+
data-testid="cap-input"
|
|
43
|
+
className={className}
|
|
44
|
+
value={value || ''}
|
|
45
|
+
onChange={onChange}
|
|
46
|
+
placeholder={placeholder}
|
|
47
|
+
required={!!isRequired}
|
|
48
|
+
/>
|
|
49
|
+
));
|
|
50
|
+
jest.mock('@capillarytech/cap-ui-library/CapLabel', () => ({ children, type, className }) => (
|
|
51
|
+
<span data-testid="cap-label" data-type={type} className={className}>{children}</span>
|
|
52
|
+
));
|
|
63
53
|
|
|
64
|
-
|
|
54
|
+
import CustomValuesEditor from '../CustomValuesEditor';
|
|
55
|
+
|
|
56
|
+
const TestWrapper = ({ children }) => (
|
|
57
|
+
<IntlProvider locale="en">{children}</IntlProvider>
|
|
58
|
+
);
|
|
59
|
+
TestWrapper.propTypes = { children: PropTypes.node.isRequired };
|
|
65
60
|
|
|
66
|
-
const
|
|
61
|
+
const defaultProps = {
|
|
67
62
|
isExtractingTags: false,
|
|
68
63
|
isUpdatePreviewDisabled: false,
|
|
69
64
|
showJSON: false,
|
|
70
65
|
setShowJSON: jest.fn(),
|
|
71
|
-
customValues: { '
|
|
66
|
+
customValues: { '{{customer.name}}': 'Alice', '{{customer.email}}': '' },
|
|
72
67
|
handleJSONTextChange: jest.fn(),
|
|
73
|
-
|
|
74
|
-
{
|
|
75
|
-
|
|
76
|
-
title: 'Section A',
|
|
77
|
-
requiredTags: [{ fullPath: 'tag.a', name: 'a' }],
|
|
78
|
-
optionalTags: [{ fullPath: 'tag.b', name: 'b' }],
|
|
79
|
-
},
|
|
68
|
+
extractedTags: [
|
|
69
|
+
{ fullPath: '{{customer.name}}' },
|
|
70
|
+
{ fullPath: '{{customer.email}}' },
|
|
80
71
|
],
|
|
72
|
+
requiredTags: [{ fullPath: '{{customer.name}}' }],
|
|
73
|
+
optionalTags: [{ fullPath: '{{customer.email}}' }],
|
|
81
74
|
handleCustomValueChange: jest.fn(),
|
|
82
75
|
handleDiscardCustomValues: jest.fn(),
|
|
83
76
|
handleUpdatePreview: jest.fn(),
|
|
84
77
|
isUpdatingPreview: false,
|
|
85
|
-
formatMessage,
|
|
78
|
+
formatMessage: jest.fn((msg) => msg.defaultMessage || msg.id),
|
|
86
79
|
};
|
|
87
80
|
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
const mockMessages = {
|
|
91
|
-
[`${scope}.extractingTags`]: 'Extracting tags...',
|
|
92
|
-
[`${scope}.valuesMissing`]: 'Some values are missing',
|
|
93
|
-
[`${scope}.showJSON`]: 'Show JSON',
|
|
94
|
-
[`${scope}.personalizationTags`]: 'Personalization Tags',
|
|
95
|
-
[`${scope}.customValues`]: 'Custom Values',
|
|
96
|
-
[`${scope}.enterValue`]: 'Enter value',
|
|
97
|
-
[`${scope}.discardCustomValues`]: 'Discard custom values',
|
|
98
|
-
[`${scope}.updatePreview`]: 'Update Preview',
|
|
99
|
-
};
|
|
81
|
+
describe('CustomValuesEditor', () => {
|
|
82
|
+
beforeEach(() => jest.clearAllMocks());
|
|
100
83
|
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
84
|
+
describe('loading state (isExtractingTags)', () => {
|
|
85
|
+
it('renders a spinner and extracting-tags message when isExtractingTags is true', () => {
|
|
86
|
+
render(
|
|
87
|
+
<TestWrapper>
|
|
88
|
+
<CustomValuesEditor {...defaultProps} isExtractingTags />
|
|
89
|
+
</TestWrapper>
|
|
90
|
+
);
|
|
91
|
+
expect(screen.getByTestId('cap-spin')).toBeTruthy();
|
|
92
|
+
expect(screen.getByText('Extracting tags...')).toBeTruthy();
|
|
93
|
+
});
|
|
106
94
|
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
95
|
+
it('does not render the editor toggle when extracting tags', () => {
|
|
96
|
+
render(
|
|
97
|
+
<TestWrapper>
|
|
98
|
+
<CustomValuesEditor {...defaultProps} isExtractingTags />
|
|
99
|
+
</TestWrapper>
|
|
100
|
+
);
|
|
101
|
+
expect(screen.queryByTestId('cap-switch')).toBeNull();
|
|
102
|
+
expect(screen.queryAllByTestId('cap-button')).toHaveLength(0);
|
|
103
|
+
});
|
|
110
104
|
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
105
|
+
it('renders the editor (not spinner) when isExtractingTags is false', () => {
|
|
106
|
+
render(
|
|
107
|
+
<TestWrapper>
|
|
108
|
+
<CustomValuesEditor {...defaultProps} isExtractingTags={false} />
|
|
109
|
+
</TestWrapper>
|
|
110
|
+
);
|
|
111
|
+
expect(screen.queryByTestId('cap-spin')).toBeNull();
|
|
112
|
+
expect(screen.getByTestId('cap-switch')).toBeTruthy();
|
|
113
|
+
});
|
|
114
114
|
});
|
|
115
115
|
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
<
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
116
|
+
describe('values missing warning', () => {
|
|
117
|
+
it('shows values-missing label when isUpdatePreviewDisabled is true', () => {
|
|
118
|
+
render(
|
|
119
|
+
<TestWrapper>
|
|
120
|
+
<CustomValuesEditor {...defaultProps} isUpdatePreviewDisabled />
|
|
121
|
+
</TestWrapper>
|
|
122
|
+
);
|
|
123
|
+
expect(screen.getByText('Values missing for some of the personalization tags')).toBeTruthy();
|
|
124
|
+
});
|
|
124
125
|
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
126
|
+
it('does not show values-missing label when isUpdatePreviewDisabled is false', () => {
|
|
127
|
+
render(
|
|
128
|
+
<TestWrapper>
|
|
129
|
+
<CustomValuesEditor {...defaultProps} isUpdatePreviewDisabled={false} />
|
|
130
|
+
</TestWrapper>
|
|
131
|
+
);
|
|
132
|
+
expect(
|
|
133
|
+
screen.queryByText('Values missing for some of the personalization tags')
|
|
134
|
+
).toBeNull();
|
|
135
|
+
});
|
|
132
136
|
});
|
|
133
137
|
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
<
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
138
|
+
describe('JSON view (showJSON = true)', () => {
|
|
139
|
+
it('renders a textarea with the formatted JSON', () => {
|
|
140
|
+
const customValues = { name: 'Alice', age: 30 };
|
|
141
|
+
render(
|
|
142
|
+
<TestWrapper>
|
|
143
|
+
<CustomValuesEditor {...defaultProps} showJSON customValues={customValues} />
|
|
144
|
+
</TestWrapper>
|
|
145
|
+
);
|
|
146
|
+
const textarea = document.querySelector('textarea.json-textarea');
|
|
147
|
+
expect(textarea).toBeTruthy();
|
|
148
|
+
expect(textarea.value).toBe(JSON.stringify(customValues, null, 2));
|
|
149
|
+
});
|
|
144
150
|
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
<
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
151
|
+
it('renders line numbers matching the number of JSON lines', () => {
|
|
152
|
+
const customValues = { a: 1, b: 2 };
|
|
153
|
+
render(
|
|
154
|
+
<TestWrapper>
|
|
155
|
+
<CustomValuesEditor {...defaultProps} showJSON customValues={customValues} />
|
|
156
|
+
</TestWrapper>
|
|
157
|
+
);
|
|
158
|
+
const lineCount = JSON.stringify(customValues, null, 2).split('\n').length;
|
|
159
|
+
const lineNumbers = document.querySelectorAll('.line-number');
|
|
160
|
+
expect(lineNumbers).toHaveLength(lineCount);
|
|
161
|
+
});
|
|
156
162
|
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
});
|
|
163
|
+
it('calls handleJSONTextChange when the textarea value changes', () => {
|
|
164
|
+
render(
|
|
165
|
+
<TestWrapper>
|
|
166
|
+
<CustomValuesEditor {...defaultProps} showJSON />
|
|
167
|
+
</TestWrapper>
|
|
168
|
+
);
|
|
169
|
+
const textarea = document.querySelector('textarea.json-textarea');
|
|
170
|
+
fireEvent.change(textarea, { target: { value: '{"key": "val"}' } });
|
|
171
|
+
expect(defaultProps.handleJSONTextChange).toHaveBeenCalledWith('{"key": "val"}');
|
|
172
|
+
});
|
|
168
173
|
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
fireEvent.click(buttons[buttons.length - 1]);
|
|
178
|
-
expect(baseProps.handleDiscardCustomValues).toHaveBeenCalled();
|
|
179
|
-
expect(baseProps.handleUpdatePreview).toHaveBeenCalled();
|
|
174
|
+
it('does not render the tag table in JSON view', () => {
|
|
175
|
+
render(
|
|
176
|
+
<TestWrapper>
|
|
177
|
+
<CustomValuesEditor {...defaultProps} showJSON />
|
|
178
|
+
</TestWrapper>
|
|
179
|
+
);
|
|
180
|
+
expect(screen.queryByText('Personalization Tags')).toBeNull();
|
|
181
|
+
});
|
|
180
182
|
});
|
|
181
183
|
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
<
|
|
186
|
-
{...
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
</IntlProvider>,
|
|
193
|
-
);
|
|
194
|
-
expect(screen.getAllByTestId('tag-input').length).toBeGreaterThan(0);
|
|
195
|
-
});
|
|
184
|
+
describe('tag table view (showJSON = false)', () => {
|
|
185
|
+
it('renders Personalization Tags and Custom Values headers when extractedTags is non-empty', () => {
|
|
186
|
+
render(
|
|
187
|
+
<TestWrapper>
|
|
188
|
+
<CustomValuesEditor {...defaultProps} showJSON={false} />
|
|
189
|
+
</TestWrapper>
|
|
190
|
+
);
|
|
191
|
+
expect(screen.getByText('Personalization Tags')).toBeTruthy();
|
|
192
|
+
expect(screen.getByText('Custom Values')).toBeTruthy();
|
|
193
|
+
});
|
|
196
194
|
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
requiredTags: [{ fullPath: 'tag.a', name: 'a' }],
|
|
207
|
-
optionalTags: [],
|
|
208
|
-
},
|
|
209
|
-
]}
|
|
210
|
-
/>
|
|
211
|
-
</IntlProvider>,
|
|
212
|
-
);
|
|
213
|
-
expect(screen.getByText('Intl Section Title')).toBeInTheDocument();
|
|
214
|
-
});
|
|
195
|
+
it('renders required tags with a required indicator (*)', () => {
|
|
196
|
+
render(
|
|
197
|
+
<TestWrapper>
|
|
198
|
+
<CustomValuesEditor {...defaultProps} showJSON={false} />
|
|
199
|
+
</TestWrapper>
|
|
200
|
+
);
|
|
201
|
+
expect(screen.getByText('{{customer.name}}')).toBeTruthy();
|
|
202
|
+
expect(screen.getByText('*')).toBeTruthy();
|
|
203
|
+
});
|
|
215
204
|
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
title: 'Plain String Title',
|
|
225
|
-
requiredTags: [{ fullPath: 'tag.a', name: 'a' }],
|
|
226
|
-
optionalTags: [],
|
|
227
|
-
},
|
|
228
|
-
]}
|
|
229
|
-
/>
|
|
230
|
-
</IntlProvider>,
|
|
231
|
-
);
|
|
232
|
-
expect(screen.getByText('Plain String Title')).toBeInTheDocument();
|
|
233
|
-
});
|
|
205
|
+
it('renders optional tags without a required indicator', () => {
|
|
206
|
+
render(
|
|
207
|
+
<TestWrapper>
|
|
208
|
+
<CustomValuesEditor {...defaultProps} showJSON={false} />
|
|
209
|
+
</TestWrapper>
|
|
210
|
+
);
|
|
211
|
+
expect(screen.getByText('{{customer.email}}')).toBeTruthy();
|
|
212
|
+
});
|
|
234
213
|
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
{
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
|
|
247
|
-
|
|
248
|
-
|
|
249
|
-
</IntlProvider>,
|
|
250
|
-
);
|
|
251
|
-
const inputs = screen.getAllByTestId('tag-input');
|
|
252
|
-
expect(inputs.length).toBeGreaterThan(0);
|
|
253
|
-
});
|
|
214
|
+
it('does not render the table when extractedTags is empty', () => {
|
|
215
|
+
render(
|
|
216
|
+
<TestWrapper>
|
|
217
|
+
<CustomValuesEditor
|
|
218
|
+
{...defaultProps}
|
|
219
|
+
showJSON={false}
|
|
220
|
+
extractedTags={[]}
|
|
221
|
+
requiredTags={[]}
|
|
222
|
+
optionalTags={[]}
|
|
223
|
+
/>
|
|
224
|
+
</TestWrapper>
|
|
225
|
+
);
|
|
226
|
+
expect(screen.queryByText('Personalization Tags')).toBeNull();
|
|
227
|
+
});
|
|
254
228
|
|
|
255
|
-
|
|
256
|
-
|
|
257
|
-
|
|
258
|
-
|
|
259
|
-
|
|
260
|
-
|
|
261
|
-
|
|
262
|
-
|
|
263
|
-
|
|
264
|
-
|
|
265
|
-
optionalTags: [],
|
|
266
|
-
},
|
|
267
|
-
]}
|
|
268
|
-
/>
|
|
269
|
-
</IntlProvider>,
|
|
270
|
-
);
|
|
271
|
-
expect(screen.getByText('myTag')).toBeInTheDocument();
|
|
272
|
-
});
|
|
229
|
+
it('calls handleCustomValueChange with the tag path and new value for required tags', () => {
|
|
230
|
+
render(
|
|
231
|
+
<TestWrapper>
|
|
232
|
+
<CustomValuesEditor {...defaultProps} showJSON={false} />
|
|
233
|
+
</TestWrapper>
|
|
234
|
+
);
|
|
235
|
+
const inputs = screen.getAllByTestId('cap-input');
|
|
236
|
+
fireEvent.change(inputs[0], { target: { value: 'Bob' } });
|
|
237
|
+
expect(defaultProps.handleCustomValueChange).toHaveBeenCalledWith('{{customer.name}}', 'Bob');
|
|
238
|
+
});
|
|
273
239
|
|
|
274
|
-
|
|
275
|
-
|
|
276
|
-
|
|
277
|
-
|
|
278
|
-
|
|
279
|
-
|
|
280
|
-
|
|
281
|
-
|
|
282
|
-
|
|
283
|
-
|
|
284
|
-
|
|
285
|
-
|
|
286
|
-
|
|
287
|
-
/>
|
|
288
|
-
</IntlProvider>,
|
|
289
|
-
);
|
|
290
|
-
const inputs = screen.getAllByTestId('tag-input');
|
|
291
|
-
expect(inputs.length).toBeGreaterThan(0);
|
|
240
|
+
it('calls handleCustomValueChange with the tag path and new value for optional tags', () => {
|
|
241
|
+
render(
|
|
242
|
+
<TestWrapper>
|
|
243
|
+
<CustomValuesEditor {...defaultProps} showJSON={false} />
|
|
244
|
+
</TestWrapper>
|
|
245
|
+
);
|
|
246
|
+
const inputs = screen.getAllByTestId('cap-input');
|
|
247
|
+
fireEvent.change(inputs[1], { target: { value: 'bob@example.com' } });
|
|
248
|
+
expect(defaultProps.handleCustomValueChange).toHaveBeenCalledWith(
|
|
249
|
+
'{{customer.email}}',
|
|
250
|
+
'bob@example.com'
|
|
251
|
+
);
|
|
252
|
+
});
|
|
292
253
|
});
|
|
293
254
|
|
|
294
|
-
|
|
295
|
-
|
|
296
|
-
|
|
297
|
-
<
|
|
298
|
-
{...
|
|
299
|
-
|
|
300
|
-
|
|
301
|
-
|
|
302
|
-
|
|
303
|
-
|
|
304
|
-
optionalTags: [{ fullPath: 'tag.opt', name: 'opt' }],
|
|
305
|
-
},
|
|
306
|
-
]}
|
|
307
|
-
/>
|
|
308
|
-
</IntlProvider>,
|
|
309
|
-
);
|
|
310
|
-
expect(screen.getByText('Optional Section')).toBeInTheDocument();
|
|
311
|
-
const inputs = screen.getAllByTestId('tag-input');
|
|
312
|
-
expect(inputs.length).toBeGreaterThan(0);
|
|
313
|
-
});
|
|
255
|
+
describe('JSON / tag toggle', () => {
|
|
256
|
+
it('calls setShowJSON(true) when toggle is clicked from tag view', () => {
|
|
257
|
+
render(
|
|
258
|
+
<TestWrapper>
|
|
259
|
+
<CustomValuesEditor {...defaultProps} showJSON={false} />
|
|
260
|
+
</TestWrapper>
|
|
261
|
+
);
|
|
262
|
+
fireEvent.click(screen.getByTestId('cap-switch'));
|
|
263
|
+
expect(defaultProps.setShowJSON).toHaveBeenCalledWith(true);
|
|
264
|
+
});
|
|
314
265
|
|
|
315
|
-
|
|
316
|
-
|
|
317
|
-
|
|
318
|
-
|
|
319
|
-
|
|
320
|
-
|
|
321
|
-
|
|
322
|
-
|
|
323
|
-
|
|
324
|
-
requiredTags: [{ fullPath: 'tag.req', name: 'req' }],
|
|
325
|
-
optionalTags: [],
|
|
326
|
-
},
|
|
327
|
-
]}
|
|
328
|
-
/>
|
|
329
|
-
</IntlProvider>,
|
|
330
|
-
);
|
|
331
|
-
expect(screen.getByText('Required Section')).toBeInTheDocument();
|
|
332
|
-
const inputs = screen.getAllByTestId('tag-input');
|
|
333
|
-
expect(inputs.length).toBeGreaterThan(0);
|
|
266
|
+
it('calls setShowJSON(false) when toggle is clicked from JSON view', () => {
|
|
267
|
+
render(
|
|
268
|
+
<TestWrapper>
|
|
269
|
+
<CustomValuesEditor {...defaultProps} showJSON />
|
|
270
|
+
</TestWrapper>
|
|
271
|
+
);
|
|
272
|
+
fireEvent.click(screen.getByTestId('cap-switch'));
|
|
273
|
+
expect(defaultProps.setShowJSON).toHaveBeenCalledWith(false);
|
|
274
|
+
});
|
|
334
275
|
});
|
|
335
276
|
|
|
336
|
-
|
|
337
|
-
|
|
338
|
-
|
|
339
|
-
|
|
340
|
-
|
|
341
|
-
|
|
342
|
-
|
|
343
|
-
|
|
344
|
-
|
|
345
|
-
|
|
346
|
-
);
|
|
347
|
-
const lineNumbers = document.querySelectorAll('.line-number');
|
|
348
|
-
const expectedLineCount = JSON.stringify(multiValueCustomValues, null, 2).split('\n').length;
|
|
349
|
-
expect(lineNumbers.length).toBe(expectedLineCount);
|
|
350
|
-
});
|
|
277
|
+
describe('action buttons', () => {
|
|
278
|
+
it('calls handleDiscardCustomValues when the discard button is clicked', () => {
|
|
279
|
+
render(
|
|
280
|
+
<TestWrapper>
|
|
281
|
+
<CustomValuesEditor {...defaultProps} />
|
|
282
|
+
</TestWrapper>
|
|
283
|
+
);
|
|
284
|
+
const buttons = screen.getAllByTestId('cap-button');
|
|
285
|
+
fireEvent.click(buttons[0]); // discard is first
|
|
286
|
+
expect(defaultProps.handleDiscardCustomValues).toHaveBeenCalled();
|
|
287
|
+
});
|
|
351
288
|
|
|
352
|
-
|
|
353
|
-
|
|
354
|
-
|
|
355
|
-
|
|
356
|
-
|
|
357
|
-
|
|
358
|
-
|
|
359
|
-
|
|
360
|
-
|
|
361
|
-
|
|
362
|
-
|
|
363
|
-
|
|
364
|
-
|
|
365
|
-
|
|
366
|
-
|
|
367
|
-
|
|
368
|
-
|
|
369
|
-
|
|
370
|
-
|
|
371
|
-
|
|
372
|
-
|
|
373
|
-
|
|
374
|
-
|
|
289
|
+
it('calls handleUpdatePreview when the update-preview button is clicked', () => {
|
|
290
|
+
render(
|
|
291
|
+
<TestWrapper>
|
|
292
|
+
<CustomValuesEditor {...defaultProps} />
|
|
293
|
+
</TestWrapper>
|
|
294
|
+
);
|
|
295
|
+
const buttons = screen.getAllByTestId('cap-button');
|
|
296
|
+
fireEvent.click(buttons[1]); // update is second
|
|
297
|
+
expect(defaultProps.handleUpdatePreview).toHaveBeenCalled();
|
|
298
|
+
});
|
|
299
|
+
|
|
300
|
+
it('disables the update-preview button when isUpdatePreviewDisabled is true', () => {
|
|
301
|
+
render(
|
|
302
|
+
<TestWrapper>
|
|
303
|
+
<CustomValuesEditor {...defaultProps} isUpdatePreviewDisabled />
|
|
304
|
+
</TestWrapper>
|
|
305
|
+
);
|
|
306
|
+
const buttons = screen.getAllByTestId('cap-button');
|
|
307
|
+
expect(buttons[1].disabled).toBe(true);
|
|
308
|
+
});
|
|
309
|
+
|
|
310
|
+
it('disables the update-preview button when isUpdatingPreview is true', () => {
|
|
311
|
+
render(
|
|
312
|
+
<TestWrapper>
|
|
313
|
+
<CustomValuesEditor {...defaultProps} isUpdatingPreview />
|
|
314
|
+
</TestWrapper>
|
|
315
|
+
);
|
|
316
|
+
const buttons = screen.getAllByTestId('cap-button');
|
|
317
|
+
expect(buttons[1].disabled).toBe(true);
|
|
318
|
+
});
|
|
319
|
+
|
|
320
|
+
it('enables the update-preview button when neither flag is set', () => {
|
|
321
|
+
render(
|
|
322
|
+
<TestWrapper>
|
|
323
|
+
<CustomValuesEditor
|
|
324
|
+
{...defaultProps}
|
|
325
|
+
isUpdatePreviewDisabled={false}
|
|
326
|
+
isUpdatingPreview={false}
|
|
327
|
+
/>
|
|
328
|
+
</TestWrapper>
|
|
329
|
+
);
|
|
330
|
+
const buttons = screen.getAllByTestId('cap-button');
|
|
331
|
+
expect(buttons[1].disabled).toBe(false);
|
|
332
|
+
});
|
|
375
333
|
});
|
|
376
334
|
});
|