@shopgate/pwa-common 7.31.5 → 7.31.6
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/helpers/mocks/mockRenderOptions.js +21 -0
- package/package.json +3 -3
- 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/providers/toast/spec.js +0 -105
- package/tsconfig.build.json +0 -16
- package/tsconfig.json +0 -3
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
|
-
});
|
|
@@ -1,68 +0,0 @@
|
|
|
1
|
-
import React from 'react';
|
|
2
|
-
import PropTypes from 'prop-types';
|
|
3
|
-
import { mount } from 'enzyme';
|
|
4
|
-
import SelectBox from "./index";
|
|
5
|
-
|
|
6
|
-
/**
|
|
7
|
-
* Mock Icon component.
|
|
8
|
-
* @returns {JSX}
|
|
9
|
-
*/
|
|
10
|
-
import { jsx as _jsx } from "react/jsx-runtime";
|
|
11
|
-
const MockIconComponent = () => /*#__PURE__*/_jsx("span", {
|
|
12
|
-
id: "icon"
|
|
13
|
-
});
|
|
14
|
-
|
|
15
|
-
/**
|
|
16
|
-
* Mock Item component.
|
|
17
|
-
* @param {Object} props The components props.
|
|
18
|
-
* @param {JSX} props.children The components children.
|
|
19
|
-
* @returns {JSX}
|
|
20
|
-
*/
|
|
21
|
-
const MockItemComponent = ({
|
|
22
|
-
children
|
|
23
|
-
}) => /*#__PURE__*/_jsx("div", {
|
|
24
|
-
children: children
|
|
25
|
-
});
|
|
26
|
-
describe('<SelectBox>', () => {
|
|
27
|
-
const dummyItems = [{
|
|
28
|
-
label: 'My item #1',
|
|
29
|
-
value: 'item_1'
|
|
30
|
-
}, {
|
|
31
|
-
label: 'My item #2',
|
|
32
|
-
value: 'item_2'
|
|
33
|
-
}, {
|
|
34
|
-
label: 'My item #3',
|
|
35
|
-
value: 'item_3'
|
|
36
|
-
}];
|
|
37
|
-
it('should render the selectbox with given mock components', () => {
|
|
38
|
-
const wrapper = mount(/*#__PURE__*/_jsx(SelectBox, {
|
|
39
|
-
icon: MockIconComponent,
|
|
40
|
-
item: MockItemComponent,
|
|
41
|
-
items: dummyItems
|
|
42
|
-
}));
|
|
43
|
-
expect(wrapper).toMatchSnapshot();
|
|
44
|
-
expect(wrapper.find(MockIconComponent).length).toEqual(1);
|
|
45
|
-
expect(wrapper.find(MockItemComponent).length).toEqual(3);
|
|
46
|
-
});
|
|
47
|
-
it('should render with a default text', () => {
|
|
48
|
-
const wrapper = mount(/*#__PURE__*/_jsx(SelectBox, {
|
|
49
|
-
icon: MockIconComponent,
|
|
50
|
-
item: MockItemComponent,
|
|
51
|
-
items: dummyItems,
|
|
52
|
-
defaultText: "Foo"
|
|
53
|
-
}));
|
|
54
|
-
expect(wrapper).toMatchSnapshot();
|
|
55
|
-
expect(wrapper.find('span').at(0).text()).toEqual('Foo');
|
|
56
|
-
});
|
|
57
|
-
it('should render with a preselected selection', () => {
|
|
58
|
-
const wrapper = mount(/*#__PURE__*/_jsx(SelectBox, {
|
|
59
|
-
icon: MockIconComponent,
|
|
60
|
-
item: MockItemComponent,
|
|
61
|
-
items: dummyItems,
|
|
62
|
-
defaultText: "Foo",
|
|
63
|
-
initialValue: "item_2"
|
|
64
|
-
}));
|
|
65
|
-
expect(wrapper).toMatchSnapshot();
|
|
66
|
-
expect(wrapper.find('span').at(0).text()).toEqual('My item #2');
|
|
67
|
-
});
|
|
68
|
-
});
|
|
@@ -1,26 +0,0 @@
|
|
|
1
|
-
import React from 'react';
|
|
2
|
-
import { shallow } from 'enzyme';
|
|
3
|
-
import { CLASS_PREFIX } from '@shopgate/engage/styles/tss';
|
|
4
|
-
import SwiperItem from '.';
|
|
5
|
-
import { jsx as _jsx } from "react/jsx-runtime";
|
|
6
|
-
jest.mock('react', () => ({
|
|
7
|
-
...jest.requireActual('react'),
|
|
8
|
-
useLayoutEffect: jest.requireActual('react').useEffect
|
|
9
|
-
}));
|
|
10
|
-
describe('<SwiperItem />', () => {
|
|
11
|
-
it('should not render without children', () => {
|
|
12
|
-
const wrapper = shallow(/*#__PURE__*/_jsx(SwiperItem, {
|
|
13
|
-
children: /*#__PURE__*/_jsx("div", {})
|
|
14
|
-
}));
|
|
15
|
-
expect(wrapper).toMatchSnapshot();
|
|
16
|
-
expect(wrapper.html()).toMatch(new RegExp(`^<div class="swiper-slide ${CLASS_PREFIX}-[^"]+" data-test-id="Slider"><div></div></div>$`));
|
|
17
|
-
});
|
|
18
|
-
it('should add custom className', () => {
|
|
19
|
-
const wrapper = shallow(/*#__PURE__*/_jsx(SwiperItem, {
|
|
20
|
-
className: "test",
|
|
21
|
-
children: /*#__PURE__*/_jsx("div", {})
|
|
22
|
-
}));
|
|
23
|
-
expect(wrapper).toMatchSnapshot();
|
|
24
|
-
expect(wrapper.html()).toMatch(new RegExp(`^<div class="swiper-slide ${CLASS_PREFIX}-[^"]+ test" data-test-id="Slider"><div></div></div>$`));
|
|
25
|
-
});
|
|
26
|
-
});
|
|
@@ -1,75 +0,0 @@
|
|
|
1
|
-
import React from 'react';
|
|
2
|
-
import { mount } from 'enzyme';
|
|
3
|
-
import Grid from "../../../Grid";
|
|
4
|
-
import Widget from "./index";
|
|
5
|
-
import { jsx as _jsx } from "react/jsx-runtime";
|
|
6
|
-
jest.mock('react', () => {
|
|
7
|
-
const actual = jest.requireActual('react');
|
|
8
|
-
return {
|
|
9
|
-
...actual,
|
|
10
|
-
memo: c => c,
|
|
11
|
-
Suspense: function Suspense({
|
|
12
|
-
children
|
|
13
|
-
}) {
|
|
14
|
-
return children;
|
|
15
|
-
}
|
|
16
|
-
};
|
|
17
|
-
});
|
|
18
|
-
|
|
19
|
-
/**
|
|
20
|
-
* A dummy component.
|
|
21
|
-
* @returns {JSX}
|
|
22
|
-
*/
|
|
23
|
-
const MyComponent = () => /*#__PURE__*/_jsx("div", {});
|
|
24
|
-
const widgets = {
|
|
25
|
-
'@shopgate/commerce-widgets/image': MyComponent
|
|
26
|
-
};
|
|
27
|
-
describe('<Widget />', () => {
|
|
28
|
-
it('should render an image widget', () => {
|
|
29
|
-
const config = {
|
|
30
|
-
type: '@shopgate/commerce-widgets/image',
|
|
31
|
-
col: 1,
|
|
32
|
-
row: 1,
|
|
33
|
-
width: 12,
|
|
34
|
-
height: 6
|
|
35
|
-
};
|
|
36
|
-
const wrapper = mount(/*#__PURE__*/_jsx(Widget, {
|
|
37
|
-
config: config,
|
|
38
|
-
component: widgets[config.type]
|
|
39
|
-
}));
|
|
40
|
-
expect(wrapper).toMatchSnapshot();
|
|
41
|
-
expect(wrapper.find(Grid.Item).exists()).toBe(true);
|
|
42
|
-
});
|
|
43
|
-
it('should render an image widget with offset', () => {
|
|
44
|
-
const config = {
|
|
45
|
-
type: '@shopgate/commerce-widgets/image',
|
|
46
|
-
col: 1,
|
|
47
|
-
row: 1,
|
|
48
|
-
width: 6,
|
|
49
|
-
height: 6
|
|
50
|
-
};
|
|
51
|
-
const wrapper = mount(/*#__PURE__*/_jsx(Widget, {
|
|
52
|
-
config: config,
|
|
53
|
-
component: widgets[config.type],
|
|
54
|
-
cellSize: 100
|
|
55
|
-
}));
|
|
56
|
-
expect(wrapper).toMatchSnapshot();
|
|
57
|
-
expect(wrapper.find(Grid.Item).exists()).toBe(true);
|
|
58
|
-
});
|
|
59
|
-
it('should not render when the `type` prop is invalid', () => {
|
|
60
|
-
const config = {
|
|
61
|
-
type: 'some_widget',
|
|
62
|
-
// Invalid
|
|
63
|
-
col: 1,
|
|
64
|
-
row: 1,
|
|
65
|
-
width: 12,
|
|
66
|
-
height: 6
|
|
67
|
-
};
|
|
68
|
-
const wrapper = mount(/*#__PURE__*/_jsx(Widget, {
|
|
69
|
-
config: config,
|
|
70
|
-
component: widgets[config.type]
|
|
71
|
-
}));
|
|
72
|
-
expect(wrapper).toMatchSnapshot();
|
|
73
|
-
expect(wrapper.find(Grid.Item).exists()).toBe(false);
|
|
74
|
-
});
|
|
75
|
-
});
|
|
@@ -1,53 +0,0 @@
|
|
|
1
|
-
import React from 'react';
|
|
2
|
-
import { mount } from 'enzyme';
|
|
3
|
-
import WidgetGrid from "./index";
|
|
4
|
-
import { jsx as _jsx } from "react/jsx-runtime";
|
|
5
|
-
jest.mock('react', () => {
|
|
6
|
-
const actual = jest.requireActual('react');
|
|
7
|
-
return {
|
|
8
|
-
...actual,
|
|
9
|
-
memo: c => c,
|
|
10
|
-
Suspense: function Suspense({
|
|
11
|
-
children
|
|
12
|
-
}) {
|
|
13
|
-
return children;
|
|
14
|
-
}
|
|
15
|
-
};
|
|
16
|
-
});
|
|
17
|
-
|
|
18
|
-
/**
|
|
19
|
-
* A mock Image component.
|
|
20
|
-
* @returns {JSX}
|
|
21
|
-
*/
|
|
22
|
-
const Image = () => /*#__PURE__*/_jsx("div", {});
|
|
23
|
-
const components = {
|
|
24
|
-
'@shopgate/commerce-widgets/image': Image
|
|
25
|
-
};
|
|
26
|
-
describe('<WidgetGrid />', () => {
|
|
27
|
-
it('should render with a config', () => {
|
|
28
|
-
const config = [{
|
|
29
|
-
col: 0,
|
|
30
|
-
row: 0,
|
|
31
|
-
width: 12,
|
|
32
|
-
height: 3,
|
|
33
|
-
settings: {
|
|
34
|
-
id: 83535,
|
|
35
|
-
image: 'https://data.shopgate.com/shop_widget_images/23836/92204c0f264ac30d6836994c2fb64eb1.min.jpeg'
|
|
36
|
-
},
|
|
37
|
-
type: '@shopgate/commerce-widgets/image'
|
|
38
|
-
}];
|
|
39
|
-
const wrapper = mount(/*#__PURE__*/_jsx(WidgetGrid, {
|
|
40
|
-
config: config,
|
|
41
|
-
components: components
|
|
42
|
-
}));
|
|
43
|
-
expect(wrapper).toMatchSnapshot();
|
|
44
|
-
expect(wrapper.find(Image).length).toEqual(1);
|
|
45
|
-
});
|
|
46
|
-
it('should not render without a `config` prop', () => {
|
|
47
|
-
const wrapper = mount(/*#__PURE__*/_jsx(WidgetGrid, {
|
|
48
|
-
components: components
|
|
49
|
-
}));
|
|
50
|
-
expect(wrapper).toMatchSnapshot();
|
|
51
|
-
expect(wrapper.find(Image).length).toEqual(0);
|
|
52
|
-
});
|
|
53
|
-
});
|