@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/FormElement/spec.js
DELETED
|
@@ -1,68 +0,0 @@
|
|
|
1
|
-
import React from 'react';
|
|
2
|
-
import { mount } from 'enzyme';
|
|
3
|
-
import FormElement from "./index";
|
|
4
|
-
import { jsx as _jsx } from "react/jsx-runtime";
|
|
5
|
-
const inputProps = {
|
|
6
|
-
htmlFor: 'test-input'
|
|
7
|
-
};
|
|
8
|
-
describe('<FormElement />', () => {
|
|
9
|
-
// Simple tests for snapshots
|
|
10
|
-
const tests = {
|
|
11
|
-
'should render a form element with no children': {
|
|
12
|
-
props: {}
|
|
13
|
-
},
|
|
14
|
-
'should render a form element with 1 child': {
|
|
15
|
-
props: {
|
|
16
|
-
children: [/*#__PURE__*/_jsx("input", {}, "test-key")]
|
|
17
|
-
}
|
|
18
|
-
},
|
|
19
|
-
'should render a focused form element': {
|
|
20
|
-
props: {
|
|
21
|
-
isFocused: true
|
|
22
|
-
}
|
|
23
|
-
},
|
|
24
|
-
'should show the label': {
|
|
25
|
-
props: {
|
|
26
|
-
label: 'The label'
|
|
27
|
-
},
|
|
28
|
-
find: 'Label',
|
|
29
|
-
equal: 'The label'
|
|
30
|
-
},
|
|
31
|
-
'should show the error message': {
|
|
32
|
-
props: {
|
|
33
|
-
errorText: 'The error text'
|
|
34
|
-
},
|
|
35
|
-
find: 'ErrorText',
|
|
36
|
-
equal: 'The error text'
|
|
37
|
-
},
|
|
38
|
-
'should show the placeholder text': {
|
|
39
|
-
props: {
|
|
40
|
-
placeholder: 'The placeholder'
|
|
41
|
-
},
|
|
42
|
-
find: 'Placeholder',
|
|
43
|
-
equal: 'The placeholder'
|
|
44
|
-
}
|
|
45
|
-
};
|
|
46
|
-
Object.keys(tests).forEach(test => {
|
|
47
|
-
it(test, () => {
|
|
48
|
-
const testFixtures = tests[test];
|
|
49
|
-
const wrapper = mount(/*#__PURE__*/_jsx(FormElement, {
|
|
50
|
-
...inputProps,
|
|
51
|
-
...testFixtures.props
|
|
52
|
-
}));
|
|
53
|
-
expect(wrapper).toMatchSnapshot();
|
|
54
|
-
if (testFixtures.find) {
|
|
55
|
-
expect(wrapper.find(testFixtures.find).find('Translate').props().string).toEqual(testFixtures.equal);
|
|
56
|
-
}
|
|
57
|
-
});
|
|
58
|
-
});
|
|
59
|
-
it('Should hide placeholder with hasValue', () => {
|
|
60
|
-
const wrapper = mount(/*#__PURE__*/_jsx(FormElement, {
|
|
61
|
-
label: "testlabel",
|
|
62
|
-
...inputProps,
|
|
63
|
-
hasValue: true
|
|
64
|
-
}));
|
|
65
|
-
expect(wrapper).toMatchSnapshot();
|
|
66
|
-
expect(wrapper.find('Placeholder').props().visible).toEqual(false);
|
|
67
|
-
});
|
|
68
|
-
});
|
package/Glow/spec.js
DELETED
|
@@ -1,14 +0,0 @@
|
|
|
1
|
-
import React from 'react';
|
|
2
|
-
import { mount } from 'enzyme';
|
|
3
|
-
import Glow from "./index";
|
|
4
|
-
import { jsx as _jsx } from "react/jsx-runtime";
|
|
5
|
-
describe('<Glow />', () => {
|
|
6
|
-
it('should render with a smile', () => {
|
|
7
|
-
const wrapper = mount(/*#__PURE__*/_jsx(Glow, {
|
|
8
|
-
children: /*#__PURE__*/_jsx("p", {
|
|
9
|
-
children: "Glowing!"
|
|
10
|
-
})
|
|
11
|
-
}));
|
|
12
|
-
expect(wrapper).toMatchSnapshot();
|
|
13
|
-
});
|
|
14
|
-
});
|
package/IndicatorCircle/spec.js
DELETED
|
@@ -1,26 +0,0 @@
|
|
|
1
|
-
import React from 'react';
|
|
2
|
-
import { shallow, mount } from 'enzyme';
|
|
3
|
-
import IndicatorCircle from "./index";
|
|
4
|
-
import { jsx as _jsx } from "react/jsx-runtime";
|
|
5
|
-
describe('<IndicatorCircle />', () => {
|
|
6
|
-
it('should apply the given size', () => {
|
|
7
|
-
const wrapper = shallow(/*#__PURE__*/_jsx(IndicatorCircle, {
|
|
8
|
-
size: 32
|
|
9
|
-
}));
|
|
10
|
-
expect(wrapper).toMatchSnapshot();
|
|
11
|
-
const svg = wrapper.find('svg');
|
|
12
|
-
expect(svg.props().width).toBe(32);
|
|
13
|
-
expect(svg.props().height).toBe(32);
|
|
14
|
-
});
|
|
15
|
-
it('should apply the given color', () => {
|
|
16
|
-
const wrapper = mount(/*#__PURE__*/_jsx(IndicatorCircle, {
|
|
17
|
-
size: 32,
|
|
18
|
-
color: "#fff",
|
|
19
|
-
strokeWidth: 4
|
|
20
|
-
}));
|
|
21
|
-
expect(wrapper).toMatchSnapshot();
|
|
22
|
-
const circleHtml = wrapper.find('circle');
|
|
23
|
-
expect(circleHtml.html()).toMatch(/class="[^"]*"/);
|
|
24
|
-
expect(circleHtml.html()).not.toEqual('');
|
|
25
|
-
});
|
|
26
|
-
});
|
package/PlaceholderLabel/spec.js
DELETED
|
@@ -1,26 +0,0 @@
|
|
|
1
|
-
import React from 'react';
|
|
2
|
-
import { mount } from 'enzyme';
|
|
3
|
-
import PlaceholderLabel from "./index";
|
|
4
|
-
import { jsx as _jsx } from "react/jsx-runtime";
|
|
5
|
-
describe('<PlaceholderLabel />', () => {
|
|
6
|
-
it('should render placeholder ', () => {
|
|
7
|
-
const wrapper = mount(/*#__PURE__*/_jsx(PlaceholderLabel, {
|
|
8
|
-
ready: false,
|
|
9
|
-
children: /*#__PURE__*/_jsx("h1", {
|
|
10
|
-
children: "foo"
|
|
11
|
-
})
|
|
12
|
-
}));
|
|
13
|
-
expect(wrapper).toMatchSnapshot();
|
|
14
|
-
expect(wrapper.find('h1').length).toEqual(0);
|
|
15
|
-
});
|
|
16
|
-
it('should render children', () => {
|
|
17
|
-
const wrapper = mount(/*#__PURE__*/_jsx(PlaceholderLabel, {
|
|
18
|
-
ready: true,
|
|
19
|
-
children: /*#__PURE__*/_jsx("h1", {
|
|
20
|
-
children: "foo"
|
|
21
|
-
})
|
|
22
|
-
}));
|
|
23
|
-
expect(wrapper).toMatchSnapshot();
|
|
24
|
-
expect(wrapper.find('h1').length).toEqual(1);
|
|
25
|
-
});
|
|
26
|
-
});
|
|
@@ -1,26 +0,0 @@
|
|
|
1
|
-
import React from 'react';
|
|
2
|
-
import { mount } from 'enzyme';
|
|
3
|
-
import PlaceholderParagraph from "./index";
|
|
4
|
-
import { jsx as _jsx } from "react/jsx-runtime";
|
|
5
|
-
describe('<PlaceholderParagraph />', () => {
|
|
6
|
-
it('should render placeholder ', () => {
|
|
7
|
-
const wrapper = mount(/*#__PURE__*/_jsx(PlaceholderParagraph, {
|
|
8
|
-
ready: false,
|
|
9
|
-
children: /*#__PURE__*/_jsx("h1", {
|
|
10
|
-
children: "foo"
|
|
11
|
-
})
|
|
12
|
-
}));
|
|
13
|
-
expect(wrapper).toMatchSnapshot();
|
|
14
|
-
expect(wrapper.find('h1').length).toEqual(0);
|
|
15
|
-
});
|
|
16
|
-
it('should render children', () => {
|
|
17
|
-
const wrapper = mount(/*#__PURE__*/_jsx(PlaceholderParagraph, {
|
|
18
|
-
ready: true,
|
|
19
|
-
children: /*#__PURE__*/_jsx("h1", {
|
|
20
|
-
children: "foo"
|
|
21
|
-
})
|
|
22
|
-
}));
|
|
23
|
-
expect(wrapper).toMatchSnapshot();
|
|
24
|
-
expect(wrapper.find('h1').length).toEqual(1);
|
|
25
|
-
});
|
|
26
|
-
});
|
package/ProgressBar/spec.js
DELETED
|
@@ -1,14 +0,0 @@
|
|
|
1
|
-
import React from 'react';
|
|
2
|
-
import { shallow } from 'enzyme';
|
|
3
|
-
import Transition from 'react-transition-group/Transition';
|
|
4
|
-
import ProgressBar from "./index";
|
|
5
|
-
import { jsx as _jsx } from "react/jsx-runtime";
|
|
6
|
-
describe('<ProgressBar />', () => {
|
|
7
|
-
it('renders an indeterminate progress bar.', () => {
|
|
8
|
-
const wrapper = shallow(/*#__PURE__*/_jsx(ProgressBar, {
|
|
9
|
-
isVisible: true
|
|
10
|
-
}));
|
|
11
|
-
expect(wrapper).toMatchSnapshot();
|
|
12
|
-
expect(wrapper.find(Transition).length).toBe(1);
|
|
13
|
-
});
|
|
14
|
-
});
|
package/RadioButton/spec.js
DELETED
|
@@ -1,22 +0,0 @@
|
|
|
1
|
-
import React from 'react';
|
|
2
|
-
import { mount } from 'enzyme';
|
|
3
|
-
import CheckedIcon from "../icons/RadioCheckedIcon";
|
|
4
|
-
import UncheckedIcon from "../icons/RadioUncheckedIcon";
|
|
5
|
-
import RadioButton from "./index";
|
|
6
|
-
import { jsx as _jsx } from "react/jsx-runtime";
|
|
7
|
-
describe('RadioButton', () => {
|
|
8
|
-
it('should render selected RadioButton', () => {
|
|
9
|
-
const wrapper = mount(/*#__PURE__*/_jsx(RadioButton, {
|
|
10
|
-
checked: true
|
|
11
|
-
}));
|
|
12
|
-
expect(wrapper.find(CheckedIcon).exists()).toBe(true);
|
|
13
|
-
expect(wrapper.find(UncheckedIcon).exists()).toBe(false);
|
|
14
|
-
expect(wrapper).toMatchSnapshot();
|
|
15
|
-
});
|
|
16
|
-
it('should render unselected RadioButton', () => {
|
|
17
|
-
const wrapper = mount(/*#__PURE__*/_jsx(RadioButton, {}));
|
|
18
|
-
expect(wrapper.find(CheckedIcon).exists()).toBe(false);
|
|
19
|
-
expect(wrapper.find(UncheckedIcon).exists()).toBe(true);
|
|
20
|
-
expect(wrapper).toMatchSnapshot();
|
|
21
|
-
});
|
|
22
|
-
});
|
package/RatingStars/spec.js
DELETED
|
@@ -1,91 +0,0 @@
|
|
|
1
|
-
import React from 'react';
|
|
2
|
-
import { shallow } from 'enzyme';
|
|
3
|
-
import mockRenderOptions from '@shopgate/pwa-common/helpers/mocks/mockRenderOptions';
|
|
4
|
-
import StarIcon from "../icons/StarIcon";
|
|
5
|
-
import StarHalfIcon from "../icons/StarHalfIcon";
|
|
6
|
-
import RatingStars from "./index";
|
|
7
|
-
import { jsx as _jsx } from "react/jsx-runtime";
|
|
8
|
-
const numEmptyStars = 5;
|
|
9
|
-
describe('<RatingStars />', () => {
|
|
10
|
-
it('renders with value of 50', () => {
|
|
11
|
-
const wrapper = shallow(/*#__PURE__*/_jsx(RatingStars, {
|
|
12
|
-
value: 50
|
|
13
|
-
}), mockRenderOptions);
|
|
14
|
-
expect(wrapper).toMatchSnapshot();
|
|
15
|
-
expect(wrapper.find(StarIcon).length).toBe(numEmptyStars + 2);
|
|
16
|
-
expect(wrapper.find(StarHalfIcon).length).toBe(1);
|
|
17
|
-
});
|
|
18
|
-
it('renders with value of 0', () => {
|
|
19
|
-
const wrapper = shallow(/*#__PURE__*/_jsx(RatingStars, {
|
|
20
|
-
value: 0
|
|
21
|
-
}), mockRenderOptions);
|
|
22
|
-
expect(wrapper).toMatchSnapshot();
|
|
23
|
-
expect(wrapper.find(StarIcon).length).toBe(numEmptyStars);
|
|
24
|
-
expect(wrapper.find(StarHalfIcon).length).toBe(0);
|
|
25
|
-
});
|
|
26
|
-
it('renders with value of 100', () => {
|
|
27
|
-
const wrapper = shallow(/*#__PURE__*/_jsx(RatingStars, {
|
|
28
|
-
value: 100
|
|
29
|
-
}), mockRenderOptions);
|
|
30
|
-
expect(wrapper).toMatchSnapshot();
|
|
31
|
-
expect(wrapper.find(StarIcon).length).toBe(numEmptyStars + 5);
|
|
32
|
-
expect(wrapper.find(StarHalfIcon).length).toBe(0);
|
|
33
|
-
});
|
|
34
|
-
it('should change rating on click', () => {
|
|
35
|
-
const wrapper = shallow(/*#__PURE__*/_jsx(RatingStars, {
|
|
36
|
-
value: 100,
|
|
37
|
-
isSelectable: true
|
|
38
|
-
}), mockRenderOptions);
|
|
39
|
-
expect(wrapper).toMatchSnapshot();
|
|
40
|
-
expect(wrapper.find(StarIcon).length).toBe(10);
|
|
41
|
-
wrapper.setProps({
|
|
42
|
-
value: 20
|
|
43
|
-
});
|
|
44
|
-
expect(wrapper.find(StarIcon).length).toBe(6);
|
|
45
|
-
wrapper.setProps({
|
|
46
|
-
value: 70
|
|
47
|
-
});
|
|
48
|
-
expect(wrapper.find(StarIcon).length).toBe(8);
|
|
49
|
-
expect(wrapper.find(StarHalfIcon).length).toBe(1);
|
|
50
|
-
expect(wrapper).toMatchSnapshot();
|
|
51
|
-
});
|
|
52
|
-
it('should call onSelection callback when component is selectable', () => {
|
|
53
|
-
const spy = jest.fn();
|
|
54
|
-
const wrapper = shallow(/*#__PURE__*/_jsx(RatingStars, {
|
|
55
|
-
value: 100,
|
|
56
|
-
isSelectable: true,
|
|
57
|
-
onSelection: e => {
|
|
58
|
-
wrapper.setProps({
|
|
59
|
-
value: e.target.value
|
|
60
|
-
});
|
|
61
|
-
spy();
|
|
62
|
-
}
|
|
63
|
-
}), mockRenderOptions);
|
|
64
|
-
// Click on 1 filled star.
|
|
65
|
-
wrapper.find('[role="button"]').at(5).simulate('click', {
|
|
66
|
-
target: {
|
|
67
|
-
value: 10
|
|
68
|
-
}
|
|
69
|
-
});
|
|
70
|
-
expect(spy.mock.calls.length).toBe(1);
|
|
71
|
-
expect(wrapper.find('[role="button"]').length).toBe(6);
|
|
72
|
-
// Click on 4th empty star
|
|
73
|
-
wrapper.find('[role="button"]').at(3).simulate('click', {
|
|
74
|
-
target: {
|
|
75
|
-
value: 80
|
|
76
|
-
}
|
|
77
|
-
});
|
|
78
|
-
expect(wrapper.find('[role="button"]').length).toBe(9);
|
|
79
|
-
expect(spy.mock.calls.length).toBe(2);
|
|
80
|
-
});
|
|
81
|
-
it('should NOT call onSelection callback when component is NOT selectable', () => {
|
|
82
|
-
const spy = jest.fn();
|
|
83
|
-
const wrapper = shallow(/*#__PURE__*/_jsx(RatingStars, {
|
|
84
|
-
value: 100,
|
|
85
|
-
onSelection: spy
|
|
86
|
-
}), mockRenderOptions);
|
|
87
|
-
wrapper.find(StarIcon).at(5).parent('div').simulate('click');
|
|
88
|
-
expect(wrapper.find('[role="button"]').length).toBe(0);
|
|
89
|
-
expect(spy.mock.calls.length).toBe(0);
|
|
90
|
-
});
|
|
91
|
-
});
|
package/RippleButton/spec.js
DELETED
|
@@ -1,58 +0,0 @@
|
|
|
1
|
-
import trim from 'lodash/trim';
|
|
2
|
-
import React from 'react';
|
|
3
|
-
import { mount } from 'enzyme';
|
|
4
|
-
import BaseButton from '@shopgate/pwa-common/components/Button';
|
|
5
|
-
import Ripple from "../Ripple";
|
|
6
|
-
import RippleButton from "./index";
|
|
7
|
-
import { jsx as _jsx } from "react/jsx-runtime";
|
|
8
|
-
describe('<RippleButton />', () => {
|
|
9
|
-
it('should render as a regular ripple button effect if type is omitted', () => {
|
|
10
|
-
const wrapper = mount(/*#__PURE__*/_jsx(RippleButton, {
|
|
11
|
-
children: "Press me"
|
|
12
|
-
}));
|
|
13
|
-
expect(wrapper).toMatchSnapshot();
|
|
14
|
-
expect(wrapper.find(Ripple).text()).toEqual('Press me');
|
|
15
|
-
});
|
|
16
|
-
it('should render as a regular ripple button if type is explicitly defined', () => {
|
|
17
|
-
const wrapper = mount(/*#__PURE__*/_jsx(RippleButton, {
|
|
18
|
-
type: "regular",
|
|
19
|
-
children: "Press me"
|
|
20
|
-
}));
|
|
21
|
-
const base = wrapper.find(BaseButton);
|
|
22
|
-
expect(base.exists()).toBe(true);
|
|
23
|
-
expect(trim(base.props().className)).toMatch(/^ui-shared__button /);
|
|
24
|
-
expect(trim(base.props().className)).toContain('ui-shared__ripple-button');
|
|
25
|
-
expect(wrapper.find(Ripple).render().text()).toEqual('Press me');
|
|
26
|
-
expect(wrapper).toMatchSnapshot();
|
|
27
|
-
});
|
|
28
|
-
it('should render as a primary ripple button', () => {
|
|
29
|
-
const wrapper = mount(/*#__PURE__*/_jsx(RippleButton, {
|
|
30
|
-
type: "primary",
|
|
31
|
-
children: "Press me"
|
|
32
|
-
}));
|
|
33
|
-
const base = wrapper.find(BaseButton);
|
|
34
|
-
expect(trim(base.props().className)).toMatch(/^ui-shared__button /);
|
|
35
|
-
expect(trim(base.props().className)).toContain('ui-shared__ripple-button');
|
|
36
|
-
expect(wrapper.find(Ripple).render().text()).toEqual('Press me');
|
|
37
|
-
expect(wrapper).toMatchSnapshot();
|
|
38
|
-
});
|
|
39
|
-
it('should render as a secondary ripple button', () => {
|
|
40
|
-
const wrapper = mount(/*#__PURE__*/_jsx(RippleButton, {
|
|
41
|
-
type: "secondary",
|
|
42
|
-
children: "Press me"
|
|
43
|
-
}));
|
|
44
|
-
const base = wrapper.find(BaseButton);
|
|
45
|
-
expect(trim(base.props().className)).toMatch(/^ui-shared__button /);
|
|
46
|
-
expect(trim(base.props().className)).toContain('ui-shared__ripple-button');
|
|
47
|
-
expect(wrapper.find(Ripple).render().text()).toEqual('Press me');
|
|
48
|
-
expect(wrapper).toMatchSnapshot();
|
|
49
|
-
});
|
|
50
|
-
it('should render as a disabled ripple button', () => {
|
|
51
|
-
const wrapper = mount(/*#__PURE__*/_jsx(RippleButton, {
|
|
52
|
-
disabled: true,
|
|
53
|
-
children: "Press me"
|
|
54
|
-
}));
|
|
55
|
-
expect(wrapper.find(BaseButton).props().disabled).toBe(true);
|
|
56
|
-
expect(wrapper).toMatchSnapshot();
|
|
57
|
-
});
|
|
58
|
-
});
|
|
@@ -1,22 +0,0 @@
|
|
|
1
|
-
import React from 'react';
|
|
2
|
-
import { mount } from 'enzyme';
|
|
3
|
-
import SearchBar from "./index";
|
|
4
|
-
import { jsx as _jsx } from "react/jsx-runtime";
|
|
5
|
-
describe('<SearchBar />', () => {
|
|
6
|
-
it('should call handleChange on input', async () => {
|
|
7
|
-
const handleChange = jest.fn();
|
|
8
|
-
const wrapper = await mount(/*#__PURE__*/_jsx(SearchBar, {
|
|
9
|
-
handleChange: handleChange
|
|
10
|
-
}));
|
|
11
|
-
expect(wrapper).toMatchSnapshot();
|
|
12
|
-
// Update input
|
|
13
|
-
wrapper.find('input').first().simulate('change', {
|
|
14
|
-
target: {
|
|
15
|
-
name: 'search',
|
|
16
|
-
value: 'asdf'
|
|
17
|
-
}
|
|
18
|
-
});
|
|
19
|
-
// Should call with updated state.
|
|
20
|
-
expect(handleChange).toHaveBeenCalledWith('asdf');
|
|
21
|
-
});
|
|
22
|
-
});
|
|
@@ -1,15 +0,0 @@
|
|
|
1
|
-
import React from 'react';
|
|
2
|
-
import { shallow } from 'enzyme';
|
|
3
|
-
import mockRenderOptions from '@shopgate/pwa-common/helpers/mocks/mockRenderOptions';
|
|
4
|
-
import Header from "./index";
|
|
5
|
-
import { jsx as _jsx } from "react/jsx-runtime";
|
|
6
|
-
describe('<Header />', () => {
|
|
7
|
-
it('should render with correct title', () => {
|
|
8
|
-
const title = 'My Title';
|
|
9
|
-
const wrapper = shallow(/*#__PURE__*/_jsx(Header, {
|
|
10
|
-
title: title
|
|
11
|
-
}), mockRenderOptions);
|
|
12
|
-
expect(wrapper).toMatchSnapshot();
|
|
13
|
-
expect(wrapper.find('GridItem').first().props().children).toEqual(title);
|
|
14
|
-
});
|
|
15
|
-
});
|
package/Sheet/spec.js
DELETED
|
@@ -1,100 +0,0 @@
|
|
|
1
|
-
import React from 'react';
|
|
2
|
-
import { shallow, mount } from 'enzyme';
|
|
3
|
-
import Drawer from '@shopgate/pwa-common/components/Drawer';
|
|
4
|
-
import mockRenderOptions from '@shopgate/pwa-common/helpers/mocks/mockRenderOptions';
|
|
5
|
-
import UIEvents from '@shopgate/pwa-core/emitters/ui';
|
|
6
|
-
import Sheet, { SHEET_EVENTS } from "./index";
|
|
7
|
-
import { jsx as _jsx } from "react/jsx-runtime";
|
|
8
|
-
window.requestAnimationFrame = () => {};
|
|
9
|
-
jest.mock('@shopgate/pwa-core/emitters/ui', () => ({
|
|
10
|
-
emit: jest.fn()
|
|
11
|
-
}));
|
|
12
|
-
jest.mock('@shopgate/engage/a11y/components');
|
|
13
|
-
describe('<Sheet />', () => {
|
|
14
|
-
it('should render closed without content', () => {
|
|
15
|
-
const wrapper = shallow(/*#__PURE__*/_jsx(Sheet, {}));
|
|
16
|
-
expect(wrapper).toMatchSnapshot();
|
|
17
|
-
});
|
|
18
|
-
it('should render opened without content', () => {
|
|
19
|
-
const wrapper = shallow(/*#__PURE__*/_jsx(Sheet, {
|
|
20
|
-
isOpen: true
|
|
21
|
-
}));
|
|
22
|
-
expect(wrapper).toMatchSnapshot();
|
|
23
|
-
});
|
|
24
|
-
it('should render with content and title', () => {
|
|
25
|
-
const wrapper = shallow(/*#__PURE__*/_jsx(Sheet, {
|
|
26
|
-
isOpen: true,
|
|
27
|
-
title: "Test-Title",
|
|
28
|
-
children: /*#__PURE__*/_jsx("div", {
|
|
29
|
-
children: "Test"
|
|
30
|
-
})
|
|
31
|
-
}));
|
|
32
|
-
expect(wrapper).toMatchSnapshot();
|
|
33
|
-
});
|
|
34
|
-
it('should call onDidOpen callback when the Sheet was opened', () => {
|
|
35
|
-
const onOpen = jest.fn();
|
|
36
|
-
const onDidOpen = jest.fn();
|
|
37
|
-
const wrapper = mount(/*#__PURE__*/_jsx(Sheet, {
|
|
38
|
-
isOpen: false,
|
|
39
|
-
onOpen: onOpen,
|
|
40
|
-
onDidOpen: onDidOpen,
|
|
41
|
-
children: /*#__PURE__*/_jsx("div", {
|
|
42
|
-
children: "Test"
|
|
43
|
-
})
|
|
44
|
-
}), mockRenderOptions);
|
|
45
|
-
expect(onOpen).not.toHaveBeenCalled();
|
|
46
|
-
expect(onDidOpen).not.toHaveBeenCalled();
|
|
47
|
-
wrapper.setProps({
|
|
48
|
-
isOpen: true
|
|
49
|
-
});
|
|
50
|
-
wrapper.update();
|
|
51
|
-
expect(onOpen).toHaveBeenCalled();
|
|
52
|
-
wrapper.find(Drawer).simulate('animationEnd');
|
|
53
|
-
expect(onDidOpen).toHaveBeenCalled();
|
|
54
|
-
expect(UIEvents.emit).nthCalledWith(1, SHEET_EVENTS.OPEN);
|
|
55
|
-
});
|
|
56
|
-
it('should trigger onClose callback and close the Sheet', () => {
|
|
57
|
-
const onCloseSpy = jest.fn();
|
|
58
|
-
const wrapper = mount(/*#__PURE__*/_jsx(Sheet, {
|
|
59
|
-
isOpen: true,
|
|
60
|
-
title: "Test-Title",
|
|
61
|
-
onClose: onCloseSpy,
|
|
62
|
-
children: /*#__PURE__*/_jsx("div", {
|
|
63
|
-
children: "Test"
|
|
64
|
-
})
|
|
65
|
-
}), mockRenderOptions);
|
|
66
|
-
|
|
67
|
-
// Trigger a click on the close button of the Sheet.
|
|
68
|
-
wrapper.find('button').first().simulate('click');
|
|
69
|
-
return new Promise(resolve => {
|
|
70
|
-
// Wait until the drawer is closed and has updated it's state.
|
|
71
|
-
setTimeout(() => {
|
|
72
|
-
resolve();
|
|
73
|
-
}, wrapper.find(Drawer).prop('animation').duration);
|
|
74
|
-
}).then(() => {
|
|
75
|
-
// Check if onClose callback was called.
|
|
76
|
-
expect(onCloseSpy).toHaveBeenCalled();
|
|
77
|
-
|
|
78
|
-
// Check if the Drawer component was closed.
|
|
79
|
-
expect(wrapper.find(Drawer).prop('isOpen')).not.toBeTruthy();
|
|
80
|
-
expect(wrapper).toMatchSnapshot();
|
|
81
|
-
wrapper.find(Drawer).simulate('animationEnd');
|
|
82
|
-
expect(UIEvents.emit).lastCalledWith(SHEET_EVENTS.CLOSE);
|
|
83
|
-
});
|
|
84
|
-
});
|
|
85
|
-
it('should open', () => {
|
|
86
|
-
const wrapper = mount(/*#__PURE__*/_jsx(Sheet, {
|
|
87
|
-
isOpen: false,
|
|
88
|
-
title: "Test-Title",
|
|
89
|
-
children: /*#__PURE__*/_jsx("div", {
|
|
90
|
-
children: "Test"
|
|
91
|
-
})
|
|
92
|
-
}), mockRenderOptions);
|
|
93
|
-
wrapper.setProps({
|
|
94
|
-
isOpen: true
|
|
95
|
-
});
|
|
96
|
-
wrapper.update();
|
|
97
|
-
expect(wrapper.find(Drawer).prop('isOpen')).toBeTruthy();
|
|
98
|
-
expect(wrapper).toMatchSnapshot();
|
|
99
|
-
});
|
|
100
|
-
});
|
package/TaxDisclaimer/spec.js
DELETED
|
@@ -1,43 +0,0 @@
|
|
|
1
|
-
import React from 'react';
|
|
2
|
-
import { shallow } from 'enzyme';
|
|
3
|
-
import { I18n } from '@shopgate/engage/components';
|
|
4
|
-
import { jsx as _jsx } from "react/jsx-runtime";
|
|
5
|
-
jest.mock('@shopgate/engage/components');
|
|
6
|
-
jest.mock('@shopgate/engage/styles', () => ({
|
|
7
|
-
makeStyles: () => function mockUseStylesFactory() {
|
|
8
|
-
return function useStylesMock() {
|
|
9
|
-
return {
|
|
10
|
-
classes: {
|
|
11
|
-
text: 'mock-class-text'
|
|
12
|
-
}
|
|
13
|
-
};
|
|
14
|
-
};
|
|
15
|
-
},
|
|
16
|
-
keyframes: () => ({})
|
|
17
|
-
}));
|
|
18
|
-
jest.mock('@shopgate/engage/core/hooks/useWidgetSettings', () => ({
|
|
19
|
-
useWidgetSettings: jest.fn().mockReturnValue({
|
|
20
|
-
show: null,
|
|
21
|
-
hint: '*',
|
|
22
|
-
text: null
|
|
23
|
-
})
|
|
24
|
-
}));
|
|
25
|
-
describe('<TaxDisclaimer />', () => {
|
|
26
|
-
afterEach(() => {
|
|
27
|
-
jest.resetModules();
|
|
28
|
-
});
|
|
29
|
-
it('should display the component', () => {
|
|
30
|
-
jest.mock('@shopgate/pwa-common-commerce/market/helpers/showTaxDisclaimer', () => true);
|
|
31
|
-
const TaxDisclaimer = jest.requireActual("./index").default;
|
|
32
|
-
const wrapper = shallow(/*#__PURE__*/_jsx(TaxDisclaimer, {}));
|
|
33
|
-
expect(wrapper).toMatchSnapshot();
|
|
34
|
-
expect(wrapper.find(I18n.Text).exists()).toBe(true);
|
|
35
|
-
});
|
|
36
|
-
it('should display null', () => {
|
|
37
|
-
jest.mock('@shopgate/pwa-common-commerce/market/helpers/showTaxDisclaimer', () => false);
|
|
38
|
-
const TaxDisclaimer = jest.requireActual("./index").default;
|
|
39
|
-
const wrapper = shallow(/*#__PURE__*/_jsx(TaxDisclaimer, {}));
|
|
40
|
-
expect(wrapper).toMatchSnapshot();
|
|
41
|
-
expect(wrapper.find(I18n.Text).exists()).toBe(false);
|
|
42
|
-
});
|
|
43
|
-
});
|
package/TextField/spec.js
DELETED
|
@@ -1,146 +0,0 @@
|
|
|
1
|
-
import React from 'react';
|
|
2
|
-
import { mount } from 'enzyme';
|
|
3
|
-
import TextField from "./index";
|
|
4
|
-
import { jsx as _jsx } from "react/jsx-runtime";
|
|
5
|
-
const inputProps = {
|
|
6
|
-
name: 'test-input'
|
|
7
|
-
};
|
|
8
|
-
describe('<TextField />', () => {
|
|
9
|
-
it('should render a simple text field', () => {
|
|
10
|
-
const wrapper = mount(/*#__PURE__*/_jsx(TextField, {
|
|
11
|
-
...inputProps
|
|
12
|
-
}));
|
|
13
|
-
expect(wrapper).toMatchSnapshot();
|
|
14
|
-
expect(wrapper.find('input').length).toBe(1);
|
|
15
|
-
});
|
|
16
|
-
it('should render the text field as password', () => {
|
|
17
|
-
const wrapper = mount(/*#__PURE__*/_jsx(TextField, {
|
|
18
|
-
...inputProps,
|
|
19
|
-
password: true
|
|
20
|
-
}));
|
|
21
|
-
expect(wrapper).toMatchSnapshot();
|
|
22
|
-
expect(wrapper.find('input[type="password"]').length).toBe(1);
|
|
23
|
-
});
|
|
24
|
-
it('should render the text field with a default value', () => {
|
|
25
|
-
const wrapper = mount(/*#__PURE__*/_jsx(TextField, {
|
|
26
|
-
...inputProps,
|
|
27
|
-
value: "FooBar"
|
|
28
|
-
}));
|
|
29
|
-
expect(wrapper).toMatchSnapshot();
|
|
30
|
-
expect(wrapper.find('input[value="FooBar"]').length).toBe(1);
|
|
31
|
-
});
|
|
32
|
-
it('should trigger the onChange callback', () => {
|
|
33
|
-
const onChangeMock = jest.fn();
|
|
34
|
-
const wrapper = mount(/*#__PURE__*/_jsx(TextField, {
|
|
35
|
-
...inputProps,
|
|
36
|
-
onChange: onChangeMock
|
|
37
|
-
}));
|
|
38
|
-
wrapper.find('input').simulate('change', {
|
|
39
|
-
target: {
|
|
40
|
-
value: 'a'
|
|
41
|
-
}
|
|
42
|
-
});
|
|
43
|
-
expect(onChangeMock).toHaveBeenCalledTimes(2);
|
|
44
|
-
expect(wrapper.find('input').props().value).toEqual('a');
|
|
45
|
-
});
|
|
46
|
-
it('should receive the correct value while typing', () => {
|
|
47
|
-
const wrapper = mount(/*#__PURE__*/_jsx(TextField, {
|
|
48
|
-
...inputProps
|
|
49
|
-
}));
|
|
50
|
-
const input = wrapper.find('input');
|
|
51
|
-
input.simulate('change', {
|
|
52
|
-
target: {
|
|
53
|
-
value: 'foobar'
|
|
54
|
-
}
|
|
55
|
-
});
|
|
56
|
-
expect(wrapper).toMatchSnapshot();
|
|
57
|
-
expect(input.instance().value).toBe('foobar');
|
|
58
|
-
});
|
|
59
|
-
it('should sanitize the input', () => {
|
|
60
|
-
const wrapper = mount(/*#__PURE__*/_jsx(TextField, {
|
|
61
|
-
...inputProps,
|
|
62
|
-
onSanitize: value => value.toUpperCase()
|
|
63
|
-
}));
|
|
64
|
-
const input = wrapper.find('input');
|
|
65
|
-
input.simulate('change', {
|
|
66
|
-
target: {
|
|
67
|
-
value: 'foobar'
|
|
68
|
-
}
|
|
69
|
-
});
|
|
70
|
-
expect(wrapper).toMatchSnapshot();
|
|
71
|
-
expect(input.instance().value).toBe('FOOBAR');
|
|
72
|
-
});
|
|
73
|
-
it('should trigger the validation callback', () => {
|
|
74
|
-
const onValidateMock = jest.fn();
|
|
75
|
-
const wrapper = mount(/*#__PURE__*/_jsx(TextField, {
|
|
76
|
-
...inputProps,
|
|
77
|
-
onValidate: onValidateMock
|
|
78
|
-
}));
|
|
79
|
-
expect(wrapper).toMatchSnapshot();
|
|
80
|
-
expect(onValidateMock).toHaveBeenCalled();
|
|
81
|
-
});
|
|
82
|
-
it('should focus the input', () => {
|
|
83
|
-
const onFocusMock = jest.fn();
|
|
84
|
-
const wrapper = mount(/*#__PURE__*/_jsx(TextField, {
|
|
85
|
-
...inputProps,
|
|
86
|
-
onFocusChange: onFocusMock
|
|
87
|
-
}));
|
|
88
|
-
const input = wrapper.find('input');
|
|
89
|
-
expect(wrapper).toMatchSnapshot();
|
|
90
|
-
expect(onFocusMock).toHaveBeenCalledTimes(0);
|
|
91
|
-
input.simulate('focus');
|
|
92
|
-
expect(onFocusMock).toHaveBeenCalledTimes(1);
|
|
93
|
-
expect(onFocusMock).toHaveBeenCalledWith(true);
|
|
94
|
-
input.simulate('blur');
|
|
95
|
-
expect(onFocusMock).toHaveBeenCalledTimes(2);
|
|
96
|
-
expect(onFocusMock).toHaveBeenCalledWith(false);
|
|
97
|
-
});
|
|
98
|
-
it('should show the error message', () => {
|
|
99
|
-
const errorText = 'This is an error here';
|
|
100
|
-
const wrapper = mount(/*#__PURE__*/_jsx(TextField, {
|
|
101
|
-
...inputProps,
|
|
102
|
-
errorText: errorText
|
|
103
|
-
}));
|
|
104
|
-
expect(wrapper).toMatchSnapshot();
|
|
105
|
-
expect(wrapper.find('Translate').at(2).props().string).toEqual(errorText);
|
|
106
|
-
});
|
|
107
|
-
it('should show the label', () => {
|
|
108
|
-
const label = 'This is the label';
|
|
109
|
-
const wrapper = mount(/*#__PURE__*/_jsx(TextField, {
|
|
110
|
-
...inputProps,
|
|
111
|
-
label: label
|
|
112
|
-
}));
|
|
113
|
-
expect(wrapper).toMatchSnapshot();
|
|
114
|
-
expect(wrapper.find('Label').find('Translate').props().string).toEqual(label);
|
|
115
|
-
});
|
|
116
|
-
it('should show the hint text', () => {
|
|
117
|
-
const hintText = 'This is the hint text';
|
|
118
|
-
const wrapper = mount(/*#__PURE__*/_jsx(TextField, {
|
|
119
|
-
...inputProps,
|
|
120
|
-
hintText: hintText
|
|
121
|
-
}));
|
|
122
|
-
expect(wrapper).toMatchSnapshot();
|
|
123
|
-
expect(wrapper.find('Hint').find('Translate').at(0).props().string).toEqual(hintText);
|
|
124
|
-
});
|
|
125
|
-
it('should replace the error text with custom validation error', () => {
|
|
126
|
-
/**
|
|
127
|
-
* A custom validation method that always returns an error.
|
|
128
|
-
* @return {string} The error message.
|
|
129
|
-
*/
|
|
130
|
-
const onValidate = () => 'Custom validation error';
|
|
131
|
-
const wrapper = mount(/*#__PURE__*/_jsx(TextField, {
|
|
132
|
-
...inputProps,
|
|
133
|
-
onValidate: onValidate
|
|
134
|
-
}));
|
|
135
|
-
wrapper.find('input').simulate('blur');
|
|
136
|
-
expect(wrapper).toMatchSnapshot();
|
|
137
|
-
// Expect at least one element containing the validation error text.
|
|
138
|
-
expect(wrapper.findWhere(node => {
|
|
139
|
-
try {
|
|
140
|
-
return node.text() === onValidate();
|
|
141
|
-
} catch (e) {
|
|
142
|
-
return false;
|
|
143
|
-
}
|
|
144
|
-
}).length).toBeGreaterThan(0);
|
|
145
|
-
});
|
|
146
|
-
});
|