@shopgate/pwa-common 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/helpers/mocks/mockRenderOptions.js +21 -0
- package/package.json +3 -3
- package/action-creators/app/spec.js +0 -96
- package/action-creators/client/spec.js +0 -44
- package/action-creators/menu/spec.js +0 -37
- package/action-creators/modal/spec.js +0 -26
- package/action-creators/page/spec.js +0 -38
- package/action-creators/url/spec.js +0 -45
- package/action-creators/user/spec.js +0 -186
- package/components/Backdrop/spec.js +0 -24
- package/components/Button/spec.js +0 -42
- package/components/Checkbox/spec.js +0 -111
- package/components/CountdownTimer/spec.js +0 -141
- package/components/Drawer/spec.js +0 -79
- package/components/Ellipsis/spec.js +0 -15
- package/components/EmbeddedMedia/spec.js +0 -61
- package/components/Grid/components/Item/spec.js +0 -24
- package/components/Grid/spec.js +0 -24
- package/components/HtmlSanitizer/spec.js +0 -229
- package/components/I18n/components/FormatDate/spec.js +0 -54
- package/components/I18n/components/FormatNumber/spec.js +0 -51
- package/components/I18n/components/FormatPrice/spec.js +0 -54
- package/components/I18n/components/FormatTime/spec.js +0 -51
- package/components/I18n/components/I18nProvider/spec.js +0 -40
- package/components/I18n/components/Placeholder/spec.js +0 -37
- package/components/I18n/components/Translate/spec.js +0 -33
- package/components/InfiniteContainer/spec.js +0 -204
- package/components/Input/spec.js +0 -123
- package/components/Link/spec.js +0 -60
- package/components/List/spec.js +0 -26
- package/components/ModalContainer/spec.js +0 -115
- package/components/Select/spec.js +0 -122
- package/components/SelectBox/spec.js +0 -68
- package/components/Swiper/components/SwiperItem/spec.js +0 -26
- package/components/Widgets/components/Widget/spec.js +0 -75
- package/components/Widgets/components/WidgetGrid/spec.js +0 -53
- package/components/Widgets/spec.js +0 -234
- package/helpers/data/spec.js +0 -194
- package/helpers/date/spec.js +0 -92
- package/helpers/style/spec.js +0 -108
- package/helpers/validation/spec.js +0 -10
- package/providers/toast/spec.js +0 -105
- package/tsconfig.build.json +0 -16
- package/tsconfig.json +0 -3
|
@@ -1,234 +0,0 @@
|
|
|
1
|
-
import React from 'react';
|
|
2
|
-
import { mount } from 'enzyme';
|
|
3
|
-
import { ThemeResourcesProvider } from '@shopgate/engage/core/providers';
|
|
4
|
-
import Widgets from "./index";
|
|
5
|
-
import { jsx as _jsx } from "react/jsx-runtime";
|
|
6
|
-
jest.useFakeTimers();
|
|
7
|
-
jest.mock('@shopgate/pwa-common/context', () => ({
|
|
8
|
-
ThemeContext: {
|
|
9
|
-
Provider: ({
|
|
10
|
-
children
|
|
11
|
-
}) => children
|
|
12
|
-
}
|
|
13
|
-
}));
|
|
14
|
-
|
|
15
|
-
/**
|
|
16
|
-
* A mock Image component.
|
|
17
|
-
* @returns {JSX}
|
|
18
|
-
*/
|
|
19
|
-
const Image = () => /*#__PURE__*/_jsx("img", {
|
|
20
|
-
alt: ""
|
|
21
|
-
});
|
|
22
|
-
/* eslint-disable react/prop-types */
|
|
23
|
-
/**
|
|
24
|
-
* A mock WidgetGrid component.
|
|
25
|
-
* @param {Array} children Array of children.
|
|
26
|
-
* @returns {JSX}
|
|
27
|
-
*/
|
|
28
|
-
const WidgetGrid = ({
|
|
29
|
-
children
|
|
30
|
-
}) => /*#__PURE__*/_jsx("div", {
|
|
31
|
-
className: "widget-grid",
|
|
32
|
-
children: children
|
|
33
|
-
});
|
|
34
|
-
/* eslint-enable react/prop-types */
|
|
35
|
-
|
|
36
|
-
const components = {
|
|
37
|
-
v1: {
|
|
38
|
-
'@shopgate/commerce-widgets/image': Image,
|
|
39
|
-
'@shopgate/commerce-widgets/widget-grid': WidgetGrid
|
|
40
|
-
}
|
|
41
|
-
};
|
|
42
|
-
|
|
43
|
-
/**
|
|
44
|
-
* @param {Object[]} widgets Widgets to be rendered.
|
|
45
|
-
* @returns {JSX.Element}
|
|
46
|
-
*/
|
|
47
|
-
const createWrapper = widgets => mount(/*#__PURE__*/_jsx(ThemeResourcesProvider, {
|
|
48
|
-
widgets: components,
|
|
49
|
-
components: {},
|
|
50
|
-
children: /*#__PURE__*/_jsx(Widgets, {
|
|
51
|
-
widgets: widgets
|
|
52
|
-
})
|
|
53
|
-
}));
|
|
54
|
-
describe('<Widgets />', () => {
|
|
55
|
-
it('should render a grid if height is defined', () => {
|
|
56
|
-
const widgets = [{
|
|
57
|
-
col: 0,
|
|
58
|
-
row: 0,
|
|
59
|
-
width: 12,
|
|
60
|
-
height: 3,
|
|
61
|
-
settings: {
|
|
62
|
-
id: 83535,
|
|
63
|
-
image: 'https://data.shopgate.com/shop_widget_images/23836/92204c0f264ac30d6836994c2fb64eb1.min.jpeg'
|
|
64
|
-
},
|
|
65
|
-
type: '@shopgate/commerce-widgets/image'
|
|
66
|
-
}];
|
|
67
|
-
const wrapper = createWrapper(widgets);
|
|
68
|
-
expect(wrapper.find('WidgetGrid').exists()).toBe(true);
|
|
69
|
-
});
|
|
70
|
-
it('should not wrap a widget which is not a grid and has no height', () => {
|
|
71
|
-
const widgets = [{
|
|
72
|
-
col: 0,
|
|
73
|
-
row: 0,
|
|
74
|
-
width: 12,
|
|
75
|
-
settings: {
|
|
76
|
-
id: 83535,
|
|
77
|
-
image: 'https://data.shopgate.com/shop_widget_images/23836/92204c0f264ac30d6836994c2fb64eb1.min.jpeg'
|
|
78
|
-
},
|
|
79
|
-
type: '@shopgate/commerce-widgets/image'
|
|
80
|
-
}];
|
|
81
|
-
const wrapper = createWrapper(widgets);
|
|
82
|
-
expect(wrapper).toMatchSnapshot();
|
|
83
|
-
expect(wrapper.find('WidgetGrid').exists()).toBe(false);
|
|
84
|
-
});
|
|
85
|
-
it('should render a grid if the widget is of type grid', () => {
|
|
86
|
-
const widgets = [{
|
|
87
|
-
type: '@shopgate/commerce-widgets/widget-grid',
|
|
88
|
-
settings: {
|
|
89
|
-
widgets: [{
|
|
90
|
-
col: 0,
|
|
91
|
-
row: 0,
|
|
92
|
-
width: 12,
|
|
93
|
-
height: 5,
|
|
94
|
-
settings: {
|
|
95
|
-
id: '84961',
|
|
96
|
-
alt: '',
|
|
97
|
-
image: 'https://data.shopgate.com/shop_widget_images/23836/aedc545959f55e3f73851eca0ed40a75.min.jpeg',
|
|
98
|
-
link: '/category/'
|
|
99
|
-
},
|
|
100
|
-
type: '@shopgate/commerce-widgets/image'
|
|
101
|
-
}]
|
|
102
|
-
}
|
|
103
|
-
}];
|
|
104
|
-
const wrapper = createWrapper(widgets);
|
|
105
|
-
expect(wrapper).toMatchSnapshot();
|
|
106
|
-
expect(wrapper.find('WidgetGrid').exists()).toBe(true);
|
|
107
|
-
});
|
|
108
|
-
it('should render only one widget when the second one is not published and third one is invalid', () => {
|
|
109
|
-
const widgets = [{
|
|
110
|
-
col: 0,
|
|
111
|
-
row: 0,
|
|
112
|
-
width: 12,
|
|
113
|
-
settings: {
|
|
114
|
-
id: 835351,
|
|
115
|
-
image: 'https://data.shopgate.com/shop_widget_images/23836/92204c0f264ac30d6836994c2fb64eb1.min.jpeg'
|
|
116
|
-
},
|
|
117
|
-
type: '@shopgate/commerce-widgets/image'
|
|
118
|
-
}, {
|
|
119
|
-
col: 0,
|
|
120
|
-
row: 0,
|
|
121
|
-
width: 12,
|
|
122
|
-
settings: {
|
|
123
|
-
id: 835352,
|
|
124
|
-
image: 'https://data.shopgate.com/shop_widget_images/23836/92204c0f264ac30d6836994c2fb64eb1.min.jpeg'
|
|
125
|
-
},
|
|
126
|
-
type: '@shopgate/commerce-widgets/imagefoo'
|
|
127
|
-
}, {
|
|
128
|
-
col: 0,
|
|
129
|
-
row: 0,
|
|
130
|
-
width: 12,
|
|
131
|
-
settings: {
|
|
132
|
-
published: false,
|
|
133
|
-
id: 835353,
|
|
134
|
-
image: 'https://data.shopgate.com/shop_widget_images/23836/92204c0f264ac30d6836994c2fb64eb1.min.jpeg'
|
|
135
|
-
},
|
|
136
|
-
type: '@shopgate/commerce-widgets/image'
|
|
137
|
-
}];
|
|
138
|
-
const wrapper = createWrapper(widgets);
|
|
139
|
-
expect(wrapper).toMatchSnapshot();
|
|
140
|
-
expect(wrapper.find('img').length).toBe(1);
|
|
141
|
-
});
|
|
142
|
-
it('should schedule a re-render when widget is scheduled', () => {
|
|
143
|
-
// Use a fixed point in time so "next full hour" is deterministic.
|
|
144
|
-
// Pick a time that's not exactly on the hour.
|
|
145
|
-
const base = new Date('2023-01-01T10:37:00.000Z');
|
|
146
|
-
jest.setSystemTime(base);
|
|
147
|
-
const minutesToNextFullHour = 60 - base.getMinutes(); // 23
|
|
148
|
-
const msToNextFullHour = minutesToNextFullHour * 60000; // 23 * 60_000
|
|
149
|
-
|
|
150
|
-
const scheduledFromMs = Date.now() + msToNextFullHour - 1;
|
|
151
|
-
const scheduledToMs = Date.now() + minutesToNextFullHour + 1000;
|
|
152
|
-
const widgets = [{
|
|
153
|
-
col: 0,
|
|
154
|
-
row: 0,
|
|
155
|
-
width: 12,
|
|
156
|
-
settings: {
|
|
157
|
-
id: 835351,
|
|
158
|
-
image: 'https://data.shopgate.com/shop_widget_images/23836/92204c0f264ac30d6836994c2fb64eb1.min.jpeg',
|
|
159
|
-
published: true,
|
|
160
|
-
plan: true,
|
|
161
|
-
planDate: {
|
|
162
|
-
valid_from: new Date(scheduledFromMs).toISOString(),
|
|
163
|
-
valid_to: new Date(scheduledToMs).toISOString()
|
|
164
|
-
}
|
|
165
|
-
},
|
|
166
|
-
type: '@shopgate/commerce-widgets/image'
|
|
167
|
-
}];
|
|
168
|
-
const wrapper = createWrapper(widgets);
|
|
169
|
-
const instance = wrapper.find('Widgets').instance();
|
|
170
|
-
const clearSpy = jest.spyOn(global, 'clearTimeout');
|
|
171
|
-
instance.forceUpdate = jest.fn();
|
|
172
|
-
|
|
173
|
-
// Before the schedule hits, the image should not render yet.
|
|
174
|
-
expect(wrapper.find(Image).exists()).toBe(false);
|
|
175
|
-
|
|
176
|
-
// 1) Advance to the next full hour -> first forced update.
|
|
177
|
-
jest.advanceTimersByTime(msToNextFullHour);
|
|
178
|
-
expect(instance.forceUpdate).toHaveBeenCalledTimes(1);
|
|
179
|
-
|
|
180
|
-
// 2) The component should schedule the next tick for +60 min.
|
|
181
|
-
jest.advanceTimersByTime(60 * 60000);
|
|
182
|
-
expect(instance.forceUpdate).toHaveBeenCalledTimes(2);
|
|
183
|
-
|
|
184
|
-
// Unmount triggers cleanup of any pending timeouts.
|
|
185
|
-
wrapper.unmount();
|
|
186
|
-
expect(clearSpy).toHaveBeenCalled();
|
|
187
|
-
clearSpy.mockRestore();
|
|
188
|
-
});
|
|
189
|
-
it('should render only wrapper when widgets array is empty', () => {
|
|
190
|
-
const widgets = [];
|
|
191
|
-
const wrapper = createWrapper(widgets);
|
|
192
|
-
expect(wrapper.find('Image').exists()).toBe(false);
|
|
193
|
-
});
|
|
194
|
-
it('should render null when no widgets are passed', () => {
|
|
195
|
-
const wrapper = createWrapper(undefined);
|
|
196
|
-
expect(wrapper.find('Widgets').html()).toBe(null);
|
|
197
|
-
});
|
|
198
|
-
it('should check settings of child widgets inside widget-grid', () => {
|
|
199
|
-
const widgets = [{
|
|
200
|
-
height: 2,
|
|
201
|
-
id: 'index-5-@shopgate/commerce-widgets/widget-grid',
|
|
202
|
-
type: '@shopgate/commerce-widgets/widget-grid',
|
|
203
|
-
settings: {
|
|
204
|
-
widgets: [{
|
|
205
|
-
col: 0,
|
|
206
|
-
row: 0,
|
|
207
|
-
height: 2,
|
|
208
|
-
width: 2,
|
|
209
|
-
settings: {
|
|
210
|
-
id: 835351,
|
|
211
|
-
image: 'https://data.shopgate.com/shop_widget_images/23836/92204c0f264ac30d6836994c2fb64eb1.min.jpeg',
|
|
212
|
-
published: true,
|
|
213
|
-
plan: false
|
|
214
|
-
},
|
|
215
|
-
type: '@shopgate/commerce-widgets/image'
|
|
216
|
-
}, {
|
|
217
|
-
col: 2,
|
|
218
|
-
row: 0,
|
|
219
|
-
height: 2,
|
|
220
|
-
width: 2,
|
|
221
|
-
settings: {
|
|
222
|
-
id: 835352,
|
|
223
|
-
image: 'https://data.shopgate.com/shop_widget_images/23836/92204c0f264ac30d6836994c2fb64eb1.min.jpeg',
|
|
224
|
-
published: false,
|
|
225
|
-
plan: false
|
|
226
|
-
},
|
|
227
|
-
type: '@shopgate/commerce-widgets/image'
|
|
228
|
-
}]
|
|
229
|
-
}
|
|
230
|
-
}];
|
|
231
|
-
const wrapper = createWrapper(widgets);
|
|
232
|
-
expect(wrapper.find('img').length).toBe(1);
|
|
233
|
-
});
|
|
234
|
-
});
|
package/helpers/data/spec.js
DELETED
|
@@ -1,194 +0,0 @@
|
|
|
1
|
-
import { assignObjectDeep } from '.';
|
|
2
|
-
import { isObject } from "../validation";
|
|
3
|
-
describe('helpers/data', () => {
|
|
4
|
-
describe('assignObjectDeep', () => {
|
|
5
|
-
it('should merge simple objects correctly', () => {
|
|
6
|
-
const modifier = {
|
|
7
|
-
b: 0,
|
|
8
|
-
c: null,
|
|
9
|
-
d: undefined,
|
|
10
|
-
g: 1.7,
|
|
11
|
-
h: 'g',
|
|
12
|
-
i: {
|
|
13
|
-
x: 'x'
|
|
14
|
-
},
|
|
15
|
-
j: ['a', 'b']
|
|
16
|
-
};
|
|
17
|
-
|
|
18
|
-
// Object to be mutated
|
|
19
|
-
const actual = {
|
|
20
|
-
a: 0,
|
|
21
|
-
b: 1,
|
|
22
|
-
c: 'abc',
|
|
23
|
-
d: 'def',
|
|
24
|
-
e: 'ghi',
|
|
25
|
-
f: null,
|
|
26
|
-
g: 1.6
|
|
27
|
-
};
|
|
28
|
-
assignObjectDeep(actual, modifier, false);
|
|
29
|
-
expect(actual).toEqual({
|
|
30
|
-
a: 0,
|
|
31
|
-
b: 0,
|
|
32
|
-
c: null,
|
|
33
|
-
d: undefined,
|
|
34
|
-
e: 'ghi',
|
|
35
|
-
f: null,
|
|
36
|
-
g: 1.7,
|
|
37
|
-
h: 'g',
|
|
38
|
-
i: {
|
|
39
|
-
x: 'x'
|
|
40
|
-
},
|
|
41
|
-
j: ['a', 'b']
|
|
42
|
-
});
|
|
43
|
-
});
|
|
44
|
-
it('should merge objects containing sub-objects correctly', () => {
|
|
45
|
-
const modifier = {
|
|
46
|
-
a: {
|
|
47
|
-
x: 2,
|
|
48
|
-
y: {
|
|
49
|
-
i: 'first mod',
|
|
50
|
-
k: 'new entry'
|
|
51
|
-
}
|
|
52
|
-
},
|
|
53
|
-
b: 'c',
|
|
54
|
-
c: undefined,
|
|
55
|
-
d: {
|
|
56
|
-
x: 'x'
|
|
57
|
-
},
|
|
58
|
-
e: ['a', 'b']
|
|
59
|
-
};
|
|
60
|
-
|
|
61
|
-
// Object to be mutated
|
|
62
|
-
const actual = {
|
|
63
|
-
a: {
|
|
64
|
-
x: 1,
|
|
65
|
-
y: {
|
|
66
|
-
i: 'first',
|
|
67
|
-
j: 'second'
|
|
68
|
-
}
|
|
69
|
-
},
|
|
70
|
-
b: {
|
|
71
|
-
x: 2,
|
|
72
|
-
y: {
|
|
73
|
-
i: 'first',
|
|
74
|
-
j: 'second'
|
|
75
|
-
}
|
|
76
|
-
}
|
|
77
|
-
};
|
|
78
|
-
assignObjectDeep(actual, modifier, false);
|
|
79
|
-
expect(actual).toEqual({
|
|
80
|
-
a: {
|
|
81
|
-
x: 2,
|
|
82
|
-
y: {
|
|
83
|
-
i: 'first mod',
|
|
84
|
-
j: 'second',
|
|
85
|
-
k: 'new entry'
|
|
86
|
-
}
|
|
87
|
-
},
|
|
88
|
-
b: 'c',
|
|
89
|
-
c: undefined,
|
|
90
|
-
d: {
|
|
91
|
-
x: 'x'
|
|
92
|
-
},
|
|
93
|
-
e: ['a', 'b']
|
|
94
|
-
});
|
|
95
|
-
});
|
|
96
|
-
it('should merge objects containing arrays correctly', () => {
|
|
97
|
-
/**
|
|
98
|
-
* This comparator detects unique scalar types and objects containing an id
|
|
99
|
-
* within the 'a' prop
|
|
100
|
-
*
|
|
101
|
-
* @param {string} path path
|
|
102
|
-
* @param {*} prev prev
|
|
103
|
-
* @param {*} next next
|
|
104
|
-
* @returns {boolean}
|
|
105
|
-
*/
|
|
106
|
-
const comparator = (path, prev, next) => {
|
|
107
|
-
// Scalar types
|
|
108
|
-
if (!isObject(prev) || !isObject(next)) {
|
|
109
|
-
return prev === next;
|
|
110
|
-
}
|
|
111
|
-
|
|
112
|
-
// Object merge only occurring on array object-items within the 'a' prop
|
|
113
|
-
if (path.startsWith('$.a.')) {
|
|
114
|
-
return prev.id === next.id;
|
|
115
|
-
}
|
|
116
|
-
return false;
|
|
117
|
-
};
|
|
118
|
-
const modifier = {
|
|
119
|
-
b: [1, 2, 3],
|
|
120
|
-
a: [['non-unique1', 'non-unique1'], 'unique element', 2, {
|
|
121
|
-
id: 'custom-id-2',
|
|
122
|
-
data: {
|
|
123
|
-
x: null,
|
|
124
|
-
y: {
|
|
125
|
-
i: 'first',
|
|
126
|
-
j: 'second mod',
|
|
127
|
-
k: 'third'
|
|
128
|
-
},
|
|
129
|
-
z: 'new data entry'
|
|
130
|
-
}
|
|
131
|
-
}, {
|
|
132
|
-
id: 'custom-id-3',
|
|
133
|
-
data: {
|
|
134
|
-
x: 'a'
|
|
135
|
-
}
|
|
136
|
-
}]
|
|
137
|
-
};
|
|
138
|
-
|
|
139
|
-
// Object to be mutated
|
|
140
|
-
const actual = {
|
|
141
|
-
a: [1, 'unique element', {
|
|
142
|
-
id: 'custom-id-1',
|
|
143
|
-
data: {
|
|
144
|
-
x: 1,
|
|
145
|
-
y: {
|
|
146
|
-
i: 'first',
|
|
147
|
-
j: 'second'
|
|
148
|
-
}
|
|
149
|
-
}
|
|
150
|
-
}, {
|
|
151
|
-
id: 'custom-id-2',
|
|
152
|
-
data: {
|
|
153
|
-
x: 1,
|
|
154
|
-
y: {
|
|
155
|
-
i: 'first',
|
|
156
|
-
j: 'second'
|
|
157
|
-
}
|
|
158
|
-
}
|
|
159
|
-
}, ['non-unique1', 'non-unique1']],
|
|
160
|
-
b: [0]
|
|
161
|
-
};
|
|
162
|
-
assignObjectDeep(actual, modifier, false, comparator, '$');
|
|
163
|
-
expect(actual).toEqual({
|
|
164
|
-
a: [1, 'unique element', {
|
|
165
|
-
id: 'custom-id-1',
|
|
166
|
-
data: {
|
|
167
|
-
x: 1,
|
|
168
|
-
y: {
|
|
169
|
-
i: 'first',
|
|
170
|
-
j: 'second'
|
|
171
|
-
}
|
|
172
|
-
}
|
|
173
|
-
}, {
|
|
174
|
-
id: 'custom-id-2',
|
|
175
|
-
data: {
|
|
176
|
-
x: null,
|
|
177
|
-
y: {
|
|
178
|
-
i: 'first',
|
|
179
|
-
j: 'second mod',
|
|
180
|
-
k: 'third'
|
|
181
|
-
},
|
|
182
|
-
z: 'new data entry'
|
|
183
|
-
}
|
|
184
|
-
}, ['non-unique1', 'non-unique1'], ['non-unique1', 'non-unique1'], 2, {
|
|
185
|
-
id: 'custom-id-3',
|
|
186
|
-
data: {
|
|
187
|
-
x: 'a'
|
|
188
|
-
}
|
|
189
|
-
}],
|
|
190
|
-
b: [0, 1, 2, 3]
|
|
191
|
-
});
|
|
192
|
-
});
|
|
193
|
-
});
|
|
194
|
-
});
|
package/helpers/date/spec.js
DELETED
|
@@ -1,92 +0,0 @@
|
|
|
1
|
-
import { isBefore, isAfter, isBetween, parseDuration, addDuration } from '.';
|
|
2
|
-
describe('helpers/date', () => {
|
|
3
|
-
const date10Hours = new Date('2019-01-01T10:00:00.000Z');
|
|
4
|
-
const date12Hours = new Date('2019-01-01T12:00:00.000Z');
|
|
5
|
-
describe('isBefore', () => {
|
|
6
|
-
it('should be before', () => {
|
|
7
|
-
expect(isBefore(new Date('2019-01-01T09:59:59.000Z'), date10Hours)).toBeTruthy();
|
|
8
|
-
});
|
|
9
|
-
it('should be not before', () => {
|
|
10
|
-
expect(isBefore(new Date('2019-01-01T10:00:00.000Z'), date10Hours)).toBeFalsy();
|
|
11
|
-
});
|
|
12
|
-
});
|
|
13
|
-
describe('isAfter', () => {
|
|
14
|
-
it('should be after', () => {
|
|
15
|
-
expect(isAfter(new Date('2019-01-01T10:00:01.000Z'), date10Hours)).toBeTruthy();
|
|
16
|
-
});
|
|
17
|
-
it('should be not after', () => {
|
|
18
|
-
expect(isAfter(new Date('2019-01-01T10:00:00.000Z'), date10Hours)).toBeFalsy();
|
|
19
|
-
});
|
|
20
|
-
});
|
|
21
|
-
describe('isBetween', () => {
|
|
22
|
-
it('should be between', () => {
|
|
23
|
-
expect(isBetween(new Date('2019-01-01T11:00:00.000Z'), date10Hours, date12Hours)).toBeTruthy();
|
|
24
|
-
});
|
|
25
|
-
it('should be not between', () => {
|
|
26
|
-
expect(isBetween(new Date('2019-01-01T09:00:00.000Z'), date10Hours, date12Hours)).toBeFalsy();
|
|
27
|
-
expect(isBetween(new Date('2019-01-01T13:00:00.000Z'), date10Hours, date12Hours)).toBeFalsy();
|
|
28
|
-
});
|
|
29
|
-
it('should be inclusively between', () => {
|
|
30
|
-
expect(isBetween(new Date('2019-01-01T10:00:00.000Z'), date10Hours, date12Hours)).toBeTruthy();
|
|
31
|
-
expect(isBetween(new Date('2019-01-01T12:00:00.000Z'), date10Hours, date12Hours)).toBeTruthy();
|
|
32
|
-
});
|
|
33
|
-
});
|
|
34
|
-
describe('parseDuration', () => {
|
|
35
|
-
const parsed = {
|
|
36
|
-
Year: undefined,
|
|
37
|
-
Month: undefined,
|
|
38
|
-
Week: undefined,
|
|
39
|
-
Day: undefined,
|
|
40
|
-
Hour: undefined,
|
|
41
|
-
Minute: undefined,
|
|
42
|
-
Second: undefined
|
|
43
|
-
};
|
|
44
|
-
it('should parse 10 second', () => {
|
|
45
|
-
expect(parseDuration('PT10S')).toEqual({
|
|
46
|
-
...parsed,
|
|
47
|
-
Second: 10
|
|
48
|
-
});
|
|
49
|
-
});
|
|
50
|
-
it('should parse 1 hour', () => {
|
|
51
|
-
expect(parseDuration('PT1H')).toEqual({
|
|
52
|
-
...parsed,
|
|
53
|
-
Hour: 1
|
|
54
|
-
});
|
|
55
|
-
});
|
|
56
|
-
it('should parse 5 day', () => {
|
|
57
|
-
expect(parseDuration('P5D')).toEqual({
|
|
58
|
-
...parsed,
|
|
59
|
-
Day: 5
|
|
60
|
-
});
|
|
61
|
-
});
|
|
62
|
-
it('should parse -5 day', () => {
|
|
63
|
-
expect(parseDuration('-P5D')).toEqual({
|
|
64
|
-
...parsed,
|
|
65
|
-
Day: -5
|
|
66
|
-
});
|
|
67
|
-
});
|
|
68
|
-
});
|
|
69
|
-
describe('addDuration', () => {
|
|
70
|
-
const dateStub = '2019-01-01T11:00:00.000Z';
|
|
71
|
-
let date;
|
|
72
|
-
beforeEach(() => {
|
|
73
|
-
date = new Date(dateStub);
|
|
74
|
-
});
|
|
75
|
-
it('should add 0sec', () => {
|
|
76
|
-
addDuration(date, 'PT0S');
|
|
77
|
-
expect(date).toEqual(date);
|
|
78
|
-
});
|
|
79
|
-
it('should add 1 hour', () => {
|
|
80
|
-
addDuration(date, 'PT1H');
|
|
81
|
-
expect(date).toEqual(new Date('2019-01-01T12:00:00.000Z'));
|
|
82
|
-
});
|
|
83
|
-
it('should add 5 day', () => {
|
|
84
|
-
addDuration(date, 'P5D');
|
|
85
|
-
expect(date).toEqual(new Date('2019-01-06T11:00:00.000Z'));
|
|
86
|
-
});
|
|
87
|
-
it('should subtract 5 day', () => {
|
|
88
|
-
addDuration(date, '-P5D');
|
|
89
|
-
expect(date).toEqual(new Date('2018-12-27T11:00:00.000Z'));
|
|
90
|
-
});
|
|
91
|
-
});
|
|
92
|
-
});
|
package/helpers/style/spec.js
DELETED
|
@@ -1,108 +0,0 @@
|
|
|
1
|
-
import { rem, physicalPixelSize } from "./index";
|
|
2
|
-
describe('style helper', () => {
|
|
3
|
-
describe('rem helper with 16px rootSize', () => {
|
|
4
|
-
it('should output 0.875rem for 16px input', () => {
|
|
5
|
-
expect(rem(16)).toBe('1rem');
|
|
6
|
-
});
|
|
7
|
-
it('should output 0.875rem for 14px input', () => {
|
|
8
|
-
expect(rem(14)).toBe('0.875rem');
|
|
9
|
-
});
|
|
10
|
-
it('should output 0.75rem for 12px input', () => {
|
|
11
|
-
expect(rem(12)).toBe('0.75rem');
|
|
12
|
-
});
|
|
13
|
-
it('should output 0rem for 0px input', () => {
|
|
14
|
-
expect(rem(0)).toBe('0rem');
|
|
15
|
-
});
|
|
16
|
-
});
|
|
17
|
-
describe('rem helper error handling', () => {
|
|
18
|
-
let consoleSpy;
|
|
19
|
-
beforeAll(() => {
|
|
20
|
-
// Deactivate the console for the next tests to avoid logs within the test report.
|
|
21
|
-
consoleSpy = jest.spyOn(console, 'error').mockImplementation();
|
|
22
|
-
});
|
|
23
|
-
afterAll(() => {
|
|
24
|
-
consoleSpy.mockRestore();
|
|
25
|
-
});
|
|
26
|
-
afterEach(() => {
|
|
27
|
-
consoleSpy.mockReset();
|
|
28
|
-
});
|
|
29
|
-
it('should output 1rem as fallback for wrong parameters', () => {
|
|
30
|
-
expect(rem('rem')).toBe('1rem');
|
|
31
|
-
expect(consoleSpy).toHaveBeenCalledTimes(1);
|
|
32
|
-
});
|
|
33
|
-
});
|
|
34
|
-
describe('physicalPixelSize', () => {
|
|
35
|
-
describe('non-Android devices', () => {
|
|
36
|
-
beforeAll(() => {
|
|
37
|
-
Object.defineProperty(window.navigator, 'userAgent', {
|
|
38
|
-
value: 'Not And... user agent',
|
|
39
|
-
configurable: true
|
|
40
|
-
});
|
|
41
|
-
});
|
|
42
|
-
it('should output declarations for 1px size', () => {
|
|
43
|
-
expect(physicalPixelSize('foo', 1)).toEqual({
|
|
44
|
-
foo: 1,
|
|
45
|
-
'@media (min-device-pixel-ratio: 2)': {
|
|
46
|
-
foo: 0.5
|
|
47
|
-
},
|
|
48
|
-
'@media (-webkit-min-device-pixel-ratio: 2)': {
|
|
49
|
-
foo: 0.5
|
|
50
|
-
},
|
|
51
|
-
'@media (min-device-pixel-ratio: 3)': {
|
|
52
|
-
foo: 0.33
|
|
53
|
-
},
|
|
54
|
-
'@media (-webkit-min-device-pixel-ratio: 3)': {
|
|
55
|
-
foo: 0.33
|
|
56
|
-
}
|
|
57
|
-
});
|
|
58
|
-
});
|
|
59
|
-
it('should output declarations for 2px size', () => {
|
|
60
|
-
expect(physicalPixelSize('foo', 2)).toEqual({
|
|
61
|
-
foo: 2,
|
|
62
|
-
'@media (min-device-pixel-ratio: 2)': {
|
|
63
|
-
foo: 1
|
|
64
|
-
},
|
|
65
|
-
'@media (-webkit-min-device-pixel-ratio: 2)': {
|
|
66
|
-
foo: 1
|
|
67
|
-
},
|
|
68
|
-
'@media (min-device-pixel-ratio: 3)': {
|
|
69
|
-
foo: 0.67
|
|
70
|
-
},
|
|
71
|
-
'@media (-webkit-min-device-pixel-ratio: 3)': {
|
|
72
|
-
foo: 0.67
|
|
73
|
-
}
|
|
74
|
-
});
|
|
75
|
-
});
|
|
76
|
-
it('should output declarations for 3px size', () => {
|
|
77
|
-
expect(physicalPixelSize('foo', 3)).toEqual({
|
|
78
|
-
foo: 3,
|
|
79
|
-
'@media (min-device-pixel-ratio: 2)': {
|
|
80
|
-
foo: 1.5
|
|
81
|
-
},
|
|
82
|
-
'@media (-webkit-min-device-pixel-ratio: 2)': {
|
|
83
|
-
foo: 1.5
|
|
84
|
-
},
|
|
85
|
-
'@media (min-device-pixel-ratio: 3)': {
|
|
86
|
-
foo: 1
|
|
87
|
-
},
|
|
88
|
-
'@media (-webkit-min-device-pixel-ratio: 3)': {
|
|
89
|
-
foo: 1
|
|
90
|
-
}
|
|
91
|
-
});
|
|
92
|
-
});
|
|
93
|
-
});
|
|
94
|
-
describe('android devices', () => {
|
|
95
|
-
beforeAll(() => {
|
|
96
|
-
Object.defineProperty(window.navigator, 'userAgent', {
|
|
97
|
-
value: 'Foo Android',
|
|
98
|
-
configurable: true
|
|
99
|
-
});
|
|
100
|
-
});
|
|
101
|
-
it('should return natural number rules only', () => {
|
|
102
|
-
expect(physicalPixelSize('foo', 3)).toEqual({
|
|
103
|
-
foo: 3
|
|
104
|
-
});
|
|
105
|
-
});
|
|
106
|
-
});
|
|
107
|
-
});
|
|
108
|
-
});
|
|
@@ -1,10 +0,0 @@
|
|
|
1
|
-
import { isNumeric } from "./index";
|
|
2
|
-
describe('helpers/validation', () => {
|
|
3
|
-
describe('isNumeric', () => {
|
|
4
|
-
describe('Non-regression, "123" is not numeric', () => {
|
|
5
|
-
it('should treat numeric number as numeric', () => {
|
|
6
|
-
expect(isNumeric('123')).toBe(true);
|
|
7
|
-
});
|
|
8
|
-
});
|
|
9
|
-
});
|
|
10
|
-
});
|