@shopgate/pwa-common 7.32.0-beta.9 → 7.32.1-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/actions/app/handleLink.js +6 -2
- package/components/Swiper/index.js +16 -2
- package/helpers/html/decodeHTML.js +5 -3
- package/helpers/html/htmlToText.js +15 -0
- package/helpers/mocks/mockRenderOptions.js +21 -0
- package/helpers/router/index.js +85 -0
- package/package.json +3 -3
- package/subscriptions/router.js +20 -6
- 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 -110
- package/tsconfig.build.json +0 -16
- package/tsconfig.json +0 -3
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
|
-
});
|
package/providers/toast/spec.js
DELETED
|
@@ -1,110 +0,0 @@
|
|
|
1
|
-
import React, { useContext } from 'react';
|
|
2
|
-
import { render, act } from '@testing-library/react';
|
|
3
|
-
import ToastProvider from "./index";
|
|
4
|
-
import ToastContext from "./context";
|
|
5
|
-
import { jsx as _jsx } from "react/jsx-runtime";
|
|
6
|
-
jest.mock('@shopgate/pwa-core', () => ({
|
|
7
|
-
UIEvents: {
|
|
8
|
-
addListener: jest.fn(),
|
|
9
|
-
removeListener: jest.fn(),
|
|
10
|
-
emit: jest.fn()
|
|
11
|
-
}
|
|
12
|
-
}));
|
|
13
|
-
jest.mock('@shopgate/pwa-common/helpers/config', () => ({
|
|
14
|
-
themeConfig: {
|
|
15
|
-
variables: {
|
|
16
|
-
toast: {
|
|
17
|
-
duration: 5000
|
|
18
|
-
}
|
|
19
|
-
}
|
|
20
|
-
}
|
|
21
|
-
}));
|
|
22
|
-
let ctx;
|
|
23
|
-
const Capture = () => {
|
|
24
|
-
ctx = useContext(ToastContext);
|
|
25
|
-
return null;
|
|
26
|
-
};
|
|
27
|
-
const renderProvider = () => render(/*#__PURE__*/_jsx(ToastProvider, {
|
|
28
|
-
children: /*#__PURE__*/_jsx(Capture, {})
|
|
29
|
-
}));
|
|
30
|
-
const toast = (id, message) => ({
|
|
31
|
-
id,
|
|
32
|
-
message
|
|
33
|
-
});
|
|
34
|
-
describe('ToastProvider', () => {
|
|
35
|
-
beforeEach(() => {
|
|
36
|
-
ctx = undefined;
|
|
37
|
-
});
|
|
38
|
-
it('exposes the event name statics on the exported component', () => {
|
|
39
|
-
// They survive the withTheme() wrapping - consumers emit UIEvents on them.
|
|
40
|
-
expect(ToastProvider.ADD).toBe('toast_add');
|
|
41
|
-
expect(ToastProvider.FLUSH).toBe('toast_flush');
|
|
42
|
-
});
|
|
43
|
-
it('appends a toast and applies the default duration', () => {
|
|
44
|
-
renderProvider();
|
|
45
|
-
act(() => {
|
|
46
|
-
ctx.addToast(toast('a', 'A'));
|
|
47
|
-
});
|
|
48
|
-
expect(ctx.toasts).toHaveLength(1);
|
|
49
|
-
expect(ctx.toasts[0]).toMatchObject({
|
|
50
|
-
id: 'a',
|
|
51
|
-
message: 'A',
|
|
52
|
-
duration: 5000
|
|
53
|
-
});
|
|
54
|
-
});
|
|
55
|
-
it('ignores a toast without a message', () => {
|
|
56
|
-
renderProvider();
|
|
57
|
-
act(() => {
|
|
58
|
-
ctx.addToast({
|
|
59
|
-
id: 'x'
|
|
60
|
-
});
|
|
61
|
-
});
|
|
62
|
-
expect(ctx.toasts).toHaveLength(0);
|
|
63
|
-
});
|
|
64
|
-
it('replaces a same-id toast in place, keeping its length and position', () => {
|
|
65
|
-
renderProvider();
|
|
66
|
-
act(() => {
|
|
67
|
-
ctx.addToast(toast('a', 'A'));
|
|
68
|
-
});
|
|
69
|
-
act(() => {
|
|
70
|
-
ctx.addToast(toast('b', 'B'));
|
|
71
|
-
});
|
|
72
|
-
const before = ctx.toasts;
|
|
73
|
-
act(() => {
|
|
74
|
-
ctx.addToast(toast('a', 'A2'));
|
|
75
|
-
});
|
|
76
|
-
expect(ctx.toasts).toHaveLength(2);
|
|
77
|
-
expect(ctx.toasts[0]).toMatchObject(toast('a', 'A2')); // content updated
|
|
78
|
-
expect(ctx.toasts[1]).toMatchObject(toast('b', 'B')); // sibling untouched
|
|
79
|
-
expect(ctx.toasts).not.toBe(before); // new array reference (immutable update)
|
|
80
|
-
expect(ctx.toasts[0]).not.toBe(before[0]); // new head object
|
|
81
|
-
});
|
|
82
|
-
it('removes the first toast (FIFO) on removeToast', () => {
|
|
83
|
-
renderProvider();
|
|
84
|
-
act(() => {
|
|
85
|
-
ctx.addToast(toast('a', 'A'));
|
|
86
|
-
});
|
|
87
|
-
act(() => {
|
|
88
|
-
ctx.addToast(toast('b', 'B'));
|
|
89
|
-
});
|
|
90
|
-
act(() => {
|
|
91
|
-
ctx.removeToast();
|
|
92
|
-
});
|
|
93
|
-
expect(ctx.toasts).toHaveLength(1);
|
|
94
|
-
expect(ctx.toasts[0]).toMatchObject(toast('b', 'B'));
|
|
95
|
-
});
|
|
96
|
-
it('keeps the context value referentially stable when toasts do not change', () => {
|
|
97
|
-
const {
|
|
98
|
-
rerender
|
|
99
|
-
} = renderProvider();
|
|
100
|
-
act(() => {
|
|
101
|
-
ctx.addToast(toast('a', 'A'));
|
|
102
|
-
});
|
|
103
|
-
const provided = ctx;
|
|
104
|
-
// Re-render the provider without changing the queue.
|
|
105
|
-
rerender(/*#__PURE__*/_jsx(ToastProvider, {
|
|
106
|
-
children: /*#__PURE__*/_jsx(Capture, {})
|
|
107
|
-
}));
|
|
108
|
-
expect(ctx).toBe(provided); // same context object → consumers don't needlessly re-render
|
|
109
|
-
});
|
|
110
|
-
});
|
package/tsconfig.build.json
DELETED
|
@@ -1,16 +0,0 @@
|
|
|
1
|
-
{
|
|
2
|
-
"extends": "@shopgate/engage/tsconfig.build.json",
|
|
3
|
-
"compilerOptions": {
|
|
4
|
-
"outDir": "./dist",
|
|
5
|
-
"rootDir": "."
|
|
6
|
-
},
|
|
7
|
-
"include": ["**/*.ts", "**/*.tsx"],
|
|
8
|
-
"exclude": [
|
|
9
|
-
"dist",
|
|
10
|
-
"node_modules",
|
|
11
|
-
"**/*.spec.*",
|
|
12
|
-
"**/__tests__/**",
|
|
13
|
-
"**/__snapshots__/**",
|
|
14
|
-
"coverage"
|
|
15
|
-
]
|
|
16
|
-
}
|
package/tsconfig.json
DELETED