@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
|
@@ -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 { shallow } from 'enzyme';
|
|
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 = shallow(/*#__PURE__*/_jsx(DiscountBadge, {
|
|
9
|
-
text: "foo"
|
|
10
|
-
}));
|
|
11
|
-
expect(wrapper).toMatchSnapshot();
|
|
12
|
-
});
|
|
13
|
-
it('should render the text and discount', () => {
|
|
14
|
-
const wrapper = shallow(/*#__PURE__*/_jsx(DiscountBadge, {
|
|
15
|
-
text: "SAVE {0}%",
|
|
16
|
-
discount: 20
|
|
17
|
-
}));
|
|
18
|
-
expect(wrapper).toMatchSnapshot();
|
|
19
|
-
});
|
|
20
|
-
});
|
package/FavoritesButton/spec.js
DELETED
|
@@ -1,131 +0,0 @@
|
|
|
1
|
-
import React from 'react';
|
|
2
|
-
import { act } from 'react-dom/test-utils';
|
|
3
|
-
import { Provider } from 'react-redux';
|
|
4
|
-
import configureStore from 'redux-mock-store';
|
|
5
|
-
import { mount } from 'enzyme';
|
|
6
|
-
import mockRenderOptions from '@shopgate/pwa-common/helpers/mocks/mockRenderOptions';
|
|
7
|
-
import appConfig from '@shopgate/pwa-common/helpers/config';
|
|
8
|
-
import FavoritesButton from "./index";
|
|
9
|
-
import { mockedStateEmpty, mockedStateOnList, mockedStateNotOnList } from "./mock";
|
|
10
|
-
import { jsx as _jsx } from "react/jsx-runtime";
|
|
11
|
-
const mockedStore = configureStore();
|
|
12
|
-
const dispatcher = jest.fn();
|
|
13
|
-
jest.mock('@shopgate/pwa-common/helpers/config');
|
|
14
|
-
jest.mock('@shopgate/pwa-common-commerce/favorites/selectors/index', () => ({
|
|
15
|
-
isFetching: () => false
|
|
16
|
-
}));
|
|
17
|
-
beforeEach(() => {
|
|
18
|
-
jest.resetModules();
|
|
19
|
-
});
|
|
20
|
-
describe('<FavoritesButton />', () => {
|
|
21
|
-
let component = null;
|
|
22
|
-
|
|
23
|
-
/**
|
|
24
|
-
* Creates component with provided store state.
|
|
25
|
-
* @param {Object} mockedState Mocked stage.
|
|
26
|
-
* @param {Object} props Additional props.
|
|
27
|
-
* @return {ReactWrapper}
|
|
28
|
-
*/
|
|
29
|
-
const createComponent = (mockedState, props = {
|
|
30
|
-
active: false
|
|
31
|
-
}) => {
|
|
32
|
-
const store = mockedStore(mockedState);
|
|
33
|
-
store.dispatch = dispatcher;
|
|
34
|
-
return mount(/*#__PURE__*/_jsx(Provider, {
|
|
35
|
-
store: store,
|
|
36
|
-
children: /*#__PURE__*/_jsx(FavoritesButton, {
|
|
37
|
-
...props
|
|
38
|
-
})
|
|
39
|
-
}), mockRenderOptions);
|
|
40
|
-
};
|
|
41
|
-
beforeEach(() => {
|
|
42
|
-
dispatcher.mockReset();
|
|
43
|
-
});
|
|
44
|
-
it('should only render when no favorites set', () => {
|
|
45
|
-
component = createComponent(mockedStateEmpty);
|
|
46
|
-
expect(component).toMatchSnapshot();
|
|
47
|
-
expect(component.find('Heart').exists()).toBe(false);
|
|
48
|
-
expect(component.find('HeartOutline').exists()).toBe(true);
|
|
49
|
-
component.find('button').simulate('click');
|
|
50
|
-
});
|
|
51
|
-
it('should render when favorites set', () => {
|
|
52
|
-
component = createComponent(mockedStateOnList, {
|
|
53
|
-
active: true
|
|
54
|
-
});
|
|
55
|
-
expect(component).toMatchSnapshot();
|
|
56
|
-
expect(component.find('Heart').exists()).toBe(true);
|
|
57
|
-
expect(component.find('HeartOutline').exists()).toBe(false);
|
|
58
|
-
});
|
|
59
|
-
it('should add to favorites on click', () => {
|
|
60
|
-
component = createComponent(mockedStateNotOnList, {
|
|
61
|
-
productId: '1',
|
|
62
|
-
active: false
|
|
63
|
-
});
|
|
64
|
-
expect(component.find('Heart').exists()).toBe(false);
|
|
65
|
-
expect(component.find('HeartOutline').exists()).toBe(true);
|
|
66
|
-
component.find('button').simulate('click');
|
|
67
|
-
component.update();
|
|
68
|
-
expect(dispatcher).toHaveBeenCalled();
|
|
69
|
-
});
|
|
70
|
-
it('should remove from favorites on click', done => {
|
|
71
|
-
component = createComponent(mockedStateOnList, {
|
|
72
|
-
productId: '1',
|
|
73
|
-
active: true
|
|
74
|
-
});
|
|
75
|
-
expect(component.find('Heart').exists()).toBe(true);
|
|
76
|
-
expect(component.find('HeartOutline').exists()).toBe(false);
|
|
77
|
-
component.find('button').simulate('click');
|
|
78
|
-
component.update();
|
|
79
|
-
setTimeout(() => {
|
|
80
|
-
expect(dispatcher).toHaveBeenCalled();
|
|
81
|
-
done();
|
|
82
|
-
}, 0);
|
|
83
|
-
});
|
|
84
|
-
it('should process ripple complete callback', async () => {
|
|
85
|
-
const onRippleComplete = jest.fn();
|
|
86
|
-
component = createComponent(mockedStateOnList, {
|
|
87
|
-
productId: '1',
|
|
88
|
-
active: true,
|
|
89
|
-
onRippleComplete
|
|
90
|
-
});
|
|
91
|
-
await act(async () => {
|
|
92
|
-
component.find('Ripple').invoke('onComplete')();
|
|
93
|
-
});
|
|
94
|
-
component.update();
|
|
95
|
-
expect(onRippleComplete).toHaveBeenCalled();
|
|
96
|
-
});
|
|
97
|
-
it('should only react on first click', done => {
|
|
98
|
-
component = createComponent(mockedStateOnList, {
|
|
99
|
-
once: true,
|
|
100
|
-
productId: '1',
|
|
101
|
-
active: false
|
|
102
|
-
});
|
|
103
|
-
component.find('button').simulate('click');
|
|
104
|
-
component.update();
|
|
105
|
-
component.find('button').simulate('click');
|
|
106
|
-
component.update();
|
|
107
|
-
setTimeout(() => {
|
|
108
|
-
expect(dispatcher.mock.calls.length).toBe(1);
|
|
109
|
-
done();
|
|
110
|
-
}, 1);
|
|
111
|
-
});
|
|
112
|
-
it('should only react on both clicks', done => {
|
|
113
|
-
component = createComponent(mockedStateOnList, {
|
|
114
|
-
productId: '1',
|
|
115
|
-
active: false
|
|
116
|
-
});
|
|
117
|
-
component.find('button').simulate('click');
|
|
118
|
-
component.update();
|
|
119
|
-
component.find('button').simulate('click');
|
|
120
|
-
component.update();
|
|
121
|
-
setTimeout(() => {
|
|
122
|
-
expect(dispatcher.mock.calls.length).toBe(2);
|
|
123
|
-
done();
|
|
124
|
-
}, 1);
|
|
125
|
-
});
|
|
126
|
-
it('should render null when feature flag is off', () => {
|
|
127
|
-
jest.spyOn(appConfig, 'hasFavorites', 'get').mockReturnValue(false);
|
|
128
|
-
component = createComponent(mockedStateOnList);
|
|
129
|
-
expect(component.isEmptyRender()).toBe(true);
|
|
130
|
-
});
|
|
131
|
-
});
|
|
@@ -1,323 +0,0 @@
|
|
|
1
|
-
import ActionListener from "./index";
|
|
2
|
-
import { ACTION_TYPE_SET_VISIBILITY, ACTION_TYPE_SET_VALUE, ACTION_TYPE_TRANSFORM, ACTION_SET_VALUE_COPY_FROM, ACTION_RULE_TYPE_ONE_OF } from "./constants";
|
|
3
|
-
jest.mock('@shopgate/pwa-core/helpers', () => ({
|
|
4
|
-
logger: {
|
|
5
|
-
error: () => {}
|
|
6
|
-
}
|
|
7
|
-
}));
|
|
8
|
-
|
|
9
|
-
/**
|
|
10
|
-
* Mock for provinces
|
|
11
|
-
* @returns {{ST: string}}
|
|
12
|
-
*/
|
|
13
|
-
const mockGetProvincesList = () => ({
|
|
14
|
-
ST: 'State',
|
|
15
|
-
DF: 'Default-State'
|
|
16
|
-
});
|
|
17
|
-
describe('ActionListener', () => {
|
|
18
|
-
describe('createSetVisibilityHandler', () => {
|
|
19
|
-
it('should handle visibility changes correctly', () => {
|
|
20
|
-
// -------------------------------------------------------------------------------------------
|
|
21
|
-
|
|
22
|
-
const element = {
|
|
23
|
-
id: 'province'
|
|
24
|
-
};
|
|
25
|
-
const action = {
|
|
26
|
-
type: ACTION_TYPE_SET_VISIBILITY,
|
|
27
|
-
rules: [{
|
|
28
|
-
context: 'country',
|
|
29
|
-
type: ACTION_RULE_TYPE_ONE_OF,
|
|
30
|
-
data: ['US']
|
|
31
|
-
}]
|
|
32
|
-
};
|
|
33
|
-
const actionListener = new ActionListener(mockGetProvincesList, {});
|
|
34
|
-
const handler = actionListener.createSetVisibilityHandler(element, action);
|
|
35
|
-
let nextState;
|
|
36
|
-
let expected;
|
|
37
|
-
|
|
38
|
-
// Perform "make visible" test
|
|
39
|
-
nextState = {
|
|
40
|
-
formData: {
|
|
41
|
-
country: 'US'
|
|
42
|
-
}
|
|
43
|
-
};
|
|
44
|
-
expected = {
|
|
45
|
-
formData: {
|
|
46
|
-
country: 'US'
|
|
47
|
-
},
|
|
48
|
-
elementVisibility: {
|
|
49
|
-
province: true
|
|
50
|
-
}
|
|
51
|
-
};
|
|
52
|
-
expect(handler({}, nextState)).toEqual(expected);
|
|
53
|
-
|
|
54
|
-
// Perform "make invisible" test
|
|
55
|
-
nextState = {
|
|
56
|
-
formData: {
|
|
57
|
-
country: ''
|
|
58
|
-
}
|
|
59
|
-
};
|
|
60
|
-
expected = {
|
|
61
|
-
formData: {
|
|
62
|
-
country: ''
|
|
63
|
-
},
|
|
64
|
-
elementVisibility: {
|
|
65
|
-
province: false
|
|
66
|
-
}
|
|
67
|
-
};
|
|
68
|
-
expect(handler({}, nextState)).toEqual(expected);
|
|
69
|
-
});
|
|
70
|
-
it('should handle call follow up changes correctly when visibility changed', () => {
|
|
71
|
-
// -------------------------------------------------------------------------------------------
|
|
72
|
-
|
|
73
|
-
const element = {
|
|
74
|
-
id: 'province'
|
|
75
|
-
};
|
|
76
|
-
const action = {
|
|
77
|
-
type: ACTION_TYPE_SET_VISIBILITY,
|
|
78
|
-
rules: [{
|
|
79
|
-
context: 'country',
|
|
80
|
-
type: ACTION_RULE_TYPE_ONE_OF,
|
|
81
|
-
data: ['US']
|
|
82
|
-
}]
|
|
83
|
-
};
|
|
84
|
-
const actionListener = new ActionListener(mockGetProvincesList, {});
|
|
85
|
-
const handleVisibility = actionListener.createSetVisibilityHandler(element, action);
|
|
86
|
-
|
|
87
|
-
// Province element is supposed to be hidden and therefore the follow up
|
|
88
|
-
const followUpHandler = jest.fn();
|
|
89
|
-
actionListener.register('province', followUpHandler);
|
|
90
|
-
const prevState = {
|
|
91
|
-
formData: {
|
|
92
|
-
province: 'to be changed'
|
|
93
|
-
}
|
|
94
|
-
};
|
|
95
|
-
const nextStateBeforeVisibilityChange = {
|
|
96
|
-
formData: {
|
|
97
|
-
country: '',
|
|
98
|
-
province: 'to be changed'
|
|
99
|
-
}
|
|
100
|
-
};
|
|
101
|
-
const nextStateAfterVisibilityChange = {
|
|
102
|
-
elementVisibility: {
|
|
103
|
-
province: false
|
|
104
|
-
},
|
|
105
|
-
formData: {
|
|
106
|
-
country: ''
|
|
107
|
-
}
|
|
108
|
-
};
|
|
109
|
-
handleVisibility(prevState, nextStateBeforeVisibilityChange);
|
|
110
|
-
expect(followUpHandler).toHaveBeenCalledWith(prevState, nextStateAfterVisibilityChange);
|
|
111
|
-
});
|
|
112
|
-
});
|
|
113
|
-
describe('updateProvinceElementHandler', () => {
|
|
114
|
-
it('should select the first province in the list, when country changes and no default is ' + 'available', () => {
|
|
115
|
-
// -------------------------------------------------------------------------------------------
|
|
116
|
-
|
|
117
|
-
const element = {
|
|
118
|
-
id: 'province',
|
|
119
|
-
required: true
|
|
120
|
-
};
|
|
121
|
-
const action = {
|
|
122
|
-
type: 'update',
|
|
123
|
-
rules: [{
|
|
124
|
-
context: 'country'
|
|
125
|
-
}]
|
|
126
|
-
};
|
|
127
|
-
const actionListener = new ActionListener(mockGetProvincesList, {});
|
|
128
|
-
const handler = actionListener.createUpdateProvinceElementHandler(element, action);
|
|
129
|
-
const prevState = {
|
|
130
|
-
formData: {
|
|
131
|
-
province: ''
|
|
132
|
-
}
|
|
133
|
-
};
|
|
134
|
-
const nextState = {
|
|
135
|
-
formData: {
|
|
136
|
-
country: 'US'
|
|
137
|
-
}
|
|
138
|
-
};
|
|
139
|
-
// eslint-disable-next-line extra-rules/no-single-line-objects
|
|
140
|
-
const expected = {
|
|
141
|
-
formData: {
|
|
142
|
-
country: 'US',
|
|
143
|
-
province: 'ST'
|
|
144
|
-
}
|
|
145
|
-
};
|
|
146
|
-
expect(handler(prevState, nextState)).toEqual(expected);
|
|
147
|
-
});
|
|
148
|
-
it('should select the default province in the list on country changes when a match with ' + 'default is available', () => {
|
|
149
|
-
// -------------------------------------------------------------------------------------------
|
|
150
|
-
|
|
151
|
-
const provinceElement = {
|
|
152
|
-
id: 'province',
|
|
153
|
-
default: 'DF',
|
|
154
|
-
required: true
|
|
155
|
-
};
|
|
156
|
-
const countryElement = {
|
|
157
|
-
id: 'country',
|
|
158
|
-
default: 'US'
|
|
159
|
-
};
|
|
160
|
-
const action = {
|
|
161
|
-
type: 'update',
|
|
162
|
-
rules: [{
|
|
163
|
-
context: countryElement.id
|
|
164
|
-
}]
|
|
165
|
-
};
|
|
166
|
-
const prevState = {};
|
|
167
|
-
const nextState = {
|
|
168
|
-
formData: {
|
|
169
|
-
[countryElement.id]: countryElement.default
|
|
170
|
-
}
|
|
171
|
-
};
|
|
172
|
-
const expected = {
|
|
173
|
-
formData: {
|
|
174
|
-
[provinceElement.id]: provinceElement.default,
|
|
175
|
-
[countryElement.id]: countryElement.default
|
|
176
|
-
}
|
|
177
|
-
};
|
|
178
|
-
|
|
179
|
-
// Defaults matches the same object structure as 'formData'
|
|
180
|
-
const actionListener = new ActionListener(mockGetProvincesList, expected.formData);
|
|
181
|
-
const handler = actionListener.createUpdateProvinceElementHandler(provinceElement, action);
|
|
182
|
-
|
|
183
|
-
// Expects the handler to take over the defaults in this test
|
|
184
|
-
expect(handler(prevState, nextState)).toEqual(expected);
|
|
185
|
-
});
|
|
186
|
-
});
|
|
187
|
-
describe('setValueHandler', () => {
|
|
188
|
-
it('should create copy the referenced element value into the current element', () => {
|
|
189
|
-
// -------------------------------------------------------------------------------------------
|
|
190
|
-
|
|
191
|
-
const element = {
|
|
192
|
-
id: 'street2'
|
|
193
|
-
};
|
|
194
|
-
const action = {
|
|
195
|
-
type: ACTION_TYPE_SET_VALUE,
|
|
196
|
-
params: {
|
|
197
|
-
type: ACTION_SET_VALUE_COPY_FROM,
|
|
198
|
-
value: 'street'
|
|
199
|
-
}
|
|
200
|
-
};
|
|
201
|
-
const actionListener = new ActionListener(mockGetProvincesList, {});
|
|
202
|
-
const handler = actionListener.createSetValueHandler(element, action);
|
|
203
|
-
|
|
204
|
-
// eslint-disable-next-line extra-rules/no-single-line-objects
|
|
205
|
-
const prevState = {
|
|
206
|
-
formData: {
|
|
207
|
-
street: '',
|
|
208
|
-
street2: ''
|
|
209
|
-
}
|
|
210
|
-
};
|
|
211
|
-
// eslint-disable-next-line extra-rules/no-single-line-objects
|
|
212
|
-
const nextState = {
|
|
213
|
-
formData: {
|
|
214
|
-
street: 'Street 1',
|
|
215
|
-
street2: ''
|
|
216
|
-
}
|
|
217
|
-
};
|
|
218
|
-
// eslint-disable-next-line extra-rules/no-single-line-objects
|
|
219
|
-
const expected = {
|
|
220
|
-
formData: {
|
|
221
|
-
street: 'Street 1',
|
|
222
|
-
street2: 'Street 1'
|
|
223
|
-
}
|
|
224
|
-
};
|
|
225
|
-
expect(handler(prevState, nextState)).toEqual(expected);
|
|
226
|
-
});
|
|
227
|
-
});
|
|
228
|
-
describe('transformHandler', () => {
|
|
229
|
-
it('should apply the transformHandler correctly for "String" operations', () => {
|
|
230
|
-
// -------------------------------------------------------------------------------------------
|
|
231
|
-
|
|
232
|
-
const element = {
|
|
233
|
-
id: 'street'
|
|
234
|
-
};
|
|
235
|
-
const action = {
|
|
236
|
-
type: ACTION_TYPE_TRANSFORM,
|
|
237
|
-
params: {
|
|
238
|
-
type: 'toUpperCase'
|
|
239
|
-
}
|
|
240
|
-
};
|
|
241
|
-
const actionListener = new ActionListener(mockGetProvincesList, {});
|
|
242
|
-
const handler = actionListener.createTransformHandler(element, action);
|
|
243
|
-
const prevState = {
|
|
244
|
-
formData: {
|
|
245
|
-
street: ''
|
|
246
|
-
}
|
|
247
|
-
};
|
|
248
|
-
const nextState = {
|
|
249
|
-
formData: {
|
|
250
|
-
street: 'Street'
|
|
251
|
-
}
|
|
252
|
-
};
|
|
253
|
-
const expected = {
|
|
254
|
-
formData: {
|
|
255
|
-
street: 'STREET'
|
|
256
|
-
}
|
|
257
|
-
};
|
|
258
|
-
expect(handler(prevState, nextState)).toEqual(expected);
|
|
259
|
-
});
|
|
260
|
-
it('should apply the transformHandler correctly for "Boolean" operations', () => {
|
|
261
|
-
// -------------------------------------------------------------------------------------------
|
|
262
|
-
|
|
263
|
-
const element = {
|
|
264
|
-
id: 'boolTest'
|
|
265
|
-
};
|
|
266
|
-
const action = {
|
|
267
|
-
type: ACTION_TYPE_TRANSFORM,
|
|
268
|
-
params: {
|
|
269
|
-
type: 'toString'
|
|
270
|
-
}
|
|
271
|
-
};
|
|
272
|
-
const actionListener = new ActionListener(mockGetProvincesList, {});
|
|
273
|
-
const handler = actionListener.createTransformHandler(element, action);
|
|
274
|
-
const prevState = {
|
|
275
|
-
formData: {
|
|
276
|
-
boolTest: true
|
|
277
|
-
}
|
|
278
|
-
};
|
|
279
|
-
const nextState = {
|
|
280
|
-
formData: {
|
|
281
|
-
boolTest: true
|
|
282
|
-
}
|
|
283
|
-
};
|
|
284
|
-
const expected = {
|
|
285
|
-
formData: {
|
|
286
|
-
boolTest: 'true'
|
|
287
|
-
}
|
|
288
|
-
};
|
|
289
|
-
expect(handler(prevState, nextState)).toEqual(expected);
|
|
290
|
-
});
|
|
291
|
-
it('should apply the transformHandler correctly for "Number" operations', () => {
|
|
292
|
-
// -------------------------------------------------------------------------------------------
|
|
293
|
-
|
|
294
|
-
const element = {
|
|
295
|
-
id: 'numberTest'
|
|
296
|
-
};
|
|
297
|
-
const action = {
|
|
298
|
-
type: ACTION_TYPE_TRANSFORM,
|
|
299
|
-
params: {
|
|
300
|
-
type: 'isInteger'
|
|
301
|
-
}
|
|
302
|
-
};
|
|
303
|
-
const actionListener = new ActionListener(mockGetProvincesList, {});
|
|
304
|
-
const handler = actionListener.createTransformHandler(element, action);
|
|
305
|
-
const prevState = {
|
|
306
|
-
formData: {
|
|
307
|
-
numberTest: 7.88
|
|
308
|
-
}
|
|
309
|
-
};
|
|
310
|
-
const nextState = {
|
|
311
|
-
formData: {
|
|
312
|
-
numberTest: 7.88
|
|
313
|
-
}
|
|
314
|
-
};
|
|
315
|
-
const expected = {
|
|
316
|
-
formData: {
|
|
317
|
-
numberTest: false
|
|
318
|
-
}
|
|
319
|
-
};
|
|
320
|
-
expect(handler(prevState, nextState)).toEqual(expected);
|
|
321
|
-
});
|
|
322
|
-
});
|
|
323
|
-
});
|