piral-core 0.11.8-pre.1620 → 0.11.8
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/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "piral-core",
|
|
3
|
-
"version": "0.11.8
|
|
3
|
+
"version": "0.11.8",
|
|
4
4
|
"description": "The core library for creating a Piral instance.",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"portal",
|
|
@@ -51,7 +51,7 @@
|
|
|
51
51
|
},
|
|
52
52
|
"dependencies": {
|
|
53
53
|
"@dbeining/react-atom": "^4.0.0",
|
|
54
|
-
"piral-base": "^0.11.8
|
|
54
|
+
"piral-base": "^0.11.8"
|
|
55
55
|
},
|
|
56
|
-
"gitHead": "
|
|
56
|
+
"gitHead": "617df77a2d553e455ec66b04936967ff3ce21a47"
|
|
57
57
|
}
|
package/src/helpers.test.tsx
CHANGED
|
@@ -3,13 +3,13 @@ import { globalDependencies } from './modules';
|
|
|
3
3
|
import { PiletMetadata, Pilet, AvailableDependencies } from 'piral-base';
|
|
4
4
|
import { Atom, swap } from '@dbeining/react-atom';
|
|
5
5
|
|
|
6
|
-
function createMockApi(meta: PiletMetadata){
|
|
6
|
+
function createMockApi(meta: PiletMetadata) {
|
|
7
7
|
return {
|
|
8
8
|
meta,
|
|
9
9
|
emit: jest.fn(),
|
|
10
10
|
off: jest.fn(),
|
|
11
11
|
on: jest.fn(),
|
|
12
|
-
}as any;
|
|
12
|
+
} as any;
|
|
13
13
|
}
|
|
14
14
|
|
|
15
15
|
function createMockContainer() {
|
|
@@ -36,13 +36,11 @@ function createMockContainer() {
|
|
|
36
36
|
}
|
|
37
37
|
|
|
38
38
|
describe('Piral-Core helpers module', () => {
|
|
39
|
-
|
|
40
39
|
it('setSharedDependencies set the shared dependecies', () => {
|
|
41
|
-
|
|
42
40
|
// Arrange
|
|
43
41
|
const dependencies: AvailableDependencies = {
|
|
44
|
-
|
|
45
|
-
|
|
42
|
+
gg: {},
|
|
43
|
+
ff: {},
|
|
46
44
|
};
|
|
47
45
|
|
|
48
46
|
// Act
|
|
@@ -51,14 +49,13 @@ describe('Piral-Core helpers module', () => {
|
|
|
51
49
|
|
|
52
50
|
// Assert
|
|
53
51
|
expect(result).not.toBeUndefined();
|
|
54
|
-
})
|
|
52
|
+
});
|
|
55
53
|
|
|
56
54
|
it('extendSharedDependencies should extend the dependecies', () => {
|
|
57
|
-
|
|
58
55
|
// Arrange
|
|
59
56
|
const additionalDependencies: AvailableDependencies = {
|
|
60
|
-
|
|
61
|
-
|
|
57
|
+
gg: {},
|
|
58
|
+
ff: {},
|
|
62
59
|
};
|
|
63
60
|
|
|
64
61
|
// Act
|
|
@@ -69,14 +66,13 @@ describe('Piral-Core helpers module', () => {
|
|
|
69
66
|
});
|
|
70
67
|
|
|
71
68
|
it('createPiletOptions creates the options using the provided pilets', () => {
|
|
72
|
-
|
|
73
69
|
const wasUndefined = process.env.DEBUG_PIRAL === undefined;
|
|
74
70
|
|
|
75
|
-
process.env.DEBUG_PIRAL =
|
|
71
|
+
process.env.DEBUG_PIRAL = 'true';
|
|
76
72
|
|
|
77
73
|
// Arrange
|
|
78
74
|
const setupMock = jest.fn();
|
|
79
|
-
const globalContext = createMockContainer().context
|
|
75
|
+
const globalContext = createMockContainer().context;
|
|
80
76
|
const providedPilets: Array<Pilet> = [
|
|
81
77
|
{
|
|
82
78
|
setup: setupMock,
|
|
@@ -99,8 +95,8 @@ describe('Piral-Core helpers module', () => {
|
|
|
99
95
|
getDependencies: jest.fn(),
|
|
100
96
|
loadPilet: jest.fn(),
|
|
101
97
|
requestPilets: jest.fn(() => Promise.resolve(providedPilets)),
|
|
102
|
-
strategy: jest.fn()
|
|
103
|
-
}
|
|
98
|
+
strategy: jest.fn(),
|
|
99
|
+
};
|
|
104
100
|
|
|
105
101
|
// Act
|
|
106
102
|
const options = createPiletOptions(optionsConfig);
|
|
@@ -108,16 +104,15 @@ describe('Piral-Core helpers module', () => {
|
|
|
108
104
|
// Assert
|
|
109
105
|
expect(options.pilets.length).toEqual(providedPilets.length);
|
|
110
106
|
|
|
111
|
-
if(wasUndefined) {
|
|
107
|
+
if (wasUndefined) {
|
|
112
108
|
process.env.DEBUG_PIRAL = undefined;
|
|
113
109
|
}
|
|
114
110
|
});
|
|
115
111
|
|
|
116
112
|
it('createPiletOptions creates the options exposing the global dependencies', () => {
|
|
117
|
-
|
|
118
113
|
// Arrange
|
|
119
114
|
const setupMock = jest.fn();
|
|
120
|
-
const globalContext = createMockContainer().context
|
|
115
|
+
const globalContext = createMockContainer().context;
|
|
121
116
|
const providedPilets: Array<Pilet> = [
|
|
122
117
|
{
|
|
123
118
|
setup: setupMock,
|
|
@@ -140,8 +135,8 @@ describe('Piral-Core helpers module', () => {
|
|
|
140
135
|
getDependencies: () => globalDependencies,
|
|
141
136
|
loadPilet: jest.fn(),
|
|
142
137
|
requestPilets: jest.fn(() => Promise.resolve(providedPilets)),
|
|
143
|
-
strategy: jest.fn()
|
|
144
|
-
}
|
|
138
|
+
strategy: jest.fn(),
|
|
139
|
+
};
|
|
145
140
|
|
|
146
141
|
// Act
|
|
147
142
|
const options = createPiletOptions(optionsConfig);
|
|
@@ -151,14 +146,13 @@ describe('Piral-Core helpers module', () => {
|
|
|
151
146
|
});
|
|
152
147
|
|
|
153
148
|
it('createPiletOptions creates the options with provided requestPilets', () => {
|
|
154
|
-
|
|
155
149
|
const wasUndefined = process.env.DEBUG_PIRAL === undefined;
|
|
156
150
|
|
|
157
151
|
// Arrange
|
|
158
|
-
process.env.DEBUG_PIRAL =
|
|
152
|
+
process.env.DEBUG_PIRAL = 'true';
|
|
159
153
|
const setupMock = jest.fn();
|
|
160
154
|
const requestPilets = jest.fn(() => Promise.resolve(providedPilets));
|
|
161
|
-
const globalContext = createMockContainer().context
|
|
155
|
+
const globalContext = createMockContainer().context;
|
|
162
156
|
const providedPilets: Array<Pilet> = [
|
|
163
157
|
{
|
|
164
158
|
setup: setupMock,
|
|
@@ -181,8 +175,8 @@ describe('Piral-Core helpers module', () => {
|
|
|
181
175
|
getDependencies: jest.fn(),
|
|
182
176
|
loadPilet: jest.fn(),
|
|
183
177
|
requestPilets: requestPilets,
|
|
184
|
-
strategy: jest.fn()
|
|
185
|
-
}
|
|
178
|
+
strategy: jest.fn(),
|
|
179
|
+
};
|
|
186
180
|
|
|
187
181
|
// Act
|
|
188
182
|
const options = createPiletOptions(optionsConfig);
|
|
@@ -191,7 +185,7 @@ describe('Piral-Core helpers module', () => {
|
|
|
191
185
|
// Assert
|
|
192
186
|
expect(requestPilets).toHaveBeenCalled();
|
|
193
187
|
|
|
194
|
-
if(wasUndefined) {
|
|
188
|
+
if (wasUndefined) {
|
|
195
189
|
process.env.DEBUG_PIRAL = undefined;
|
|
196
190
|
}
|
|
197
191
|
});
|
|
@@ -200,10 +194,10 @@ describe('Piral-Core helpers module', () => {
|
|
|
200
194
|
const wasUndefined = process.env.DEBUG_PILET === undefined;
|
|
201
195
|
|
|
202
196
|
// Arrange
|
|
203
|
-
process.env.DEBUG_PILET =
|
|
197
|
+
process.env.DEBUG_PILET = 'localhost:1234';
|
|
204
198
|
const setupMock = jest.fn();
|
|
205
199
|
const requestPilets = jest.fn(() => Promise.resolve(providedPilets));
|
|
206
|
-
const globalContext = createMockContainer().context
|
|
200
|
+
const globalContext = createMockContainer().context;
|
|
207
201
|
const providedPilets: Array<Pilet> = [
|
|
208
202
|
{
|
|
209
203
|
setup: setupMock,
|
|
@@ -226,8 +220,8 @@ describe('Piral-Core helpers module', () => {
|
|
|
226
220
|
getDependencies: jest.fn(),
|
|
227
221
|
loadPilet: jest.fn(),
|
|
228
222
|
requestPilets: requestPilets,
|
|
229
|
-
strategy: jest.fn()
|
|
230
|
-
}
|
|
223
|
+
strategy: jest.fn(),
|
|
224
|
+
};
|
|
231
225
|
|
|
232
226
|
let hasFailed = false;
|
|
233
227
|
|
|
@@ -235,15 +229,14 @@ describe('Piral-Core helpers module', () => {
|
|
|
235
229
|
const options = createPiletOptions(optionsConfig);
|
|
236
230
|
try {
|
|
237
231
|
options.fetchPilets(); //This call should not work in node.js test environment
|
|
238
|
-
}
|
|
239
|
-
catch {
|
|
232
|
+
} catch {
|
|
240
233
|
hasFailed = true;
|
|
241
234
|
}
|
|
242
235
|
|
|
243
236
|
// Assert
|
|
244
237
|
expect(hasFailed).toBeTruthy();
|
|
245
238
|
|
|
246
|
-
if(wasUndefined) {
|
|
239
|
+
if (wasUndefined) {
|
|
247
240
|
process.env.DEBUG_PILET = undefined;
|
|
248
241
|
}
|
|
249
242
|
});
|
|
@@ -2,6 +2,25 @@ import * as React from 'react';
|
|
|
2
2
|
import * as hooks from '../hooks';
|
|
3
3
|
import { mount } from 'enzyme';
|
|
4
4
|
import { withApi } from './withApi';
|
|
5
|
+
import { ComponentConverters } from '../types';
|
|
6
|
+
import { StateContext } from '../state';
|
|
7
|
+
import { Atom } from '@dbeining/react-atom';
|
|
8
|
+
import { unmountComponentAtNode } from 'react-dom';
|
|
9
|
+
|
|
10
|
+
function createMockContainer() {
|
|
11
|
+
const state = Atom.of({
|
|
12
|
+
portals: {},
|
|
13
|
+
});
|
|
14
|
+
return {
|
|
15
|
+
context: {
|
|
16
|
+
on: jest.fn(),
|
|
17
|
+
off: jest.fn(),
|
|
18
|
+
emit: jest.fn(),
|
|
19
|
+
state,
|
|
20
|
+
destroyPortal: id => {},
|
|
21
|
+
} as any,
|
|
22
|
+
};
|
|
23
|
+
}
|
|
5
24
|
|
|
6
25
|
jest.mock('../hooks');
|
|
7
26
|
|
|
@@ -12,6 +31,10 @@ jest.mock('../hooks');
|
|
|
12
31
|
},
|
|
13
32
|
});
|
|
14
33
|
|
|
34
|
+
(hooks as any).useActions = () => ({
|
|
35
|
+
destroyPortal: jest.fn(),
|
|
36
|
+
});
|
|
37
|
+
|
|
15
38
|
const StubErrorInfo: React.FC = props => <div />;
|
|
16
39
|
StubErrorInfo.displayName = 'StubErrorInfo';
|
|
17
40
|
|
|
@@ -60,4 +83,42 @@ describe('withApi Module', () => {
|
|
|
60
83
|
mount(<Component shouldCrash />);
|
|
61
84
|
expect(console.error).toHaveBeenCalled();
|
|
62
85
|
});
|
|
86
|
+
|
|
87
|
+
it('Wraps component of type object', () => {
|
|
88
|
+
const api: any = {};
|
|
89
|
+
const converters: ComponentConverters<any> = {
|
|
90
|
+
html: component => {
|
|
91
|
+
return component.component;
|
|
92
|
+
},
|
|
93
|
+
};
|
|
94
|
+
const context = createMockContainer();
|
|
95
|
+
const Component = withApi(converters, { type: 'html', component: { mount: () => {} } }, api, 'unknown');
|
|
96
|
+
|
|
97
|
+
const node = mount(
|
|
98
|
+
<StateContext.Provider value={context.context}>
|
|
99
|
+
<Component />
|
|
100
|
+
</StateContext.Provider>,
|
|
101
|
+
);
|
|
102
|
+
|
|
103
|
+
expect(node.children.length).toBe(1);
|
|
104
|
+
});
|
|
105
|
+
|
|
106
|
+
it('Wraps component which is object == null.', () => {
|
|
107
|
+
const api: any = {};
|
|
108
|
+
const converters: ComponentConverters<any> = {
|
|
109
|
+
html: component => {
|
|
110
|
+
return component.component;
|
|
111
|
+
},
|
|
112
|
+
};
|
|
113
|
+
const context = createMockContainer();
|
|
114
|
+
const Component = withApi(converters, null, api, 'unknown');
|
|
115
|
+
|
|
116
|
+
const node = mount(
|
|
117
|
+
<StateContext.Provider value={context.context}>
|
|
118
|
+
<Component />
|
|
119
|
+
</StateContext.Provider>,
|
|
120
|
+
);
|
|
121
|
+
|
|
122
|
+
expect(Component.displayName).toBeUndefined();
|
|
123
|
+
});
|
|
63
124
|
});
|