@shopgate/pwa-ui-shared 7.31.5 → 7.31.6-beta.1
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/package.json +5 -5
- package/AccordionContainer/spec.js +0 -35
- package/ActionButton/spec.js +0 -69
- package/AddToCartButton/spec.js +0 -68
- package/Availability/spec.js +0 -42
- package/Button/spec.js +0 -38
- package/ButtonLink/spec.js +0 -25
- package/Chip/spec.js +0 -27
- package/ContextMenu/spec.js +0 -113
- package/Dialog/components/HtmlContentDialog/spec.js +0 -101
- package/Dialog/components/PipelineErrorDialog/spec.js +0 -105
- package/Dialog/components/TextMessageDialog/spec.js +0 -62
- package/Dialog/components/VariantSelectModal/spec.js +0 -55
- package/Dialog/spec.js +0 -84
- package/DiscountBadge/spec.js +0 -20
- package/FavoritesButton/spec.js +0 -131
- package/Form/Builder/classes/ActionListener/spec.js +0 -323
- package/Form/Builder/spec.js +0 -309
- package/Form/InfoField/spec.js +0 -12
- package/Form/Password/spec.js +0 -39
- package/Form/RadioGroup/spec.js +0 -97
- package/Form/Select/spec.js +0 -39
- package/Form/SelectContextChoices/spec.js +0 -36
- package/Form/TextField/spec.js +0 -124
- package/FormElement/spec.js +0 -68
- package/Glow/spec.js +0 -14
- package/IndicatorCircle/spec.js +0 -26
- package/PlaceholderLabel/spec.js +0 -26
- package/PlaceholderParagraph/spec.js +0 -26
- package/ProgressBar/spec.js +0 -14
- package/RadioButton/spec.js +0 -22
- package/RatingStars/spec.js +0 -91
- package/RippleButton/spec.js +0 -58
- package/Sheet/components/Header/components/SearchBar/spec.js +0 -22
- package/Sheet/components/Header/spec.js +0 -15
- package/Sheet/spec.js +0 -100
- package/TaxDisclaimer/spec.js +0 -43
- package/TextField/spec.js +0 -146
- package/ToggleIcon/spec.js +0 -39
- package/tsconfig.build.json +0 -16
- package/tsconfig.json +0 -3
package/Form/Builder/spec.js
DELETED
|
@@ -1,309 +0,0 @@
|
|
|
1
|
-
/* eslint-disable extra-rules/no-single-line-objects */
|
|
2
|
-
import React from 'react';
|
|
3
|
-
import { mount } from 'enzyme';
|
|
4
|
-
import FormBuilder from '.';
|
|
5
|
-
import { jsx as _jsx } from "react/jsx-runtime";
|
|
6
|
-
jest.mock('@shopgate/engage/components');
|
|
7
|
-
describe('<FormBuilder />', () => {
|
|
8
|
-
it('should render empty form', () => {
|
|
9
|
-
const wrapper = mount(/*#__PURE__*/_jsx(FormBuilder, {
|
|
10
|
-
config: {
|
|
11
|
-
fields: {}
|
|
12
|
-
},
|
|
13
|
-
name: "foo",
|
|
14
|
-
handleUpdate: () => {}
|
|
15
|
-
}));
|
|
16
|
-
expect(wrapper).toMatchSnapshot();
|
|
17
|
-
});
|
|
18
|
-
it('should render two text fields', () => {
|
|
19
|
-
const wrapper = mount(/*#__PURE__*/_jsx(FormBuilder, {
|
|
20
|
-
config: {
|
|
21
|
-
fields: {
|
|
22
|
-
firstName: {
|
|
23
|
-
label: 'foo',
|
|
24
|
-
type: 'text',
|
|
25
|
-
visible: true
|
|
26
|
-
},
|
|
27
|
-
lastName: {
|
|
28
|
-
label: 'bar',
|
|
29
|
-
type: 'text',
|
|
30
|
-
visible: true
|
|
31
|
-
}
|
|
32
|
-
}
|
|
33
|
-
},
|
|
34
|
-
name: "foo",
|
|
35
|
-
handleUpdate: () => {}
|
|
36
|
-
}));
|
|
37
|
-
expect(wrapper).toMatchSnapshot();
|
|
38
|
-
expect(wrapper.find('TextField').length).toEqual(2);
|
|
39
|
-
});
|
|
40
|
-
it('should not render invisible field', () => {
|
|
41
|
-
const wrapper = mount(/*#__PURE__*/_jsx(FormBuilder, {
|
|
42
|
-
config: {
|
|
43
|
-
fields: {
|
|
44
|
-
firstName: {
|
|
45
|
-
label: 'foo',
|
|
46
|
-
type: 'text',
|
|
47
|
-
visible: false
|
|
48
|
-
}
|
|
49
|
-
}
|
|
50
|
-
},
|
|
51
|
-
name: "foo",
|
|
52
|
-
handleUpdate: () => {}
|
|
53
|
-
}));
|
|
54
|
-
expect(wrapper).toMatchSnapshot();
|
|
55
|
-
expect(wrapper.find('TextField').length).toEqual(0);
|
|
56
|
-
});
|
|
57
|
-
it('should hide element if setVisibilty rule applies', () => {
|
|
58
|
-
const wrapper = mount(/*#__PURE__*/_jsx(FormBuilder, {
|
|
59
|
-
config: {
|
|
60
|
-
fields: {
|
|
61
|
-
foo: {
|
|
62
|
-
label: 'foo',
|
|
63
|
-
type: 'text',
|
|
64
|
-
visible: true
|
|
65
|
-
},
|
|
66
|
-
bar: {
|
|
67
|
-
label: 'bar',
|
|
68
|
-
type: 'text',
|
|
69
|
-
actions: [{
|
|
70
|
-
type: 'setVisibility',
|
|
71
|
-
rules: [{
|
|
72
|
-
context: 'foo',
|
|
73
|
-
type: 'notIn',
|
|
74
|
-
data: ['abc']
|
|
75
|
-
}]
|
|
76
|
-
}]
|
|
77
|
-
}
|
|
78
|
-
}
|
|
79
|
-
},
|
|
80
|
-
name: "foo",
|
|
81
|
-
handleUpdate: () => {}
|
|
82
|
-
}));
|
|
83
|
-
|
|
84
|
-
// Both should be visible at the beginning.
|
|
85
|
-
expect(wrapper).toMatchSnapshot();
|
|
86
|
-
expect(wrapper.find('TextField').length).toEqual(2);
|
|
87
|
-
|
|
88
|
-
// Simulate user input to the text field.
|
|
89
|
-
wrapper.find('input').first().simulate('change', {
|
|
90
|
-
target: {
|
|
91
|
-
value: 'abc'
|
|
92
|
-
}
|
|
93
|
-
});
|
|
94
|
-
|
|
95
|
-
// Second field should be hidden now.
|
|
96
|
-
expect(wrapper).toMatchSnapshot();
|
|
97
|
-
expect(wrapper.find('TextField').length).toEqual(1);
|
|
98
|
-
});
|
|
99
|
-
it('should reset value when rule applies', () => {
|
|
100
|
-
const wrapper = mount(/*#__PURE__*/_jsx(FormBuilder, {
|
|
101
|
-
config: {
|
|
102
|
-
fields: {
|
|
103
|
-
foo: {
|
|
104
|
-
label: 'foo',
|
|
105
|
-
type: 'text',
|
|
106
|
-
visible: true,
|
|
107
|
-
default: 'default'
|
|
108
|
-
},
|
|
109
|
-
bar: {
|
|
110
|
-
label: 'bar',
|
|
111
|
-
type: 'text',
|
|
112
|
-
default: 'default',
|
|
113
|
-
actions: [{
|
|
114
|
-
type: 'setValue',
|
|
115
|
-
params: {
|
|
116
|
-
value: 'cheat',
|
|
117
|
-
type: 'fixed'
|
|
118
|
-
},
|
|
119
|
-
rules: [{
|
|
120
|
-
context: 'foo',
|
|
121
|
-
type: 'notIn',
|
|
122
|
-
data: ['default']
|
|
123
|
-
}]
|
|
124
|
-
}]
|
|
125
|
-
}
|
|
126
|
-
}
|
|
127
|
-
},
|
|
128
|
-
name: "foo",
|
|
129
|
-
handleUpdate: () => {}
|
|
130
|
-
}));
|
|
131
|
-
|
|
132
|
-
// Default values should be in the inputs.
|
|
133
|
-
expect(wrapper).toMatchSnapshot();
|
|
134
|
-
expect(wrapper.find('TextField').length).toEqual(2);
|
|
135
|
-
expect(wrapper.find('input').at(0).props().value).toEqual('default');
|
|
136
|
-
expect(wrapper.find('input').at(1).props().value).toEqual('default');
|
|
137
|
-
|
|
138
|
-
// Simulate text input to trigger rule.
|
|
139
|
-
wrapper.find('input').first().simulate('change', {
|
|
140
|
-
target: {
|
|
141
|
-
value: 'abc'
|
|
142
|
-
}
|
|
143
|
-
});
|
|
144
|
-
wrapper.update();
|
|
145
|
-
|
|
146
|
-
// Second field should be hidden now.
|
|
147
|
-
expect(wrapper).toMatchSnapshot();
|
|
148
|
-
expect(wrapper.find('TextField').length).toEqual(2);
|
|
149
|
-
expect(wrapper.find('input').at(0).props().value).toEqual('abc');
|
|
150
|
-
expect(wrapper.find('input').at(1).props().value).toEqual('cheat');
|
|
151
|
-
});
|
|
152
|
-
it('should call onChange callback when input is changed', () => {
|
|
153
|
-
const handleUpdate = jest.fn();
|
|
154
|
-
const wrapper = mount(/*#__PURE__*/_jsx(FormBuilder, {
|
|
155
|
-
config: {
|
|
156
|
-
fields: {
|
|
157
|
-
foo: {
|
|
158
|
-
label: 'foo',
|
|
159
|
-
type: 'text',
|
|
160
|
-
visible: true,
|
|
161
|
-
default: 'default'
|
|
162
|
-
}
|
|
163
|
-
}
|
|
164
|
-
},
|
|
165
|
-
name: "foo",
|
|
166
|
-
id: "foo",
|
|
167
|
-
handleUpdate: handleUpdate
|
|
168
|
-
}));
|
|
169
|
-
|
|
170
|
-
// Should call with initial state.
|
|
171
|
-
expect(wrapper).toMatchSnapshot();
|
|
172
|
-
expect(handleUpdate).toHaveBeenCalledWith({
|
|
173
|
-
foo: 'default'
|
|
174
|
-
}, false);
|
|
175
|
-
handleUpdate.mockClear();
|
|
176
|
-
|
|
177
|
-
// Update input
|
|
178
|
-
wrapper.find('input').first().simulate('change', {
|
|
179
|
-
target: {
|
|
180
|
-
value: 'abc'
|
|
181
|
-
}
|
|
182
|
-
});
|
|
183
|
-
|
|
184
|
-
// Should call with updated state.
|
|
185
|
-
expect(handleUpdate).toHaveBeenCalledWith({
|
|
186
|
-
foo: 'abc'
|
|
187
|
-
}, false);
|
|
188
|
-
});
|
|
189
|
-
describe('FormBuilder::elementChangeHandler', () => {
|
|
190
|
-
it('should take the updated state from action listener', () => {
|
|
191
|
-
const handleUpdate = jest.fn();
|
|
192
|
-
const ref = /*#__PURE__*/React.createRef();
|
|
193
|
-
mount(/*#__PURE__*/_jsx(FormBuilder, {
|
|
194
|
-
ref: ref,
|
|
195
|
-
validationErrors: [],
|
|
196
|
-
config: {
|
|
197
|
-
fields: {
|
|
198
|
-
foo: {
|
|
199
|
-
label: 'foo',
|
|
200
|
-
type: 'text',
|
|
201
|
-
visible: true,
|
|
202
|
-
default: 'default'
|
|
203
|
-
}
|
|
204
|
-
}
|
|
205
|
-
},
|
|
206
|
-
name: "foo",
|
|
207
|
-
id: "foo",
|
|
208
|
-
handleUpdate: handleUpdate
|
|
209
|
-
}));
|
|
210
|
-
ref.current.actionListener.notify = () => ({
|
|
211
|
-
formData: {
|
|
212
|
-
foo: 'bar'
|
|
213
|
-
},
|
|
214
|
-
errors: {},
|
|
215
|
-
elementVisibility: {
|
|
216
|
-
foo: true
|
|
217
|
-
}
|
|
218
|
-
});
|
|
219
|
-
|
|
220
|
-
// Trigger update
|
|
221
|
-
ref.current.elementChangeHandler('foo', 'bar');
|
|
222
|
-
|
|
223
|
-
// Test
|
|
224
|
-
expect(handleUpdate).toHaveBeenCalledWith({
|
|
225
|
-
foo: 'bar'
|
|
226
|
-
}, false);
|
|
227
|
-
});
|
|
228
|
-
it('should consider backend validations', () => {
|
|
229
|
-
// Create mocked Form builder.
|
|
230
|
-
const handleUpdate = jest.fn();
|
|
231
|
-
const ref = /*#__PURE__*/React.createRef();
|
|
232
|
-
mount(/*#__PURE__*/_jsx(FormBuilder, {
|
|
233
|
-
ref: ref,
|
|
234
|
-
validationErrors: [{}],
|
|
235
|
-
config: {
|
|
236
|
-
fields: {
|
|
237
|
-
foo: {
|
|
238
|
-
label: 'foo',
|
|
239
|
-
type: 'text',
|
|
240
|
-
visible: true,
|
|
241
|
-
default: 'default'
|
|
242
|
-
}
|
|
243
|
-
}
|
|
244
|
-
},
|
|
245
|
-
name: "foo",
|
|
246
|
-
id: "foo",
|
|
247
|
-
handleUpdate: handleUpdate
|
|
248
|
-
}));
|
|
249
|
-
ref.current.actionListener.notify = () => ({
|
|
250
|
-
formData: {
|
|
251
|
-
foo: 'bar'
|
|
252
|
-
},
|
|
253
|
-
errors: {},
|
|
254
|
-
elementVisibility: {
|
|
255
|
-
foo: true
|
|
256
|
-
}
|
|
257
|
-
});
|
|
258
|
-
|
|
259
|
-
// Trigger update
|
|
260
|
-
ref.current.elementChangeHandler('foo', 'bar');
|
|
261
|
-
|
|
262
|
-
// Test
|
|
263
|
-
expect(handleUpdate).toHaveBeenCalledWith({
|
|
264
|
-
foo: 'bar'
|
|
265
|
-
}, true);
|
|
266
|
-
});
|
|
267
|
-
});
|
|
268
|
-
describe('FormBuilder::elementSortFunc', () => {
|
|
269
|
-
const builder = new FormBuilder({
|
|
270
|
-
validationErrors: [{}],
|
|
271
|
-
config: {
|
|
272
|
-
fields: {}
|
|
273
|
-
},
|
|
274
|
-
handleUpdate: jest.fn()
|
|
275
|
-
});
|
|
276
|
-
const field1 = {
|
|
277
|
-
id: 'foo',
|
|
278
|
-
label: 'foo'
|
|
279
|
-
};
|
|
280
|
-
const field2 = {
|
|
281
|
-
id: 'foo2',
|
|
282
|
-
label: 'foo2'
|
|
283
|
-
};
|
|
284
|
-
it('should keep sortOrder for undefined', () => {
|
|
285
|
-
expect([field2, field1].sort(builder.elementSortFunc)).toEqual([field2, field1]);
|
|
286
|
-
});
|
|
287
|
-
it('should sort elements', () => {
|
|
288
|
-
const fields = [{
|
|
289
|
-
...field1,
|
|
290
|
-
sortOrder: 2
|
|
291
|
-
}, {
|
|
292
|
-
...field2,
|
|
293
|
-
sortOrder: 1
|
|
294
|
-
}];
|
|
295
|
-
expect(fields.sort(builder.elementSortFunc)).toEqual(fields.reverse());
|
|
296
|
-
});
|
|
297
|
-
it('should keep sortOrder', () => {
|
|
298
|
-
const fields = [{
|
|
299
|
-
...field2,
|
|
300
|
-
sortOrder: 1
|
|
301
|
-
}, {
|
|
302
|
-
...field1,
|
|
303
|
-
sortOrder: 2
|
|
304
|
-
}];
|
|
305
|
-
expect(fields.sort(builder.elementSortFunc)).toEqual([].concat(fields));
|
|
306
|
-
});
|
|
307
|
-
});
|
|
308
|
-
});
|
|
309
|
-
/* eslint-enable extra-rules/no-single-line-objects */
|
package/Form/InfoField/spec.js
DELETED
|
@@ -1,12 +0,0 @@
|
|
|
1
|
-
import React from 'react';
|
|
2
|
-
import { shallow } from 'enzyme';
|
|
3
|
-
import InfoField from "./index";
|
|
4
|
-
import { jsx as _jsx } from "react/jsx-runtime";
|
|
5
|
-
describe('<InfoField>', () => {
|
|
6
|
-
it('should render info field', () => {
|
|
7
|
-
const wrapper = shallow(/*#__PURE__*/_jsx(InfoField, {
|
|
8
|
-
children: "Some info text"
|
|
9
|
-
}));
|
|
10
|
-
expect(wrapper).toMatchSnapshot();
|
|
11
|
-
});
|
|
12
|
-
});
|
package/Form/Password/spec.js
DELETED
|
@@ -1,39 +0,0 @@
|
|
|
1
|
-
import React from 'react';
|
|
2
|
-
import { mount } from 'enzyme';
|
|
3
|
-
import Password from "./index";
|
|
4
|
-
import { jsx as _jsx } from "react/jsx-runtime";
|
|
5
|
-
const inputProps = {
|
|
6
|
-
name: 'test-input'
|
|
7
|
-
};
|
|
8
|
-
describe('<Password>', () => {
|
|
9
|
-
it('should render a password field', () => {
|
|
10
|
-
const wrapper = mount(/*#__PURE__*/_jsx(Password, {
|
|
11
|
-
...inputProps
|
|
12
|
-
}));
|
|
13
|
-
expect(wrapper).toMatchSnapshot();
|
|
14
|
-
expect(wrapper.find('input[type="password"]').length).toBe(1);
|
|
15
|
-
});
|
|
16
|
-
it('should trigger the onChange callback', () => {
|
|
17
|
-
const onChangeMock = jest.fn();
|
|
18
|
-
const wrapper = mount(/*#__PURE__*/_jsx(Password, {
|
|
19
|
-
...inputProps,
|
|
20
|
-
onChange: onChangeMock
|
|
21
|
-
}));
|
|
22
|
-
wrapper.find('input').simulate('change', {
|
|
23
|
-
target: {
|
|
24
|
-
value: 'a'
|
|
25
|
-
}
|
|
26
|
-
});
|
|
27
|
-
expect(onChangeMock).toHaveBeenCalledTimes(2);
|
|
28
|
-
expect(wrapper.find('input').props().value).toEqual('a');
|
|
29
|
-
});
|
|
30
|
-
it('should toggle password visibility', () => {
|
|
31
|
-
const wrapper = mount(/*#__PURE__*/_jsx(Password, {
|
|
32
|
-
...inputProps
|
|
33
|
-
}));
|
|
34
|
-
const input = wrapper.find('ToggleIcon');
|
|
35
|
-
expect(wrapper.find('input[type="password"]').length).toBe(1);
|
|
36
|
-
input.simulate('click');
|
|
37
|
-
expect(wrapper.find('input[type="text"]').length).toBe(1);
|
|
38
|
-
});
|
|
39
|
-
});
|
package/Form/RadioGroup/spec.js
DELETED
|
@@ -1,97 +0,0 @@
|
|
|
1
|
-
import React from 'react';
|
|
2
|
-
import { mount } from 'enzyme';
|
|
3
|
-
import RadioItem from "./components/Item";
|
|
4
|
-
import RadioGroup from '.';
|
|
5
|
-
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
6
|
-
const defProps = {
|
|
7
|
-
name: 'radio'
|
|
8
|
-
};
|
|
9
|
-
jest.mock('@shopgate/engage/components');
|
|
10
|
-
describe('<RadioGroup />', () => {
|
|
11
|
-
it('should render empty group', () => {
|
|
12
|
-
const wrapper = mount(/*#__PURE__*/_jsx(RadioGroup, {
|
|
13
|
-
...defProps
|
|
14
|
-
}));
|
|
15
|
-
expect(wrapper).toMatchSnapshot();
|
|
16
|
-
});
|
|
17
|
-
it('should render column group with items', () => {
|
|
18
|
-
const wrapper = mount(/*#__PURE__*/_jsx(RadioGroup, {
|
|
19
|
-
...defProps,
|
|
20
|
-
children: /*#__PURE__*/_jsx(RadioItem, {
|
|
21
|
-
name: "foo",
|
|
22
|
-
label: "foo"
|
|
23
|
-
})
|
|
24
|
-
}));
|
|
25
|
-
expect(wrapper).toMatchSnapshot();
|
|
26
|
-
expect(wrapper.find(RadioItem).length).toEqual(1);
|
|
27
|
-
expect(typeof wrapper.find(RadioItem).prop('onChange')).toEqual('function');
|
|
28
|
-
});
|
|
29
|
-
it('should render rows group with items', () => {
|
|
30
|
-
const wrapper = mount(/*#__PURE__*/_jsx(RadioGroup, {
|
|
31
|
-
...defProps,
|
|
32
|
-
direction: "rows",
|
|
33
|
-
children: /*#__PURE__*/_jsx(RadioItem, {
|
|
34
|
-
name: "foo",
|
|
35
|
-
label: "foo"
|
|
36
|
-
})
|
|
37
|
-
}));
|
|
38
|
-
expect(wrapper).toMatchSnapshot();
|
|
39
|
-
});
|
|
40
|
-
it('should use default value', () => {
|
|
41
|
-
const wrapper = mount(/*#__PURE__*/_jsx(RadioGroup, {
|
|
42
|
-
...defProps,
|
|
43
|
-
value: "foo",
|
|
44
|
-
children: /*#__PURE__*/_jsx(RadioItem, {
|
|
45
|
-
name: "foo",
|
|
46
|
-
label: "foo"
|
|
47
|
-
})
|
|
48
|
-
}));
|
|
49
|
-
expect(wrapper).toMatchSnapshot();
|
|
50
|
-
expect(wrapper.find(RadioItem).length).toEqual(1);
|
|
51
|
-
expect(wrapper.find(RadioItem).prop('checked')).toEqual(true);
|
|
52
|
-
});
|
|
53
|
-
it('should have on value at a time', () => {
|
|
54
|
-
const wrapper = mount(/*#__PURE__*/_jsxs(RadioGroup, {
|
|
55
|
-
...defProps,
|
|
56
|
-
children: [/*#__PURE__*/_jsx(RadioItem, {
|
|
57
|
-
name: "foo",
|
|
58
|
-
label: "foo"
|
|
59
|
-
}), /*#__PURE__*/_jsx(RadioItem, {
|
|
60
|
-
name: "bar",
|
|
61
|
-
label: "bar"
|
|
62
|
-
})]
|
|
63
|
-
}));
|
|
64
|
-
expect(wrapper).toMatchSnapshot();
|
|
65
|
-
expect(wrapper.find(RadioItem).length).toEqual(2);
|
|
66
|
-
const radio1 = wrapper.find(RadioItem).at(0).find('input');
|
|
67
|
-
const radio2 = wrapper.find(RadioItem).at(1).find('input');
|
|
68
|
-
|
|
69
|
-
// First element value
|
|
70
|
-
radio1.simulate('change');
|
|
71
|
-
wrapper.update();
|
|
72
|
-
expect(wrapper.find(RadioItem).at(0).prop('checked')).toEqual(true);
|
|
73
|
-
expect(wrapper.find(RadioItem).at(1).prop('checked')).toEqual(false);
|
|
74
|
-
|
|
75
|
-
// Second element value
|
|
76
|
-
radio2.simulate('change');
|
|
77
|
-
wrapper.update();
|
|
78
|
-
expect(wrapper.find(RadioItem).at(0).prop('checked')).toEqual(false);
|
|
79
|
-
expect(wrapper.find(RadioItem).at(1).prop('checked')).toEqual(true);
|
|
80
|
-
});
|
|
81
|
-
it('should call onChange callback', () => {
|
|
82
|
-
const onChange = jest.fn();
|
|
83
|
-
const wrapper = mount(/*#__PURE__*/_jsx(RadioGroup, {
|
|
84
|
-
...defProps,
|
|
85
|
-
onChange: onChange,
|
|
86
|
-
children: /*#__PURE__*/_jsx(RadioItem, {
|
|
87
|
-
name: "foo",
|
|
88
|
-
label: "foo"
|
|
89
|
-
})
|
|
90
|
-
}));
|
|
91
|
-
expect(wrapper).toMatchSnapshot();
|
|
92
|
-
expect(wrapper.find(RadioItem).length).toEqual(1);
|
|
93
|
-
const radio = wrapper.find(RadioItem).at(0).find('input');
|
|
94
|
-
radio.simulate('change');
|
|
95
|
-
expect(onChange).toHaveBeenCalledWith('foo');
|
|
96
|
-
});
|
|
97
|
-
});
|
package/Form/Select/spec.js
DELETED
|
@@ -1,39 +0,0 @@
|
|
|
1
|
-
import React from 'react';
|
|
2
|
-
import { mount } from 'enzyme';
|
|
3
|
-
import Select from "./index";
|
|
4
|
-
import { jsx as _jsx } from "react/jsx-runtime";
|
|
5
|
-
const inputProps = {
|
|
6
|
-
name: 'test-name'
|
|
7
|
-
};
|
|
8
|
-
describe('<Select />', () => {
|
|
9
|
-
// Simple tests for snapshots
|
|
10
|
-
const tests = {
|
|
11
|
-
'should render select with no options': {},
|
|
12
|
-
// eslint-disable-next-line extra-rules/no-single-line-objects
|
|
13
|
-
'should render select with 2 options': {
|
|
14
|
-
options: {
|
|
15
|
-
DE: 'Germany',
|
|
16
|
-
US: 'United states'
|
|
17
|
-
}
|
|
18
|
-
},
|
|
19
|
-
// eslint-disable-next-line extra-rules/no-single-line-objects
|
|
20
|
-
'should render select with 1 selected option': {
|
|
21
|
-
options: {
|
|
22
|
-
DE: 'Germany',
|
|
23
|
-
US: 'United states'
|
|
24
|
-
},
|
|
25
|
-
value: 'DE'
|
|
26
|
-
}
|
|
27
|
-
};
|
|
28
|
-
Object.keys(tests).forEach(test => {
|
|
29
|
-
it(test, () => {
|
|
30
|
-
const testFixtures = tests[test];
|
|
31
|
-
// eslint-disable-next-line extra-rules/no-single-line-objects
|
|
32
|
-
const wrapper = mount(/*#__PURE__*/_jsx(Select, {
|
|
33
|
-
...inputProps,
|
|
34
|
-
...testFixtures
|
|
35
|
-
}));
|
|
36
|
-
expect(wrapper).toMatchSnapshot();
|
|
37
|
-
});
|
|
38
|
-
});
|
|
39
|
-
});
|
|
@@ -1,36 +0,0 @@
|
|
|
1
|
-
import React from 'react';
|
|
2
|
-
import { shallow } from 'enzyme';
|
|
3
|
-
import SelectContextChoices from "./index";
|
|
4
|
-
import { jsx as _jsx } from "react/jsx-runtime";
|
|
5
|
-
jest.mock('@shopgate/engage/a11y/components');
|
|
6
|
-
jest.mock('@shopgate/engage/components');
|
|
7
|
-
describe('<SelectContextChoices />', () => {
|
|
8
|
-
// Simple tests for snapshots
|
|
9
|
-
const tests = {
|
|
10
|
-
'should render select with no options': {},
|
|
11
|
-
// eslint-disable-next-line extra-rules/no-single-line-objects
|
|
12
|
-
'should render select with 2 options': {
|
|
13
|
-
options: {
|
|
14
|
-
DE: 'Germany',
|
|
15
|
-
US: 'United states'
|
|
16
|
-
}
|
|
17
|
-
},
|
|
18
|
-
// eslint-disable-next-line extra-rules/no-single-line-objects
|
|
19
|
-
'should render select with 1 selected option': {
|
|
20
|
-
options: {
|
|
21
|
-
DE: 'Germany',
|
|
22
|
-
US: 'United states'
|
|
23
|
-
},
|
|
24
|
-
value: ['DE']
|
|
25
|
-
}
|
|
26
|
-
};
|
|
27
|
-
Object.keys(tests).forEach(test => {
|
|
28
|
-
it(test, () => {
|
|
29
|
-
const testFixtures = tests[test];
|
|
30
|
-
const wrapper = shallow(/*#__PURE__*/_jsx(SelectContextChoices, {
|
|
31
|
-
...testFixtures
|
|
32
|
-
}));
|
|
33
|
-
expect(wrapper).toMatchSnapshot();
|
|
34
|
-
});
|
|
35
|
-
});
|
|
36
|
-
});
|
package/Form/TextField/spec.js
DELETED
|
@@ -1,124 +0,0 @@
|
|
|
1
|
-
import React from 'react';
|
|
2
|
-
import { mount } from 'enzyme';
|
|
3
|
-
import TextField from "./index";
|
|
4
|
-
import { jsx as _jsx } from "react/jsx-runtime";
|
|
5
|
-
const inputProps = {
|
|
6
|
-
name: 'test-input'
|
|
7
|
-
};
|
|
8
|
-
jest.mock('@shopgate/engage/components');
|
|
9
|
-
describe('<TextField>', () => {
|
|
10
|
-
it('should render a simple text field', () => {
|
|
11
|
-
const wrapper = mount(/*#__PURE__*/_jsx(TextField, {
|
|
12
|
-
...inputProps
|
|
13
|
-
}));
|
|
14
|
-
expect(wrapper).toMatchSnapshot();
|
|
15
|
-
expect(wrapper.find('input').length).toBe(1);
|
|
16
|
-
});
|
|
17
|
-
it('should render the text field as password', () => {
|
|
18
|
-
const wrapper = mount(/*#__PURE__*/_jsx(TextField, {
|
|
19
|
-
...inputProps,
|
|
20
|
-
password: true
|
|
21
|
-
}));
|
|
22
|
-
expect(wrapper).toMatchSnapshot();
|
|
23
|
-
expect(wrapper.find('input[type="password"]').length).toBe(1);
|
|
24
|
-
});
|
|
25
|
-
it('should render the text field with a default value', () => {
|
|
26
|
-
const wrapper = mount(/*#__PURE__*/_jsx(TextField, {
|
|
27
|
-
...inputProps,
|
|
28
|
-
value: "FooBar"
|
|
29
|
-
}));
|
|
30
|
-
expect(wrapper).toMatchSnapshot();
|
|
31
|
-
expect(wrapper.find('input[value="FooBar"]').length).toBe(1);
|
|
32
|
-
});
|
|
33
|
-
it('should trigger the onChange callback', () => {
|
|
34
|
-
const onChangeMock = jest.fn();
|
|
35
|
-
const wrapper = mount(/*#__PURE__*/_jsx(TextField, {
|
|
36
|
-
...inputProps,
|
|
37
|
-
onChange: onChangeMock
|
|
38
|
-
}));
|
|
39
|
-
wrapper.find('input').simulate('change', {
|
|
40
|
-
target: {
|
|
41
|
-
value: 'a'
|
|
42
|
-
}
|
|
43
|
-
});
|
|
44
|
-
expect(onChangeMock).toHaveBeenCalledTimes(2);
|
|
45
|
-
expect(wrapper.find('input').props().value).toEqual('a');
|
|
46
|
-
});
|
|
47
|
-
it('should receive the correct value while typing', () => {
|
|
48
|
-
const wrapper = mount(/*#__PURE__*/_jsx(TextField, {
|
|
49
|
-
...inputProps
|
|
50
|
-
}));
|
|
51
|
-
const input = wrapper.find('input');
|
|
52
|
-
input.simulate('change', {
|
|
53
|
-
target: {
|
|
54
|
-
value: 'foobar'
|
|
55
|
-
}
|
|
56
|
-
});
|
|
57
|
-
expect(wrapper).toMatchSnapshot();
|
|
58
|
-
expect(input.instance().value).toBe('foobar');
|
|
59
|
-
});
|
|
60
|
-
it('should sanitize the input', () => {
|
|
61
|
-
const wrapper = mount(/*#__PURE__*/_jsx(TextField, {
|
|
62
|
-
...inputProps,
|
|
63
|
-
onSanitize: value => value.toUpperCase()
|
|
64
|
-
}));
|
|
65
|
-
const input = wrapper.find('input');
|
|
66
|
-
input.simulate('change', {
|
|
67
|
-
target: {
|
|
68
|
-
value: 'foobar'
|
|
69
|
-
}
|
|
70
|
-
});
|
|
71
|
-
expect(wrapper).toMatchSnapshot();
|
|
72
|
-
expect(input.instance().value).toBe('FOOBAR');
|
|
73
|
-
});
|
|
74
|
-
it('should trigger the validation callback', () => {
|
|
75
|
-
const onValidateMock = jest.fn();
|
|
76
|
-
const wrapper = mount(/*#__PURE__*/_jsx(TextField, {
|
|
77
|
-
...inputProps,
|
|
78
|
-
onValidate: onValidateMock
|
|
79
|
-
}));
|
|
80
|
-
expect(wrapper).toMatchSnapshot();
|
|
81
|
-
expect(onValidateMock).toHaveBeenCalled();
|
|
82
|
-
});
|
|
83
|
-
it('should focus the input', () => {
|
|
84
|
-
const onFocusMock = jest.fn();
|
|
85
|
-
const wrapper = mount(/*#__PURE__*/_jsx(TextField, {
|
|
86
|
-
...inputProps,
|
|
87
|
-
onFocusChange: onFocusMock
|
|
88
|
-
}));
|
|
89
|
-
const input = wrapper.find('SimpleInput');
|
|
90
|
-
expect(wrapper).toMatchSnapshot();
|
|
91
|
-
expect(input.instance().isFocused).toBe(false);
|
|
92
|
-
input.simulate('focus');
|
|
93
|
-
expect(input.instance().isFocused).toBe(true);
|
|
94
|
-
input.simulate('blur');
|
|
95
|
-
expect(input.instance().isFocused).toBe(false);
|
|
96
|
-
});
|
|
97
|
-
it('should show the error message', () => {
|
|
98
|
-
const errorText = 'This is an error here';
|
|
99
|
-
const wrapper = mount(/*#__PURE__*/_jsx(TextField, {
|
|
100
|
-
...inputProps,
|
|
101
|
-
errorText: errorText
|
|
102
|
-
}));
|
|
103
|
-
expect(wrapper).toMatchSnapshot();
|
|
104
|
-
expect(wrapper.find('ErrorText').find('Text').at(0).props().string).toEqual(errorText);
|
|
105
|
-
});
|
|
106
|
-
it('should show the label', () => {
|
|
107
|
-
const label = 'This is the label';
|
|
108
|
-
const wrapper = mount(/*#__PURE__*/_jsx(TextField, {
|
|
109
|
-
...inputProps,
|
|
110
|
-
label: label
|
|
111
|
-
}));
|
|
112
|
-
expect(wrapper).toMatchSnapshot();
|
|
113
|
-
expect(wrapper.find('Label').find('Text').props().string).toEqual(label);
|
|
114
|
-
});
|
|
115
|
-
it('should show the placeholder text', () => {
|
|
116
|
-
const placeholder = 'This is the placeholder text';
|
|
117
|
-
const wrapper = mount(/*#__PURE__*/_jsx(TextField, {
|
|
118
|
-
...inputProps,
|
|
119
|
-
placeholder: placeholder
|
|
120
|
-
}));
|
|
121
|
-
expect(wrapper).toMatchSnapshot();
|
|
122
|
-
expect(wrapper.find('Placeholder').find('Text').at(0).props().string).toEqual(placeholder);
|
|
123
|
-
});
|
|
124
|
-
});
|