@shopgate/pwa-common 7.32.0-beta.2 → 7.32.0-beta.20
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/components/Button/index.js +6 -0
- package/components/Image/Image.d.ts +78 -0
- package/components/Image/Image.d.ts.map +1 -0
- package/components/Image/Image.js +123 -91
- package/components/Image/ImageInner.d.ts +45 -0
- package/components/Image/ImageInner.d.ts.map +1 -0
- package/components/Image/ImageInner.js +23 -29
- package/components/Image/index.d.ts +3 -0
- package/components/Image/index.d.ts.map +1 -0
- package/components/Swiper/index.js +17 -2
- package/constants/Configuration.js +7 -0
- package/helpers/mocks/mockRenderOptions.js +21 -0
- package/package.json +3 -3
- package/providers/toast/index.js +54 -40
- package/subscriptions/error.js +50 -27
- package/subscriptions/helpers/pipeline.js +68 -0
- package/subscriptions/router.js +2 -2
- package/action-creators/app/spec.js +0 -96
- package/action-creators/client/spec.js +0 -44
- package/action-creators/menu/spec.js +0 -37
- package/action-creators/modal/spec.js +0 -26
- package/action-creators/page/spec.js +0 -38
- package/action-creators/url/spec.js +0 -45
- package/action-creators/user/spec.js +0 -186
- package/components/Backdrop/spec.js +0 -24
- package/components/Button/spec.js +0 -42
- package/components/Checkbox/spec.js +0 -111
- package/components/CountdownTimer/spec.js +0 -141
- package/components/Drawer/spec.js +0 -79
- package/components/Ellipsis/spec.js +0 -15
- package/components/EmbeddedMedia/spec.js +0 -61
- package/components/Grid/components/Item/spec.js +0 -24
- package/components/Grid/spec.js +0 -24
- package/components/HtmlSanitizer/spec.js +0 -229
- package/components/I18n/components/FormatDate/spec.js +0 -54
- package/components/I18n/components/FormatNumber/spec.js +0 -51
- package/components/I18n/components/FormatPrice/spec.js +0 -54
- package/components/I18n/components/FormatTime/spec.js +0 -51
- package/components/I18n/components/I18nProvider/spec.js +0 -40
- package/components/I18n/components/Placeholder/spec.js +0 -37
- package/components/I18n/components/Translate/spec.js +0 -33
- package/components/InfiniteContainer/spec.js +0 -204
- package/components/Input/spec.js +0 -123
- package/components/Link/spec.js +0 -60
- package/components/List/spec.js +0 -26
- package/components/ModalContainer/spec.js +0 -115
- package/components/Select/spec.js +0 -122
- package/components/SelectBox/spec.js +0 -68
- package/components/Swiper/components/SwiperItem/spec.js +0 -26
- package/components/Widgets/components/Widget/spec.js +0 -75
- package/components/Widgets/components/WidgetGrid/spec.js +0 -53
- package/components/Widgets/spec.js +0 -234
- package/helpers/data/spec.js +0 -194
- package/helpers/date/spec.js +0 -92
- package/helpers/style/spec.js +0 -108
- package/helpers/validation/spec.js +0 -10
- package/styles/reset/form.js +0 -58
- package/styles/reset/index.js +0 -8
- package/styles/reset/media.js +0 -26
- package/styles/reset/root.js +0 -37
- package/styles/reset/table.js +0 -14
- package/styles/reset/typography.js +0 -30
- package/tsconfig.build.json +0 -16
- package/tsconfig.json +0 -3
|
@@ -1,204 +0,0 @@
|
|
|
1
|
-
import range from 'lodash/range';
|
|
2
|
-
import React from 'react';
|
|
3
|
-
import { shallow, mount } from 'enzyme';
|
|
4
|
-
import { ITEMS_PER_LOAD } from "../../constants/DisplayOptions";
|
|
5
|
-
import InfiniteContainer from "./index";
|
|
6
|
-
import { jsx as _jsx } from "react/jsx-runtime";
|
|
7
|
-
global.console.error = jest.fn();
|
|
8
|
-
const context = {
|
|
9
|
-
state: {}
|
|
10
|
-
};
|
|
11
|
-
describe('<InfiniteContainer />', () => {
|
|
12
|
-
let renderedElement;
|
|
13
|
-
let renderedInstance;
|
|
14
|
-
let mockLoader;
|
|
15
|
-
let MockIterator;
|
|
16
|
-
let mockItems;
|
|
17
|
-
const mockData = range(100).map(id => ({
|
|
18
|
-
id,
|
|
19
|
-
title: `Item ${id}`
|
|
20
|
-
}));
|
|
21
|
-
|
|
22
|
-
/**
|
|
23
|
-
* The view component
|
|
24
|
-
* @param {Object} props The component props.
|
|
25
|
-
*/
|
|
26
|
-
const renderComponent = props => {
|
|
27
|
-
renderedElement = shallow(/*#__PURE__*/_jsx(InfiniteContainer, {
|
|
28
|
-
...props
|
|
29
|
-
}), {
|
|
30
|
-
context
|
|
31
|
-
});
|
|
32
|
-
renderedInstance = renderedElement.instance();
|
|
33
|
-
};
|
|
34
|
-
|
|
35
|
-
/**
|
|
36
|
-
* Mocks the mapStateToProps connector.
|
|
37
|
-
* @param {number} amount The new product amount.
|
|
38
|
-
*/
|
|
39
|
-
const receiveItemsByProp = amount => {
|
|
40
|
-
mockItems = mockData.slice(0, amount);
|
|
41
|
-
const nextProps = {
|
|
42
|
-
...renderedInstance.props,
|
|
43
|
-
items: mockItems,
|
|
44
|
-
totalItems: mockData.length
|
|
45
|
-
};
|
|
46
|
-
renderedElement.setProps(nextProps);
|
|
47
|
-
};
|
|
48
|
-
beforeEach(() => {
|
|
49
|
-
mockLoader = jest.fn();
|
|
50
|
-
MockIterator = data => /*#__PURE__*/_jsx("li", {
|
|
51
|
-
children: data.title
|
|
52
|
-
}, data.id);
|
|
53
|
-
});
|
|
54
|
-
describe('Given the component was mounted to the DOM', () => {
|
|
55
|
-
beforeEach(() => {
|
|
56
|
-
renderComponent({
|
|
57
|
-
items: [],
|
|
58
|
-
loader: mockLoader,
|
|
59
|
-
iterator: MockIterator,
|
|
60
|
-
totalItems: null
|
|
61
|
-
});
|
|
62
|
-
renderedInstance.componentDidMount();
|
|
63
|
-
});
|
|
64
|
-
it('should match snapshot', () => {
|
|
65
|
-
expect(renderedElement).toMatchSnapshot();
|
|
66
|
-
});
|
|
67
|
-
it('should call the loader function', () => {
|
|
68
|
-
const [offset] = renderedInstance.state.offset;
|
|
69
|
-
expect(mockLoader).toBeCalledWith(offset);
|
|
70
|
-
});
|
|
71
|
-
describe('Given the loader requested new items', () => {
|
|
72
|
-
const mockItemsLength = 10;
|
|
73
|
-
beforeEach(() => {
|
|
74
|
-
receiveItemsByProp(mockItemsLength);
|
|
75
|
-
});
|
|
76
|
-
it('should render the loaded items', () => {
|
|
77
|
-
expect(renderedElement.find(MockIterator)).toHaveLength(mockItemsLength);
|
|
78
|
-
});
|
|
79
|
-
});
|
|
80
|
-
describe('Given the component was mounted within a scroll container', () => {
|
|
81
|
-
const mockItemsLength = 11;
|
|
82
|
-
beforeEach(() => {
|
|
83
|
-
// Receive items from initial mounting before proceeding...
|
|
84
|
-
receiveItemsByProp(mockItemsLength);
|
|
85
|
-
|
|
86
|
-
// Reset any previous calls (e.g. from componentDidMount())
|
|
87
|
-
mockLoader.mock.calls = [];
|
|
88
|
-
renderedInstance.componentDidUpdate();
|
|
89
|
-
});
|
|
90
|
-
it('should call the loader function if scrolled to the bottom', () => {
|
|
91
|
-
renderedInstance.domScrollContainer = {
|
|
92
|
-
scrollTop: 900,
|
|
93
|
-
scrollHeight: 1000,
|
|
94
|
-
clientHeight: 100
|
|
95
|
-
};
|
|
96
|
-
renderedInstance.handleLoading();
|
|
97
|
-
expect(mockLoader).toBeCalled();
|
|
98
|
-
});
|
|
99
|
-
it('should not call the loader function if the scroll position did not change', () => {
|
|
100
|
-
renderedInstance.domScrollContainer = {
|
|
101
|
-
scrollTop: 0,
|
|
102
|
-
scrollHeight: 1000,
|
|
103
|
-
clientHeight: 100
|
|
104
|
-
};
|
|
105
|
-
renderedInstance.handleLoading();
|
|
106
|
-
expect(mockLoader.mock.calls.length).toBe(0);
|
|
107
|
-
});
|
|
108
|
-
});
|
|
109
|
-
describe('Given all items have been received', () => {
|
|
110
|
-
const mockItemsLength = mockData.length;
|
|
111
|
-
beforeEach(() => {
|
|
112
|
-
receiveItemsByProp(mockItemsLength);
|
|
113
|
-
});
|
|
114
|
-
it('should expect no more items to be received', () => {
|
|
115
|
-
expect(renderedInstance.needsToReceiveItems()).toBe(false);
|
|
116
|
-
});
|
|
117
|
-
it('should keep state.awaitingItems as true if not all items are rendered', () => {
|
|
118
|
-
expect(renderedInstance.allItemsAreRendered()).toBe(false);
|
|
119
|
-
expect(renderedInstance.state.awaitingItems).toBe(true);
|
|
120
|
-
expect(renderedElement.find(MockIterator).length).toBeLessThan(mockItemsLength);
|
|
121
|
-
});
|
|
122
|
-
it('should set state.awaitingItems to false if all items are rendered', () => {
|
|
123
|
-
renderedElement.setState({
|
|
124
|
-
offset: [0, mockItemsLength]
|
|
125
|
-
});
|
|
126
|
-
renderedInstance.handleLoading();
|
|
127
|
-
expect(renderedInstance.allItemsAreRendered()).toBe(true);
|
|
128
|
-
expect(renderedInstance.state.awaitingItems).toBe(false);
|
|
129
|
-
expect(renderedElement.find(MockIterator).length).toBe(mockItemsLength);
|
|
130
|
-
});
|
|
131
|
-
});
|
|
132
|
-
});
|
|
133
|
-
describe('Given that the initialLimit is used in the correct ways', () => {
|
|
134
|
-
describe('Given that the initialLimit is used', () => {
|
|
135
|
-
it('should render with the initialLimit', () => {
|
|
136
|
-
renderComponent({
|
|
137
|
-
items: mockData,
|
|
138
|
-
loader: mockLoader,
|
|
139
|
-
iterator: MockIterator,
|
|
140
|
-
totalItems: mockData.length
|
|
141
|
-
});
|
|
142
|
-
|
|
143
|
-
// Check if the iniLimit was used
|
|
144
|
-
expect(renderedElement.find(MockIterator).length).toBe(renderedInstance.props.initialLimit);
|
|
145
|
-
|
|
146
|
-
// Reset the limit from props.initialLimit back to props.limit
|
|
147
|
-
renderedInstance.componentDidMount();
|
|
148
|
-
renderedInstance.handleLoading();
|
|
149
|
-
|
|
150
|
-
// Re-render with the new limit
|
|
151
|
-
renderedElement.update();
|
|
152
|
-
|
|
153
|
-
// Check if the correct limit was used for the second render
|
|
154
|
-
const newLimit = renderedInstance.props.initialLimit + renderedInstance.props.limit;
|
|
155
|
-
expect(renderedElement.find(MockIterator).length).toBe(newLimit);
|
|
156
|
-
});
|
|
157
|
-
});
|
|
158
|
-
describe('Given that the initialLimit is NOT used', () => {
|
|
159
|
-
it('should render without the initialLimit', () => {
|
|
160
|
-
renderComponent({
|
|
161
|
-
items: [],
|
|
162
|
-
loader: mockLoader,
|
|
163
|
-
iterator: MockIterator,
|
|
164
|
-
totalItems: null
|
|
165
|
-
});
|
|
166
|
-
renderedInstance.componentDidMount();
|
|
167
|
-
receiveItemsByProp(ITEMS_PER_LOAD);
|
|
168
|
-
|
|
169
|
-
// Check if the iniLimit wasn't used
|
|
170
|
-
expect(renderedElement).toMatchSnapshot();
|
|
171
|
-
expect(renderedElement.find(MockIterator).length).toBe(renderedInstance.props.limit);
|
|
172
|
-
});
|
|
173
|
-
});
|
|
174
|
-
});
|
|
175
|
-
describe('Given that the requestHash changes', () => {
|
|
176
|
-
it('should reset the component', () => {
|
|
177
|
-
const props = {
|
|
178
|
-
items: mockData,
|
|
179
|
-
loader: mockLoader,
|
|
180
|
-
iterator: MockIterator,
|
|
181
|
-
totalItems: mockData.length,
|
|
182
|
-
requestHash: 'default'
|
|
183
|
-
};
|
|
184
|
-
const wrapper = mount(/*#__PURE__*/_jsx(InfiniteContainer, {
|
|
185
|
-
...props
|
|
186
|
-
}));
|
|
187
|
-
const instance = wrapper.instance();
|
|
188
|
-
instance.componentDidMount();
|
|
189
|
-
instance.domScrollContainer = document.createElement('div');
|
|
190
|
-
wrapper.setState({
|
|
191
|
-
awaitingItems: false,
|
|
192
|
-
offset: [10, 10]
|
|
193
|
-
});
|
|
194
|
-
wrapper.setProps({
|
|
195
|
-
requestHash: 'price_desc'
|
|
196
|
-
});
|
|
197
|
-
expect(wrapper.state()).toEqual({
|
|
198
|
-
offset: [0, 32],
|
|
199
|
-
awaitingItems: true,
|
|
200
|
-
itemCount: 0
|
|
201
|
-
});
|
|
202
|
-
});
|
|
203
|
-
});
|
|
204
|
-
});
|
package/components/Input/spec.js
DELETED
|
@@ -1,123 +0,0 @@
|
|
|
1
|
-
import React from 'react';
|
|
2
|
-
import { mount, shallow } from 'enzyme';
|
|
3
|
-
import Input from "./index";
|
|
4
|
-
import { jsx as _jsx } from "react/jsx-runtime";
|
|
5
|
-
describe('<Input />', () => {
|
|
6
|
-
it('should render a simple input field', () => {
|
|
7
|
-
const wrapper = mount(/*#__PURE__*/_jsx(Input, {}));
|
|
8
|
-
expect(wrapper).toMatchSnapshot();
|
|
9
|
-
expect(wrapper.find('input').length).toBe(1);
|
|
10
|
-
});
|
|
11
|
-
it('should render the input as password', () => {
|
|
12
|
-
const wrapper = mount(/*#__PURE__*/_jsx(Input, {
|
|
13
|
-
password: true
|
|
14
|
-
}));
|
|
15
|
-
expect(wrapper).toMatchSnapshot();
|
|
16
|
-
expect(wrapper.find('input[type="password"]').length).toBe(1);
|
|
17
|
-
});
|
|
18
|
-
it('should render the input with a default value', () => {
|
|
19
|
-
const wrapper = mount(/*#__PURE__*/_jsx(Input, {
|
|
20
|
-
value: "FooBar"
|
|
21
|
-
}));
|
|
22
|
-
expect(wrapper).toMatchSnapshot();
|
|
23
|
-
expect(wrapper.find('input[value="FooBar"]').length).toBe(1);
|
|
24
|
-
});
|
|
25
|
-
it('should trigger the onChange callback', () => {
|
|
26
|
-
const onChangeMock = jest.fn();
|
|
27
|
-
const wrapper = mount(/*#__PURE__*/_jsx(Input, {
|
|
28
|
-
onChange: onChangeMock
|
|
29
|
-
}));
|
|
30
|
-
wrapper.find('input').simulate('change', {
|
|
31
|
-
target: {
|
|
32
|
-
value: 'a'
|
|
33
|
-
}
|
|
34
|
-
});
|
|
35
|
-
expect(onChangeMock).toHaveBeenCalledTimes(2);
|
|
36
|
-
expect(wrapper.find('input').props().value).toEqual('a');
|
|
37
|
-
});
|
|
38
|
-
it('should receive the correct value while typing', () => {
|
|
39
|
-
const wrapper = mount(/*#__PURE__*/_jsx(Input, {}));
|
|
40
|
-
const input = wrapper.find('input');
|
|
41
|
-
input.simulate('change', {
|
|
42
|
-
target: {
|
|
43
|
-
value: 'foobar'
|
|
44
|
-
}
|
|
45
|
-
});
|
|
46
|
-
expect(wrapper).toMatchSnapshot();
|
|
47
|
-
expect(wrapper.find('SimpleInput').instance().value).toBe('foobar');
|
|
48
|
-
});
|
|
49
|
-
it('should sanitize the input', () => {
|
|
50
|
-
const wrapper = mount(/*#__PURE__*/_jsx(Input, {
|
|
51
|
-
onSanitize: value => value.toUpperCase()
|
|
52
|
-
}));
|
|
53
|
-
const input = wrapper.find('input');
|
|
54
|
-
input.simulate('change', {
|
|
55
|
-
target: {
|
|
56
|
-
value: 'foobar'
|
|
57
|
-
}
|
|
58
|
-
});
|
|
59
|
-
expect(wrapper).toMatchSnapshot();
|
|
60
|
-
expect(wrapper.find('SimpleInput').instance().value).toBe('FOOBAR');
|
|
61
|
-
});
|
|
62
|
-
it('should validate the input', () => {
|
|
63
|
-
const wrapper = mount(/*#__PURE__*/_jsx(Input, {
|
|
64
|
-
onValidate: () => false
|
|
65
|
-
}));
|
|
66
|
-
expect(wrapper).toMatchSnapshot();
|
|
67
|
-
expect(wrapper.find('SimpleInput').instance().isValid).toBe(false);
|
|
68
|
-
});
|
|
69
|
-
it('should focus the input', () => {
|
|
70
|
-
const onFocusMock = jest.fn();
|
|
71
|
-
const wrapper = mount(/*#__PURE__*/_jsx(Input, {
|
|
72
|
-
onFocusChange: onFocusMock
|
|
73
|
-
}));
|
|
74
|
-
const input = wrapper.find('input');
|
|
75
|
-
expect(wrapper).toMatchSnapshot();
|
|
76
|
-
expect(wrapper.find('SimpleInput').instance().isFocused).toBe(false);
|
|
77
|
-
input.simulate('focus');
|
|
78
|
-
expect(wrapper.find('SimpleInput').instance().isFocused).toBe(true);
|
|
79
|
-
input.simulate('blur');
|
|
80
|
-
expect(wrapper.find('SimpleInput').instance().isFocused).toBe(false);
|
|
81
|
-
});
|
|
82
|
-
it('should change the value on user input', () => {
|
|
83
|
-
const wrapper = mount(/*#__PURE__*/_jsx(Input, {
|
|
84
|
-
value: "My initial value"
|
|
85
|
-
}));
|
|
86
|
-
expect(wrapper).toMatchSnapshot();
|
|
87
|
-
expect(wrapper.find('SimpleInput').instance().value).toBe('My initial value');
|
|
88
|
-
const input = wrapper.find('input');
|
|
89
|
-
input.simulate('change', {
|
|
90
|
-
target: {
|
|
91
|
-
value: 'foobar'
|
|
92
|
-
}
|
|
93
|
-
});
|
|
94
|
-
expect(wrapper.find('SimpleInput').instance().value).toBe('foobar');
|
|
95
|
-
});
|
|
96
|
-
it('should render a multiline input with empty content and react on change', () => {
|
|
97
|
-
const multiLineValue = `dfsdsdf
|
|
98
|
-
sdfdsff
|
|
99
|
-
dsf`;
|
|
100
|
-
const wrapper = mount(/*#__PURE__*/_jsx(Input, {
|
|
101
|
-
value: "",
|
|
102
|
-
multiLine: true
|
|
103
|
-
}));
|
|
104
|
-
expect(wrapper).toMatchSnapshot();
|
|
105
|
-
expect(wrapper.find('MultiLineInput').instance().value).toEqual('');
|
|
106
|
-
wrapper.setProps({
|
|
107
|
-
value: multiLineValue
|
|
108
|
-
});
|
|
109
|
-
expect(wrapper.find('textarea').getDOMNode().innerHTML).toEqual(multiLineValue);
|
|
110
|
-
});
|
|
111
|
-
it('should render additional html attributes', () => {
|
|
112
|
-
const wrapper = shallow(/*#__PURE__*/_jsx(Input, {
|
|
113
|
-
type: "date",
|
|
114
|
-
attributes: {
|
|
115
|
-
min: '1970-01-01',
|
|
116
|
-
max: '2010-01-01'
|
|
117
|
-
}
|
|
118
|
-
})).dive();
|
|
119
|
-
expect(wrapper).toMatchSnapshot();
|
|
120
|
-
expect(wrapper.prop('min')).toEqual('1970-01-01');
|
|
121
|
-
expect(wrapper.prop('max')).toEqual('2010-01-01');
|
|
122
|
-
});
|
|
123
|
-
});
|
package/components/Link/spec.js
DELETED
|
@@ -1,60 +0,0 @@
|
|
|
1
|
-
import React from 'react';
|
|
2
|
-
import { shallow, mount } from 'enzyme';
|
|
3
|
-
import { Disconnected as Link } from "./index";
|
|
4
|
-
import { jsx as _jsx } from "react/jsx-runtime";
|
|
5
|
-
describe('<Link />', () => {
|
|
6
|
-
const historyPush = jest.fn();
|
|
7
|
-
const historyReplace = jest.fn();
|
|
8
|
-
const pathname = '/';
|
|
9
|
-
const state = {
|
|
10
|
-
x: 5
|
|
11
|
-
};
|
|
12
|
-
beforeEach(() => {
|
|
13
|
-
jest.useFakeTimers();
|
|
14
|
-
jest.clearAllMocks();
|
|
15
|
-
});
|
|
16
|
-
afterEach(() => {
|
|
17
|
-
jest.useRealTimers();
|
|
18
|
-
});
|
|
19
|
-
it('renders with children', () => {
|
|
20
|
-
const wrapper = shallow(/*#__PURE__*/_jsx(Link, {
|
|
21
|
-
href: pathname,
|
|
22
|
-
historyPush: historyPush,
|
|
23
|
-
historyReplace: historyReplace,
|
|
24
|
-
children: /*#__PURE__*/_jsx("span", {})
|
|
25
|
-
}));
|
|
26
|
-
expect(wrapper).toMatchSnapshot();
|
|
27
|
-
expect(wrapper.find('span').length).toBe(1);
|
|
28
|
-
});
|
|
29
|
-
it('handles a push', () => {
|
|
30
|
-
const wrapper = mount(/*#__PURE__*/_jsx(Link, {
|
|
31
|
-
href: pathname,
|
|
32
|
-
state: state,
|
|
33
|
-
historyPush: historyPush,
|
|
34
|
-
historyReplace: historyReplace,
|
|
35
|
-
children: /*#__PURE__*/_jsx("span", {})
|
|
36
|
-
}));
|
|
37
|
-
wrapper.find('div').simulate('click');
|
|
38
|
-
jest.runAllTimers();
|
|
39
|
-
expect(historyPush).toHaveBeenLastCalledWith({
|
|
40
|
-
pathname,
|
|
41
|
-
state
|
|
42
|
-
});
|
|
43
|
-
});
|
|
44
|
-
it('handles a replace', () => {
|
|
45
|
-
const wrapper = mount(/*#__PURE__*/_jsx(Link, {
|
|
46
|
-
href: pathname,
|
|
47
|
-
historyPush: historyPush,
|
|
48
|
-
historyReplace: historyReplace,
|
|
49
|
-
state: state,
|
|
50
|
-
replace: true,
|
|
51
|
-
children: /*#__PURE__*/_jsx("span", {})
|
|
52
|
-
}));
|
|
53
|
-
wrapper.find('div').simulate('click');
|
|
54
|
-
jest.runAllTimers();
|
|
55
|
-
expect(historyReplace).toHaveBeenLastCalledWith({
|
|
56
|
-
pathname,
|
|
57
|
-
state
|
|
58
|
-
});
|
|
59
|
-
});
|
|
60
|
-
});
|
package/components/List/spec.js
DELETED
|
@@ -1,26 +0,0 @@
|
|
|
1
|
-
import React from 'react';
|
|
2
|
-
import { shallow } from 'enzyme';
|
|
3
|
-
import List from "./index";
|
|
4
|
-
import { jsx as _jsx } from "react/jsx-runtime";
|
|
5
|
-
console.error = jest.fn();
|
|
6
|
-
describe('<List />', () => {
|
|
7
|
-
const children = [/*#__PURE__*/_jsx(List.Item, {}, "0"), /*#__PURE__*/_jsx(List.Item, {}, "1"), /*#__PURE__*/_jsx(List.Item, {}, "2")];
|
|
8
|
-
beforeEach(() => {
|
|
9
|
-
jest.clearAllMocks();
|
|
10
|
-
});
|
|
11
|
-
it('renders with children', () => {
|
|
12
|
-
const numChildren = children.length;
|
|
13
|
-
const wrapper = shallow(/*#__PURE__*/_jsx(List, {
|
|
14
|
-
children: children
|
|
15
|
-
}));
|
|
16
|
-
expect(wrapper).toMatchSnapshot();
|
|
17
|
-
expect(wrapper.find(List.Item).length).toBe(numChildren);
|
|
18
|
-
expect(console.error).not.toHaveBeenCalled();
|
|
19
|
-
});
|
|
20
|
-
it('renders without children', () => {
|
|
21
|
-
const wrapper = shallow(/*#__PURE__*/_jsx(List, {}));
|
|
22
|
-
expect(wrapper).toMatchSnapshot();
|
|
23
|
-
expect(wrapper.find(List.Item).length).toBe(0);
|
|
24
|
-
expect(console.error).toHaveBeenCalledTimes(1);
|
|
25
|
-
});
|
|
26
|
-
});
|
|
@@ -1,115 +0,0 @@
|
|
|
1
|
-
/* eslint-disable no-unused-vars, jsx-a11y/control-has-associated-label */
|
|
2
|
-
import React from 'react';
|
|
3
|
-
import { mount } from 'enzyme';
|
|
4
|
-
import { Provider } from 'react-redux';
|
|
5
|
-
import { configureStore } from "../../store";
|
|
6
|
-
import modalReducer from "../../reducers/modal";
|
|
7
|
-
import showModal from "../../actions/modal/showModal";
|
|
8
|
-
import ModalContainer from "./index";
|
|
9
|
-
|
|
10
|
-
// const store = configureStore({ modal: modalReducer });
|
|
11
|
-
// Replacement for commented out configureStore()
|
|
12
|
-
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
13
|
-
const store = {};
|
|
14
|
-
jest.mock('redux-logger', () => ({
|
|
15
|
-
createLogger: () => () => next => action => next(action)
|
|
16
|
-
}));
|
|
17
|
-
global.requestAnimationFrame = fn => fn();
|
|
18
|
-
|
|
19
|
-
/**
|
|
20
|
-
* Some mock modal component.
|
|
21
|
-
* @param {func} onConfirm Confirm callback
|
|
22
|
-
* @param {func} onDismiss Dismiss callback
|
|
23
|
-
* @constructor
|
|
24
|
-
*/
|
|
25
|
-
const MockModal = ({
|
|
26
|
-
onConfirm,
|
|
27
|
-
// eslint-disable-line react/prop-types
|
|
28
|
-
onDismiss // eslint-disable-line react/prop-types
|
|
29
|
-
}) => /*#__PURE__*/_jsxs("div", {
|
|
30
|
-
className: "modal",
|
|
31
|
-
children: [/*#__PURE__*/_jsx("button", {
|
|
32
|
-
className: "confirmBtn",
|
|
33
|
-
onClick: onConfirm,
|
|
34
|
-
type: "button"
|
|
35
|
-
}), /*#__PURE__*/_jsx("button", {
|
|
36
|
-
className: "dismissBtn",
|
|
37
|
-
onClick: onDismiss,
|
|
38
|
-
type: "button"
|
|
39
|
-
})]
|
|
40
|
-
});
|
|
41
|
-
describe.skip('<ModalContainer />', () => {
|
|
42
|
-
let renderedElement;
|
|
43
|
-
const {
|
|
44
|
-
dispatch,
|
|
45
|
-
getState
|
|
46
|
-
} = store;
|
|
47
|
-
|
|
48
|
-
/**
|
|
49
|
-
* The rendered component.
|
|
50
|
-
*/
|
|
51
|
-
const renderComponent = () => {
|
|
52
|
-
renderedElement = mount(/*#__PURE__*/_jsx(Provider, {
|
|
53
|
-
store: store,
|
|
54
|
-
children: /*#__PURE__*/_jsx("div", {
|
|
55
|
-
id: "container",
|
|
56
|
-
children: /*#__PURE__*/_jsx(ModalContainer, {
|
|
57
|
-
component: MockModal
|
|
58
|
-
})
|
|
59
|
-
})
|
|
60
|
-
}));
|
|
61
|
-
};
|
|
62
|
-
beforeEach(() => {
|
|
63
|
-
// Reset the modals state before each test.
|
|
64
|
-
getState().modal = [];
|
|
65
|
-
renderComponent();
|
|
66
|
-
});
|
|
67
|
-
describe('Given the component was mounted to the DOM', () => {
|
|
68
|
-
it('should match snapshot', () => {
|
|
69
|
-
expect(renderedElement).toMatchSnapshot();
|
|
70
|
-
});
|
|
71
|
-
it('should show no modal', () => {
|
|
72
|
-
expect(renderedElement.find('.modal').length).toBe(0);
|
|
73
|
-
});
|
|
74
|
-
describe('Given a modal gets dispatched', () => {
|
|
75
|
-
let modalPromise;
|
|
76
|
-
beforeEach(() => {
|
|
77
|
-
modalPromise = dispatch(showModal({
|
|
78
|
-
title: 'Title',
|
|
79
|
-
message: 'Message'
|
|
80
|
-
}));
|
|
81
|
-
renderedElement.update();
|
|
82
|
-
});
|
|
83
|
-
it('should contain a modal item in the state', () => {
|
|
84
|
-
expect(getState().modal.length).toBe(1);
|
|
85
|
-
});
|
|
86
|
-
it('should show the modal', () => {
|
|
87
|
-
expect(renderedElement.find('.modal').length).toBe(1);
|
|
88
|
-
});
|
|
89
|
-
describe('Given the modal gets confirmed', () => {
|
|
90
|
-
beforeEach(() => {
|
|
91
|
-
renderedElement.find('.confirmBtn').simulate('click');
|
|
92
|
-
});
|
|
93
|
-
it('should resolve the promise as confirmed', () => {
|
|
94
|
-
modalPromise.then(confirmed => expect(confirmed).toBe(true));
|
|
95
|
-
});
|
|
96
|
-
it('should contain no modal item in the state', () => {
|
|
97
|
-
expect(getState().modal.length).toBe(0);
|
|
98
|
-
});
|
|
99
|
-
it('should not show the modal anymore', () => {
|
|
100
|
-
expect(renderedElement.find('.modal').length).toBe(0);
|
|
101
|
-
});
|
|
102
|
-
});
|
|
103
|
-
describe('Given the modal gets dismissed', () => {
|
|
104
|
-
beforeEach(() => {
|
|
105
|
-
renderedElement.find('.dismissBtn').simulate('click');
|
|
106
|
-
});
|
|
107
|
-
it('should resolve the promise as dismissed', () => {
|
|
108
|
-
modalPromise.then(confirmed => expect(confirmed).toBe(false));
|
|
109
|
-
});
|
|
110
|
-
});
|
|
111
|
-
});
|
|
112
|
-
});
|
|
113
|
-
});
|
|
114
|
-
|
|
115
|
-
/* eslint-enable no-unused-vars, jsx-a11y/control-has-associated-label */
|
|
@@ -1,122 +0,0 @@
|
|
|
1
|
-
import React from 'react';
|
|
2
|
-
import { mount } from 'enzyme';
|
|
3
|
-
import { act } from 'react-dom/test-utils';
|
|
4
|
-
import Select from "./index";
|
|
5
|
-
import SelectItem from "./components/Item";
|
|
6
|
-
|
|
7
|
-
/**
|
|
8
|
-
* Returns whether the given Enzyme wrapper contains at least one node
|
|
9
|
-
* with a class name that ends with the provided suffix.
|
|
10
|
-
*
|
|
11
|
-
* This checks individual class tokens, so it works with elements that
|
|
12
|
-
* have multiple classes.
|
|
13
|
-
*
|
|
14
|
-
* @param {Object} wrapper Enzyme wrapper (mount or shallow result).
|
|
15
|
-
* @param {string} suffix Class name suffix to match, e.g. "-innerShadow".
|
|
16
|
-
* @returns {boolean} True if a matching node exists.
|
|
17
|
-
*/
|
|
18
|
-
import { jsx as _jsx } from "react/jsx-runtime";
|
|
19
|
-
export function containsClassWithEnding(wrapper, suffix) {
|
|
20
|
-
if (!wrapper || typeof wrapper.findWhere !== 'function' || !suffix) {
|
|
21
|
-
return false;
|
|
22
|
-
}
|
|
23
|
-
return wrapper.findWhere(node => {
|
|
24
|
-
const className = node.prop('className');
|
|
25
|
-
if (typeof className !== 'string') {
|
|
26
|
-
return false;
|
|
27
|
-
}
|
|
28
|
-
return className.split(/\s+/).some(cls => cls.endsWith(suffix));
|
|
29
|
-
}).length > 0;
|
|
30
|
-
}
|
|
31
|
-
|
|
32
|
-
/**
|
|
33
|
-
* Helper to simulate toggling the open state by touching the handle area.
|
|
34
|
-
* @param {Object} wrapper Enzyme wrapper.
|
|
35
|
-
*/
|
|
36
|
-
const toggleOpen = wrapper => {
|
|
37
|
-
wrapper.find('[role="presentation"]').simulate('touchstart');
|
|
38
|
-
wrapper.update();
|
|
39
|
-
};
|
|
40
|
-
describe('<Select />', () => {
|
|
41
|
-
jest.useFakeTimers();
|
|
42
|
-
it('opens and closes the item list', () => {
|
|
43
|
-
const wrapper = mount(/*#__PURE__*/_jsx(Select, {}));
|
|
44
|
-
expect(wrapper.find(SelectItem).length).toBe(0);
|
|
45
|
-
toggleOpen(wrapper);
|
|
46
|
-
// opened – still 0 items because no items prop
|
|
47
|
-
expect(containsClassWithEnding(wrapper, '-items')).toBe(true);
|
|
48
|
-
toggleOpen(wrapper);
|
|
49
|
-
expect(containsClassWithEnding(wrapper, '-items')).toBe(false);
|
|
50
|
-
});
|
|
51
|
-
it('renders without items', () => {
|
|
52
|
-
const wrapper = mount(/*#__PURE__*/_jsx(Select, {}));
|
|
53
|
-
toggleOpen(wrapper);
|
|
54
|
-
expect(wrapper).toMatchSnapshot();
|
|
55
|
-
expect(wrapper.find(SelectItem).length).toBe(0);
|
|
56
|
-
});
|
|
57
|
-
it('renders with implicit items (closed)', () => {
|
|
58
|
-
const items = ['a', 'b', 'c', 'd', 'e', 'f'];
|
|
59
|
-
const wrapper = mount(/*#__PURE__*/_jsx(Select, {
|
|
60
|
-
items: items
|
|
61
|
-
}));
|
|
62
|
-
expect(wrapper).toMatchSnapshot();
|
|
63
|
-
expect(wrapper.find(SelectItem).length).toBe(0);
|
|
64
|
-
});
|
|
65
|
-
it('renders with implicit items (opened)', () => {
|
|
66
|
-
const items = ['a', 'b', 'c', 'd', 'e', 'f'];
|
|
67
|
-
const wrapper = mount(/*#__PURE__*/_jsx(Select, {
|
|
68
|
-
items: items
|
|
69
|
-
}));
|
|
70
|
-
toggleOpen(wrapper);
|
|
71
|
-
expect(wrapper).toMatchSnapshot();
|
|
72
|
-
expect(wrapper.find(SelectItem).length).toBe(items.length);
|
|
73
|
-
});
|
|
74
|
-
it('accepts implicit and explicit items', () => {
|
|
75
|
-
const items = ['a', 'b', {
|
|
76
|
-
value: 'c'
|
|
77
|
-
}, 'd', {
|
|
78
|
-
value: 'e',
|
|
79
|
-
label: 'E'
|
|
80
|
-
}, 'f'];
|
|
81
|
-
const wrapper = mount(/*#__PURE__*/_jsx(Select, {
|
|
82
|
-
items: items
|
|
83
|
-
}));
|
|
84
|
-
toggleOpen(wrapper);
|
|
85
|
-
expect(wrapper).toMatchSnapshot();
|
|
86
|
-
expect(wrapper.find(SelectItem).length).toBe(items.length);
|
|
87
|
-
let i = 0;
|
|
88
|
-
wrapper.find(SelectItem).forEach(item => {
|
|
89
|
-
let expectedLabel = items[i];
|
|
90
|
-
if (expectedLabel.label) {
|
|
91
|
-
expectedLabel = expectedLabel.label;
|
|
92
|
-
}
|
|
93
|
-
if (expectedLabel.value) {
|
|
94
|
-
expectedLabel = expectedLabel.value;
|
|
95
|
-
}
|
|
96
|
-
expect(item.prop('label')).toBe(expectedLabel);
|
|
97
|
-
i += 1;
|
|
98
|
-
});
|
|
99
|
-
});
|
|
100
|
-
it('triggers callback on change', () => {
|
|
101
|
-
const items = ['a', 'b', 'c', 'd', 'e', 'f'];
|
|
102
|
-
const selectionIndex = Math.floor(items.length / 2);
|
|
103
|
-
|
|
104
|
-
/**
|
|
105
|
-
* Mocked callback for the onSelect event
|
|
106
|
-
* @param {string} value Mocked value
|
|
107
|
-
*/
|
|
108
|
-
const callback = value => {
|
|
109
|
-
expect(value).toBe(items[selectionIndex]);
|
|
110
|
-
};
|
|
111
|
-
const wrapper = mount(/*#__PURE__*/_jsx(Select, {
|
|
112
|
-
items: items,
|
|
113
|
-
onChange: callback
|
|
114
|
-
}));
|
|
115
|
-
toggleOpen(wrapper);
|
|
116
|
-
expect(wrapper).toMatchSnapshot();
|
|
117
|
-
const node = wrapper.find(SelectItem).at(selectionIndex);
|
|
118
|
-
act(() => {
|
|
119
|
-
node.prop('onSelect')(node.prop('value'), node.prop('label'));
|
|
120
|
-
});
|
|
121
|
-
});
|
|
122
|
-
});
|