@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
package/providers/toast/spec.js
DELETED
|
@@ -1,105 +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('appends a toast and applies the default duration', () => {
|
|
39
|
-
renderProvider();
|
|
40
|
-
act(() => {
|
|
41
|
-
ctx.addToast(toast('a', 'A'));
|
|
42
|
-
});
|
|
43
|
-
expect(ctx.toasts).toHaveLength(1);
|
|
44
|
-
expect(ctx.toasts[0]).toMatchObject({
|
|
45
|
-
id: 'a',
|
|
46
|
-
message: 'A',
|
|
47
|
-
duration: 5000
|
|
48
|
-
});
|
|
49
|
-
});
|
|
50
|
-
it('ignores a toast without a message', () => {
|
|
51
|
-
renderProvider();
|
|
52
|
-
act(() => {
|
|
53
|
-
ctx.addToast({
|
|
54
|
-
id: 'x'
|
|
55
|
-
});
|
|
56
|
-
});
|
|
57
|
-
expect(ctx.toasts).toHaveLength(0);
|
|
58
|
-
});
|
|
59
|
-
it('replaces a same-id toast in place, keeping its length and position', () => {
|
|
60
|
-
renderProvider();
|
|
61
|
-
act(() => {
|
|
62
|
-
ctx.addToast(toast('a', 'A'));
|
|
63
|
-
});
|
|
64
|
-
act(() => {
|
|
65
|
-
ctx.addToast(toast('b', 'B'));
|
|
66
|
-
});
|
|
67
|
-
const before = ctx.toasts;
|
|
68
|
-
act(() => {
|
|
69
|
-
ctx.addToast(toast('a', 'A2'));
|
|
70
|
-
});
|
|
71
|
-
expect(ctx.toasts).toHaveLength(2);
|
|
72
|
-
expect(ctx.toasts[0]).toMatchObject(toast('a', 'A2')); // content updated
|
|
73
|
-
expect(ctx.toasts[1]).toMatchObject(toast('b', 'B')); // sibling untouched
|
|
74
|
-
expect(ctx.toasts).not.toBe(before); // new array reference (immutable update)
|
|
75
|
-
expect(ctx.toasts[0]).not.toBe(before[0]); // new head object
|
|
76
|
-
});
|
|
77
|
-
it('removes the first toast (FIFO) on removeToast', () => {
|
|
78
|
-
renderProvider();
|
|
79
|
-
act(() => {
|
|
80
|
-
ctx.addToast(toast('a', 'A'));
|
|
81
|
-
});
|
|
82
|
-
act(() => {
|
|
83
|
-
ctx.addToast(toast('b', 'B'));
|
|
84
|
-
});
|
|
85
|
-
act(() => {
|
|
86
|
-
ctx.removeToast();
|
|
87
|
-
});
|
|
88
|
-
expect(ctx.toasts).toHaveLength(1);
|
|
89
|
-
expect(ctx.toasts[0]).toMatchObject(toast('b', 'B'));
|
|
90
|
-
});
|
|
91
|
-
it('keeps the context value referentially stable when toasts do not change', () => {
|
|
92
|
-
const {
|
|
93
|
-
rerender
|
|
94
|
-
} = renderProvider();
|
|
95
|
-
act(() => {
|
|
96
|
-
ctx.addToast(toast('a', 'A'));
|
|
97
|
-
});
|
|
98
|
-
const provided = ctx;
|
|
99
|
-
// Re-render the provider without changing the queue.
|
|
100
|
-
rerender(/*#__PURE__*/_jsx(ToastProvider, {
|
|
101
|
-
children: /*#__PURE__*/_jsx(Capture, {})
|
|
102
|
-
}));
|
|
103
|
-
expect(ctx).toBe(provided); // same context object → consumers don't needlessly re-render
|
|
104
|
-
});
|
|
105
|
-
});
|
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