@shopgate/engage 7.31.5 → 7.31.6
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/mocks/date.js +31 -0
- package/mocks/index.js +3 -0
- package/mocks/pipelineRequest.js +1 -0
- package/mocks/subscriptions.js +1 -0
- package/package.json +7 -7
- package/product/selectors/mocks/productProperties.mock.js +49 -0
- package/components/ChipLayout/spec.js +0 -41
- package/components/Logo/spec.js +0 -12
- package/components/NavigationHandler/spec.js +0 -84
- package/components/Picker/spec.js +0 -87
- package/components/PickerUtilize/spec.js +0 -32
- package/components/RangeSlider/spec.js +0 -190
- package/components/SheetList/components/Item/spec.js +0 -101
- package/components/SheetList/spec.js +0 -43
- package/components/TimeBoundary/spec.js +0 -83
- package/filter/components/FilterItem/spec.js +0 -14
- package/filter/components/FilterPageContent/components/ApplyButton/spec.js +0 -46
- package/filter/components/FilterPageContent/components/ResetButton/spec.js +0 -29
- package/filter/components/FilterPageContent/components/Selector/components/Selected/spec.js +0 -26
- package/filter/components/FilterPageContent/components/Selector/components/Toggle/spec.js +0 -34
- package/filter/components/FilterPageContent/components/Selector/components/ValueButton/spec.js +0 -32
- package/filter/components/FilterPageContent/components/Selector/spec.js +0 -33
- package/filter/components/PriceSlider/components/Label/spec.js +0 -17
- package/filter/components/PriceSlider/spec.js +0 -25
- package/product/components/FilterBar/components/Content/spec.js +0 -136
- package/product/components/Header/Shipping/spec.js +0 -37
- package/product/components/Header/Tiers/components/Tier/spec.js +0 -48
- package/product/components/Header/Tiers/spec.js +0 -64
- package/product/components/Options/components/Content/spec.js +0 -73
- package/product/components/Options/components/TextOption/components/OptionInfo/spec.js +0 -63
- package/product/components/ProductDiscountBadge/spec.js +0 -58
- package/product/components/ProductGrid/components/Item/components/ItemDetails/spec.js +0 -73
- package/product/components/ProductGrid/components/Item/components/ItemFavoritesButton/spec.js +0 -33
- package/product/components/ProductGrid/components/Item/components/ItemImage/spec.js +0 -16
- package/product/components/ProductGrid/components/Item/components/ItemName/spec.js +0 -21
- package/product/components/ProductGrid/components/Item/components/ItemPrice/spec.js +0 -37
- package/product/components/ProductGrid/spec.js +0 -52
- package/product/components/ProductImage/spec.js +0 -87
- package/product/components/ProductSlider/spec.js +0 -37
- package/product/components/Rating/spec.js +0 -57
- package/reviews/components/Reviews/components/Header/components/WriteReviewLink/spec.js +0 -35
- package/reviews/components/Reviews/components/Header/spec.js +0 -60
- package/reviews/components/Reviews/components/List/spec.js +0 -69
- package/reviews/components/Reviews/components/RatingCount/spec.js +0 -18
- package/reviews/components/Reviews/spec.js +0 -73
- package/tsconfig.build.json +0 -26
- package/tsconfig.json +0 -18
package/mocks/date.js
ADDED
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
import _assertThisInitialized from "@babel/runtime/helpers/assertThisInitialized";
|
|
2
|
+
import _inheritsLoose from "@babel/runtime/helpers/inheritsLoose";
|
|
3
|
+
import _wrapNativeSuper from "@babel/runtime/helpers/wrapNativeSuper";
|
|
4
|
+
const RealDate = global.Date;
|
|
5
|
+
|
|
6
|
+
/**
|
|
7
|
+
* Replace the global Date with a mocked one.
|
|
8
|
+
* @param {string|number} isoDate Data and time to set
|
|
9
|
+
*/
|
|
10
|
+
export function mockDate(isoDate) {
|
|
11
|
+
global.Date = /*#__PURE__*/function (_Date) {
|
|
12
|
+
/**
|
|
13
|
+
* Builds a new Date object with a mocked date/time value.
|
|
14
|
+
*/
|
|
15
|
+
function _class() {
|
|
16
|
+
var _this;
|
|
17
|
+
_this = _Date.call(this) || this;
|
|
18
|
+
// eslint-disable-next-line no-constructor-return
|
|
19
|
+
return new RealDate(isoDate) || _assertThisInitialized(_this);
|
|
20
|
+
}
|
|
21
|
+
_inheritsLoose(_class, _Date);
|
|
22
|
+
return _class;
|
|
23
|
+
}(/*#__PURE__*/_wrapNativeSuper(Date));
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
/**
|
|
27
|
+
* Resets a previously mocked Date class back to it's original.
|
|
28
|
+
*/
|
|
29
|
+
export function resetMockDate() {
|
|
30
|
+
global.Date = RealDate;
|
|
31
|
+
}
|
package/mocks/index.js
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export { mockedPipelineRequestFactory } from '@shopgate/pwa-core/classes/PipelineRequest/mock';
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export { subscribe, invoke as invokeSubscription, getSubscriptionCount, resetSubscriptions } from '@shopgate/pwa-common/subscriptions/mock';
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@shopgate/engage",
|
|
3
|
-
"version": "7.31.
|
|
3
|
+
"version": "7.31.6",
|
|
4
4
|
"description": "Shopgate's ENGAGE library.",
|
|
5
5
|
"license": "Apache-2.0",
|
|
6
6
|
"author": "Shopgate <support@shopgate.com>",
|
|
@@ -18,12 +18,12 @@
|
|
|
18
18
|
"dependencies": {
|
|
19
19
|
"@emotion/react": "^11.14.0",
|
|
20
20
|
"@shopgate/native-modules": "1.0.0-beta.34",
|
|
21
|
-
"@shopgate/pwa-common": "7.31.
|
|
22
|
-
"@shopgate/pwa-common-commerce": "7.31.
|
|
23
|
-
"@shopgate/pwa-core": "7.31.
|
|
24
|
-
"@shopgate/pwa-ui-ios": "7.31.
|
|
25
|
-
"@shopgate/pwa-ui-material": "7.31.
|
|
26
|
-
"@shopgate/pwa-ui-shared": "7.31.
|
|
21
|
+
"@shopgate/pwa-common": "7.31.6",
|
|
22
|
+
"@shopgate/pwa-common-commerce": "7.31.6",
|
|
23
|
+
"@shopgate/pwa-core": "7.31.6",
|
|
24
|
+
"@shopgate/pwa-ui-ios": "7.31.6",
|
|
25
|
+
"@shopgate/pwa-ui-material": "7.31.6",
|
|
26
|
+
"@shopgate/pwa-ui-shared": "7.31.6",
|
|
27
27
|
"@stripe/react-stripe-js": "^1.16.5",
|
|
28
28
|
"@stripe/stripe-js": "^1.44.1",
|
|
29
29
|
"@virtuous/conductor": "~2.5.0",
|
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
export default [{
|
|
2
|
+
label: 'TestProperty1',
|
|
3
|
+
value: '15kg',
|
|
4
|
+
displayGroup: 'Weights'
|
|
5
|
+
}, {
|
|
6
|
+
label: 'TestProperty2',
|
|
7
|
+
value: '120kg',
|
|
8
|
+
displayGroup: 'Weights'
|
|
9
|
+
}, {
|
|
10
|
+
label: 'TestProperty3',
|
|
11
|
+
value: 'kg = lbs',
|
|
12
|
+
displayGroup: 'Weights',
|
|
13
|
+
subDisplayGroup: 'Units'
|
|
14
|
+
}, {
|
|
15
|
+
label: 'TestProperty4',
|
|
16
|
+
value: 'sep = sup',
|
|
17
|
+
displayGroup: 'Weights',
|
|
18
|
+
subDisplayGroup: 'Units'
|
|
19
|
+
}, {
|
|
20
|
+
label: 'TestProperty5',
|
|
21
|
+
value: 'Foo',
|
|
22
|
+
displayGroup: 'Weights',
|
|
23
|
+
subDisplayGroup: 'Something'
|
|
24
|
+
}, {
|
|
25
|
+
label: 'TestProperty6',
|
|
26
|
+
value: 'Bar',
|
|
27
|
+
displayGroup: 'Weights',
|
|
28
|
+
subDisplayGroup: 'Something'
|
|
29
|
+
}, {
|
|
30
|
+
label: 'TestProperty3',
|
|
31
|
+
value: 'kg = lbs',
|
|
32
|
+
displayGroup: 'Something Else',
|
|
33
|
+
subDisplayGroup: 'Units'
|
|
34
|
+
}, {
|
|
35
|
+
label: 'TestProperty4',
|
|
36
|
+
value: 'sep = sup',
|
|
37
|
+
displayGroup: 'Something Else',
|
|
38
|
+
subDisplayGroup: 'Units'
|
|
39
|
+
}, {
|
|
40
|
+
label: 'TestProperty5',
|
|
41
|
+
value: 'Foo',
|
|
42
|
+
displayGroup: 'Something Else',
|
|
43
|
+
subDisplayGroup: 'Something'
|
|
44
|
+
}, {
|
|
45
|
+
label: 'TestProperty6',
|
|
46
|
+
value: 'Bar',
|
|
47
|
+
displayGroup: 'Something Else',
|
|
48
|
+
subDisplayGroup: 'Something'
|
|
49
|
+
}];
|
|
@@ -1,41 +0,0 @@
|
|
|
1
|
-
import React from 'react';
|
|
2
|
-
import { mount } from 'enzyme';
|
|
3
|
-
import Chip from '@shopgate/pwa-ui-shared/Chip';
|
|
4
|
-
import ChipsLayout from "./index";
|
|
5
|
-
|
|
6
|
-
/**
|
|
7
|
-
* Since the component uses the <Measure> component it needs an actual
|
|
8
|
-
* browser to be tested as it needs a full browser that supports styling and
|
|
9
|
-
* width/height calculation.
|
|
10
|
-
*/
|
|
11
|
-
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
12
|
-
describe('<ChipsLayout />', () => {
|
|
13
|
-
it('should render with one chip', () => {
|
|
14
|
-
const Component = /*#__PURE__*/_jsx(ChipsLayout, {
|
|
15
|
-
children: /*#__PURE__*/_jsx(Chip, {
|
|
16
|
-
id: "some-id",
|
|
17
|
-
children: "foo"
|
|
18
|
-
})
|
|
19
|
-
});
|
|
20
|
-
const wrapper = mount(Component);
|
|
21
|
-
expect(wrapper).toMatchSnapshot();
|
|
22
|
-
expect(wrapper.find(Chip).length).toEqual(1);
|
|
23
|
-
expect(wrapper.find(Chip).at(0).find('button').at(1).text()).toEqual('foo');
|
|
24
|
-
});
|
|
25
|
-
it('should render with two chips', () => {
|
|
26
|
-
const Component = /*#__PURE__*/_jsxs(ChipsLayout, {
|
|
27
|
-
children: [/*#__PURE__*/_jsx(Chip, {
|
|
28
|
-
id: "some-id",
|
|
29
|
-
children: "foo"
|
|
30
|
-
}), /*#__PURE__*/_jsx(Chip, {
|
|
31
|
-
id: "some-other-id",
|
|
32
|
-
children: "bar"
|
|
33
|
-
})]
|
|
34
|
-
});
|
|
35
|
-
const wrapper = mount(Component);
|
|
36
|
-
expect(wrapper).toMatchSnapshot();
|
|
37
|
-
expect(wrapper.find(Chip).length).toEqual(2);
|
|
38
|
-
expect(wrapper.find(Chip).at(0).find('button').at(1).text()).toEqual('foo');
|
|
39
|
-
expect(wrapper.find(Chip).at(1).find('button').at(1).text()).toEqual('bar');
|
|
40
|
-
});
|
|
41
|
-
});
|
package/components/Logo/spec.js
DELETED
|
@@ -1,12 +0,0 @@
|
|
|
1
|
-
import React from 'react';
|
|
2
|
-
import { shallow } from 'enzyme';
|
|
3
|
-
import Logo from "./index";
|
|
4
|
-
import { jsx as _jsx } from "react/jsx-runtime";
|
|
5
|
-
jest.mock("./connector", () => Component => Component);
|
|
6
|
-
describe('<Logo />', () => {
|
|
7
|
-
it('should render an image', () => {
|
|
8
|
-
const wrapper = shallow(/*#__PURE__*/_jsx(Logo, {}));
|
|
9
|
-
expect(wrapper).toMatchSnapshot();
|
|
10
|
-
expect(wrapper.find('img').exists()).toBe(true);
|
|
11
|
-
});
|
|
12
|
-
});
|
|
@@ -1,84 +0,0 @@
|
|
|
1
|
-
import "core-js/modules/es.string.replace.js";
|
|
2
|
-
import React from 'react';
|
|
3
|
-
import { Provider } from 'react-redux';
|
|
4
|
-
import { mount } from 'enzyme';
|
|
5
|
-
import { UIEvents } from '@shopgate/pwa-core';
|
|
6
|
-
import { createMockStore } from '@shopgate/pwa-common/store';
|
|
7
|
-
import NavigationHandler from "./index";
|
|
8
|
-
import { NAVIGATION_PUSH, NAVIGATION_POP, NAVIGATION_REPLACE, NAVIGATION_RESET, push, pop, replace, reset } from "../../core/router/helpers";
|
|
9
|
-
import { jsx as _jsx } from "react/jsx-runtime";
|
|
10
|
-
jest.mock('@shopgate/pwa-core', () => {
|
|
11
|
-
const map = {};
|
|
12
|
-
return {
|
|
13
|
-
UIEvents: {
|
|
14
|
-
addListener: jest.fn((event, cb) => {
|
|
15
|
-
map[event] = cb;
|
|
16
|
-
}),
|
|
17
|
-
removeListener: jest.fn(),
|
|
18
|
-
emit: jest.fn((event, params) => {
|
|
19
|
-
map[event](params);
|
|
20
|
-
})
|
|
21
|
-
}
|
|
22
|
-
};
|
|
23
|
-
});
|
|
24
|
-
describe('<NavigationHandler />', () => {
|
|
25
|
-
const store = createMockStore();
|
|
26
|
-
const wrapper = mount(/*#__PURE__*/_jsx(Provider, {
|
|
27
|
-
store: store,
|
|
28
|
-
children: /*#__PURE__*/_jsx(NavigationHandler, {
|
|
29
|
-
children: /*#__PURE__*/_jsx("div", {
|
|
30
|
-
children: "Some content"
|
|
31
|
-
})
|
|
32
|
-
})
|
|
33
|
-
}));
|
|
34
|
-
it('should render as expected', () => {
|
|
35
|
-
expect(wrapper).toMatchSnapshot();
|
|
36
|
-
});
|
|
37
|
-
it('should trigger the push() callbacks on navigation.push event', async () => {
|
|
38
|
-
await push({
|
|
39
|
-
pathname: '/test'
|
|
40
|
-
});
|
|
41
|
-
expect(UIEvents.emit).toBeCalledWith(NAVIGATION_PUSH, {
|
|
42
|
-
pathname: '/test'
|
|
43
|
-
});
|
|
44
|
-
UIEvents.emit.mockClear();
|
|
45
|
-
});
|
|
46
|
-
it('should trigger the pop() callbacks on navigation.pop event', async () => {
|
|
47
|
-
await pop();
|
|
48
|
-
expect(UIEvents.emit).toBeCalledWith(NAVIGATION_POP);
|
|
49
|
-
UIEvents.emit.mockClear();
|
|
50
|
-
});
|
|
51
|
-
it('should trigger the replace() callbacks on navigation.replace event', async () => {
|
|
52
|
-
await replace({
|
|
53
|
-
pathname: '/test'
|
|
54
|
-
});
|
|
55
|
-
expect(UIEvents.emit).toBeCalledWith(NAVIGATION_REPLACE, {
|
|
56
|
-
pathname: '/test'
|
|
57
|
-
});
|
|
58
|
-
UIEvents.emit.mockClear();
|
|
59
|
-
});
|
|
60
|
-
it('should trigger the reset() callbacks on navigation.reset event', async () => {
|
|
61
|
-
await reset();
|
|
62
|
-
expect(UIEvents.emit).toBeCalledWith(NAVIGATION_RESET);
|
|
63
|
-
UIEvents.emit.mockClear();
|
|
64
|
-
});
|
|
65
|
-
it('should register the navigation event listener', () => {
|
|
66
|
-
const props = wrapper.find('NavigationHandler').props();
|
|
67
|
-
expect(UIEvents.addListener.mock.calls.length).toBe(4);
|
|
68
|
-
expect(UIEvents.addListener.mock.calls[0][0]).toEqual(NAVIGATION_PUSH, props.push);
|
|
69
|
-
expect(UIEvents.addListener.mock.calls[1][0]).toEqual(NAVIGATION_POP, props.pop);
|
|
70
|
-
expect(UIEvents.addListener.mock.calls[2][0]).toEqual(NAVIGATION_REPLACE, props.replace);
|
|
71
|
-
expect(UIEvents.addListener.mock.calls[3][0]).toEqual(NAVIGATION_RESET, props.reset);
|
|
72
|
-
UIEvents.addListener.mockClear();
|
|
73
|
-
});
|
|
74
|
-
it('should unregister the navigation event listener when the component unmounts', () => {
|
|
75
|
-
const props = wrapper.find('NavigationHandler').props();
|
|
76
|
-
wrapper.unmount();
|
|
77
|
-
expect(UIEvents.removeListener.mock.calls.length).toBe(4);
|
|
78
|
-
expect(UIEvents.removeListener.mock.calls[0][0]).toEqual(NAVIGATION_PUSH, props.push);
|
|
79
|
-
expect(UIEvents.removeListener.mock.calls[1][0]).toEqual(NAVIGATION_POP, props.pop);
|
|
80
|
-
expect(UIEvents.removeListener.mock.calls[2][0]).toEqual(NAVIGATION_REPLACE, props.replace);
|
|
81
|
-
expect(UIEvents.removeListener.mock.calls[3][0]).toEqual(NAVIGATION_RESET, props.reset);
|
|
82
|
-
UIEvents.removeListener.mockClear();
|
|
83
|
-
});
|
|
84
|
-
});
|
|
@@ -1,87 +0,0 @@
|
|
|
1
|
-
import React from 'react';
|
|
2
|
-
import { mount } from 'enzyme';
|
|
3
|
-
import Picker from "./index";
|
|
4
|
-
import PickerList from "./components/List";
|
|
5
|
-
import { jsx as _jsx } from "react/jsx-runtime";
|
|
6
|
-
jest.mock('@shopgate/engage/components');
|
|
7
|
-
describe('<Picker />', () => {
|
|
8
|
-
let renderedElement;
|
|
9
|
-
let renderedInstance;
|
|
10
|
-
const mockItems = ['String only', {
|
|
11
|
-
value: 'Value only'
|
|
12
|
-
}, {
|
|
13
|
-
value: 'value',
|
|
14
|
-
label: 'Value and label'
|
|
15
|
-
}];
|
|
16
|
-
const mockOnChange = jest.fn();
|
|
17
|
-
const mockOnSelect = jest.fn();
|
|
18
|
-
|
|
19
|
-
/**
|
|
20
|
-
* The view component
|
|
21
|
-
* @param {Object} props The component props.
|
|
22
|
-
*/
|
|
23
|
-
const renderComponent = props => {
|
|
24
|
-
renderedElement = mount(/*#__PURE__*/_jsx(Picker, {
|
|
25
|
-
...props
|
|
26
|
-
}));
|
|
27
|
-
renderedInstance = renderedElement.find('Picker').instance();
|
|
28
|
-
};
|
|
29
|
-
beforeEach(() => {
|
|
30
|
-
renderComponent({
|
|
31
|
-
items: mockItems,
|
|
32
|
-
onChange: mockOnChange,
|
|
33
|
-
onSelect: mockOnSelect
|
|
34
|
-
});
|
|
35
|
-
renderedElement.update();
|
|
36
|
-
});
|
|
37
|
-
describe('Given the component was mounted to the DOM', () => {
|
|
38
|
-
it('should match snapshot', () => {
|
|
39
|
-
expect(renderedElement).toMatchSnapshot();
|
|
40
|
-
});
|
|
41
|
-
it('should have no selected value', () => {
|
|
42
|
-
expect(renderedInstance.selectedItem).toBe(null);
|
|
43
|
-
});
|
|
44
|
-
describe('Given picker component gets opened', () => {
|
|
45
|
-
beforeEach(() => {
|
|
46
|
-
renderedInstance.toggleOpenState(true);
|
|
47
|
-
renderedElement.update();
|
|
48
|
-
});
|
|
49
|
-
it('should have isOpen state', () => {
|
|
50
|
-
expect(renderedInstance.state.isOpen).toBe(true);
|
|
51
|
-
});
|
|
52
|
-
it('should render the picker list', () => {
|
|
53
|
-
expect(renderedElement.find(PickerList).length).toBe(1);
|
|
54
|
-
});
|
|
55
|
-
it('should render the picker items', () => {
|
|
56
|
-
expect(renderedElement.find('li button').length).toBe(mockItems.length);
|
|
57
|
-
});
|
|
58
|
-
describe('Given a item gets selected', () => {
|
|
59
|
-
jest.useFakeTimers();
|
|
60
|
-
beforeEach(() => {
|
|
61
|
-
jest.clearAllMocks();
|
|
62
|
-
renderedElement.find('li button').first().simulate('click');
|
|
63
|
-
jest.runAllTimers();
|
|
64
|
-
});
|
|
65
|
-
afterEach(() => {
|
|
66
|
-
jest.clearAllTimers();
|
|
67
|
-
});
|
|
68
|
-
it('should trigger onChange when the value changed', () => {
|
|
69
|
-
expect(mockOnChange).toHaveBeenCalledTimes(1);
|
|
70
|
-
});
|
|
71
|
-
it('should trigger onSelect when the value changed', () => {
|
|
72
|
-
expect(mockOnSelect).toHaveBeenCalledTimes(1);
|
|
73
|
-
});
|
|
74
|
-
it('should not trigger onChange when the value did not change, but trigger onSelect', () => {
|
|
75
|
-
renderedInstance.setState({
|
|
76
|
-
selectedIndex: 0
|
|
77
|
-
});
|
|
78
|
-
renderedInstance.toggleOpenState(true);
|
|
79
|
-
renderedElement.find('li button').first().simulate('click');
|
|
80
|
-
jest.runAllTimers();
|
|
81
|
-
expect(mockOnChange).toHaveBeenCalledTimes(1);
|
|
82
|
-
expect(mockOnSelect).toHaveBeenCalledTimes(2);
|
|
83
|
-
});
|
|
84
|
-
});
|
|
85
|
-
});
|
|
86
|
-
});
|
|
87
|
-
});
|
|
@@ -1,32 +0,0 @@
|
|
|
1
|
-
import React from 'react';
|
|
2
|
-
import { mount } from 'enzyme';
|
|
3
|
-
import Picker from "./index";
|
|
4
|
-
import { jsx as _jsx } from "react/jsx-runtime";
|
|
5
|
-
jest.mock('@shopgate/engage/components/View');
|
|
6
|
-
jest.mock('@shopgate/engage/components', () => {
|
|
7
|
-
function SheetList({
|
|
8
|
-
children
|
|
9
|
-
}) {
|
|
10
|
-
return children;
|
|
11
|
-
}
|
|
12
|
-
SheetList.Item = function Item() {
|
|
13
|
-
return null;
|
|
14
|
-
};
|
|
15
|
-
return {
|
|
16
|
-
SheetList,
|
|
17
|
-
Sheet: ({
|
|
18
|
-
children
|
|
19
|
-
}) => children,
|
|
20
|
-
Picker: jest.requireActual('@shopgate/engage/components/Picker').default,
|
|
21
|
-
ConnectedReactPortal: jest.requireActual('@shopgate/engage/components/ConnectedReactPortal/__mocks__').default
|
|
22
|
-
};
|
|
23
|
-
});
|
|
24
|
-
describe('<Picker />', () => {
|
|
25
|
-
it('should render the picker', () => {
|
|
26
|
-
const label = 'Picker label';
|
|
27
|
-
const wrapper = mount(/*#__PURE__*/_jsx(Picker, {
|
|
28
|
-
label: label
|
|
29
|
-
}));
|
|
30
|
-
expect(wrapper).toMatchSnapshot();
|
|
31
|
-
});
|
|
32
|
-
});
|
|
@@ -1,190 +0,0 @@
|
|
|
1
|
-
/* eslint-disable function-call-argument-newline */
|
|
2
|
-
import React from 'react';
|
|
3
|
-
import { shallow, mount } from 'enzyme';
|
|
4
|
-
import RangeSlider from "./index";
|
|
5
|
-
import RangeSliderHandle from "./components/Handle";
|
|
6
|
-
import { generateLinearEasingCallback, generateExponentialEasingCallback, getAbsoluteValue, getRelativeValue } from "./helper";
|
|
7
|
-
|
|
8
|
-
/**
|
|
9
|
-
* Creates a (fake) touch event.
|
|
10
|
-
* @param {number} pageX the x page offset of the simulated touch event
|
|
11
|
-
* @returns {Object} the new fake event containing only the properties required for testing.
|
|
12
|
-
*/
|
|
13
|
-
import { jsx as _jsx } from "react/jsx-runtime";
|
|
14
|
-
const createTouchEvent = pageX => {
|
|
15
|
-
// Simulate a handle of 16px width.
|
|
16
|
-
const simulatedHandleWidth = 16;
|
|
17
|
-
const simulatedHandleHalfWidth = simulatedHandleWidth / 2;
|
|
18
|
-
const touchEvent = {
|
|
19
|
-
target: {
|
|
20
|
-
offsetWidth: simulatedHandleWidth,
|
|
21
|
-
getBoundingClientRect: () => ({
|
|
22
|
-
// Simulate a touch on the center of the handle.
|
|
23
|
-
left: pageX - simulatedHandleHalfWidth
|
|
24
|
-
})
|
|
25
|
-
},
|
|
26
|
-
touches: [{
|
|
27
|
-
pageX
|
|
28
|
-
}]
|
|
29
|
-
};
|
|
30
|
-
return touchEvent;
|
|
31
|
-
};
|
|
32
|
-
|
|
33
|
-
/**
|
|
34
|
-
* Simulates a series of touch events.
|
|
35
|
-
* This function will automatically validate the from/to values of the range slider.
|
|
36
|
-
* An extra testCallback may be provided to perform additional checks.
|
|
37
|
-
*
|
|
38
|
-
* @param {number} pxWidth The simulated width of the DOM element (in px).
|
|
39
|
-
* @param {number} pxOffset The simulated left offset of the DOM element (in px).
|
|
40
|
-
* @param {number} min The absolute minimum value of the slider.
|
|
41
|
-
* @param {number} max The absolute maximum value of the slider.
|
|
42
|
-
* @param {Array} value The initial value(s) of the slider.
|
|
43
|
-
* @param {string} easing The name of the easing function.
|
|
44
|
-
* @param {number} resolutionOrFactor The resolution or factor for the easing function.
|
|
45
|
-
* @param {Array} simulateSteps A set of relative horizontal pixel movements to simulate.
|
|
46
|
-
* @param {Function} testCallback An optional callback for the onChange event of the slider.
|
|
47
|
-
*/
|
|
48
|
-
const simulateInputTest = (pxWidth, pxOffset, min, max, value, easing, resolutionOrFactor, simulateSteps, testCallback) => {
|
|
49
|
-
const config = {
|
|
50
|
-
totalPixelWidth: pxWidth,
|
|
51
|
-
leftPixelOffset: pxOffset,
|
|
52
|
-
min,
|
|
53
|
-
max,
|
|
54
|
-
easing,
|
|
55
|
-
resolution: resolutionOrFactor,
|
|
56
|
-
factor: resolutionOrFactor,
|
|
57
|
-
initialValue: value,
|
|
58
|
-
valuePixelSize: pxWidth / (max - min),
|
|
59
|
-
currentTouchDeltaX: 0
|
|
60
|
-
};
|
|
61
|
-
config.currentTouchDeltaX = config.valuePixelSize * value[1];
|
|
62
|
-
const ease = {
|
|
63
|
-
linear: generateLinearEasingCallback(config.resolution),
|
|
64
|
-
exponential: generateExponentialEasingCallback(config.factor)
|
|
65
|
-
}[config.easing];
|
|
66
|
-
const callback = ([from, to]) => {
|
|
67
|
-
const {
|
|
68
|
-
currentTouchDeltaX,
|
|
69
|
-
valuePixelSize
|
|
70
|
-
} = config;
|
|
71
|
-
const relativeValue = getRelativeValue(currentTouchDeltaX / valuePixelSize, min, max);
|
|
72
|
-
const expected = getAbsoluteValue(ease(relativeValue), config.min, config.max, true);
|
|
73
|
-
expect(expected === from || expected === to).toBe(true);
|
|
74
|
-
if (testCallback) {
|
|
75
|
-
testCallback(config, from, to);
|
|
76
|
-
}
|
|
77
|
-
};
|
|
78
|
-
const wrapper = mount(/*#__PURE__*/_jsx(RangeSlider, {
|
|
79
|
-
min: config.min,
|
|
80
|
-
max: config.max,
|
|
81
|
-
value: config.initialValue,
|
|
82
|
-
easing: easing,
|
|
83
|
-
resolution: config.resolution,
|
|
84
|
-
factor: config.factor,
|
|
85
|
-
onChange: callback
|
|
86
|
-
}));
|
|
87
|
-
expect(wrapper).toMatchSnapshot();
|
|
88
|
-
|
|
89
|
-
// Create a simulated touch event.
|
|
90
|
-
const pageX = config.leftPixelOffset + config.currentTouchDeltaX;
|
|
91
|
-
const touchEvent = createTouchEvent(pageX);
|
|
92
|
-
const inst = wrapper.instance();
|
|
93
|
-
inst.handleTouchStart(touchEvent, 1);
|
|
94
|
-
simulateSteps.forEach(deltaX => {
|
|
95
|
-
config.currentTouchDeltaX += deltaX;
|
|
96
|
-
touchEvent.touches[0].pageX = config.leftPixelOffset + config.currentTouchDeltaX;
|
|
97
|
-
Object.defineProperty(inst.domElement, 'offsetLeft', {
|
|
98
|
-
get: () => config.leftPixelOffset,
|
|
99
|
-
configurable: true
|
|
100
|
-
});
|
|
101
|
-
Object.defineProperty(inst.domElement, 'offsetWidth', {
|
|
102
|
-
get: () => config.totalPixelWidth,
|
|
103
|
-
configurable: true
|
|
104
|
-
});
|
|
105
|
-
inst.handleTouchMove(touchEvent);
|
|
106
|
-
});
|
|
107
|
-
inst.handleTouchEnd();
|
|
108
|
-
};
|
|
109
|
-
describe.skip('<RangeSlider />', () => {
|
|
110
|
-
/**
|
|
111
|
-
* Simple attribute tests
|
|
112
|
-
*/
|
|
113
|
-
|
|
114
|
-
it('renders with boundaries', () => {
|
|
115
|
-
const wrapper = shallow(/*#__PURE__*/_jsx(RangeSlider, {
|
|
116
|
-
min: 0,
|
|
117
|
-
max: 100
|
|
118
|
-
}));
|
|
119
|
-
expect(wrapper).toMatchSnapshot();
|
|
120
|
-
expect(wrapper.find(RangeSliderHandle).length).toBe(2);
|
|
121
|
-
});
|
|
122
|
-
it('renders without boundaries', () => {
|
|
123
|
-
const wrapper = shallow(/*#__PURE__*/_jsx(RangeSlider, {}));
|
|
124
|
-
expect(wrapper).toMatchSnapshot();
|
|
125
|
-
expect(wrapper.find(RangeSliderHandle).length).toBe(2);
|
|
126
|
-
});
|
|
127
|
-
it('renders without a value pair', () => {
|
|
128
|
-
const wrapper = shallow(/*#__PURE__*/_jsx(RangeSlider, {
|
|
129
|
-
value: [10, 50]
|
|
130
|
-
}));
|
|
131
|
-
expect(wrapper).toMatchSnapshot();
|
|
132
|
-
expect(wrapper.find(RangeSliderHandle).length).toBe(2);
|
|
133
|
-
});
|
|
134
|
-
|
|
135
|
-
/**
|
|
136
|
-
* Callback tests
|
|
137
|
-
*/
|
|
138
|
-
it('emits onChange if handle was touched (linear)', () => {
|
|
139
|
-
simulateInputTest(100, 73,
|
|
140
|
-
// Range slider pixel width and offset.
|
|
141
|
-
0, 100,
|
|
142
|
-
// Range slider minimum and maximum value.
|
|
143
|
-
[50, 75],
|
|
144
|
-
// Initial value.
|
|
145
|
-
'linear',
|
|
146
|
-
// Which easing should be used.
|
|
147
|
-
0.01,
|
|
148
|
-
// Resolution.
|
|
149
|
-
[
|
|
150
|
-
// A series of pixel offsets to move the slider handle.
|
|
151
|
-
+0, +3, -15, +17, -80, +75]);
|
|
152
|
-
});
|
|
153
|
-
it('emits onChange if handle was touched (exponential)', () => {
|
|
154
|
-
simulateInputTest(78, 12,
|
|
155
|
-
// Range slider pixel width and offset.
|
|
156
|
-
0, 1000,
|
|
157
|
-
// Range slider minimum maximum value.
|
|
158
|
-
[10, 450],
|
|
159
|
-
// Initial value.
|
|
160
|
-
'exponential',
|
|
161
|
-
// Which easing should be used.
|
|
162
|
-
0.01,
|
|
163
|
-
// Resolution.
|
|
164
|
-
[
|
|
165
|
-
// A series of pixel offsets to move the slider handle.
|
|
166
|
-
+10, +10, +10, +10, +10, +10, +10, +10, -10, -10, -10, -10, -10, -10, -10, -10, +3, -15, +17, -80, +104, -23, -12, +67]);
|
|
167
|
-
});
|
|
168
|
-
it('emits onChange if the outer range was touched', () => {
|
|
169
|
-
const callback = value => expect(value).toEqual([-80, 0]);
|
|
170
|
-
const wrapper = mount(/*#__PURE__*/_jsx(RangeSlider, {
|
|
171
|
-
min: -100,
|
|
172
|
-
max: 100,
|
|
173
|
-
value: [0, 0],
|
|
174
|
-
onChange: callback
|
|
175
|
-
}));
|
|
176
|
-
// Create a simulated touch event at a page x offset of 20px.
|
|
177
|
-
const touchEvent = createTouchEvent(20);
|
|
178
|
-
const inst = wrapper.instance();
|
|
179
|
-
Object.defineProperty(inst.domElement, 'offsetLeft', {
|
|
180
|
-
get: () => 0,
|
|
181
|
-
configurable: true
|
|
182
|
-
});
|
|
183
|
-
Object.defineProperty(inst.domElement, 'offsetWidth', {
|
|
184
|
-
get: () => 200,
|
|
185
|
-
configurable: true
|
|
186
|
-
});
|
|
187
|
-
inst.handleRangeTouch(touchEvent);
|
|
188
|
-
});
|
|
189
|
-
});
|
|
190
|
-
/* eslint-enable function-call-argument-newline */
|
|
@@ -1,101 +0,0 @@
|
|
|
1
|
-
import React from 'react';
|
|
2
|
-
import { mount } from 'enzyme';
|
|
3
|
-
import Glow from '@shopgate/pwa-ui-shared/Glow';
|
|
4
|
-
import Item from "./index";
|
|
5
|
-
import { jsx as _jsx } from "react/jsx-runtime";
|
|
6
|
-
jest.mock('@shopgate/pwa-common/components/Link', () => {
|
|
7
|
-
/**
|
|
8
|
-
* Mocked LinkComponent.
|
|
9
|
-
* @return {JSX}
|
|
10
|
-
*/
|
|
11
|
-
const Link = () => /*#__PURE__*/_jsx("div", {});
|
|
12
|
-
return Link;
|
|
13
|
-
});
|
|
14
|
-
describe('<SheetList.Item />', () => {
|
|
15
|
-
const title = 'My Title';
|
|
16
|
-
it('should render with a title but no image', () => {
|
|
17
|
-
const wrapper = mount(/*#__PURE__*/_jsx(Item, {
|
|
18
|
-
title: title
|
|
19
|
-
}));
|
|
20
|
-
expect(wrapper).toMatchSnapshot();
|
|
21
|
-
expect(wrapper.find('img').exists()).toBeFalsy();
|
|
22
|
-
});
|
|
23
|
-
it('should render with an image', () => {
|
|
24
|
-
const image = /*#__PURE__*/_jsx("img", {
|
|
25
|
-
src: "url/to/image",
|
|
26
|
-
alt: "Alternative text"
|
|
27
|
-
});
|
|
28
|
-
const wrapper = mount(/*#__PURE__*/_jsx(Item, {
|
|
29
|
-
title: title,
|
|
30
|
-
image: image
|
|
31
|
-
}));
|
|
32
|
-
expect(wrapper).toMatchSnapshot();
|
|
33
|
-
expect(wrapper.find('img').exists()).toBeTruthy();
|
|
34
|
-
});
|
|
35
|
-
it('should render with a right component', () => {
|
|
36
|
-
const rightComponent = /*#__PURE__*/_jsx("span", {
|
|
37
|
-
children: "I`m a span."
|
|
38
|
-
});
|
|
39
|
-
const wrapper = mount(/*#__PURE__*/_jsx(Item, {
|
|
40
|
-
title: title,
|
|
41
|
-
rightComponent: rightComponent
|
|
42
|
-
}));
|
|
43
|
-
expect(wrapper).toMatchSnapshot();
|
|
44
|
-
expect(wrapper.contains(/*#__PURE__*/_jsx("span", {
|
|
45
|
-
children: "I`m a span."
|
|
46
|
-
}))).toEqual(true);
|
|
47
|
-
});
|
|
48
|
-
it('should render without a Glow when selected', () => {
|
|
49
|
-
const wrapper = mount(/*#__PURE__*/_jsx(Item, {
|
|
50
|
-
title: title,
|
|
51
|
-
isSelected: true
|
|
52
|
-
}));
|
|
53
|
-
expect(wrapper).toMatchSnapshot();
|
|
54
|
-
expect(wrapper.find(Glow).exists()).toBeFalsy();
|
|
55
|
-
});
|
|
56
|
-
it('should render without a Glow when disabled', () => {
|
|
57
|
-
const wrapper = mount(/*#__PURE__*/_jsx(Item, {
|
|
58
|
-
title: title,
|
|
59
|
-
isDisabled: true
|
|
60
|
-
}));
|
|
61
|
-
expect(wrapper).toMatchSnapshot();
|
|
62
|
-
expect(wrapper.find(Glow).exists()).toBeFalsy();
|
|
63
|
-
});
|
|
64
|
-
it('should render with a link', () => {
|
|
65
|
-
const wrapper = mount(/*#__PURE__*/_jsx(Item, {
|
|
66
|
-
title: title,
|
|
67
|
-
link: "url/to/somewhere"
|
|
68
|
-
}));
|
|
69
|
-
expect(wrapper).toMatchSnapshot();
|
|
70
|
-
expect(wrapper.find('Link').exists()).toBeTruthy();
|
|
71
|
-
});
|
|
72
|
-
it('should render with an onClick element', () => {
|
|
73
|
-
const spy = jest.fn();
|
|
74
|
-
const clickHandler = () => {
|
|
75
|
-
/**
|
|
76
|
-
* The spy can't be assigned directly to the event, since the snapshot gets too big
|
|
77
|
-
* and the test execution is heavily slowed down.
|
|
78
|
-
*/
|
|
79
|
-
spy();
|
|
80
|
-
};
|
|
81
|
-
const wrapper = mount(/*#__PURE__*/_jsx(Item, {
|
|
82
|
-
title: title,
|
|
83
|
-
onClick: clickHandler
|
|
84
|
-
}));
|
|
85
|
-
wrapper.simulate('click');
|
|
86
|
-
expect(wrapper).toMatchSnapshot();
|
|
87
|
-
expect(spy).toHaveBeenCalledTimes(1);
|
|
88
|
-
});
|
|
89
|
-
it('should re-render when isDisabled changes (memo allows leftComponent path)', () => {
|
|
90
|
-
const wrapper = mount(/*#__PURE__*/_jsx(Item, {
|
|
91
|
-
title: title,
|
|
92
|
-
isDisabled: true
|
|
93
|
-
}));
|
|
94
|
-
expect(wrapper.find('.engage__sheet-list__item').exists()).toBe(true);
|
|
95
|
-
wrapper.setProps({
|
|
96
|
-
isDisabled: false
|
|
97
|
-
});
|
|
98
|
-
wrapper.update();
|
|
99
|
-
expect(wrapper.find('.engage__sheet-list__item').exists()).toBe(true);
|
|
100
|
-
});
|
|
101
|
-
});
|