@shopgate/pwa-ui-shared 7.31.5 → 7.31.6-beta.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/package.json +5 -5
- package/AccordionContainer/spec.js +0 -35
- package/ActionButton/spec.js +0 -69
- package/AddToCartButton/spec.js +0 -68
- package/Availability/spec.js +0 -42
- package/Button/spec.js +0 -38
- package/ButtonLink/spec.js +0 -25
- package/Chip/spec.js +0 -27
- package/ContextMenu/spec.js +0 -113
- package/Dialog/components/HtmlContentDialog/spec.js +0 -101
- package/Dialog/components/PipelineErrorDialog/spec.js +0 -105
- package/Dialog/components/TextMessageDialog/spec.js +0 -62
- package/Dialog/components/VariantSelectModal/spec.js +0 -55
- package/Dialog/spec.js +0 -84
- package/DiscountBadge/spec.js +0 -20
- package/FavoritesButton/spec.js +0 -131
- package/Form/Builder/classes/ActionListener/spec.js +0 -323
- package/Form/Builder/spec.js +0 -309
- package/Form/InfoField/spec.js +0 -12
- package/Form/Password/spec.js +0 -39
- package/Form/RadioGroup/spec.js +0 -97
- package/Form/Select/spec.js +0 -39
- package/Form/SelectContextChoices/spec.js +0 -36
- package/Form/TextField/spec.js +0 -124
- package/FormElement/spec.js +0 -68
- package/Glow/spec.js +0 -14
- package/IndicatorCircle/spec.js +0 -26
- package/PlaceholderLabel/spec.js +0 -26
- package/PlaceholderParagraph/spec.js +0 -26
- package/ProgressBar/spec.js +0 -14
- package/RadioButton/spec.js +0 -22
- package/RatingStars/spec.js +0 -91
- package/RippleButton/spec.js +0 -58
- package/Sheet/components/Header/components/SearchBar/spec.js +0 -22
- package/Sheet/components/Header/spec.js +0 -15
- package/Sheet/spec.js +0 -100
- package/TaxDisclaimer/spec.js +0 -43
- package/TextField/spec.js +0 -146
- package/ToggleIcon/spec.js +0 -39
- package/tsconfig.build.json +0 -16
- package/tsconfig.json +0 -3
package/package.json
CHANGED
|
@@ -1,16 +1,16 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@shopgate/pwa-ui-shared",
|
|
3
|
-
"version": "7.31.
|
|
3
|
+
"version": "7.31.6-beta.1",
|
|
4
4
|
"description": "Shopgate's shared UI components.",
|
|
5
5
|
"main": "index.js",
|
|
6
6
|
"license": "Apache-2.0",
|
|
7
7
|
"dependencies": {
|
|
8
|
-
"@shopgate/pwa-ui-ios": "7.31.
|
|
9
|
-
"@shopgate/pwa-ui-material": "7.31.
|
|
8
|
+
"@shopgate/pwa-ui-ios": "7.31.6-beta.1",
|
|
9
|
+
"@shopgate/pwa-ui-material": "7.31.6-beta.1"
|
|
10
10
|
},
|
|
11
11
|
"devDependencies": {
|
|
12
|
-
"@shopgate/pwa-common": "7.31.
|
|
13
|
-
"@shopgate/pwa-common-commerce": "7.31.
|
|
12
|
+
"@shopgate/pwa-common": "7.31.6-beta.1",
|
|
13
|
+
"@shopgate/pwa-common-commerce": "7.31.6-beta.1",
|
|
14
14
|
"classnames": "2.5.1",
|
|
15
15
|
"react": "^17.0.2"
|
|
16
16
|
},
|
|
@@ -1,35 +0,0 @@
|
|
|
1
|
-
import React from 'react';
|
|
2
|
-
import { shallow } from 'enzyme';
|
|
3
|
-
import AccordionContainer from "./index";
|
|
4
|
-
|
|
5
|
-
/**
|
|
6
|
-
* @returns {JSX}
|
|
7
|
-
*/
|
|
8
|
-
import { jsx as _jsx } from "react/jsx-runtime";
|
|
9
|
-
const Child = () => /*#__PURE__*/_jsx("div", {});
|
|
10
|
-
describe('<AccordionContainer />', () => {
|
|
11
|
-
it('should render children with props', () => {
|
|
12
|
-
const wrapper = shallow(/*#__PURE__*/_jsx(AccordionContainer, {
|
|
13
|
-
children: props => /*#__PURE__*/_jsx(Child, {
|
|
14
|
-
...props
|
|
15
|
-
})
|
|
16
|
-
}));
|
|
17
|
-
const props = wrapper.find('Child').props();
|
|
18
|
-
expect(wrapper).toMatchSnapshot();
|
|
19
|
-
expect(props.open).toEqual(false);
|
|
20
|
-
expect(typeof props.handleOpen).toEqual('function');
|
|
21
|
-
expect(typeof props.handleClose).toEqual('function');
|
|
22
|
-
});
|
|
23
|
-
it('should update children props when state changes', () => {
|
|
24
|
-
const wrapper = shallow(/*#__PURE__*/_jsx(AccordionContainer, {
|
|
25
|
-
children: props => /*#__PURE__*/_jsx(Child, {
|
|
26
|
-
...props
|
|
27
|
-
})
|
|
28
|
-
}));
|
|
29
|
-
wrapper.setState({
|
|
30
|
-
open: true
|
|
31
|
-
});
|
|
32
|
-
expect(wrapper).toMatchSnapshot();
|
|
33
|
-
expect(wrapper.find('Child').props().open).toEqual(true);
|
|
34
|
-
});
|
|
35
|
-
});
|
package/ActionButton/spec.js
DELETED
|
@@ -1,69 +0,0 @@
|
|
|
1
|
-
import React from 'react';
|
|
2
|
-
import { shallow } from 'enzyme';
|
|
3
|
-
import IndicatorCircle from "../IndicatorCircle";
|
|
4
|
-
import RippleButton from "../RippleButton";
|
|
5
|
-
import ActionButton from "./index";
|
|
6
|
-
import { jsx as _jsx } from "react/jsx-runtime";
|
|
7
|
-
describe('<ActionButton />', () => {
|
|
8
|
-
let renderedElement;
|
|
9
|
-
let mockOnClick;
|
|
10
|
-
jest.useFakeTimers();
|
|
11
|
-
|
|
12
|
-
/**
|
|
13
|
-
* Renders the component.
|
|
14
|
-
* @param {Object} props The component props.
|
|
15
|
-
*/
|
|
16
|
-
const renderComponent = (props = {}) => {
|
|
17
|
-
renderedElement = shallow(/*#__PURE__*/_jsx(ActionButton, {
|
|
18
|
-
...props,
|
|
19
|
-
children: "Action Button"
|
|
20
|
-
}));
|
|
21
|
-
};
|
|
22
|
-
describe('Given the component was mounted to the DOM', () => {
|
|
23
|
-
beforeEach(() => {
|
|
24
|
-
mockOnClick = jest.fn();
|
|
25
|
-
renderComponent({
|
|
26
|
-
onClick: mockOnClick
|
|
27
|
-
});
|
|
28
|
-
});
|
|
29
|
-
it('should match snapshot', () => {
|
|
30
|
-
expect(renderedElement).toMatchSnapshot();
|
|
31
|
-
});
|
|
32
|
-
it('should not show the loading indicator by default', () => {
|
|
33
|
-
const indicator = renderedElement.find(IndicatorCircle);
|
|
34
|
-
expect(indicator.length).toBe(0);
|
|
35
|
-
});
|
|
36
|
-
describe('Given the loading prop is set to true', () => {
|
|
37
|
-
beforeEach(() => {
|
|
38
|
-
renderedElement.setProps({
|
|
39
|
-
loading: true
|
|
40
|
-
});
|
|
41
|
-
});
|
|
42
|
-
it('should match snapshot', () => {
|
|
43
|
-
expect(renderedElement).toMatchSnapshot();
|
|
44
|
-
});
|
|
45
|
-
it('should show the loading indicator', () => {
|
|
46
|
-
const indicator = renderedElement.find(IndicatorCircle);
|
|
47
|
-
expect(indicator.length).toBe(1);
|
|
48
|
-
});
|
|
49
|
-
});
|
|
50
|
-
describe('Given the component gets clicked', () => {
|
|
51
|
-
let timeoutSpy;
|
|
52
|
-
beforeEach(() => {
|
|
53
|
-
timeoutSpy = jest.spyOn(global, 'setTimeout');
|
|
54
|
-
renderedElement.find(RippleButton).simulate('click');
|
|
55
|
-
});
|
|
56
|
-
afterEach(() => {
|
|
57
|
-
timeoutSpy.mockRestore();
|
|
58
|
-
});
|
|
59
|
-
it('should use setTimeout for delaying the onClick handler', () => {
|
|
60
|
-
expect(timeoutSpy).toHaveBeenCalledTimes(1);
|
|
61
|
-
expect(timeoutSpy.mock.calls[0][1]).toBe(ActionButton.clickDelay);
|
|
62
|
-
});
|
|
63
|
-
it('should eventually call the onClick handler', () => {
|
|
64
|
-
jest.runOnlyPendingTimers();
|
|
65
|
-
expect(mockOnClick).toHaveBeenCalledTimes(1);
|
|
66
|
-
});
|
|
67
|
-
});
|
|
68
|
-
});
|
|
69
|
-
});
|
package/AddToCartButton/spec.js
DELETED
|
@@ -1,68 +0,0 @@
|
|
|
1
|
-
import React from 'react';
|
|
2
|
-
import { mount } from 'enzyme';
|
|
3
|
-
import { act } from 'react-dom/test-utils';
|
|
4
|
-
import AddToCartButton from "./index";
|
|
5
|
-
|
|
6
|
-
/**
|
|
7
|
-
* Flushes the promise queue.
|
|
8
|
-
* @returns {Promise}
|
|
9
|
-
*/
|
|
10
|
-
import { jsx as _jsx } from "react/jsx-runtime";
|
|
11
|
-
const flushMicrotasks = () => Promise.resolve();
|
|
12
|
-
describe('<AddToCartButton />', () => {
|
|
13
|
-
it('should render in loading state and should not be clickable', () => {
|
|
14
|
-
const spy = jest.fn(() => Promise.resolve());
|
|
15
|
-
const wrapper = mount(/*#__PURE__*/_jsx(AddToCartButton, {
|
|
16
|
-
onClick: spy,
|
|
17
|
-
isLoading: true,
|
|
18
|
-
isOrderable: true,
|
|
19
|
-
isDisabled: false
|
|
20
|
-
}));
|
|
21
|
-
|
|
22
|
-
// Click shouldn’t fire when loading
|
|
23
|
-
wrapper.find('button').prop('onClick')();
|
|
24
|
-
expect(wrapper).toMatchSnapshot();
|
|
25
|
-
expect(spy).toHaveBeenCalledTimes(0);
|
|
26
|
-
});
|
|
27
|
-
it('should render with checkmark icon and should not be clickable the second time', async () => {
|
|
28
|
-
const spy = jest.fn(() => Promise.resolve());
|
|
29
|
-
const wrapper = mount(/*#__PURE__*/_jsx(AddToCartButton, {
|
|
30
|
-
onClick: spy,
|
|
31
|
-
isLoading: false,
|
|
32
|
-
isOrderable: true,
|
|
33
|
-
isDisabled: false
|
|
34
|
-
}));
|
|
35
|
-
|
|
36
|
-
// First click triggers async work
|
|
37
|
-
await act(async () => {
|
|
38
|
-
wrapper.find('button').prop('onClick')();
|
|
39
|
-
await flushMicrotasks();
|
|
40
|
-
});
|
|
41
|
-
wrapper.update();
|
|
42
|
-
|
|
43
|
-
// Second click should be ignored
|
|
44
|
-
await act(async () => {
|
|
45
|
-
wrapper.find('button').prop('onClick')();
|
|
46
|
-
await flushMicrotasks();
|
|
47
|
-
});
|
|
48
|
-
wrapper.update();
|
|
49
|
-
expect(wrapper).toMatchSnapshot();
|
|
50
|
-
expect(spy).toHaveBeenCalledTimes(1);
|
|
51
|
-
});
|
|
52
|
-
it('should render with cart icon and should be clickable', async () => {
|
|
53
|
-
const spy = jest.fn(() => Promise.resolve());
|
|
54
|
-
const wrapper = mount(/*#__PURE__*/_jsx(AddToCartButton, {
|
|
55
|
-
onClick: spy,
|
|
56
|
-
isLoading: false,
|
|
57
|
-
isOrderable: true,
|
|
58
|
-
isDisabled: false
|
|
59
|
-
}));
|
|
60
|
-
await act(async () => {
|
|
61
|
-
wrapper.find('button').prop('onClick')();
|
|
62
|
-
await flushMicrotasks();
|
|
63
|
-
});
|
|
64
|
-
wrapper.update();
|
|
65
|
-
expect(wrapper).toMatchSnapshot();
|
|
66
|
-
expect(spy).toHaveBeenCalledTimes(1);
|
|
67
|
-
});
|
|
68
|
-
});
|
package/Availability/spec.js
DELETED
|
@@ -1,42 +0,0 @@
|
|
|
1
|
-
import React from 'react';
|
|
2
|
-
import { mount } from 'enzyme';
|
|
3
|
-
import { AVAILABILITY_STATE_OK, AVAILABILITY_STATE_WARNING, AVAILABILITY_STATE_ALERT } from '@shopgate/pwa-common-commerce/product/constants';
|
|
4
|
-
import Availability from "./index";
|
|
5
|
-
import { jsx as _jsx } from "react/jsx-runtime";
|
|
6
|
-
describe('<Availability />', () => {
|
|
7
|
-
it('should not render when text is empty', () => {
|
|
8
|
-
const wrapper = mount(/*#__PURE__*/_jsx(Availability, {
|
|
9
|
-
text: ""
|
|
10
|
-
}));
|
|
11
|
-
expect(wrapper).toMatchSnapshot();
|
|
12
|
-
});
|
|
13
|
-
it('should not render by default if state is "ok"', () => {
|
|
14
|
-
const wrapper = mount(/*#__PURE__*/_jsx(Availability, {
|
|
15
|
-
state: AVAILABILITY_STATE_OK,
|
|
16
|
-
text: "Available"
|
|
17
|
-
}));
|
|
18
|
-
expect(wrapper).toMatchSnapshot();
|
|
19
|
-
});
|
|
20
|
-
it('should render if state is "ok" when "showWhenAvailable" is set', () => {
|
|
21
|
-
const wrapper = mount(/*#__PURE__*/_jsx(Availability, {
|
|
22
|
-
state: AVAILABILITY_STATE_OK,
|
|
23
|
-
text: "Available",
|
|
24
|
-
showWhenAvailable: true
|
|
25
|
-
}));
|
|
26
|
-
expect(wrapper).toMatchSnapshot();
|
|
27
|
-
});
|
|
28
|
-
it('should render if state is "warning"', () => {
|
|
29
|
-
const wrapper = mount(/*#__PURE__*/_jsx(Availability, {
|
|
30
|
-
state: AVAILABILITY_STATE_WARNING,
|
|
31
|
-
text: "Only 5 left"
|
|
32
|
-
}));
|
|
33
|
-
expect(wrapper).toMatchSnapshot();
|
|
34
|
-
});
|
|
35
|
-
it('should render if state is "warning"', () => {
|
|
36
|
-
const wrapper = mount(/*#__PURE__*/_jsx(Availability, {
|
|
37
|
-
state: AVAILABILITY_STATE_ALERT,
|
|
38
|
-
text: "Out of stock"
|
|
39
|
-
}));
|
|
40
|
-
expect(wrapper).toMatchSnapshot();
|
|
41
|
-
});
|
|
42
|
-
});
|
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,25 +0,0 @@
|
|
|
1
|
-
import React from 'react';
|
|
2
|
-
import { shallow } from 'enzyme';
|
|
3
|
-
import ActionButton from "../ActionButton";
|
|
4
|
-
import { UnwrappedButtonLink as ButtonLink } from "./index";
|
|
5
|
-
import { jsx as _jsx } from "react/jsx-runtime";
|
|
6
|
-
describe('<ButtonLink>', () => {
|
|
7
|
-
describe('On click action', () => {
|
|
8
|
-
beforeAll(() => {
|
|
9
|
-
ActionButton.clickDelay = 0;
|
|
10
|
-
});
|
|
11
|
-
it('should create component and open page on click', () => {
|
|
12
|
-
const mockedNavigate = jest.fn();
|
|
13
|
-
const link = 'https://example.com';
|
|
14
|
-
const component = shallow(/*#__PURE__*/_jsx(ButtonLink, {
|
|
15
|
-
href: link,
|
|
16
|
-
navigate: mockedNavigate,
|
|
17
|
-
children: "Text inside"
|
|
18
|
-
}));
|
|
19
|
-
expect(component).toMatchSnapshot();
|
|
20
|
-
component.simulate('click');
|
|
21
|
-
expect(mockedNavigate).toHaveBeenCalledTimes(1);
|
|
22
|
-
expect(mockedNavigate).toHaveBeenCalledWith(link);
|
|
23
|
-
});
|
|
24
|
-
});
|
|
25
|
-
});
|
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,101 +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
|
-
return {
|
|
42
|
-
I18n,
|
|
43
|
-
Ellipsis,
|
|
44
|
-
Button
|
|
45
|
-
};
|
|
46
|
-
});
|
|
47
|
-
describe('<HtmlContentDialog />', () => {
|
|
48
|
-
it('should render with minimal props', () => {
|
|
49
|
-
const wrapper = shallow(/*#__PURE__*/_jsx(HtmlContentDialog, {
|
|
50
|
-
message: message,
|
|
51
|
-
actions: []
|
|
52
|
-
}));
|
|
53
|
-
expect(wrapper).toMatchSnapshot();
|
|
54
|
-
expect(wrapper.html()).toMatch(message);
|
|
55
|
-
});
|
|
56
|
-
it('should render with title and html message', () => {
|
|
57
|
-
const wrapper = shallow(/*#__PURE__*/_jsx(HtmlContentDialog, {
|
|
58
|
-
title: title,
|
|
59
|
-
message: message,
|
|
60
|
-
actions: []
|
|
61
|
-
}));
|
|
62
|
-
expect(wrapper).toMatchSnapshot();
|
|
63
|
-
expect(wrapper.html()).toMatch(title);
|
|
64
|
-
});
|
|
65
|
-
it('should render with title, html message and messageParams', () => {
|
|
66
|
-
const wrapper = shallow(/*#__PURE__*/_jsx(HtmlContentDialog, {
|
|
67
|
-
title: title,
|
|
68
|
-
message: "Message with {name}",
|
|
69
|
-
params: {
|
|
70
|
-
name: 'Placeholder'
|
|
71
|
-
},
|
|
72
|
-
actions: []
|
|
73
|
-
}));
|
|
74
|
-
expect(wrapper).toMatchSnapshot();
|
|
75
|
-
});
|
|
76
|
-
it('should render the actions', () => {
|
|
77
|
-
const actions = [{
|
|
78
|
-
label: 'fooAction',
|
|
79
|
-
action: () => {}
|
|
80
|
-
}];
|
|
81
|
-
const wrapper = shallow(/*#__PURE__*/_jsx(HtmlContentDialog, {
|
|
82
|
-
title: title,
|
|
83
|
-
message: message,
|
|
84
|
-
actions: actions
|
|
85
|
-
}));
|
|
86
|
-
expect(wrapper).toMatchSnapshot();
|
|
87
|
-
expect(wrapper.html()).toMatch(actions[0].label);
|
|
88
|
-
});
|
|
89
|
-
it('should pass title through', () => {
|
|
90
|
-
const customTitle = /*#__PURE__*/_jsx("div", {
|
|
91
|
-
children: "Title"
|
|
92
|
-
});
|
|
93
|
-
const wrapper = shallow(/*#__PURE__*/_jsx(HtmlContentDialog, {
|
|
94
|
-
title: customTitle,
|
|
95
|
-
message: message,
|
|
96
|
-
params: {},
|
|
97
|
-
actions: []
|
|
98
|
-
}));
|
|
99
|
-
expect(wrapper.find('BasicDialog').prop('title')).toEqual(customTitle);
|
|
100
|
-
});
|
|
101
|
-
});
|
|
@@ -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
|
-
});
|