piral-core 1.3.3-beta.6187 → 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
package/lib/utils/extension.js
CHANGED
|
@@ -1,7 +1,8 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.reactifyContent = exports.toExtension = void 0;
|
|
4
|
-
const
|
|
4
|
+
const tslib_1 = require("tslib");
|
|
5
|
+
const React = tslib_1.__importStar(require("react"));
|
|
5
6
|
function removeAll(nodes) {
|
|
6
7
|
nodes.forEach((node) => node.remove());
|
|
7
8
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"extension.js","sourceRoot":"","sources":["../../src/utils/extension.tsx"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"extension.js","sourceRoot":"","sources":["../../src/utils/extension.tsx"],"names":[],"mappings":";;;;AAAA,qDAA+B;AAI/B,SAAS,SAAS,CAAC,KAAuB;IACxC,KAAK,CAAC,OAAO,CAAC,CAAC,IAAI,EAAE,EAAE,CAAC,IAAI,CAAC,MAAM,EAAE,CAAC,CAAC;AACzC,CAAC;AAMD,MAAM,WAAW,GAA+B,CAAC,EAAE,KAAK,EAAE,EAAE,EAAE;IAC5D,MAAM,IAAI,GAAG,KAAK,CAAC,MAAM,EAAmB,CAAC;IAE7C,KAAK,CAAC,SAAS,CAAC,GAAG,EAAE;;QACnB,MAAA,IAAI,CAAC,OAAO,0CAAE,MAAM,CAAC,GAAG,KAAK,CAAC,CAAC;QAC/B,OAAO,GAAG,EAAE,CAAC,SAAS,CAAC,KAAK,CAAC,CAAC;IAChC,CAAC,EAAE,CAAC,KAAK,CAAC,CAAC,CAAC;IAEZ,IAAI,KAAK,CAAC,MAAM,EAAE;QAChB,OAAO,oCAAY,GAAG,EAAE,IAAI,GAAI,CAAC;KAClC;IAED,OAAO,IAAI,CAAC;AACd,CAAC,CAAC;AAEF;;;;GAIG;AACH,SAAgB,WAAW,CAAI,SAAiC;IAC9D,OAAO,CAAC,KAAK,EAAE,EAAE,CAAC,oBAAC,SAAS,oBAAK,KAAK,CAAC,MAAM,EAAI,CAAC;AACpD,CAAC;AAFD,kCAEC;AAED;;;;;;GAMG;AACH,SAAgB,eAAe,CAAC,UAAiC;IAC/D,MAAM,KAAK,GAAqB,KAAK,CAAC,SAAS,CAAC,MAAM,CAAC,IAAI,CAAC,UAAU,EAAE,OAAO,CAAC,CAAC;IACjF,SAAS,CAAC,KAAK,CAAC,CAAC;IACjB,OAAO,oBAAC,WAAW,IAAC,KAAK,EAAE,KAAK,GAAI,CAAC;AACvC,CAAC;AAJD,0CAIC"}
|
package/lib/utils/react.js
CHANGED
|
@@ -1,7 +1,8 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.defaultRender = void 0;
|
|
4
|
-
const
|
|
4
|
+
const tslib_1 = require("tslib");
|
|
5
|
+
const React = tslib_1.__importStar(require("react"));
|
|
5
6
|
function defaultRender(children, key) {
|
|
6
7
|
return React.createElement(React.Fragment, { key: key }, children);
|
|
7
8
|
}
|
package/lib/utils/react.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"react.js","sourceRoot":"","sources":["../../src/utils/react.tsx"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"react.js","sourceRoot":"","sources":["../../src/utils/react.tsx"],"names":[],"mappings":";;;;AAAA,qDAA+B;AAE/B,SAAgB,aAAa,CAAC,QAAyB,EAAE,GAAY;IACnE,OAAO,oBAAC,KAAK,CAAC,QAAQ,IAAC,GAAG,EAAE,GAAG,IAAG,QAAQ,CAAkB,CAAC;AAC/D,CAAC;AAFD,sCAEC"}
|
package/lib/utils/routes.js
CHANGED
|
@@ -1,11 +1,10 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.createRouteMatcher = void 0;
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
const ptr = require('path-to-regexp');
|
|
4
|
+
const tslib_1 = require("tslib");
|
|
5
|
+
const path_to_regexp_1 = tslib_1.__importDefault(require("path-to-regexp"));
|
|
7
6
|
function createRouteMatcher(path) {
|
|
8
|
-
return
|
|
7
|
+
return (0, path_to_regexp_1.default)(path);
|
|
9
8
|
}
|
|
10
9
|
exports.createRouteMatcher = createRouteMatcher;
|
|
11
10
|
//# sourceMappingURL=routes.js.map
|
package/lib/utils/routes.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"routes.js","sourceRoot":"","sources":["../../src/utils/routes.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"routes.js","sourceRoot":"","sources":["../../src/utils/routes.ts"],"names":[],"mappings":";;;;AAAA,4EAAiC;AAEjC,SAAgB,kBAAkB,CAAC,IAAY;IAC7C,OAAO,IAAA,wBAAG,EAAC,IAAI,CAAC,CAAC;AACnB,CAAC;AAFD,gDAEC"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "piral-core",
|
|
3
|
-
"version": "1.3.3-beta.
|
|
3
|
+
"version": "1.3.3-beta.6201",
|
|
4
4
|
"description": "The core library for creating a Piral instance.",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"portal",
|
|
@@ -73,8 +73,8 @@
|
|
|
73
73
|
},
|
|
74
74
|
"dependencies": {
|
|
75
75
|
"path-to-regexp": "^1.8.0",
|
|
76
|
-
"piral-base": "1.3.3-beta.
|
|
77
|
-
"piral-debug-utils": "1.3.3-beta.
|
|
76
|
+
"piral-base": "1.3.3-beta.6201",
|
|
77
|
+
"piral-debug-utils": "1.3.3-beta.6201",
|
|
78
78
|
"zustand": "^3.0.0"
|
|
79
79
|
},
|
|
80
80
|
"devDependencies": {
|
|
@@ -94,5 +94,5 @@
|
|
|
94
94
|
"react-router-dom",
|
|
95
95
|
"tslib"
|
|
96
96
|
],
|
|
97
|
-
"gitHead": "
|
|
97
|
+
"gitHead": "6e9f4e6f83514b5c38960ce015e073efc668f3d6"
|
|
98
98
|
}
|
package/src/Piral.test.tsx
CHANGED
|
@@ -1,8 +1,56 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @vitest-environment jsdom
|
|
3
|
+
*/
|
|
1
4
|
import * as React from 'react';
|
|
5
|
+
import { describe, it, expect, vitest } from 'vitest';
|
|
2
6
|
import { render, act } from '@testing-library/react';
|
|
3
7
|
import { Piral } from './Piral';
|
|
4
8
|
import { createInstance } from './createInstance';
|
|
5
9
|
|
|
10
|
+
import { DefaultErrorInfo } from './defaults/DefaultErrorInfo';
|
|
11
|
+
import { DefaultLoadingIndicator } from './defaults/DefaultLoadingIndicator';
|
|
12
|
+
import { DefaultLayout } from './defaults/DefaultLayout';
|
|
13
|
+
import { DefaultRouteSwitch } from './defaults/DefaultRouteSwitch_v5';
|
|
14
|
+
import { DefaultRouter } from './defaults/DefaultRouter_v5';
|
|
15
|
+
|
|
16
|
+
vitest.mock('../app.codegen', () => ({
|
|
17
|
+
createNavigation: vitest.fn(() => ({
|
|
18
|
+
publicPath: '/',
|
|
19
|
+
})),
|
|
20
|
+
fillDependencies: vitest.fn(),
|
|
21
|
+
integrateDebugger: vitest.fn(),
|
|
22
|
+
integrateEmulator: vitest.fn(),
|
|
23
|
+
publicPath: '/',
|
|
24
|
+
useRouteFilter(routes) {
|
|
25
|
+
return routes;
|
|
26
|
+
},
|
|
27
|
+
createDefaultState() {
|
|
28
|
+
return {
|
|
29
|
+
app: {
|
|
30
|
+
error: undefined,
|
|
31
|
+
loading: typeof window !== 'undefined',
|
|
32
|
+
},
|
|
33
|
+
components: {
|
|
34
|
+
ErrorInfo: DefaultErrorInfo,
|
|
35
|
+
LoadingIndicator: DefaultLoadingIndicator,
|
|
36
|
+
Router: DefaultRouter,
|
|
37
|
+
RouteSwitch: DefaultRouteSwitch,
|
|
38
|
+
Layout: DefaultLayout,
|
|
39
|
+
},
|
|
40
|
+
errorComponents: {},
|
|
41
|
+
registry: {
|
|
42
|
+
extensions: {},
|
|
43
|
+
pages: {},
|
|
44
|
+
wrappers: {},
|
|
45
|
+
},
|
|
46
|
+
routes: {},
|
|
47
|
+
data: {},
|
|
48
|
+
portals: {},
|
|
49
|
+
modules: [],
|
|
50
|
+
};
|
|
51
|
+
},
|
|
52
|
+
}));
|
|
53
|
+
|
|
6
54
|
describe('Piral Component', () => {
|
|
7
55
|
it('renders the Piral instance with default settings', async () => {
|
|
8
56
|
const node = render(<Piral />);
|
|
@@ -1,8 +1,12 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @vitest-environment jsdom
|
|
3
|
+
*/
|
|
1
4
|
import * as React from 'react';
|
|
5
|
+
import { describe, it, expect, vitest } from 'vitest';
|
|
2
6
|
import { render, act } from '@testing-library/react';
|
|
3
7
|
import { RootListener } from './RootListener';
|
|
4
8
|
|
|
5
|
-
|
|
9
|
+
vitest.mock('./hooks/globalState', () => ({
|
|
6
10
|
useGlobalStateContext: () => ({
|
|
7
11
|
showPortal() {},
|
|
8
12
|
}),
|
|
@@ -15,7 +19,7 @@ function resolveAfter(time = 5) {
|
|
|
15
19
|
describe('RootListener Component', () => {
|
|
16
20
|
it('renders the RootListener instance with default settings', async () => {
|
|
17
21
|
const element = document.createElement('div');
|
|
18
|
-
const removed =
|
|
22
|
+
const removed = vitest.fn();
|
|
19
23
|
document.body.appendChild(element);
|
|
20
24
|
render(<RootListener />);
|
|
21
25
|
document.body.removeEventListener = removed;
|
|
@@ -35,7 +39,7 @@ describe('RootListener Component', () => {
|
|
|
35
39
|
});
|
|
36
40
|
|
|
37
41
|
it('removes the RootListener successfully', async () => {
|
|
38
|
-
const removed =
|
|
42
|
+
const removed = vitest.fn();
|
|
39
43
|
const container = render(<RootListener />);
|
|
40
44
|
document.body.removeEventListener = removed;
|
|
41
45
|
await act(resolveAfter);
|
package/src/actions/app.test.ts
CHANGED
|
@@ -1,4 +1,8 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @vitest-environment jsdom
|
|
3
|
+
*/
|
|
1
4
|
import create from 'zustand';
|
|
5
|
+
import { describe, it, expect, vitest } from 'vitest';
|
|
2
6
|
import { render } from '@testing-library/react';
|
|
3
7
|
import { createElement } from 'react';
|
|
4
8
|
import { createListener, Pilet } from 'piral-base';
|
|
@@ -14,6 +18,14 @@ import {
|
|
|
14
18
|
import { createActions } from '../state';
|
|
15
19
|
import { RootListener } from '../RootListener';
|
|
16
20
|
|
|
21
|
+
vitest.mock('../../app.codegen', () => ({
|
|
22
|
+
createNavigation: vitest.fn(publicPath => ({
|
|
23
|
+
publicPath,
|
|
24
|
+
})),
|
|
25
|
+
fillDependencies: vitest.fn(),
|
|
26
|
+
publicPath: '/',
|
|
27
|
+
}));
|
|
28
|
+
|
|
17
29
|
const pilet: Pilet = {
|
|
18
30
|
name: 'my-pilet',
|
|
19
31
|
version: '1.0.0',
|
|
@@ -1,8 +1,19 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @vitest-environment jsdom
|
|
3
|
+
*/
|
|
1
4
|
import create from 'zustand';
|
|
5
|
+
import { describe, it, expect, vitest } from 'vitest';
|
|
2
6
|
import { createListener } from 'piral-base';
|
|
3
7
|
import { registerExtension, registerPage, unregisterExtension, unregisterPage } from './components';
|
|
4
8
|
import { createActions } from '../state';
|
|
5
9
|
|
|
10
|
+
vitest.mock('../../app.codegen', () => ({
|
|
11
|
+
createNavigation: vitest.fn(publicPath => ({
|
|
12
|
+
publicPath,
|
|
13
|
+
})),
|
|
14
|
+
publicPath: '/',
|
|
15
|
+
}));
|
|
16
|
+
|
|
6
17
|
describe('Components Actions Module', () => {
|
|
7
18
|
it('registerExtension and unregisterExtension', () => {
|
|
8
19
|
const state: any = create(() => ({
|
package/src/actions/data.test.ts
CHANGED
|
@@ -1,4 +1,8 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @vitest-environment jsdom
|
|
3
|
+
*/
|
|
1
4
|
import create from 'zustand';
|
|
5
|
+
import { describe, it, expect } from 'vitest';
|
|
2
6
|
import { createListener } from 'piral-base';
|
|
3
7
|
import { readDataItem, readDataValue, resetData, tryWriteDataItem, writeDataItem } from './data';
|
|
4
8
|
|
|
@@ -1,13 +1,14 @@
|
|
|
1
1
|
import create from 'zustand';
|
|
2
|
+
import { describe, it, expect, vitest } from 'vitest';
|
|
2
3
|
import { defineAction, defineActions } from './define';
|
|
3
4
|
|
|
4
5
|
function createMockContainer(initialState = {}) {
|
|
5
6
|
const state = create(() => initialState);
|
|
6
7
|
return {
|
|
7
8
|
context: {
|
|
8
|
-
on:
|
|
9
|
-
off:
|
|
10
|
-
emit:
|
|
9
|
+
on: vitest.fn(),
|
|
10
|
+
off: vitest.fn(),
|
|
11
|
+
emit: vitest.fn(),
|
|
11
12
|
state,
|
|
12
13
|
} as any,
|
|
13
14
|
};
|
|
@@ -1,13 +1,14 @@
|
|
|
1
1
|
import create from 'zustand';
|
|
2
|
+
import { describe, it, expect, vitest } from 'vitest';
|
|
2
3
|
import { readState, dispatch } from './state';
|
|
3
4
|
|
|
4
5
|
function createMockContainer(initialState = {}) {
|
|
5
6
|
const state = create(() => initialState);
|
|
6
7
|
return {
|
|
7
8
|
context: {
|
|
8
|
-
on:
|
|
9
|
-
off:
|
|
10
|
-
emit:
|
|
9
|
+
on: vitest.fn(),
|
|
10
|
+
off: vitest.fn(),
|
|
11
|
+
emit: vitest.fn(),
|
|
11
12
|
defineActions() {},
|
|
12
13
|
state,
|
|
13
14
|
read() {
|
|
@@ -1,8 +1,12 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @vitest-environment jsdom
|
|
3
|
+
*/
|
|
1
4
|
import * as React from 'react';
|
|
2
|
-
import {
|
|
5
|
+
import { describe, it, expect, vitest, afterEach } from 'vitest';
|
|
6
|
+
import { render, cleanup } from '@testing-library/react';
|
|
3
7
|
import { ExtensionSlot } from './ExtensionSlot';
|
|
4
8
|
|
|
5
|
-
|
|
9
|
+
vitest.mock('../hooks/globalState', () => ({
|
|
6
10
|
useGlobalState: (select: any) => select(state),
|
|
7
11
|
useGlobalStateContext: () => ({
|
|
8
12
|
converters: {
|
|
@@ -21,11 +25,18 @@ jest.mock('../hooks/globalState', () => ({
|
|
|
21
25
|
readState() {
|
|
22
26
|
return '/';
|
|
23
27
|
},
|
|
24
|
-
destroyPortal:
|
|
28
|
+
destroyPortal: vitest.fn(),
|
|
25
29
|
}),
|
|
26
30
|
}));
|
|
27
31
|
|
|
28
|
-
(
|
|
32
|
+
vitest.mock('react', async () => ({
|
|
33
|
+
...(await vitest.importActual('react') as any),
|
|
34
|
+
useMemo(cb) {
|
|
35
|
+
return cb();
|
|
36
|
+
},
|
|
37
|
+
}));
|
|
38
|
+
|
|
39
|
+
// (React as any).useMemo = (cb) => cb();
|
|
29
40
|
|
|
30
41
|
const StubComponent1: React.FC<any> = (props) => <div role="stub1" children={props.children} />;
|
|
31
42
|
StubComponent1.displayName = 'StubComponent1';
|
|
@@ -66,6 +77,10 @@ const state = {
|
|
|
66
77
|
};
|
|
67
78
|
|
|
68
79
|
describe('Extension Module', () => {
|
|
80
|
+
afterEach(() => {
|
|
81
|
+
cleanup();
|
|
82
|
+
});
|
|
83
|
+
|
|
69
84
|
it('is able to default render not available extension', () => {
|
|
70
85
|
const node = render(<ExtensionSlot name="qxz" />);
|
|
71
86
|
expect(node.queryAllByRole("stub1").length).toBe(0);
|
|
@@ -1,4 +1,8 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @vitest-environment jsdom
|
|
3
|
+
*/
|
|
1
4
|
import * as React from 'react';
|
|
5
|
+
import { describe, it, expect, vitest } from 'vitest';
|
|
2
6
|
import { render, act } from '@testing-library/react';
|
|
3
7
|
import { ForeignComponentContainer } from './ForeignComponentContainer';
|
|
4
8
|
|
|
@@ -8,7 +12,7 @@ function resolveAfter(time = 5) {
|
|
|
8
12
|
|
|
9
13
|
describe('ForeignComponentContainer component', () => {
|
|
10
14
|
it('mounts an HTML component', async () => {
|
|
11
|
-
const mount =
|
|
15
|
+
const mount = vitest.fn();
|
|
12
16
|
const component = { mount };
|
|
13
17
|
const container = render(
|
|
14
18
|
<ForeignComponentContainer $component={component} $context={undefined} $portalId="foo" innerProps={{}} />,
|
|
@@ -19,8 +23,8 @@ describe('ForeignComponentContainer component', () => {
|
|
|
19
23
|
});
|
|
20
24
|
|
|
21
25
|
it('unmounts an HTML component', async () => {
|
|
22
|
-
const mount =
|
|
23
|
-
const unmount =
|
|
26
|
+
const mount = vitest.fn();
|
|
27
|
+
const unmount = vitest.fn();
|
|
24
28
|
const component = { mount, unmount };
|
|
25
29
|
const container = render(
|
|
26
30
|
<ForeignComponentContainer $component={component} $context={undefined} $portalId="foo" innerProps={{}} />,
|
|
@@ -33,8 +37,8 @@ describe('ForeignComponentContainer component', () => {
|
|
|
33
37
|
});
|
|
34
38
|
|
|
35
39
|
it('updates an HTML component', async () => {
|
|
36
|
-
const mount =
|
|
37
|
-
const update =
|
|
40
|
+
const mount = vitest.fn();
|
|
41
|
+
const update = vitest.fn();
|
|
38
42
|
const component = { mount, update };
|
|
39
43
|
const container = render(
|
|
40
44
|
<ForeignComponentContainer
|
|
@@ -68,9 +72,9 @@ describe('ForeignComponentContainer component', () => {
|
|
|
68
72
|
removeEventListener() {},
|
|
69
73
|
};
|
|
70
74
|
};
|
|
71
|
-
const mount =
|
|
72
|
-
const update =
|
|
73
|
-
const unmount =
|
|
75
|
+
const mount = vitest.fn();
|
|
76
|
+
const update = vitest.fn();
|
|
77
|
+
const unmount = vitest.fn();
|
|
74
78
|
const component = { mount, update, unmount };
|
|
75
79
|
const container = render(
|
|
76
80
|
<ForeignComponentContainer
|
|
@@ -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 { Mediator } from './Mediator';
|
|
5
9
|
import { StateContext } from '../state';
|
|
@@ -15,9 +19,9 @@ function createMockContainer() {
|
|
|
15
19
|
}));
|
|
16
20
|
return {
|
|
17
21
|
context: {
|
|
18
|
-
on:
|
|
19
|
-
off:
|
|
20
|
-
emit:
|
|
22
|
+
on: vitest.fn(),
|
|
23
|
+
off: vitest.fn(),
|
|
24
|
+
emit: vitest.fn(),
|
|
21
25
|
state,
|
|
22
26
|
dispatch(update) {
|
|
23
27
|
state.setState(update(state.getState()));
|
|
@@ -44,7 +48,7 @@ function createMockContainer() {
|
|
|
44
48
|
describe('Component Mediator', () => {
|
|
45
49
|
it('Create mediator component.', () => {
|
|
46
50
|
const options = {
|
|
47
|
-
createApi:
|
|
51
|
+
createApi: vitest.fn(),
|
|
48
52
|
fetchPilets: () => {
|
|
49
53
|
return new Promise<Array<PiletMetadata>>((resolve) => resolve([]));
|
|
50
54
|
},
|
|
@@ -1,7 +1,11 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @vitest-environment jsdom
|
|
3
|
+
*/
|
|
1
4
|
import * as React from 'react';
|
|
2
5
|
import * as hooks from '../hooks';
|
|
6
|
+
import { describe, it, expect, vitest, afterEach } from 'vitest';
|
|
3
7
|
import { MemoryRouter } from 'react-router';
|
|
4
|
-
import { render } from '@testing-library/react';
|
|
8
|
+
import { render, cleanup } from '@testing-library/react';
|
|
5
9
|
import { PiralRoutes } from './PiralRoutes';
|
|
6
10
|
import { DefaultRouteSwitch } from '../defaults/DefaultRouteSwitch_v5';
|
|
7
11
|
|
|
@@ -12,7 +16,13 @@ const mountWithRouter = (node, url = '/') =>
|
|
|
12
16
|
</MemoryRouter>,
|
|
13
17
|
);
|
|
14
18
|
|
|
15
|
-
|
|
19
|
+
vitest.mock('../hooks');
|
|
20
|
+
|
|
21
|
+
vitest.mock('../../app.codegen', () => ({
|
|
22
|
+
useRouteFilter(routes) {
|
|
23
|
+
return routes;
|
|
24
|
+
},
|
|
25
|
+
}));
|
|
16
26
|
|
|
17
27
|
(hooks as any).useGlobalState = (cb) =>
|
|
18
28
|
cb({
|
|
@@ -50,6 +60,10 @@ const StubBarPage: React.FC<{ data: any }> = (props) => <div role="bar-page" />;
|
|
|
50
60
|
StubBarPage.displayName = 'StubBarPage';
|
|
51
61
|
|
|
52
62
|
describe('Routes Module', () => {
|
|
63
|
+
afterEach(() => {
|
|
64
|
+
cleanup();
|
|
65
|
+
});
|
|
66
|
+
|
|
53
67
|
it('always goes to the given home on "/"', () => {
|
|
54
68
|
const node = mountWithRouter(<PiralRoutes NotFound={StubNotFound} RouteSwitch={DefaultRouteSwitch} />, '/');
|
|
55
69
|
expect(node.queryAllByRole('home').length).toBe(1);
|
|
@@ -1,10 +1,11 @@
|
|
|
1
1
|
/**
|
|
2
|
-
* @
|
|
2
|
+
* @vitest-environment node
|
|
3
3
|
*/
|
|
4
4
|
|
|
5
5
|
import * as React from 'react';
|
|
6
6
|
import * as hooks from '../hooks';
|
|
7
7
|
import * as routes from './PiralRoutes';
|
|
8
|
+
import { describe, it, expect, vitest } from 'vitest';
|
|
8
9
|
import { renderToString } from 'react-dom/server';
|
|
9
10
|
import { PiralView } from './PiralView';
|
|
10
11
|
|
|
@@ -23,8 +24,8 @@ StubRouter.displayName = 'StubRouter';
|
|
|
23
24
|
const StubLayout: React.FC<React.PropsWithChildren<{}>> = ({ children }) => <div>{children}</div>;
|
|
24
25
|
StubLayout.displayName = 'StubLayout';
|
|
25
26
|
|
|
26
|
-
|
|
27
|
-
|
|
27
|
+
vitest.mock('../hooks');
|
|
28
|
+
vitest.mock('./PiralRoutes');
|
|
28
29
|
|
|
29
30
|
const state = {
|
|
30
31
|
app: {
|
|
@@ -1,7 +1,11 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @vitest-environment jsdom
|
|
3
|
+
*/
|
|
1
4
|
import * as React from 'react';
|
|
2
5
|
import * as hooks from '../hooks';
|
|
3
6
|
import * as routes from './PiralRoutes';
|
|
4
|
-
import {
|
|
7
|
+
import { describe, it, expect, vitest, afterEach } from 'vitest';
|
|
8
|
+
import { render, cleanup } from '@testing-library/react';
|
|
5
9
|
import { PiralView } from './PiralView';
|
|
6
10
|
|
|
7
11
|
const StubDashboard: React.FC<any> = () => <div role="dashboard" />;
|
|
@@ -19,8 +23,8 @@ StubRouter.displayName = 'StubRouter';
|
|
|
19
23
|
const StubLayout: React.FC<any> = ({ children }) => <div role="layout">{children}</div>;
|
|
20
24
|
StubLayout.displayName = 'StubLayout';
|
|
21
25
|
|
|
22
|
-
|
|
23
|
-
|
|
26
|
+
vitest.mock('../hooks');
|
|
27
|
+
vitest.mock('./PiralRoutes');
|
|
24
28
|
|
|
25
29
|
const state = {
|
|
26
30
|
app: {
|
|
@@ -47,6 +51,10 @@ const state = {
|
|
|
47
51
|
(routes as any).PiralRoutes = ({ }) => <StubDashboard />;
|
|
48
52
|
|
|
49
53
|
describe('Portal Module', () => {
|
|
54
|
+
afterEach(() => {
|
|
55
|
+
cleanup();
|
|
56
|
+
});
|
|
57
|
+
|
|
50
58
|
it('renders the dashboard / content in layout if loaded without error', () => {
|
|
51
59
|
state.app.loading = false;
|
|
52
60
|
state.app.error = undefined;
|
|
@@ -1,15 +1,19 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @vitest-environment jsdom
|
|
3
|
+
*/
|
|
1
4
|
import * as React from 'react';
|
|
2
5
|
import * as hooks from '../hooks';
|
|
3
6
|
import { render } from '@testing-library/react';
|
|
7
|
+
import { describe, it, expect, vitest } from 'vitest';
|
|
4
8
|
import { ResponsiveLayout } from './ResponsiveLayout';
|
|
5
9
|
import { defaultBreakpoints } from '../utils';
|
|
6
10
|
|
|
7
|
-
|
|
11
|
+
vitest.mock('../hooks');
|
|
8
12
|
|
|
9
13
|
describe('Responsive Module', () => {
|
|
10
14
|
it('always renders the given children', () => {
|
|
11
15
|
(hooks as any).useMedia = () => 'desktop';
|
|
12
|
-
const Layout: React.FC =
|
|
16
|
+
const Layout: React.FC = vitest.fn().mockImplementation(({ children }) => <div>{children}</div>);
|
|
13
17
|
Layout.displayName = 'Layout';
|
|
14
18
|
const StubComponent: React.FC = () => <div role="stub" />;
|
|
15
19
|
StubComponent.displayName = 'StubComponent';
|
|
@@ -23,21 +27,21 @@ describe('Responsive Module', () => {
|
|
|
23
27
|
|
|
24
28
|
it('does not call changeTo when nothing changed', () => {
|
|
25
29
|
(hooks as any).useMedia = () => 'desktop';
|
|
26
|
-
const Layout =
|
|
30
|
+
const Layout = vitest.fn().mockImplementation(({ children }) => <div>{children}</div>);
|
|
27
31
|
render(<ResponsiveLayout Layout={Layout} breakpoints={defaultBreakpoints} />);
|
|
28
32
|
expect(Layout).toHaveBeenCalledWith({ currentLayout: 'desktop' }, {});
|
|
29
33
|
});
|
|
30
34
|
|
|
31
35
|
it('does calls changeTo when someething changed (desktop -> tablet)', () => {
|
|
32
36
|
(hooks as any).useMedia = () => 'tablet';
|
|
33
|
-
const Layout =
|
|
37
|
+
const Layout = vitest.fn().mockImplementation(({ children }) => <div>{children}</div>);
|
|
34
38
|
render(<ResponsiveLayout Layout={Layout} breakpoints={defaultBreakpoints} />);
|
|
35
39
|
expect(Layout).toHaveBeenCalledWith({ currentLayout: 'tablet' }, {});
|
|
36
40
|
});
|
|
37
41
|
|
|
38
42
|
it('does calls changeTo when someething changed (desktop -> mobile)', () => {
|
|
39
43
|
(hooks as any).useMedia = () => 'mobile';
|
|
40
|
-
const Layout =
|
|
44
|
+
const Layout = vitest.fn().mockImplementation(({ children }) => <div>{children}</div>);
|
|
41
45
|
render(<ResponsiveLayout Layout={Layout} breakpoints={defaultBreakpoints} />);
|
|
42
46
|
expect(Layout).toHaveBeenCalledWith({ currentLayout: 'mobile' }, {});
|
|
43
47
|
});
|
|
@@ -1,13 +1,22 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @vitest-environment jsdom
|
|
3
|
+
*/
|
|
1
4
|
import * as React from 'react';
|
|
2
|
-
import {
|
|
5
|
+
import { describe, it, expect, vitest, afterEach } from 'vitest';
|
|
6
|
+
import { render, cleanup } from '@testing-library/react';
|
|
3
7
|
import { SwitchErrorInfo } from './SwitchErrorInfo';
|
|
4
8
|
|
|
5
|
-
|
|
9
|
+
vitest.mock('../hooks/globalState', () => ({
|
|
6
10
|
useGlobalState(select: any) {
|
|
7
11
|
return select(state);
|
|
8
12
|
},
|
|
9
13
|
}));
|
|
10
14
|
|
|
15
|
+
vitest.mock('react', async () => ({
|
|
16
|
+
...(await vitest.importActual('react') as any),
|
|
17
|
+
useMemo: (cb) => cb(),
|
|
18
|
+
}));
|
|
19
|
+
|
|
11
20
|
const StubComponent1: React.FC<any> = (props) => <div role="stub" children={props.children} />;
|
|
12
21
|
const Unknown: React.FC<any> = (props) => <div role="unknown" children={props.children} />;
|
|
13
22
|
|
|
@@ -21,9 +30,11 @@ const state = {
|
|
|
21
30
|
},
|
|
22
31
|
};
|
|
23
32
|
|
|
24
|
-
(React as any).useMemo = (cb) => cb();
|
|
25
|
-
|
|
26
33
|
describe('SwitchErrorInfo Module', () => {
|
|
34
|
+
afterEach(() => {
|
|
35
|
+
cleanup();
|
|
36
|
+
});
|
|
37
|
+
|
|
27
38
|
it('is able to render StubComponent1 component', () => {
|
|
28
39
|
const node = render(<SwitchErrorInfo type="stubComponent1" />);
|
|
29
40
|
expect(node.queryAllByRole('stub').length).toBe(1);
|
|
@@ -1,6 +1,20 @@
|
|
|
1
|
+
import { describe, it, expect, vitest } from 'vitest';
|
|
1
2
|
import { createInstance } from './createInstance';
|
|
2
3
|
import { standardStrategy, blazingStrategy } from 'piral-base';
|
|
3
4
|
|
|
5
|
+
vitest.mock('../app.codegen', () => ({
|
|
6
|
+
createNavigation: vitest.fn(() => ({
|
|
7
|
+
publicPath: '/',
|
|
8
|
+
})),
|
|
9
|
+
fillDependencies: vitest.fn(),
|
|
10
|
+
integrateDebugger: vitest.fn(),
|
|
11
|
+
integrateEmulator: vitest.fn(),
|
|
12
|
+
publicPath: '/',
|
|
13
|
+
createDefaultState() {
|
|
14
|
+
return {};
|
|
15
|
+
},
|
|
16
|
+
}));
|
|
17
|
+
|
|
4
18
|
describe('Piral-Core createInstance module', () => {
|
|
5
19
|
it('createInstance without arguments uses the standard strategy', () => {
|
|
6
20
|
const instance = createInstance();
|
|
@@ -1,8 +1,12 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @vitest-environment jsdom
|
|
3
|
+
*/
|
|
1
4
|
import * as React from 'react';
|
|
5
|
+
import { describe, it, expect, vitest } from 'vitest';
|
|
2
6
|
import { render } from '@testing-library/react';
|
|
3
7
|
import { DefaultErrorInfo } from './DefaultErrorInfo';
|
|
4
8
|
|
|
5
|
-
|
|
9
|
+
vitest.mock('../hooks/globalState', () => ({
|
|
6
10
|
useGlobalState(select: any) {
|
|
7
11
|
return select(state);
|
|
8
12
|
},
|