@shopgate/pwa-common 7.32.0-beta.2 → 7.32.0-beta.21

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (68) hide show
  1. package/actions/app/handleLink.js +6 -2
  2. package/components/Button/index.js +6 -0
  3. package/components/Image/Image.d.ts +78 -0
  4. package/components/Image/Image.d.ts.map +1 -0
  5. package/components/Image/Image.js +123 -91
  6. package/components/Image/ImageInner.d.ts +45 -0
  7. package/components/Image/ImageInner.d.ts.map +1 -0
  8. package/components/Image/ImageInner.js +23 -29
  9. package/components/Image/index.d.ts +3 -0
  10. package/components/Image/index.d.ts.map +1 -0
  11. package/components/Swiper/index.js +17 -2
  12. package/constants/Configuration.js +7 -0
  13. package/helpers/html/decodeHTML.js +5 -3
  14. package/helpers/html/htmlToText.js +15 -0
  15. package/helpers/mocks/mockRenderOptions.js +21 -0
  16. package/helpers/router/index.js +85 -0
  17. package/package.json +3 -3
  18. package/providers/toast/index.js +54 -40
  19. package/subscriptions/error.js +50 -27
  20. package/subscriptions/helpers/pipeline.js +68 -0
  21. package/subscriptions/router.js +22 -8
  22. package/action-creators/app/spec.js +0 -96
  23. package/action-creators/client/spec.js +0 -44
  24. package/action-creators/menu/spec.js +0 -37
  25. package/action-creators/modal/spec.js +0 -26
  26. package/action-creators/page/spec.js +0 -38
  27. package/action-creators/url/spec.js +0 -45
  28. package/action-creators/user/spec.js +0 -186
  29. package/components/Backdrop/spec.js +0 -24
  30. package/components/Button/spec.js +0 -42
  31. package/components/Checkbox/spec.js +0 -111
  32. package/components/CountdownTimer/spec.js +0 -141
  33. package/components/Drawer/spec.js +0 -79
  34. package/components/Ellipsis/spec.js +0 -15
  35. package/components/EmbeddedMedia/spec.js +0 -61
  36. package/components/Grid/components/Item/spec.js +0 -24
  37. package/components/Grid/spec.js +0 -24
  38. package/components/HtmlSanitizer/spec.js +0 -229
  39. package/components/I18n/components/FormatDate/spec.js +0 -54
  40. package/components/I18n/components/FormatNumber/spec.js +0 -51
  41. package/components/I18n/components/FormatPrice/spec.js +0 -54
  42. package/components/I18n/components/FormatTime/spec.js +0 -51
  43. package/components/I18n/components/I18nProvider/spec.js +0 -40
  44. package/components/I18n/components/Placeholder/spec.js +0 -37
  45. package/components/I18n/components/Translate/spec.js +0 -33
  46. package/components/InfiniteContainer/spec.js +0 -204
  47. package/components/Input/spec.js +0 -123
  48. package/components/Link/spec.js +0 -60
  49. package/components/List/spec.js +0 -26
  50. package/components/ModalContainer/spec.js +0 -115
  51. package/components/Select/spec.js +0 -122
  52. package/components/SelectBox/spec.js +0 -68
  53. package/components/Swiper/components/SwiperItem/spec.js +0 -26
  54. package/components/Widgets/components/Widget/spec.js +0 -75
  55. package/components/Widgets/components/WidgetGrid/spec.js +0 -53
  56. package/components/Widgets/spec.js +0 -234
  57. package/helpers/data/spec.js +0 -194
  58. package/helpers/date/spec.js +0 -92
  59. package/helpers/style/spec.js +0 -108
  60. package/helpers/validation/spec.js +0 -10
  61. package/styles/reset/form.js +0 -58
  62. package/styles/reset/index.js +0 -8
  63. package/styles/reset/media.js +0 -26
  64. package/styles/reset/root.js +0 -37
  65. package/styles/reset/table.js +0 -14
  66. package/styles/reset/typography.js +0 -30
  67. package/tsconfig.build.json +0 -16
  68. package/tsconfig.json +0 -3
