piral-core 1.3.3-beta.6190 → 1.3.3-beta.6201
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/app.codegen +2 -1
- package/esm/utils/routes.js +1 -3
- package/esm/utils/routes.js.map +1 -1
- package/lib/Piral.js +2 -1
- package/lib/Piral.js.map +1 -1
- package/lib/PiralContext.js +2 -1
- package/lib/PiralContext.js.map +1 -1
- package/lib/RootListener.js +2 -1
- package/lib/RootListener.js.map +1 -1
- package/lib/components/ErrorBoundary.js +1 -1
- package/lib/components/ErrorBoundary.js.map +1 -1
- package/lib/components/ExtensionSlot.js +2 -1
- package/lib/components/ExtensionSlot.js.map +1 -1
- package/lib/components/ForeignComponentContainer.js +2 -1
- package/lib/components/ForeignComponentContainer.js.map +1 -1
- package/lib/components/Mediator.js +2 -1
- package/lib/components/Mediator.js.map +1 -1
- package/lib/components/PiralGlobals.js +2 -1
- package/lib/components/PiralGlobals.js.map +1 -1
- package/lib/components/PiralRoutes.js +1 -1
- package/lib/components/PiralRoutes.js.map +1 -1
- package/lib/components/PiralSuspense.js +2 -1
- package/lib/components/PiralSuspense.js.map +1 -1
- package/lib/components/PiralView.js +2 -1
- package/lib/components/PiralView.js.map +1 -1
- package/lib/components/ResponsiveLayout.js +2 -1
- package/lib/components/ResponsiveLayout.js.map +1 -1
- package/lib/components/SwitchErrorInfo.js +2 -1
- package/lib/components/SwitchErrorInfo.js.map +1 -1
- package/lib/components/components.js +2 -1
- package/lib/components/components.js.map +1 -1
- package/lib/components/wrapComponent.js +2 -1
- package/lib/components/wrapComponent.js.map +1 -1
- package/lib/defaults/DefaultErrorInfo.js +2 -1
- package/lib/defaults/DefaultErrorInfo.js.map +1 -1
- package/lib/defaults/DefaultLoadingIndicator.js +2 -1
- package/lib/defaults/DefaultLoadingIndicator.js.map +1 -1
- package/lib/defaults/DefaultRouteSwitch_v5.js +1 -1
- package/lib/defaults/DefaultRouteSwitch_v5.js.map +1 -1
- package/lib/defaults/DefaultRouteSwitch_v6.js +1 -1
- package/lib/defaults/DefaultRouteSwitch_v6.js.map +1 -1
- package/lib/defaults/DefaultRouter_v5.js +2 -1
- package/lib/defaults/DefaultRouter_v5.js.map +1 -1
- package/lib/defaults/DefaultRouter_v6.js +2 -1
- package/lib/defaults/DefaultRouter_v6.js.map +1 -1
- package/lib/defaults/navigator_v5.js +2 -1
- package/lib/defaults/navigator_v5.js.map +1 -1
- package/lib/defaults/navigator_v6.js +2 -1
- package/lib/defaults/navigator_v6.js.map +1 -1
- package/lib/setters/SetErrors.js +2 -1
- package/lib/setters/SetErrors.js.map +1 -1
- package/lib/setters/SetLayout.js +2 -1
- package/lib/setters/SetLayout.js.map +1 -1
- package/lib/state/createActions.js +2 -1
- package/lib/state/createActions.js.map +1 -1
- package/lib/state/createGlobalState.js +2 -1
- package/lib/state/createGlobalState.js.map +1 -1
- package/lib/state/stateContext.js +2 -1
- package/lib/state/stateContext.js.map +1 -1
- package/lib/state/withApi.js +2 -1
- package/lib/state/withApi.js.map +1 -1
- package/lib/utils/extension.js +2 -1
- package/lib/utils/extension.js.map +1 -1
- package/lib/utils/react.js +2 -1
- package/lib/utils/react.js.map +1 -1
- package/lib/utils/routes.js +3 -4
- package/lib/utils/routes.js.map +1 -1
- package/package.json +4 -4
- package/src/Piral.test.tsx +48 -0
- package/src/RootListener.test.tsx +7 -3
- package/src/actions/app.test.ts +12 -0
- package/src/actions/components.test.ts +11 -0
- package/src/actions/data.test.ts +4 -0
- package/src/actions/define.test.ts +4 -3
- package/src/actions/portal.test.ts +1 -0
- package/src/actions/state.test.ts +4 -3
- package/src/components/ExtensionSlot.test.tsx +19 -4
- package/src/components/ForeignComponentContainer.test.tsx +12 -8
- package/src/components/Mediator.test.tsx +8 -4
- package/src/components/PiralRoutes.test.tsx +16 -2
- package/src/components/PiralView-server.test.tsx +4 -3
- package/src/components/PiralView.test.tsx +11 -3
- package/src/components/ResponsiveLayout.test.tsx +9 -5
- package/src/components/SwitchErrorInfo.test.tsx +15 -4
- package/src/createInstance.test.tsx +14 -0
- package/src/defaults/DefaultErrorInfo.test.tsx +5 -1
- package/src/defaults/DefaultLayout.test.tsx +4 -0
- package/src/defaults/DefaultLoadingIndicator.test.tsx +4 -0
- package/src/helpers.test.tsx +47 -27
- package/src/hooks/action.test.ts +4 -3
- package/src/hooks/actions.test.ts +4 -3
- package/src/hooks/media.test.ts +31 -23
- package/src/hooks/setter-server.test.ts +3 -2
- package/src/hooks/setter.test.ts +5 -1
- package/src/hooks/sharedData.test.ts +11 -8
- package/src/modules/api.test.ts +19 -18
- package/src/modules/core.test.ts +19 -18
- package/src/modules/dependencies.test.ts +1 -0
- package/src/modules/element-server.test.ts +9 -1
- package/src/modules/element.test.ts +11 -0
- package/src/setters/SetComponent.test.tsx +7 -3
- package/src/setters/SetError.test.tsx +7 -3
- package/src/setters/SetErrors.test.tsx +7 -3
- package/src/setters/SetLayout.test.tsx +7 -3
- package/src/setters/SetProvider.test.tsx +7 -3
- package/src/setters/SetRedirect.test.tsx +13 -3
- package/src/setters/SetRoute.test.tsx +7 -3
- package/src/state/createActions.test.ts +12 -1
- package/src/state/createGlobalState.test.ts +35 -59
- package/src/state/withApi.test.tsx +12 -8
- package/src/utils/compare.test.ts +1 -0
- package/src/utils/data.test.ts +5 -0
- package/src/utils/extension.test.tsx +5 -1
- package/src/utils/foreign.test.ts +9 -8
- package/src/utils/guid.test.ts +1 -0
- package/src/utils/helpers.test.ts +14 -13
- package/src/utils/media-server.test.ts +2 -1
- package/src/utils/media.test.ts +19 -11
- package/src/utils/routes.test.ts +1 -0
- package/src/utils/routes.ts +1 -3
- package/src/utils/state.test.ts +7 -6
- package/src/utils/storage.test.ts +9 -4
|
@@ -1,5 +1,9 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @vitest-environment jsdom
|
|
3
|
+
*/
|
|
1
4
|
import * as React from 'react';
|
|
2
5
|
import create from 'zustand';
|
|
6
|
+
import { describe, it, expect, vitest } from 'vitest';
|
|
3
7
|
import { render } from '@testing-library/react';
|
|
4
8
|
import { SetError } from './SetError';
|
|
5
9
|
import { StateContext } from '../state';
|
|
@@ -13,9 +17,9 @@ function createMockContainer() {
|
|
|
13
17
|
}));
|
|
14
18
|
return {
|
|
15
19
|
context: {
|
|
16
|
-
on:
|
|
17
|
-
off:
|
|
18
|
-
emit:
|
|
20
|
+
on: vitest.fn(),
|
|
21
|
+
off: vitest.fn(),
|
|
22
|
+
emit: vitest.fn(),
|
|
19
23
|
state,
|
|
20
24
|
setErrorComponent(name, comp) {
|
|
21
25
|
const s = state.getState();
|
|
@@ -1,5 +1,9 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @vitest-environment jsdom
|
|
3
|
+
*/
|
|
1
4
|
import * as React from 'react';
|
|
2
5
|
import create from 'zustand';
|
|
6
|
+
import { describe, it, expect, vitest } from 'vitest';
|
|
3
7
|
import { render } from '@testing-library/react';
|
|
4
8
|
import { SetErrors } from './SetErrors';
|
|
5
9
|
import { StateContext } from '../state/stateContext';
|
|
@@ -13,9 +17,9 @@ function createMockContainer() {
|
|
|
13
17
|
}));
|
|
14
18
|
return {
|
|
15
19
|
context: {
|
|
16
|
-
on:
|
|
17
|
-
off:
|
|
18
|
-
emit:
|
|
20
|
+
on: vitest.fn(),
|
|
21
|
+
off: vitest.fn(),
|
|
22
|
+
emit: vitest.fn(),
|
|
19
23
|
state,
|
|
20
24
|
setErrorComponent(name, comp) {
|
|
21
25
|
const s = state.getState();
|
|
@@ -1,5 +1,9 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @vitest-environment jsdom
|
|
3
|
+
*/
|
|
1
4
|
import * as React from 'react';
|
|
2
5
|
import create from 'zustand';
|
|
6
|
+
import { describe, it, expect, vitest } from 'vitest';
|
|
3
7
|
import { render } from '@testing-library/react';
|
|
4
8
|
import { SetLayout } from './SetLayout';
|
|
5
9
|
import { StateContext } from '../state/stateContext';
|
|
@@ -13,9 +17,9 @@ function createMockContainer() {
|
|
|
13
17
|
}));
|
|
14
18
|
return {
|
|
15
19
|
context: {
|
|
16
|
-
on:
|
|
17
|
-
off:
|
|
18
|
-
emit:
|
|
20
|
+
on: vitest.fn(),
|
|
21
|
+
off: vitest.fn(),
|
|
22
|
+
emit: vitest.fn(),
|
|
19
23
|
state,
|
|
20
24
|
setComponent(name, comp) {
|
|
21
25
|
const s = state.getState();
|
|
@@ -1,5 +1,9 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @vitest-environment jsdom
|
|
3
|
+
*/
|
|
1
4
|
import * as React from 'react';
|
|
2
5
|
import create from 'zustand';
|
|
6
|
+
import { describe, it, expect, vitest } from 'vitest';
|
|
3
7
|
import { render } from '@testing-library/react';
|
|
4
8
|
import { SetProvider } from './SetProvider';
|
|
5
9
|
import { StateContext } from '../state';
|
|
@@ -13,9 +17,9 @@ function createMockContainer() {
|
|
|
13
17
|
}));
|
|
14
18
|
return {
|
|
15
19
|
context: {
|
|
16
|
-
on:
|
|
17
|
-
off:
|
|
18
|
-
emit:
|
|
20
|
+
on: vitest.fn(),
|
|
21
|
+
off: vitest.fn(),
|
|
22
|
+
emit: vitest.fn(),
|
|
19
23
|
state,
|
|
20
24
|
includeProvider(provider) {
|
|
21
25
|
const update = (s) => ({
|
|
@@ -1,18 +1,28 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @vitest-environment jsdom
|
|
3
|
+
*/
|
|
1
4
|
import * as React from 'react';
|
|
2
5
|
import create from 'zustand';
|
|
6
|
+
import { describe, it, expect, vitest } from 'vitest';
|
|
3
7
|
import { render } from '@testing-library/react';
|
|
4
8
|
import { SetRedirect } from './SetRedirect';
|
|
5
9
|
import { StateContext } from '../state';
|
|
6
10
|
|
|
11
|
+
vitest.mock('../../app.codegen', () => ({
|
|
12
|
+
createRedirect(to) {
|
|
13
|
+
return to;
|
|
14
|
+
},
|
|
15
|
+
}));
|
|
16
|
+
|
|
7
17
|
function createMockContainer() {
|
|
8
18
|
const state = create(() => ({
|
|
9
19
|
routes: {},
|
|
10
20
|
}));
|
|
11
21
|
return {
|
|
12
22
|
context: {
|
|
13
|
-
on:
|
|
14
|
-
off:
|
|
15
|
-
emit:
|
|
23
|
+
on: vitest.fn(),
|
|
24
|
+
off: vitest.fn(),
|
|
25
|
+
emit: vitest.fn(),
|
|
16
26
|
state,
|
|
17
27
|
setRoute(name, comp) {
|
|
18
28
|
const update = (s) => ({
|
|
@@ -1,5 +1,9 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @vitest-environment jsdom
|
|
3
|
+
*/
|
|
1
4
|
import * as React from 'react';
|
|
2
5
|
import create from 'zustand';
|
|
6
|
+
import { describe, it, expect, vitest } from 'vitest';
|
|
3
7
|
import { render } from '@testing-library/react';
|
|
4
8
|
import { SetRoute } from './SetRoute';
|
|
5
9
|
import { StateContext } from '../state';
|
|
@@ -13,9 +17,9 @@ function createMockContainer() {
|
|
|
13
17
|
}));
|
|
14
18
|
return {
|
|
15
19
|
context: {
|
|
16
|
-
on:
|
|
17
|
-
off:
|
|
18
|
-
emit:
|
|
20
|
+
on: vitest.fn(),
|
|
21
|
+
off: vitest.fn(),
|
|
22
|
+
emit: vitest.fn(),
|
|
19
23
|
state,
|
|
20
24
|
setRoute(name, comp) {
|
|
21
25
|
const update = (s) => ({
|
|
@@ -1,7 +1,11 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @vitest-environment jsdom
|
|
3
|
+
*/
|
|
4
|
+
import { describe, it, expect, vitest } from 'vitest';
|
|
1
5
|
import { createListener } from 'piral-base';
|
|
2
6
|
import { createActions, includeActions } from './createActions';
|
|
3
7
|
|
|
4
|
-
|
|
8
|
+
vitest.mock('../actions', () => ({
|
|
5
9
|
a(arg) {
|
|
6
10
|
return arg.state;
|
|
7
11
|
},
|
|
@@ -10,6 +14,13 @@ jest.mock('../actions', () => ({
|
|
|
10
14
|
},
|
|
11
15
|
}));
|
|
12
16
|
|
|
17
|
+
vitest.mock('../../app.codegen', () => ({
|
|
18
|
+
createNavigation: vitest.fn(publicPath => ({
|
|
19
|
+
publicPath,
|
|
20
|
+
})),
|
|
21
|
+
publicPath: '/',
|
|
22
|
+
}));
|
|
23
|
+
|
|
13
24
|
describe('Create Actions Module', () => {
|
|
14
25
|
it('createActions works with all actions', () => {
|
|
15
26
|
const events = createListener(undefined);
|
|
@@ -1,29 +1,47 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @vitest-environment jsdom
|
|
3
|
+
*/
|
|
4
|
+
import { describe, it, expect, vitest } from 'vitest';
|
|
1
5
|
import { createGlobalState } from './createGlobalState';
|
|
2
6
|
|
|
3
7
|
process.env.PIRAL_PUBLIC_PATH = '/';
|
|
4
8
|
|
|
9
|
+
vitest.mock('../../app.codegen', () => ({
|
|
10
|
+
createDefaultState() {
|
|
11
|
+
return {
|
|
12
|
+
app: {
|
|
13
|
+
error: undefined,
|
|
14
|
+
loading: typeof window !== 'undefined',
|
|
15
|
+
},
|
|
16
|
+
components: {},
|
|
17
|
+
errorComponents: {},
|
|
18
|
+
registry: {
|
|
19
|
+
extensions: {},
|
|
20
|
+
pages: {},
|
|
21
|
+
wrappers: {},
|
|
22
|
+
},
|
|
23
|
+
routes: {},
|
|
24
|
+
data: {},
|
|
25
|
+
portals: {},
|
|
26
|
+
modules: [],
|
|
27
|
+
};
|
|
28
|
+
},
|
|
29
|
+
}));
|
|
30
|
+
|
|
5
31
|
describe('Create Global State Module', () => {
|
|
6
|
-
window.matchMedia =
|
|
32
|
+
window.matchMedia = vitest.fn((q) => ({ matches: false })) as any;
|
|
7
33
|
|
|
8
34
|
it('global state works with language as empty string', () => {
|
|
9
35
|
const globalState = createGlobalState({});
|
|
10
36
|
const tmp = globalState.getState();
|
|
11
37
|
|
|
12
|
-
console.log(tmp);
|
|
13
|
-
|
|
14
38
|
expect(tmp).toEqual({
|
|
15
39
|
app: {
|
|
16
40
|
loading: true,
|
|
17
41
|
error: undefined,
|
|
18
42
|
},
|
|
19
43
|
errorComponents: {},
|
|
20
|
-
components: {
|
|
21
|
-
ErrorInfo: expect.anything(),
|
|
22
|
-
LoadingIndicator: expect.anything(),
|
|
23
|
-
Router: expect.anything(),
|
|
24
|
-
Layout: expect.anything(),
|
|
25
|
-
RouteSwitch: expect.anything(),
|
|
26
|
-
},
|
|
44
|
+
components: {},
|
|
27
45
|
routes: {},
|
|
28
46
|
registry: {
|
|
29
47
|
extensions: {},
|
|
@@ -44,13 +62,7 @@ describe('Create Global State Module', () => {
|
|
|
44
62
|
error: undefined,
|
|
45
63
|
},
|
|
46
64
|
errorComponents: {},
|
|
47
|
-
components: {
|
|
48
|
-
ErrorInfo: expect.anything(),
|
|
49
|
-
LoadingIndicator: expect.anything(),
|
|
50
|
-
Router: expect.anything(),
|
|
51
|
-
Layout: expect.anything(),
|
|
52
|
-
RouteSwitch: expect.anything(),
|
|
53
|
-
},
|
|
65
|
+
components: {},
|
|
54
66
|
routes: {},
|
|
55
67
|
registry: {
|
|
56
68
|
extensions: {},
|
|
@@ -75,13 +87,7 @@ describe('Create Global State Module', () => {
|
|
|
75
87
|
loading: true,
|
|
76
88
|
},
|
|
77
89
|
errorComponents: {},
|
|
78
|
-
components: {
|
|
79
|
-
ErrorInfo: expect.anything(),
|
|
80
|
-
LoadingIndicator: expect.anything(),
|
|
81
|
-
Router: expect.anything(),
|
|
82
|
-
Layout: expect.anything(),
|
|
83
|
-
RouteSwitch: expect.anything(),
|
|
84
|
-
},
|
|
90
|
+
components: {},
|
|
85
91
|
routes,
|
|
86
92
|
registry: {
|
|
87
93
|
extensions: {},
|
|
@@ -102,13 +108,7 @@ describe('Create Global State Module', () => {
|
|
|
102
108
|
error: undefined,
|
|
103
109
|
},
|
|
104
110
|
errorComponents: {},
|
|
105
|
-
components: {
|
|
106
|
-
ErrorInfo: expect.anything(),
|
|
107
|
-
LoadingIndicator: expect.anything(),
|
|
108
|
-
Router: expect.anything(),
|
|
109
|
-
Layout: expect.anything(),
|
|
110
|
-
RouteSwitch: expect.anything(),
|
|
111
|
-
},
|
|
111
|
+
components: {},
|
|
112
112
|
registry: {
|
|
113
113
|
extensions: {},
|
|
114
114
|
pages: {},
|
|
@@ -131,13 +131,7 @@ describe('Create Global State Module', () => {
|
|
|
131
131
|
error: undefined,
|
|
132
132
|
},
|
|
133
133
|
errorComponents: {},
|
|
134
|
-
components: {
|
|
135
|
-
ErrorInfo: expect.anything(),
|
|
136
|
-
LoadingIndicator: expect.anything(),
|
|
137
|
-
Router: expect.anything(),
|
|
138
|
-
Layout: expect.anything(),
|
|
139
|
-
RouteSwitch: expect.anything(),
|
|
140
|
-
},
|
|
134
|
+
components: {},
|
|
141
135
|
registry: {
|
|
142
136
|
extensions: {},
|
|
143
137
|
pages: {},
|
|
@@ -160,13 +154,7 @@ describe('Create Global State Module', () => {
|
|
|
160
154
|
error: undefined,
|
|
161
155
|
},
|
|
162
156
|
errorComponents: {},
|
|
163
|
-
components: {
|
|
164
|
-
ErrorInfo: expect.anything(),
|
|
165
|
-
LoadingIndicator: expect.anything(),
|
|
166
|
-
Router: expect.anything(),
|
|
167
|
-
Layout: expect.anything(),
|
|
168
|
-
RouteSwitch: expect.anything(),
|
|
169
|
-
},
|
|
157
|
+
components: {},
|
|
170
158
|
registry: {
|
|
171
159
|
extensions: {},
|
|
172
160
|
pages: {},
|
|
@@ -193,13 +181,7 @@ describe('Create Global State Module', () => {
|
|
|
193
181
|
error: undefined,
|
|
194
182
|
},
|
|
195
183
|
errorComponents: {},
|
|
196
|
-
components: {
|
|
197
|
-
ErrorInfo: expect.anything(),
|
|
198
|
-
LoadingIndicator: expect.anything(),
|
|
199
|
-
Router: expect.anything(),
|
|
200
|
-
Layout: expect.anything(),
|
|
201
|
-
RouteSwitch: expect.anything(),
|
|
202
|
-
},
|
|
184
|
+
components: {},
|
|
203
185
|
registry: {
|
|
204
186
|
extensions: {},
|
|
205
187
|
pages: {},
|
|
@@ -227,13 +209,7 @@ describe('Create Global State Module', () => {
|
|
|
227
209
|
error: undefined,
|
|
228
210
|
},
|
|
229
211
|
errorComponents: {},
|
|
230
|
-
components: {
|
|
231
|
-
ErrorInfo: expect.anything(),
|
|
232
|
-
LoadingIndicator: expect.anything(),
|
|
233
|
-
Router: expect.anything(),
|
|
234
|
-
Layout: expect.anything(),
|
|
235
|
-
RouteSwitch: expect.anything(),
|
|
236
|
-
},
|
|
212
|
+
components: {},
|
|
237
213
|
registry: {
|
|
238
214
|
extensions: {},
|
|
239
215
|
pages: {},
|
|
@@ -1,5 +1,9 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @vitest-environment jsdom
|
|
3
|
+
*/
|
|
1
4
|
import * as React from 'react';
|
|
2
5
|
import create from 'zustand';
|
|
6
|
+
import { describe, it, expect, vitest } from 'vitest';
|
|
3
7
|
import { render } from '@testing-library/react';
|
|
4
8
|
import { withApi } from './withApi';
|
|
5
9
|
import { StateContext } from '../state';
|
|
@@ -24,9 +28,9 @@ function createMockContainer() {
|
|
|
24
28
|
navigation: {
|
|
25
29
|
router: undefined,
|
|
26
30
|
},
|
|
27
|
-
on:
|
|
28
|
-
off:
|
|
29
|
-
emit:
|
|
31
|
+
on: vitest.fn(),
|
|
32
|
+
off: vitest.fn(),
|
|
33
|
+
emit: vitest.fn(),
|
|
30
34
|
state,
|
|
31
35
|
destroyPortal: (id) => {},
|
|
32
36
|
} as any,
|
|
@@ -51,9 +55,9 @@ function createMockContainerWithNoWrappers() {
|
|
|
51
55
|
},
|
|
52
56
|
});
|
|
53
57
|
},
|
|
54
|
-
on:
|
|
55
|
-
off:
|
|
56
|
-
emit:
|
|
58
|
+
on: vitest.fn(),
|
|
59
|
+
off: vitest.fn(),
|
|
60
|
+
emit: vitest.fn(),
|
|
57
61
|
state,
|
|
58
62
|
destroyPortal: (id) => {},
|
|
59
63
|
} as any,
|
|
@@ -89,7 +93,7 @@ describe('withApi Module', () => {
|
|
|
89
93
|
});
|
|
90
94
|
|
|
91
95
|
it('is protected against a component crash', () => {
|
|
92
|
-
console.error =
|
|
96
|
+
console.error = vitest.fn();
|
|
93
97
|
const api: any = {
|
|
94
98
|
meta: {
|
|
95
99
|
name: 'foo',
|
|
@@ -106,7 +110,7 @@ describe('withApi Module', () => {
|
|
|
106
110
|
});
|
|
107
111
|
|
|
108
112
|
it('reports to console.error when an error is hit', () => {
|
|
109
|
-
console.error =
|
|
113
|
+
console.error = vitest.fn();
|
|
110
114
|
const api: any = {
|
|
111
115
|
meta: {
|
|
112
116
|
name: 'my pilet',
|
package/src/utils/data.test.ts
CHANGED
|
@@ -1,3 +1,7 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @vitest-environment jsdom
|
|
3
|
+
*/
|
|
4
|
+
import { describe, it, expect } from 'vitest';
|
|
1
5
|
import { getDataExpiration, createDataOptions, createDataView } from './data';
|
|
2
6
|
import { Dict, SharedDataItem } from '../types';
|
|
3
7
|
|
|
@@ -69,6 +73,7 @@ describe('Data Module', () => {
|
|
|
69
73
|
it('createDataView returns undefined if not supported', () => {
|
|
70
74
|
const proxyName = 'Proxy';
|
|
71
75
|
const Proxy = window[proxyName];
|
|
76
|
+
// @ts-ignore
|
|
72
77
|
window[proxyName] = undefined;
|
|
73
78
|
const view = createDataView({});
|
|
74
79
|
window[proxyName] = Proxy;
|
|
@@ -1,4 +1,8 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @vitest-environment jsdom
|
|
3
|
+
*/
|
|
1
4
|
import * as React from 'react';
|
|
5
|
+
import { describe, it, expect } from 'vitest';
|
|
2
6
|
import { render } from '@testing-library/react';
|
|
3
7
|
import { reactifyContent, toExtension } from './extension';
|
|
4
8
|
|
|
@@ -6,7 +10,7 @@ describe('Util Extension.', () => {
|
|
|
6
10
|
it('Convert some component to an extension component.', () => {
|
|
7
11
|
const Component = ({ title }) => <b>{title}</b>;
|
|
8
12
|
const piral: any = {};
|
|
9
|
-
const Extension = toExtension(Component);
|
|
13
|
+
const Extension = toExtension(Component) as any;
|
|
10
14
|
const node = render(<Extension piral={piral} params={{ title: 'Foo' }} />);
|
|
11
15
|
expect(node.container.querySelectorAll('b').length).toBe(1);
|
|
12
16
|
});
|
|
@@ -1,18 +1,19 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @vitest-environment jsdom
|
|
3
|
+
*/
|
|
1
4
|
import * as React from 'react';
|
|
5
|
+
import { describe, it, expect, vitest } from 'vitest';
|
|
2
6
|
import { changeDomPortal, convertComponent, renderInDom } from './foreign';
|
|
3
7
|
import { DefaultLoadingIndicator } from '../defaults/DefaultLoadingIndicator';
|
|
4
8
|
import { ForeignComponent } from '../types';
|
|
5
9
|
|
|
6
|
-
// const StubComponent: React.FC = (props) => <div />;
|
|
7
|
-
// StubComponent.displayName = 'StubComponent';
|
|
8
|
-
|
|
9
10
|
describe('Util Foreign.', () => {
|
|
10
11
|
it('changeDomPortal changes dom in portal', () => {
|
|
11
12
|
const children = React.createElement('div');
|
|
12
|
-
const current: React.ReactPortal = { key: 'current', children: { children }, type: 'div', props: null };
|
|
13
|
+
const current: React.ReactPortal = { key: 'current', children: { children } as any, type: 'div', props: null };
|
|
13
14
|
|
|
14
15
|
const context = {
|
|
15
|
-
updatePortal:
|
|
16
|
+
updatePortal: vitest.fn(),
|
|
16
17
|
} as any;
|
|
17
18
|
const portalId = 'pid';
|
|
18
19
|
const element = document.createElement('piral-portal') as HTMLElement;
|
|
@@ -24,7 +25,7 @@ describe('Util Foreign.', () => {
|
|
|
24
25
|
|
|
25
26
|
it('Convert component function throws error due to missing converter function.', () => {
|
|
26
27
|
const t = () => {
|
|
27
|
-
convertComponent(null, React.createElement('div'));
|
|
28
|
+
convertComponent(null as any, React.createElement('div'));
|
|
28
29
|
};
|
|
29
30
|
expect(t).toThrow('No converter for component of type "div" registered.');
|
|
30
31
|
});
|
|
@@ -41,7 +42,7 @@ describe('Util Foreign.', () => {
|
|
|
41
42
|
|
|
42
43
|
it('Render in DOM', () => {
|
|
43
44
|
const context = {
|
|
44
|
-
showPortal:
|
|
45
|
+
showPortal: vitest.fn(),
|
|
45
46
|
} as any;
|
|
46
47
|
const portalId = 'pid';
|
|
47
48
|
const element = document.createElement('piral-portal') as HTMLElement;
|
|
@@ -52,7 +53,7 @@ describe('Util Foreign.', () => {
|
|
|
52
53
|
|
|
53
54
|
it('Render in DOM with parent node missing', () => {
|
|
54
55
|
const context = {
|
|
55
|
-
showPortal:
|
|
56
|
+
showPortal: vitest.fn(),
|
|
56
57
|
} as any;
|
|
57
58
|
const element = document.createElement('piral-portal') as HTMLElement;
|
|
58
59
|
var [result] = renderInDom(context, element, DefaultLoadingIndicator, {});
|
package/src/utils/guid.test.ts
CHANGED
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { describe, it, expect } from 'vitest';
|
|
1
2
|
import {
|
|
2
3
|
appendItem,
|
|
3
4
|
excludeItem,
|
|
@@ -69,7 +70,7 @@ describe('Helpers Module', () => {
|
|
|
69
70
|
});
|
|
70
71
|
|
|
71
72
|
it('prependItem works without an existing array', () => {
|
|
72
|
-
const result = prependItem(undefined, 4);
|
|
73
|
+
const result = prependItem(undefined as any, 4);
|
|
73
74
|
expect(result).toEqual([4]);
|
|
74
75
|
});
|
|
75
76
|
|
|
@@ -85,7 +86,7 @@ describe('Helpers Module', () => {
|
|
|
85
86
|
});
|
|
86
87
|
|
|
87
88
|
it('appendItem works without an existing array', () => {
|
|
88
|
-
const result = appendItem(undefined, 4);
|
|
89
|
+
const result = appendItem(undefined as any, 4);
|
|
89
90
|
expect(result).toEqual([4]);
|
|
90
91
|
});
|
|
91
92
|
|
|
@@ -111,7 +112,7 @@ describe('Helpers Module', () => {
|
|
|
111
112
|
});
|
|
112
113
|
|
|
113
114
|
it('prependItems works without an existing array', () => {
|
|
114
|
-
const result = prependItems(undefined, [4]);
|
|
115
|
+
const result = prependItems(undefined as any, [4]);
|
|
115
116
|
expect(result).toEqual([4]);
|
|
116
117
|
});
|
|
117
118
|
|
|
@@ -127,7 +128,7 @@ describe('Helpers Module', () => {
|
|
|
127
128
|
});
|
|
128
129
|
|
|
129
130
|
it('appendItems works without an existing array', () => {
|
|
130
|
-
const result = appendItems(undefined, [4]);
|
|
131
|
+
const result = appendItems(undefined as any, [4]);
|
|
131
132
|
expect(result).toEqual([4]);
|
|
132
133
|
});
|
|
133
134
|
|
|
@@ -155,7 +156,7 @@ describe('Helpers Module', () => {
|
|
|
155
156
|
});
|
|
156
157
|
|
|
157
158
|
it('excludeItem works without an existing array', () => {
|
|
158
|
-
const result = excludeItem(undefined, 2);
|
|
159
|
+
const result = excludeItem(undefined as any, 2);
|
|
159
160
|
expect(result).toEqual([]);
|
|
160
161
|
});
|
|
161
162
|
|
|
@@ -176,7 +177,7 @@ describe('Helpers Module', () => {
|
|
|
176
177
|
});
|
|
177
178
|
|
|
178
179
|
it('excludeOn works without an existing array', () => {
|
|
179
|
-
const result = excludeOn(undefined, (x) => x === 2);
|
|
180
|
+
const result = excludeOn(undefined as any, (x) => x === 2);
|
|
180
181
|
expect(result).toEqual([]);
|
|
181
182
|
});
|
|
182
183
|
|
|
@@ -193,7 +194,7 @@ describe('Helpers Module', () => {
|
|
|
193
194
|
|
|
194
195
|
it('withKey works with an existing object', () => {
|
|
195
196
|
const original = { a: 5 };
|
|
196
|
-
const result = withKey(original, 'b', 6);
|
|
197
|
+
const result = withKey(original, 'b' as any, 6);
|
|
197
198
|
expect(result).toEqual({
|
|
198
199
|
a: 5,
|
|
199
200
|
b: 6,
|
|
@@ -202,12 +203,12 @@ describe('Helpers Module', () => {
|
|
|
202
203
|
|
|
203
204
|
it('withKey does not modify existing object', () => {
|
|
204
205
|
const original = { a: 5 };
|
|
205
|
-
const result = withKey(original, 'b', 6);
|
|
206
|
+
const result = withKey(original, 'b' as any, 6);
|
|
206
207
|
expect(result).not.toBe(original);
|
|
207
208
|
});
|
|
208
209
|
|
|
209
210
|
it('withKey works without an existing object', () => {
|
|
210
|
-
const result = withKey(undefined, 'b', 6);
|
|
211
|
+
const result = withKey(undefined, 'b' as never, 6 as never);
|
|
211
212
|
expect(result).toEqual({
|
|
212
213
|
b: 6,
|
|
213
214
|
});
|
|
@@ -215,7 +216,7 @@ describe('Helpers Module', () => {
|
|
|
215
216
|
|
|
216
217
|
it('withoutKey ignores non-existing key', () => {
|
|
217
218
|
const original = { a: 5 };
|
|
218
|
-
const result = withoutKey(original, 'b');
|
|
219
|
+
const result = withoutKey(original, 'b' as any);
|
|
219
220
|
expect(result).toEqual({
|
|
220
221
|
a: 5,
|
|
221
222
|
});
|
|
@@ -246,12 +247,12 @@ describe('Helpers Module', () => {
|
|
|
246
247
|
});
|
|
247
248
|
|
|
248
249
|
it('withoutKey works without an existing object', () => {
|
|
249
|
-
const result = withoutKey(undefined, 'a');
|
|
250
|
+
const result = withoutKey(undefined, 'a' as never);
|
|
250
251
|
expect(result).toEqual({});
|
|
251
252
|
});
|
|
252
253
|
|
|
253
254
|
it('withoutKey works without a valid key', () => {
|
|
254
|
-
const result = withoutKey({}, undefined as
|
|
255
|
+
const result = withoutKey({}, undefined as never);
|
|
255
256
|
expect(result).toEqual({});
|
|
256
257
|
});
|
|
257
258
|
|
|
@@ -261,7 +262,7 @@ describe('Helpers Module', () => {
|
|
|
261
262
|
});
|
|
262
263
|
|
|
263
264
|
it('updateKey with the removeIndicator', () => {
|
|
264
|
-
const result = updateKey({ b: '1233' }, 'b', null);
|
|
265
|
+
const result = updateKey({ b: '1233' }, 'b', null as any);
|
|
265
266
|
expect(result).toEqual({});
|
|
266
267
|
});
|
|
267
268
|
|
package/src/utils/media.test.ts
CHANGED
|
@@ -1,40 +1,48 @@
|
|
|
1
|
-
|
|
1
|
+
/**
|
|
2
|
+
* @vitest-environment jsdom
|
|
3
|
+
*/
|
|
4
|
+
import { describe, it, expect, vitest } from 'vitest';
|
|
2
5
|
|
|
3
6
|
describe('Media Module', () => {
|
|
4
|
-
it('getCurrentLayout correctly takes matched first layout', () => {
|
|
7
|
+
it('getCurrentLayout correctly takes matched first layout', async () => {
|
|
5
8
|
const breakpoints = ['min-width: 200px', 'max-width: 199px'];
|
|
6
|
-
window.matchMedia =
|
|
9
|
+
window.matchMedia = vitest.fn((q) => ({ matches: q === breakpoints[0] })) as any;
|
|
10
|
+
const { getCurrentLayout } = await import('./media');
|
|
7
11
|
const result = getCurrentLayout(breakpoints, ['foo', 'bar'], 'foo');
|
|
8
12
|
expect(window.matchMedia).toHaveBeenCalledTimes(1);
|
|
9
13
|
expect(result).toBe('foo');
|
|
10
14
|
});
|
|
11
15
|
|
|
12
|
-
it('getCurrentLayout correctly takes matched second layout', () => {
|
|
16
|
+
it('getCurrentLayout correctly takes matched second layout', async () => {
|
|
13
17
|
const breakpoints = ['min-width: 200px', 'max-width: 199px'];
|
|
14
|
-
window.matchMedia =
|
|
18
|
+
window.matchMedia = vitest.fn((q) => ({ matches: q === breakpoints[1] }) as any);
|
|
19
|
+
const { getCurrentLayout } = await import('./media');
|
|
15
20
|
const result = getCurrentLayout(breakpoints, ['foo', 'bar'], 'foo');
|
|
16
21
|
expect(window.matchMedia).toHaveBeenCalledTimes(2);
|
|
17
22
|
expect(result).toBe('bar');
|
|
18
23
|
});
|
|
19
24
|
|
|
20
|
-
it('getCurrentLayout uses default layout if nothing matches', () => {
|
|
25
|
+
it('getCurrentLayout uses default layout if nothing matches', async () => {
|
|
21
26
|
const breakpoints = ['min-width: 200px', 'max-width: 199px'];
|
|
22
|
-
window.matchMedia =
|
|
27
|
+
window.matchMedia = vitest.fn((q) => ({ matches: false })) as any;
|
|
28
|
+
const { getCurrentLayout } = await import('./media');
|
|
23
29
|
const result = getCurrentLayout(breakpoints, ['foo', 'bar'], 'foo');
|
|
24
30
|
expect(window.matchMedia).toHaveBeenCalledTimes(2);
|
|
25
31
|
expect(result).toBe('foo');
|
|
26
32
|
});
|
|
27
33
|
|
|
28
|
-
it('getCurrentLayout uses default layout which not be a given layoput', () => {
|
|
34
|
+
it('getCurrentLayout uses default layout which not be a given layoput', async () => {
|
|
29
35
|
const breakpoints = ['min-width: 200px', 'max-width: 199px'];
|
|
30
|
-
window.matchMedia =
|
|
36
|
+
window.matchMedia = vitest.fn((q) => ({ matches: false })) as any;
|
|
37
|
+
const { getCurrentLayout } = await import('./media');
|
|
31
38
|
const result = getCurrentLayout(breakpoints, ['foo', 'bar'], 'qxz');
|
|
32
39
|
expect(window.matchMedia).toHaveBeenCalledTimes(2);
|
|
33
40
|
expect(result).toBe('qxz');
|
|
34
41
|
});
|
|
35
42
|
|
|
36
|
-
it('getCurrentLayout uses default layout if no breakpoint given', () => {
|
|
37
|
-
window.matchMedia =
|
|
43
|
+
it('getCurrentLayout uses default layout if no breakpoint given', async () => {
|
|
44
|
+
window.matchMedia = vitest.fn((q) => ({ matches: true })) as any;
|
|
45
|
+
const { getCurrentLayout } = await import('./media');
|
|
38
46
|
const result = getCurrentLayout([], ['foo', 'bar'], 'qxz');
|
|
39
47
|
expect(window.matchMedia).toHaveBeenCalledTimes(0);
|
|
40
48
|
expect(result).toBe('qxz');
|
package/src/utils/routes.test.ts
CHANGED