piral-core 0.15.0-alpha.4345 → 0.15.0-alpha.4399
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/esm/defaults/DefaultErrorInfo.js +1 -1
- package/esm/defaults/DefaultErrorInfo.js.map +1 -1
- package/lib/defaults/DefaultErrorInfo.js +1 -1
- package/lib/defaults/DefaultErrorInfo.js.map +1 -1
- package/package.json +4 -4
- package/src/Piral.test.tsx +7 -18
- package/src/RootListener.test.tsx +5 -10
- package/src/actions/app.test.ts +16 -16
- package/src/components/ExtensionSlot.test.tsx +44 -47
- package/src/components/ForeignComponentContainer.test.tsx +21 -35
- package/src/components/Mediator.test.tsx +2 -2
- package/src/components/PiralRoutes.test.tsx +35 -35
- package/src/components/PiralView-server.test.tsx +3 -3
- package/src/components/PiralView.test.tsx +25 -25
- package/src/components/ResponsiveLayout.test.tsx +8 -8
- package/src/components/SwitchErrorInfo.test.tsx +23 -25
- package/src/defaults/DefaultErrorInfo.test.tsx +15 -18
- package/src/defaults/DefaultErrorInfo.tsx +1 -1
- package/src/defaults/DefaultLayout.test.tsx +7 -7
- package/src/defaults/DefaultLoadingIndicator.test.tsx +3 -3
- package/src/hooks/setter.test.ts +3 -5
- package/src/setters/SetComponent.test.tsx +2 -2
- package/src/setters/SetError.test.tsx +2 -2
- package/src/setters/SetErrors.test.tsx +2 -2
- package/src/setters/SetLayout.test.tsx +2 -2
- package/src/setters/SetProvider.test.tsx +2 -2
- package/src/setters/SetRedirect.test.tsx +2 -2
- package/src/setters/SetRoute.test.tsx +2 -2
- package/src/state/withApi.test.tsx +39 -39
- package/src/utils/extension.test.tsx +7 -8
- package/src/utils/state.test.ts +0 -2
|
@@ -1,35 +1,40 @@
|
|
|
1
1
|
import * as React from 'react';
|
|
2
|
-
import * as hooks from '../hooks';
|
|
3
2
|
import create from 'zustand';
|
|
4
|
-
import {
|
|
3
|
+
import { render } from '@testing-library/react';
|
|
5
4
|
import { withApi } from './withApi';
|
|
6
5
|
import { StateContext } from '../state';
|
|
7
6
|
|
|
8
7
|
function createMockContainer() {
|
|
9
8
|
const state = create(() => ({
|
|
9
|
+
components: {
|
|
10
|
+
ErrorInfo: StubErrorInfo,
|
|
11
|
+
},
|
|
12
|
+
registry: {
|
|
13
|
+
wrappers: { feed: 'test', '*': 'test' },
|
|
14
|
+
},
|
|
10
15
|
portals: {},
|
|
11
16
|
}));
|
|
12
17
|
return {
|
|
13
18
|
context: {
|
|
14
19
|
converters: {},
|
|
15
20
|
readState(cb) {
|
|
16
|
-
return cb(
|
|
17
|
-
registry: {
|
|
18
|
-
wrappers: { "feed": "test", "*": "test" },
|
|
19
|
-
},
|
|
20
|
-
});
|
|
21
|
+
return cb(state.getState());
|
|
21
22
|
},
|
|
22
23
|
on: jest.fn(),
|
|
23
24
|
off: jest.fn(),
|
|
24
25
|
emit: jest.fn(),
|
|
25
26
|
state,
|
|
26
|
-
destroyPortal: (id) => {
|
|
27
|
+
destroyPortal: (id) => {},
|
|
27
28
|
} as any,
|
|
28
29
|
};
|
|
29
30
|
}
|
|
30
31
|
|
|
31
32
|
function createMockContainerWithNoWrappers() {
|
|
32
33
|
const state = create(() => ({
|
|
34
|
+
components: {
|
|
35
|
+
ErrorInfo: StubErrorInfo,
|
|
36
|
+
},
|
|
37
|
+
registry: {},
|
|
33
38
|
portals: {},
|
|
34
39
|
}));
|
|
35
40
|
return {
|
|
@@ -46,36 +51,19 @@ function createMockContainerWithNoWrappers() {
|
|
|
46
51
|
off: jest.fn(),
|
|
47
52
|
emit: jest.fn(),
|
|
48
53
|
state,
|
|
49
|
-
destroyPortal: (id) => {
|
|
54
|
+
destroyPortal: (id) => {},
|
|
50
55
|
} as any,
|
|
51
56
|
};
|
|
52
57
|
}
|
|
53
58
|
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
(hooks as any).useGlobalStateContext = () => ({
|
|
57
|
-
state: {},
|
|
58
|
-
});
|
|
59
|
-
|
|
60
|
-
(hooks as any).useGlobalState = (select: any) =>
|
|
61
|
-
select({
|
|
62
|
-
components: {
|
|
63
|
-
ErrorInfo: StubErrorInfo,
|
|
64
|
-
},
|
|
65
|
-
});
|
|
66
|
-
|
|
67
|
-
(hooks as any).useActions = () => ({
|
|
68
|
-
destroyPortal: jest.fn(),
|
|
69
|
-
});
|
|
70
|
-
|
|
71
|
-
const StubErrorInfo: React.FC = (props) => <div />;
|
|
59
|
+
const StubErrorInfo: React.FC<any> = ({ type }) => <div role="error">{type}</div>;
|
|
72
60
|
StubErrorInfo.displayName = 'StubErrorInfo';
|
|
73
61
|
|
|
74
|
-
const StubComponent: React.FC<{ shouldCrash?: boolean }> = ({ shouldCrash }) => {
|
|
62
|
+
const StubComponent: React.FC<{ shouldCrash?: boolean; piral?: any }> = ({ shouldCrash, piral }) => {
|
|
75
63
|
if (shouldCrash) {
|
|
76
64
|
throw new Error('I should crash!');
|
|
77
65
|
}
|
|
78
|
-
return <div
|
|
66
|
+
return <div role="component">{piral && 'piral'}</div>;
|
|
79
67
|
};
|
|
80
68
|
StubComponent.displayName = 'StubComponent';
|
|
81
69
|
|
|
@@ -88,8 +76,12 @@ describe('withApi Module', () => {
|
|
|
88
76
|
};
|
|
89
77
|
const { context } = createMockContainer();
|
|
90
78
|
const Component = withApi(context, StubComponent, api, 'feed' as any);
|
|
91
|
-
const node =
|
|
92
|
-
|
|
79
|
+
const node = render(
|
|
80
|
+
<StateContext.Provider value={context}>
|
|
81
|
+
<Component />
|
|
82
|
+
</StateContext.Provider>,
|
|
83
|
+
);
|
|
84
|
+
expect(node.getByRole('component').textContent).toBe('piral');
|
|
93
85
|
});
|
|
94
86
|
|
|
95
87
|
it('is protected against a component crash', () => {
|
|
@@ -101,8 +93,12 @@ describe('withApi Module', () => {
|
|
|
101
93
|
};
|
|
102
94
|
const { context } = createMockContainer();
|
|
103
95
|
const Component = withApi(context, StubComponent, api, 'feed' as any);
|
|
104
|
-
const node =
|
|
105
|
-
|
|
96
|
+
const node = render(
|
|
97
|
+
<StateContext.Provider value={context}>
|
|
98
|
+
<Component shouldCrash />
|
|
99
|
+
</StateContext.Provider>,
|
|
100
|
+
);
|
|
101
|
+
expect(node.getByRole('error').textContent).toBe('feed');
|
|
106
102
|
});
|
|
107
103
|
|
|
108
104
|
it('reports to console.error when an error is hit', () => {
|
|
@@ -114,7 +110,11 @@ describe('withApi Module', () => {
|
|
|
114
110
|
};
|
|
115
111
|
const { context } = createMockContainer();
|
|
116
112
|
const Component = withApi(context, StubComponent, api, 'feed' as any);
|
|
117
|
-
|
|
113
|
+
render(
|
|
114
|
+
<StateContext.Provider value={context}>
|
|
115
|
+
<Component shouldCrash />
|
|
116
|
+
</StateContext.Provider>,
|
|
117
|
+
);
|
|
118
118
|
expect(console.error).toHaveBeenCalled();
|
|
119
119
|
});
|
|
120
120
|
|
|
@@ -128,15 +128,15 @@ describe('withApi Module', () => {
|
|
|
128
128
|
context.converters = {
|
|
129
129
|
html: ({ component }) => component,
|
|
130
130
|
};
|
|
131
|
-
const Component = withApi(context, { type: 'html', component: { mount: () => {
|
|
131
|
+
const Component = withApi(context, { type: 'html', component: { mount: () => {} } }, api, 'unknown');
|
|
132
132
|
|
|
133
|
-
const node =
|
|
133
|
+
const node = render(
|
|
134
134
|
<StateContext.Provider value={context}>
|
|
135
135
|
<Component />
|
|
136
136
|
</StateContext.Provider>,
|
|
137
137
|
);
|
|
138
138
|
|
|
139
|
-
expect(node.children.length).toBe(1);
|
|
139
|
+
expect(node.container.children.length).toBe(1);
|
|
140
140
|
});
|
|
141
141
|
|
|
142
142
|
it('Wraps component which is object == null.', () => {
|
|
@@ -149,9 +149,9 @@ describe('withApi Module', () => {
|
|
|
149
149
|
context.converters = {
|
|
150
150
|
html: ({ component }) => component,
|
|
151
151
|
};
|
|
152
|
-
const Component = withApi(context, null, api, 'unknown');
|
|
152
|
+
const Component = withApi(context, null as any, api, 'unknown');
|
|
153
153
|
|
|
154
|
-
|
|
154
|
+
render(
|
|
155
155
|
<StateContext.Provider value={context}>
|
|
156
156
|
<Component />
|
|
157
157
|
</StateContext.Provider>,
|
|
@@ -1,22 +1,21 @@
|
|
|
1
1
|
import * as React from 'react';
|
|
2
|
-
import {
|
|
2
|
+
import { render } from '@testing-library/react';
|
|
3
3
|
import { reactifyContent, toExtension } from './extension';
|
|
4
4
|
|
|
5
|
-
|
|
6
5
|
describe('Util Extension.', () => {
|
|
7
6
|
it('Convert some component to an extension component.', () => {
|
|
8
|
-
const Component = (
|
|
7
|
+
const Component = ({ title }) => <b>{title}</b>;
|
|
8
|
+
const piral: any = {};
|
|
9
9
|
const Extension = toExtension(Component);
|
|
10
|
-
const node =
|
|
11
|
-
expect(node.
|
|
10
|
+
const node = render(<Extension piral={piral} params={{ title: 'Foo' }} />);
|
|
11
|
+
expect(node.container.querySelectorAll('b').length).toBe(1);
|
|
12
12
|
});
|
|
13
13
|
|
|
14
14
|
it('reactifyContent.', async () => {
|
|
15
15
|
const container = document.body.appendChild(document.createElement('div'));
|
|
16
16
|
container.innerHTML = `<div>FOO<</div>`;
|
|
17
17
|
const result = reactifyContent(container.childNodes) as React.ReactElement;
|
|
18
|
-
const node =
|
|
19
|
-
expect(node.
|
|
18
|
+
const node = render(result);
|
|
19
|
+
expect(node.container.querySelectorAll('slot').length).toBe(1);
|
|
20
20
|
});
|
|
21
21
|
});
|
|
22
|
-
|
package/src/utils/state.test.ts
CHANGED
|
@@ -1,7 +1,5 @@
|
|
|
1
|
-
import * as hooks from '../hooks';
|
|
2
1
|
import { withAll, withRootExtension } from './state';
|
|
3
2
|
import { RootListener } from '../RootListener';
|
|
4
|
-
import { createGlobalState } from '../state';
|
|
5
3
|
|
|
6
4
|
describe('State Module', () => {
|
|
7
5
|
it('withRootExtension should create an extension key', () => {
|