@@ -1,54 +0,0 @@
1
- import React from 'react';
2
- import { mount } from 'enzyme';
3
- import { i18n } from '@shopgate/engage/core';
4
- import I18n from "../../index";
5
- import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
6
- jest.unmock('@shopgate/engage/core/helpers/i18n');
7
- describe('<FormatPrice />', () => {
8
- const locales = {
9
- greeting: 'Hello {price}'
10
- };
11
- const price = 1234.56;
12
- const formattedPrice = '€1,234.56';
13
- const currency = 'EUR';
14
- const lang = 'en-US';
15
- i18n.init({
16
- locales,
17
- lang
18
- });
19
- describe('Given the component was mounted to the DOM', () => {
20
- let renderedElement;
21
- it('should match snapshot', () => {
22
- renderedElement = mount(/*#__PURE__*/_jsx(I18n.Provider, {
23
- children: /*#__PURE__*/_jsxs("div", {
24
- children: [/*#__PURE__*/_jsx("span", {
25
- className: "only-price",
26
- children: /*#__PURE__*/_jsx(I18n.Price, {
27
- price: price,
28
- currency: currency
29
- })
30
- }), /*#__PURE__*/_jsx("span", {
31
- className: "text-with-price",
32
- children: /*#__PURE__*/_jsx(I18n.Text, {
33
- string: "greeting",
34
- children: /*#__PURE__*/_jsx(I18n.Price, {
35
- forKey: "price",
36
- price: price,
37
- currency: currency
38
- })
39
- })
40
- })]
41
- })
42
- }));
43
- expect(renderedElement).toMatchSnapshot();
44
- });
45
- it('should render formatted price', () => {
46
- const text = renderedElement.find('.only-price').text();
47
- expect(text).toBe(formattedPrice);
48
- });
49
- it('should render within translated text', () => {
50
- const text = renderedElement.find('.text-with-price').text();
51
- expect(text).toBe(`Hello ${formattedPrice}`);
52
- });
53
- });
54
- });
@@ -1,51 +0,0 @@
1
- import React from 'react';
2
- import { mount } from 'enzyme';
3
- import { i18n } from '@shopgate/engage/core';
4
- import I18n from "../../index";
5
- import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
6
- jest.unmock('@shopgate/engage/core/helpers/i18n');
7
- describe('<FormatTime />', () => {
8
- const locales = {
9
- greeting: 'Hello {time}'
10
- };
11
- const timestamp = new Date('Dec 25, 1999 04:25:45').getTime();
12
- const formattedTime = '4:25:45 AM';
13
- const format = 'medium';
14
- const lang = 'en-US';
15
- i18n.init({
16
- locales,
17
- lang
18
- });
19
- describe('Given the component was mounted to the DOM', () => {
20
- // TODO: Handle snapshot test.
21
- const renderedElement = mount(/*#__PURE__*/_jsx(I18n.Provider, {
22
- children: /*#__PURE__*/_jsxs("div", {
23
- children: [/*#__PURE__*/_jsx("span", {
24
- className: "only-time",
25
- children: /*#__PURE__*/_jsx(I18n.Time, {
26
- timestamp: timestamp,
27
- format: format
28
- })
29
- }), /*#__PURE__*/_jsx("span", {
30
- className: "text-with-time",
31
- children: /*#__PURE__*/_jsx(I18n.Text, {
32
- string: "greeting",
33
- children: /*#__PURE__*/_jsx(I18n.Time, {
34
- forKey: "time",
35
- timestamp: timestamp,
36
- format: format
37
- })
38
- })
39
- })]
40
- })
41
- }));
42
- it('should render formatted time', () => {
43
- const text = renderedElement.find('.only-time').text();
44
- expect(text).toBe(formattedTime);
45
- });
46
- it('should render within translated text', () => {
47
- const text = renderedElement.find('.text-with-time').text();
48
- expect(text).toBe(`Hello ${formattedTime}`);
49
- });
50
- });
51
- });
@@ -1,40 +0,0 @@
1
- import React from 'react';
2
- import { shallow } from 'enzyme';
3
- import { i18n as i18nHelper } from '@shopgate/engage/core';
4
- import I18nProvider from "./index";
5
- import { jsx as _jsx } from "react/jsx-runtime";
6
- jest.unmock('@shopgate/engage/core/helpers/i18n');
7
- describe('<I18nProvider />', () => {
8
- const locales = {
9
- greeting: 'Guten Tag {name}'
10
- };
11
- const lang = 'de-DE';
12
- i18nHelper.init({
13
- locales,
14
- lang
15
- });
16
- describe('Given the component was mounted to the DOM', () => {
17
- let renderedElement;
18
- let renderedInstance;
19
- it('should match snapshot', () => {
20
- renderedElement = shallow(/*#__PURE__*/_jsx(I18nProvider, {}));
21
- renderedInstance = renderedElement.instance();
22
- expect(renderedElement).toMatchSnapshot();
23
- });
24
- it('should provide access to i18n via context', () => {
25
- const {
26
- i18n
27
- } = renderedInstance.getChildContext();
28
- expect(i18n).toEqual(renderedInstance.getI18nInstance);
29
- });
30
- it('should translate when calling an instance method', () => {
31
- const {
32
- __
33
- } = renderedInstance.getI18nInstance();
34
- const translated = __('greeting', {
35
- name: 'Test'
36
- });
37
- expect(translated).toBe('Guten Tag Test');
38
- });
39
- });
40
- });
@@ -1,37 +0,0 @@
1
- import React from 'react';
2
- import { mount } from 'enzyme';
3
- import { i18n } from '@shopgate/engage/core';
4
- import I18n from "../../index";
5
- import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
6
- jest.unmock('@shopgate/engage/core/helpers/i18n');
7
- describe('<Placeholder />', () => {
8
- const locales = {
9
- greeting: 'Hello {world}'
10
- };
11
- const lang = 'en-US';
12
- i18n.init({
13
- locales,
14
- lang
15
- });
16
- describe('Given the component was mounted to the DOM', () => {
17
- let renderedElement;
18
- it('should render', () => {
19
- renderedElement = mount(/*#__PURE__*/_jsx(I18n.Provider, {
20
- children: /*#__PURE__*/_jsxs(I18n.Text, {
21
- string: "greeting",
22
- children: [/*#__PURE__*/_jsx(I18n.Placeholder, {
23
- forKey: "world",
24
- children: /*#__PURE__*/_jsx("strong", {
25
- children: "WORLD"
26
- })
27
- }), "/"]
28
- })
29
- }));
30
- expect(renderedElement).toMatchSnapshot();
31
- });
32
- it('should render with a placeholder text', () => {
33
- const text = renderedElement.find('strong').text();
34
- expect(text).toBe('WORLD');
35
- });
36
- });
37
- });
@@ -1,33 +0,0 @@
1
- import React from 'react';
2
- import { mount } from 'enzyme';
3
- import { i18n } from '@shopgate/engage/core';
4
- import I18n from "../../index";
5
- import { jsx as _jsx } from "react/jsx-runtime";
6
- jest.unmock('@shopgate/engage/core/helpers/i18n');
7
- describe('<Translate />', () => {
8
- const locales = {
9
- greeting: 'Hello {name}'
10
- };
11
- i18n.init({
12
- locales,
13
- lang: 'en-US'
14
- });
15
- describe('Given the component was mounted to the DOM', () => {
16
- let renderedElement;
17
- it('should match snapshot', () => {
18
- renderedElement = mount(/*#__PURE__*/_jsx(I18n.Provider, {
19
- children: /*#__PURE__*/_jsx(I18n.Text, {
20
- string: "greeting",
21
- params: {
22
- name: 'Test'
23
- }
24
- })
25
- }));
26
- expect(renderedElement).toMatchSnapshot();
27
- });
28
- it('should render translated text', () => {
29
- const text = renderedElement.find(I18n.Text).text();
30
- expect(text).toBe('Hello Test');
31
- });
32
- });
33
- });
@@ -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
- });
@@ -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
- });
@@ -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
- });
@@ -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
- });