@shopgate/pwa-ui-shared 7.32.0-beta.9 → 7.32.0
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/DiscountBadge/index.js +1 -1
- package/FavoritesButton/FavoritesButton.d.ts +74 -0
- package/FavoritesButton/FavoritesButton.d.ts.map +1 -0
- package/FavoritesButton/FavoritesButton.js +87 -0
- package/FavoritesButton/connector.d.ts +3 -0
- package/FavoritesButton/connector.d.ts.map +1 -0
- package/FavoritesButton/index.d.ts +3 -0
- package/FavoritesButton/index.d.ts.map +1 -0
- package/FavoritesButton/index.js +1 -134
- package/Glow/index.js +4 -3
- package/NoResults/components/Icon/index.js +4 -1
- package/Price/index.js +11 -4
- package/PriceStriked/index.js +7 -1
- package/package.json +5 -5
- package/AccordionContainer/spec.js +0 -35
- package/ActionButton/spec.js +0 -66
- package/AddToCartButton/spec.js +0 -68
- package/Availability/spec.js +0 -42
- package/Button/spec.js +0 -38
- package/ButtonLink/spec.js +0 -29
- package/Chip/spec.js +0 -27
- package/ContextMenu/spec.js +0 -113
- package/Dialog/components/HtmlContentDialog/spec.js +0 -107
- 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 -94
- package/RippleButton/spec.js +0 -58
- package/Sheet/components/Header/components/SearchBar/spec.js +0 -22
- package/Sheet/components/Header/spec.js +0 -17
- package/Sheet/spec.js +0 -100
- package/TaxDisclaimer/spec.js +0 -44
- package/TextField/spec.js +0 -146
- package/ToggleIcon/spec.js +0 -39
- package/tsconfig.build.json +0 -16
- package/tsconfig.json +0 -3
package/Button/spec.js
DELETED
|
@@ -1,38 +0,0 @@
|
|
|
1
|
-
import trim from 'lodash/trim';
|
|
2
|
-
import React from 'react';
|
|
3
|
-
import { shallow } from 'enzyme';
|
|
4
|
-
import Button from "./index";
|
|
5
|
-
import { jsx as _jsx } from "react/jsx-runtime";
|
|
6
|
-
describe('<Button />', () => {
|
|
7
|
-
it('should render as a regular button if type is omitted', () => {
|
|
8
|
-
const wrapper = shallow(/*#__PURE__*/_jsx(Button, {
|
|
9
|
-
children: "Press me"
|
|
10
|
-
}));
|
|
11
|
-
expect(wrapper).toMatchSnapshot();
|
|
12
|
-
expect(wrapper.render().text()).toEqual('Press me');
|
|
13
|
-
});
|
|
14
|
-
it('should render as a regular button if type is explicitly defined', () => {
|
|
15
|
-
const wrapper = shallow(/*#__PURE__*/_jsx(Button, {
|
|
16
|
-
type: "regular",
|
|
17
|
-
children: "Press me"
|
|
18
|
-
}));
|
|
19
|
-
expect(wrapper).toMatchSnapshot();
|
|
20
|
-
expect(trim(wrapper.prop('className'))).toMatch(/^ui-shared__button\s+/);
|
|
21
|
-
});
|
|
22
|
-
it('should render as a primary button', () => {
|
|
23
|
-
const wrapper = shallow(/*#__PURE__*/_jsx(Button, {
|
|
24
|
-
type: "primary",
|
|
25
|
-
children: "Press me"
|
|
26
|
-
}));
|
|
27
|
-
expect(trim(wrapper.prop('className'))).toMatch(/^ui-shared__button\s+/);
|
|
28
|
-
expect(wrapper).toMatchSnapshot();
|
|
29
|
-
});
|
|
30
|
-
it('should render as a secondary button', () => {
|
|
31
|
-
const wrapper = shallow(/*#__PURE__*/_jsx(Button, {
|
|
32
|
-
type: "secondary",
|
|
33
|
-
children: "Press me"
|
|
34
|
-
}));
|
|
35
|
-
expect(trim(wrapper.prop('className'))).toMatch(/^ui-shared__button\s+/);
|
|
36
|
-
expect(wrapper).toMatchSnapshot();
|
|
37
|
-
});
|
|
38
|
-
});
|
package/ButtonLink/spec.js
DELETED
|
@@ -1,29 +0,0 @@
|
|
|
1
|
-
import React from 'react';
|
|
2
|
-
import { fireEvent, render } from '@testing-library/react';
|
|
3
|
-
import { UnwrappedButtonLink as ButtonLink } from "./index";
|
|
4
|
-
import { jsx as _jsx } from "react/jsx-runtime";
|
|
5
|
-
describe('<ButtonLink>', () => {
|
|
6
|
-
describe('On click action', () => {
|
|
7
|
-
beforeEach(() => {
|
|
8
|
-
jest.useFakeTimers();
|
|
9
|
-
});
|
|
10
|
-
afterEach(() => {
|
|
11
|
-
jest.runOnlyPendingTimers();
|
|
12
|
-
jest.useRealTimers();
|
|
13
|
-
});
|
|
14
|
-
it('should create component and open page on click', () => {
|
|
15
|
-
const mockedNavigate = jest.fn();
|
|
16
|
-
const link = 'https://example.com';
|
|
17
|
-
const component = render(/*#__PURE__*/_jsx(ButtonLink, {
|
|
18
|
-
href: link,
|
|
19
|
-
navigate: mockedNavigate,
|
|
20
|
-
children: "Text inside"
|
|
21
|
-
}));
|
|
22
|
-
expect(component.container.firstChild).toMatchSnapshot();
|
|
23
|
-
fireEvent.click(component.container.querySelector('button'));
|
|
24
|
-
jest.runOnlyPendingTimers();
|
|
25
|
-
expect(mockedNavigate).toHaveBeenCalledTimes(1);
|
|
26
|
-
expect(mockedNavigate).toHaveBeenCalledWith(link);
|
|
27
|
-
});
|
|
28
|
-
});
|
|
29
|
-
});
|
package/Chip/spec.js
DELETED
|
@@ -1,27 +0,0 @@
|
|
|
1
|
-
import React from 'react';
|
|
2
|
-
import { mount } from 'enzyme';
|
|
3
|
-
import Chip from '.';
|
|
4
|
-
import { jsx as _jsx } from "react/jsx-runtime";
|
|
5
|
-
describe('<Chip />', () => {
|
|
6
|
-
it('should render a tag', () => {
|
|
7
|
-
const wrapper = mount(/*#__PURE__*/_jsx(Chip, {
|
|
8
|
-
id: "some-id",
|
|
9
|
-
children: "text"
|
|
10
|
-
}));
|
|
11
|
-
expect(wrapper).toMatchSnapshot();
|
|
12
|
-
expect(wrapper.find('button').length).toEqual(2);
|
|
13
|
-
expect(wrapper.find('button').at(1).text()).toEqual('text');
|
|
14
|
-
});
|
|
15
|
-
});
|
|
16
|
-
describe('<Chip />', () => {
|
|
17
|
-
it('should render a without removable icon', () => {
|
|
18
|
-
const wrapper = mount(/*#__PURE__*/_jsx(Chip, {
|
|
19
|
-
id: "some-id",
|
|
20
|
-
removable: false,
|
|
21
|
-
children: "text"
|
|
22
|
-
}));
|
|
23
|
-
expect(wrapper).toMatchSnapshot();
|
|
24
|
-
expect(wrapper.find('button').length).toEqual(1);
|
|
25
|
-
expect(wrapper.find('button').at(0).text()).toEqual('text');
|
|
26
|
-
});
|
|
27
|
-
});
|
package/ContextMenu/spec.js
DELETED
|
@@ -1,113 +0,0 @@
|
|
|
1
|
-
import React from 'react';
|
|
2
|
-
import { mount, shallow } from 'enzyme';
|
|
3
|
-
import { act } from 'react-dom/test-utils';
|
|
4
|
-
import Backdrop from '@shopgate/pwa-common/components/Backdrop';
|
|
5
|
-
import ContextMenu from "./index";
|
|
6
|
-
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
7
|
-
jest.mock('@shopgate/engage/components');
|
|
8
|
-
jest.mock('@shopgate/engage/a11y/components');
|
|
9
|
-
global.requestAnimationFrame = fn => fn();
|
|
10
|
-
jest.useFakeTimers();
|
|
11
|
-
describe('<ContextMenu />', () => {
|
|
12
|
-
const mockItemAClick = jest.fn();
|
|
13
|
-
const mockItemBClick = jest.fn();
|
|
14
|
-
const numMenuItems = 2;
|
|
15
|
-
describe('Snapshot test', () => {
|
|
16
|
-
it('should match snapshot', () => {
|
|
17
|
-
const wrapper = shallow(/*#__PURE__*/_jsxs(ContextMenu, {
|
|
18
|
-
isOpened: true,
|
|
19
|
-
children: [/*#__PURE__*/_jsx(ContextMenu.Item, {
|
|
20
|
-
onClick: mockItemAClick,
|
|
21
|
-
className: "menu-active-item",
|
|
22
|
-
children: "Item A"
|
|
23
|
-
}), /*#__PURE__*/_jsx(ContextMenu.Item, {
|
|
24
|
-
onClick: mockItemBClick,
|
|
25
|
-
className: "menu-active-item",
|
|
26
|
-
children: "Item B"
|
|
27
|
-
})]
|
|
28
|
-
}));
|
|
29
|
-
expect(wrapper).toMatchSnapshot();
|
|
30
|
-
});
|
|
31
|
-
it('should match snapshot without toggle', () => {
|
|
32
|
-
const wrapper = shallow(/*#__PURE__*/_jsx(ContextMenu, {
|
|
33
|
-
isOpened: true,
|
|
34
|
-
showToggle: false,
|
|
35
|
-
children: /*#__PURE__*/_jsx(ContextMenu.Item, {
|
|
36
|
-
onClick: mockItemAClick,
|
|
37
|
-
className: "menu-active-item",
|
|
38
|
-
children: "Item A"
|
|
39
|
-
})
|
|
40
|
-
}));
|
|
41
|
-
expect(wrapper).toMatchSnapshot();
|
|
42
|
-
});
|
|
43
|
-
});
|
|
44
|
-
describe('Given the component was mounted to the DOM', () => {
|
|
45
|
-
let renderedElement;
|
|
46
|
-
|
|
47
|
-
/**
|
|
48
|
-
* The view component
|
|
49
|
-
*/
|
|
50
|
-
const renderComponent = () => {
|
|
51
|
-
renderedElement = mount(/*#__PURE__*/_jsxs(ContextMenu, {
|
|
52
|
-
children: [/*#__PURE__*/_jsx(ContextMenu.Item, {
|
|
53
|
-
onClick: mockItemAClick,
|
|
54
|
-
children: "Item A"
|
|
55
|
-
}), /*#__PURE__*/_jsx(ContextMenu.Item, {
|
|
56
|
-
onClick: mockItemBClick,
|
|
57
|
-
children: "Item B"
|
|
58
|
-
})]
|
|
59
|
-
}));
|
|
60
|
-
};
|
|
61
|
-
beforeEach(renderComponent);
|
|
62
|
-
it('should match snapshot', () => {
|
|
63
|
-
expect(renderedElement).toMatchSnapshot();
|
|
64
|
-
});
|
|
65
|
-
it('should have active state set to false', () => {
|
|
66
|
-
expect(renderedElement.find('ConnectedReactPortal').prop('isOpened')).toBe(null);
|
|
67
|
-
});
|
|
68
|
-
it('should render the toggle button', () => {
|
|
69
|
-
expect(renderedElement.find('button').length).toBe(1);
|
|
70
|
-
});
|
|
71
|
-
it('should not render any context menu items', () => {
|
|
72
|
-
expect(renderedElement.find(ContextMenu.Item).length).toBe(0);
|
|
73
|
-
});
|
|
74
|
-
describe('Given toggle button gets clicked', () => {
|
|
75
|
-
beforeEach(() => {
|
|
76
|
-
renderedElement.find('button').simulate('click');
|
|
77
|
-
renderedElement.update();
|
|
78
|
-
});
|
|
79
|
-
it('should have active state set to true', () => {
|
|
80
|
-
expect(renderedElement.find('ConnectedReactPortal').prop('isOpened')).toBe(true);
|
|
81
|
-
});
|
|
82
|
-
it('should render the actual context menu w/ items', () => {
|
|
83
|
-
expect(renderedElement.find(ContextMenu.Item).length).toBe(numMenuItems);
|
|
84
|
-
});
|
|
85
|
-
describe('Given the first item gets clicked', () => {
|
|
86
|
-
beforeEach(() => {
|
|
87
|
-
act(() => {
|
|
88
|
-
renderedElement.find(ContextMenu.Item).first().children().find('[data-test-id="contextMenuButton"]').first().simulate('click');
|
|
89
|
-
jest.runAllTimers();
|
|
90
|
-
});
|
|
91
|
-
});
|
|
92
|
-
it('should call the related click handler', () => {
|
|
93
|
-
expect(mockItemAClick).toBeCalled();
|
|
94
|
-
});
|
|
95
|
-
it('should close the context menu', () => {
|
|
96
|
-
renderedElement.update();
|
|
97
|
-
expect(renderedElement.find(ContextMenu.Item).length).toBe(0);
|
|
98
|
-
});
|
|
99
|
-
});
|
|
100
|
-
describe('Given the backdrop gets clicked', () => {
|
|
101
|
-
beforeEach(() => {
|
|
102
|
-
renderedElement.find(Backdrop).children().find('[onClick]').simulate('click');
|
|
103
|
-
});
|
|
104
|
-
it('should have active state reset to false', () => {
|
|
105
|
-
expect(renderedElement.find('ConnectedReactPortal').prop('isOpened')).toBe(false);
|
|
106
|
-
});
|
|
107
|
-
it('should close the context menu', () => {
|
|
108
|
-
expect(renderedElement.find(ContextMenu.Item).length).toBe(0);
|
|
109
|
-
});
|
|
110
|
-
});
|
|
111
|
-
});
|
|
112
|
-
});
|
|
113
|
-
});
|
|
@@ -1,107 +0,0 @@
|
|
|
1
|
-
import React from 'react';
|
|
2
|
-
import { shallow } from 'enzyme';
|
|
3
|
-
import HtmlContentDialog from "./index";
|
|
4
|
-
import { jsx as _jsx } from "react/jsx-runtime";
|
|
5
|
-
const message = '<p><i>This is a html message.</i></p>';
|
|
6
|
-
const title = 'This is the title.';
|
|
7
|
-
jest.mock('@shopgate/engage/a11y/components');
|
|
8
|
-
jest.mock('@shopgate/engage/components', () => {
|
|
9
|
-
const mockReact = jest.requireActual('react');
|
|
10
|
-
function Text({
|
|
11
|
-
string
|
|
12
|
-
}) {
|
|
13
|
-
return mockReact.createElement('span', null, string);
|
|
14
|
-
}
|
|
15
|
-
Text.propTypes = {
|
|
16
|
-
params: () => null
|
|
17
|
-
};
|
|
18
|
-
Text.defaultProps = {
|
|
19
|
-
params: {}
|
|
20
|
-
};
|
|
21
|
-
const I18n = {
|
|
22
|
-
Text
|
|
23
|
-
};
|
|
24
|
-
function Ellipsis({
|
|
25
|
-
children
|
|
26
|
-
}) {
|
|
27
|
-
return mockReact.createElement('span', null, children);
|
|
28
|
-
}
|
|
29
|
-
function Button({
|
|
30
|
-
children,
|
|
31
|
-
onClick,
|
|
32
|
-
disabled,
|
|
33
|
-
className
|
|
34
|
-
}) {
|
|
35
|
-
return mockReact.createElement('button', {
|
|
36
|
-
onClick,
|
|
37
|
-
disabled,
|
|
38
|
-
className
|
|
39
|
-
}, children);
|
|
40
|
-
}
|
|
41
|
-
function Typography({
|
|
42
|
-
children
|
|
43
|
-
}) {
|
|
44
|
-
return mockReact.createElement('span', null, children);
|
|
45
|
-
}
|
|
46
|
-
return {
|
|
47
|
-
I18n,
|
|
48
|
-
Ellipsis,
|
|
49
|
-
Button,
|
|
50
|
-
Typography
|
|
51
|
-
};
|
|
52
|
-
});
|
|
53
|
-
describe('<HtmlContentDialog />', () => {
|
|
54
|
-
it('should render with minimal props', () => {
|
|
55
|
-
const wrapper = shallow(/*#__PURE__*/_jsx(HtmlContentDialog, {
|
|
56
|
-
message: message,
|
|
57
|
-
actions: []
|
|
58
|
-
}));
|
|
59
|
-
expect(wrapper).toMatchSnapshot();
|
|
60
|
-
expect(wrapper.html()).toMatch(message);
|
|
61
|
-
});
|
|
62
|
-
it('should render with title and html message', () => {
|
|
63
|
-
const wrapper = shallow(/*#__PURE__*/_jsx(HtmlContentDialog, {
|
|
64
|
-
title: title,
|
|
65
|
-
message: message,
|
|
66
|
-
actions: []
|
|
67
|
-
}));
|
|
68
|
-
expect(wrapper).toMatchSnapshot();
|
|
69
|
-
expect(wrapper.html()).toMatch(title);
|
|
70
|
-
});
|
|
71
|
-
it('should render with title, html message and messageParams', () => {
|
|
72
|
-
const wrapper = shallow(/*#__PURE__*/_jsx(HtmlContentDialog, {
|
|
73
|
-
title: title,
|
|
74
|
-
message: "Message with {name}",
|
|
75
|
-
params: {
|
|
76
|
-
name: 'Placeholder'
|
|
77
|
-
},
|
|
78
|
-
actions: []
|
|
79
|
-
}));
|
|
80
|
-
expect(wrapper).toMatchSnapshot();
|
|
81
|
-
});
|
|
82
|
-
it('should render the actions', () => {
|
|
83
|
-
const actions = [{
|
|
84
|
-
label: 'fooAction',
|
|
85
|
-
action: () => {}
|
|
86
|
-
}];
|
|
87
|
-
const wrapper = shallow(/*#__PURE__*/_jsx(HtmlContentDialog, {
|
|
88
|
-
title: title,
|
|
89
|
-
message: message,
|
|
90
|
-
actions: actions
|
|
91
|
-
}));
|
|
92
|
-
expect(wrapper).toMatchSnapshot();
|
|
93
|
-
expect(wrapper.html()).toMatch(actions[0].label);
|
|
94
|
-
});
|
|
95
|
-
it('should pass title through', () => {
|
|
96
|
-
const customTitle = /*#__PURE__*/_jsx("div", {
|
|
97
|
-
children: "Title"
|
|
98
|
-
});
|
|
99
|
-
const wrapper = shallow(/*#__PURE__*/_jsx(HtmlContentDialog, {
|
|
100
|
-
title: customTitle,
|
|
101
|
-
message: message,
|
|
102
|
-
params: {},
|
|
103
|
-
actions: []
|
|
104
|
-
}));
|
|
105
|
-
expect(wrapper.find('BasicDialog').prop('title')).toEqual(customTitle);
|
|
106
|
-
});
|
|
107
|
-
});
|
|
@@ -1,105 +0,0 @@
|
|
|
1
|
-
import React from 'react';
|
|
2
|
-
import { mount } from 'enzyme';
|
|
3
|
-
import { render, screen } from '@testing-library/react';
|
|
4
|
-
import '@testing-library/jest-dom';
|
|
5
|
-
import PipelineErrorDialog from "./index";
|
|
6
|
-
import { jsx as _jsx } from "react/jsx-runtime";
|
|
7
|
-
jest.mock('@shopgate/engage/a11y/components');
|
|
8
|
-
describe('<PipelineErrorDialog />', () => {
|
|
9
|
-
const defaultParams = {
|
|
10
|
-
code: '123',
|
|
11
|
-
message: 'Error message',
|
|
12
|
-
pipeline: 'fakePipeline',
|
|
13
|
-
request: {}
|
|
14
|
-
};
|
|
15
|
-
it('should render with minimal props', () => {
|
|
16
|
-
const wrapper = mount(/*#__PURE__*/_jsx(PipelineErrorDialog, {
|
|
17
|
-
actions: [],
|
|
18
|
-
params: defaultParams
|
|
19
|
-
}));
|
|
20
|
-
expect(wrapper).toMatchSnapshot();
|
|
21
|
-
});
|
|
22
|
-
it('should show a custom message if a message is is provided', () => {
|
|
23
|
-
const message = 'Custom message';
|
|
24
|
-
const wrapper = mount(/*#__PURE__*/_jsx(PipelineErrorDialog, {
|
|
25
|
-
actions: [],
|
|
26
|
-
message: message,
|
|
27
|
-
params: defaultParams
|
|
28
|
-
}));
|
|
29
|
-
expect(wrapper).toMatchSnapshot();
|
|
30
|
-
expect(wrapper.html()).toMatch(message);
|
|
31
|
-
});
|
|
32
|
-
it('should switch modes on tap', () => {
|
|
33
|
-
const wrapper = mount(/*#__PURE__*/_jsx(PipelineErrorDialog, {
|
|
34
|
-
actions: [],
|
|
35
|
-
params: defaultParams
|
|
36
|
-
}));
|
|
37
|
-
const numTaps = 10;
|
|
38
|
-
const clickElement = wrapper.find('div[onClick]');
|
|
39
|
-
const devMarker = 'Pipeline:';
|
|
40
|
-
|
|
41
|
-
// Dev mode should be disabled.
|
|
42
|
-
for (let i = 0; i < numTaps; i += 1) {
|
|
43
|
-
expect(wrapper.text()).not.toContain(devMarker);
|
|
44
|
-
clickElement.simulate('click');
|
|
45
|
-
}
|
|
46
|
-
expect(wrapper.text()).toContain(devMarker);
|
|
47
|
-
|
|
48
|
-
// Dev mode should be enabled until 10 more taps.
|
|
49
|
-
for (let i = 0; i < numTaps - 1; i += 1) {
|
|
50
|
-
expect(wrapper.text()).toContain(devMarker);
|
|
51
|
-
clickElement.simulate('click');
|
|
52
|
-
}
|
|
53
|
-
clickElement.simulate('click');
|
|
54
|
-
expect(wrapper.text()).not.toContain(devMarker);
|
|
55
|
-
});
|
|
56
|
-
it('should open directly in developer detail mode when params.openWithDetails is set', () => {
|
|
57
|
-
render(/*#__PURE__*/_jsx(PipelineErrorDialog, {
|
|
58
|
-
actions: [],
|
|
59
|
-
params: {
|
|
60
|
-
...defaultParams,
|
|
61
|
-
openWithDetails: true
|
|
62
|
-
}
|
|
63
|
-
}));
|
|
64
|
-
|
|
65
|
-
// Developer detail view is shown immediately, without any tapping.
|
|
66
|
-
expect(screen.getByText('Pipeline:')).toBeInTheDocument();
|
|
67
|
-
expect(screen.getByText('Code:')).toBeInTheDocument();
|
|
68
|
-
expect(screen.getByText(/fakePipeline/)).toBeInTheDocument();
|
|
69
|
-
});
|
|
70
|
-
it('should not switch modes if tapped too slow', () => {
|
|
71
|
-
jest.useFakeTimers();
|
|
72
|
-
const wrapper = mount(/*#__PURE__*/_jsx(PipelineErrorDialog, {
|
|
73
|
-
actions: [],
|
|
74
|
-
params: defaultParams
|
|
75
|
-
}));
|
|
76
|
-
const numTaps = 10;
|
|
77
|
-
const numTapsUntilTimeout = Math.round(numTaps / 2);
|
|
78
|
-
const clickElement = wrapper.find('div[onClick]');
|
|
79
|
-
const devMarker = 'Pipeline:';
|
|
80
|
-
expect(wrapper.text()).not.toContain(devMarker);
|
|
81
|
-
|
|
82
|
-
/**
|
|
83
|
-
* Simulates multiple tap events.
|
|
84
|
-
* @param {number} amount The number of tap events to simulate in a row.
|
|
85
|
-
*/
|
|
86
|
-
const tapOnElement = amount => {
|
|
87
|
-
if (amount > 0) {
|
|
88
|
-
clickElement.simulate('click');
|
|
89
|
-
tapOnElement(amount - 1);
|
|
90
|
-
}
|
|
91
|
-
};
|
|
92
|
-
|
|
93
|
-
// Tap a few times.
|
|
94
|
-
tapOnElement(numTapsUntilTimeout);
|
|
95
|
-
|
|
96
|
-
// Trigger a timeout (user was too slow).
|
|
97
|
-
jest.runAllTimers();
|
|
98
|
-
|
|
99
|
-
// Tap the remaining times.
|
|
100
|
-
tapOnElement(numTaps - numTapsUntilTimeout);
|
|
101
|
-
expect(wrapper.text()).not.toContain(devMarker);
|
|
102
|
-
tapOnElement(numTapsUntilTimeout);
|
|
103
|
-
expect(wrapper.text()).toContain(devMarker);
|
|
104
|
-
});
|
|
105
|
-
});
|
|
@@ -1,62 +0,0 @@
|
|
|
1
|
-
import React from 'react';
|
|
2
|
-
import { shallow } from 'enzyme';
|
|
3
|
-
import TextMessageDialog from "./index";
|
|
4
|
-
import { jsx as _jsx } from "react/jsx-runtime";
|
|
5
|
-
const message = 'This is the message.';
|
|
6
|
-
const title = 'This is the title.';
|
|
7
|
-
jest.mock('@shopgate/engage/a11y/components');
|
|
8
|
-
describe('<TextMessageDialog />', () => {
|
|
9
|
-
it('should render with minimal props', () => {
|
|
10
|
-
const wrapper = shallow(/*#__PURE__*/_jsx(TextMessageDialog, {
|
|
11
|
-
message: message,
|
|
12
|
-
actions: []
|
|
13
|
-
}));
|
|
14
|
-
expect(wrapper).toMatchSnapshot();
|
|
15
|
-
expect(wrapper.html()).toMatch(message);
|
|
16
|
-
});
|
|
17
|
-
it('should render with title and message', () => {
|
|
18
|
-
const wrapper = shallow(/*#__PURE__*/_jsx(TextMessageDialog, {
|
|
19
|
-
title: title,
|
|
20
|
-
message: message,
|
|
21
|
-
actions: []
|
|
22
|
-
}));
|
|
23
|
-
expect(wrapper).toMatchSnapshot();
|
|
24
|
-
expect(wrapper.html()).toMatch(title);
|
|
25
|
-
});
|
|
26
|
-
it('should render with title, message and messageParams', () => {
|
|
27
|
-
const wrapper = shallow(/*#__PURE__*/_jsx(TextMessageDialog, {
|
|
28
|
-
title: title,
|
|
29
|
-
message: "Message with {name}",
|
|
30
|
-
params: {
|
|
31
|
-
name: 'Placeholder'
|
|
32
|
-
},
|
|
33
|
-
actions: []
|
|
34
|
-
}));
|
|
35
|
-
expect(wrapper).toMatchSnapshot();
|
|
36
|
-
});
|
|
37
|
-
it('should render the actions', () => {
|
|
38
|
-
const actions = [{
|
|
39
|
-
label: 'fooAction',
|
|
40
|
-
action: () => {}
|
|
41
|
-
}];
|
|
42
|
-
const wrapper = shallow(/*#__PURE__*/_jsx(TextMessageDialog, {
|
|
43
|
-
title: title,
|
|
44
|
-
message: message,
|
|
45
|
-
actions: actions
|
|
46
|
-
}));
|
|
47
|
-
expect(wrapper).toMatchSnapshot();
|
|
48
|
-
expect(wrapper.html()).toMatch(actions[0].label);
|
|
49
|
-
});
|
|
50
|
-
it('should pass title through', () => {
|
|
51
|
-
const customTitle = /*#__PURE__*/_jsx("div", {
|
|
52
|
-
children: "Title"
|
|
53
|
-
});
|
|
54
|
-
const wrapper = shallow(/*#__PURE__*/_jsx(TextMessageDialog, {
|
|
55
|
-
title: customTitle,
|
|
56
|
-
message: message,
|
|
57
|
-
params: {},
|
|
58
|
-
actions: []
|
|
59
|
-
}));
|
|
60
|
-
expect(wrapper.find('BasicDialog').prop('title')).toEqual(customTitle);
|
|
61
|
-
});
|
|
62
|
-
});
|
|
@@ -1,55 +0,0 @@
|
|
|
1
|
-
import React from 'react';
|
|
2
|
-
import { shallow } from 'enzyme';
|
|
3
|
-
import { UnwrappedVariantSelectModal as VariantSelectModal } from "./index";
|
|
4
|
-
import { jsx as _jsx } from "react/jsx-runtime";
|
|
5
|
-
const message = 'This is the message.';
|
|
6
|
-
const title = 'This is the title.';
|
|
7
|
-
jest.mock('@shopgate/engage/a11y/components');
|
|
8
|
-
describe('<VariantSelectModal />', () => {
|
|
9
|
-
it('should render with minimal props', () => {
|
|
10
|
-
const wrapper = shallow(/*#__PURE__*/_jsx(VariantSelectModal, {
|
|
11
|
-
message: message,
|
|
12
|
-
actions: [],
|
|
13
|
-
navigate: () => {}
|
|
14
|
-
}));
|
|
15
|
-
expect(wrapper).toMatchSnapshot();
|
|
16
|
-
expect(wrapper.html()).toMatch(message);
|
|
17
|
-
});
|
|
18
|
-
it('should render the actions', () => {
|
|
19
|
-
const mockConfirm = jest.fn();
|
|
20
|
-
const mockNavigate = jest.fn();
|
|
21
|
-
/**
|
|
22
|
-
* Mocks named function
|
|
23
|
-
*/
|
|
24
|
-
const onConfirm = () => {
|
|
25
|
-
mockConfirm();
|
|
26
|
-
};
|
|
27
|
-
const actions = [{
|
|
28
|
-
label: 'confirm',
|
|
29
|
-
action: onConfirm
|
|
30
|
-
}, {
|
|
31
|
-
label: 'dismiss',
|
|
32
|
-
action: () => {}
|
|
33
|
-
}];
|
|
34
|
-
const params = {
|
|
35
|
-
productId: 'product_1'
|
|
36
|
-
};
|
|
37
|
-
const mockedProps = {
|
|
38
|
-
message,
|
|
39
|
-
title,
|
|
40
|
-
params,
|
|
41
|
-
actions: [].concat(actions),
|
|
42
|
-
navigate: mockNavigate
|
|
43
|
-
};
|
|
44
|
-
const wrapper = shallow(/*#__PURE__*/_jsx(VariantSelectModal, {
|
|
45
|
-
...mockedProps
|
|
46
|
-
}));
|
|
47
|
-
expect(wrapper).toMatchSnapshot();
|
|
48
|
-
const reordered = wrapper.find('BasicDialog').props().actions;
|
|
49
|
-
const last = reordered.slice(-1)[0];
|
|
50
|
-
expect(last.label).toEqual(actions[0].label);
|
|
51
|
-
last.action();
|
|
52
|
-
expect(mockConfirm).toHaveBeenCalledTimes(1);
|
|
53
|
-
expect(mockNavigate).toHaveBeenCalledTimes(1);
|
|
54
|
-
});
|
|
55
|
-
});
|
package/Dialog/spec.js
DELETED
|
@@ -1,84 +0,0 @@
|
|
|
1
|
-
import React from 'react';
|
|
2
|
-
import { shallow, ReactWrapper } from 'enzyme';
|
|
3
|
-
import { MODAL_PIPELINE_ERROR } from '@shopgate/pwa-common/constants/ModalTypes';
|
|
4
|
-
import { MODAL_VARIANT_SELECT } from "./constants";
|
|
5
|
-
import Dialog from "./index";
|
|
6
|
-
import { jsx as _jsx } from "react/jsx-runtime";
|
|
7
|
-
jest.mock("./components/VariantSelectModal", () => {
|
|
8
|
-
/**
|
|
9
|
-
* VariantSelectModal mock.
|
|
10
|
-
* @return {JSX}
|
|
11
|
-
*/
|
|
12
|
-
const VariantSelectModal = () => /*#__PURE__*/_jsx("div", {});
|
|
13
|
-
return VariantSelectModal;
|
|
14
|
-
});
|
|
15
|
-
jest.mock('@shopgate/engage/components');
|
|
16
|
-
describe('<Dialog />', () => {
|
|
17
|
-
it('should render without props', () => {
|
|
18
|
-
const wrapper = shallow(/*#__PURE__*/_jsx(Dialog, {
|
|
19
|
-
modal: {
|
|
20
|
-
message: 'msg'
|
|
21
|
-
}
|
|
22
|
-
}));
|
|
23
|
-
expect(wrapper).toMatchSnapshot();
|
|
24
|
-
expect(wrapper.find('TextMessageDialog').length).toBe(1);
|
|
25
|
-
});
|
|
26
|
-
it('should render BasicDialog when no message given', () => {
|
|
27
|
-
const wrapper = shallow(/*#__PURE__*/_jsx(Dialog, {
|
|
28
|
-
modal: {
|
|
29
|
-
message: null
|
|
30
|
-
}
|
|
31
|
-
}));
|
|
32
|
-
expect(wrapper).toMatchSnapshot();
|
|
33
|
-
expect(wrapper.find('BasicDialog').length).toBe(1);
|
|
34
|
-
});
|
|
35
|
-
it('should render a special dialog', () => {
|
|
36
|
-
const params = {
|
|
37
|
-
errorCode: '',
|
|
38
|
-
message: '',
|
|
39
|
-
pipeline: '',
|
|
40
|
-
request: {}
|
|
41
|
-
};
|
|
42
|
-
const wrapper = shallow(/*#__PURE__*/_jsx(Dialog, {
|
|
43
|
-
modal: {
|
|
44
|
-
type: MODAL_PIPELINE_ERROR,
|
|
45
|
-
params
|
|
46
|
-
}
|
|
47
|
-
}));
|
|
48
|
-
expect(wrapper).toMatchSnapshot();
|
|
49
|
-
expect(wrapper.find('DefaultDialog').length).toBe(0);
|
|
50
|
-
expect(wrapper.find('PipelineErrorDialog').length).toBe(1);
|
|
51
|
-
});
|
|
52
|
-
it('should render variant select dialog', () => {
|
|
53
|
-
const params = {
|
|
54
|
-
productId: 'product_1'
|
|
55
|
-
};
|
|
56
|
-
const wrapper = shallow(/*#__PURE__*/_jsx(Dialog, {
|
|
57
|
-
modal: {
|
|
58
|
-
message: 'Test',
|
|
59
|
-
type: MODAL_VARIANT_SELECT,
|
|
60
|
-
params
|
|
61
|
-
}
|
|
62
|
-
}));
|
|
63
|
-
expect(wrapper).toMatchSnapshot();
|
|
64
|
-
expect(wrapper.find('DefaultDialog').length).toBe(0);
|
|
65
|
-
expect(wrapper.find('VariantSelectModal').length).toBe(1);
|
|
66
|
-
});
|
|
67
|
-
it('should convert title into translatable element', () => {
|
|
68
|
-
const title = 'translate.me';
|
|
69
|
-
const titleParams = {
|
|
70
|
-
foo: 'bar'
|
|
71
|
-
};
|
|
72
|
-
|
|
73
|
-
// eslint-disable-next-line extra-rules/no-single-line-objects
|
|
74
|
-
const wrapper = shallow(/*#__PURE__*/_jsx(Dialog, {
|
|
75
|
-
modal: {
|
|
76
|
-
title,
|
|
77
|
-
titleParams
|
|
78
|
-
}
|
|
79
|
-
}));
|
|
80
|
-
const i18n = new ReactWrapper(wrapper.find('BasicDialog').prop('title'));
|
|
81
|
-
expect(i18n.prop('string')).toEqual(title);
|
|
82
|
-
expect(i18n.prop('params')).toEqual(titleParams);
|
|
83
|
-
});
|
|
84
|
-
});
|
package/DiscountBadge/spec.js
DELETED
|
@@ -1,20 +0,0 @@
|
|
|
1
|
-
import React from 'react';
|
|
2
|
-
import { render } from '@testing-library/react';
|
|
3
|
-
import DiscountBadge from "./index";
|
|
4
|
-
import { jsx as _jsx } from "react/jsx-runtime";
|
|
5
|
-
jest.mock('@shopgate/engage/components');
|
|
6
|
-
describe('<DiscountBadge />', () => {
|
|
7
|
-
it('should render the text', () => {
|
|
8
|
-
const wrapper = render(/*#__PURE__*/_jsx(DiscountBadge, {
|
|
9
|
-
text: "foo"
|
|
10
|
-
}));
|
|
11
|
-
expect(wrapper.asFragment()).toMatchSnapshot();
|
|
12
|
-
});
|
|
13
|
-
it('should render the text and discount', () => {
|
|
14
|
-
const wrapper = render(/*#__PURE__*/_jsx(DiscountBadge, {
|
|
15
|
-
text: "SAVE {0}%",
|
|
16
|
-
discount: 20
|
|
17
|
-
}));
|
|
18
|
-
expect(wrapper.asFragment()).toMatchSnapshot();
|
|
19
|
-
});
|
|
20
|
-
});
|