piral-core 0.15.0-alpha.3975 → 0.15.0-alpha.4005

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.
@@ -3,6 +3,7 @@ import { isfunc } from 'piral-base';
3
3
  import { wrapComponent } from './wrapComponent';
4
4
  import { useGlobalState, useGlobalStateContext } from '../hooks';
5
5
  import { defaultRender, none } from '../utils';
6
+ const wrapper = ({ children }) => defaultRender(children);
6
7
  const renderExtensions = [
7
8
  {
8
9
  component: (props) => {
@@ -10,7 +11,7 @@ const renderExtensions = [
10
11
  const converters = context.converters;
11
12
  const piral = context.apis._;
12
13
  const { component, props: args } = props.params;
13
- const Component = React.useMemo(() => wrapComponent(converters, component, { piral }, defaultRender), [component]);
14
+ const Component = React.useMemo(() => wrapComponent(converters, component, { piral }, wrapper), [component]);
14
15
  return React.createElement(Component, Object.assign({}, args));
15
16
  },
16
17
  defaults: {},
@@ -1 +1 @@
1
- {"version":3,"file":"ExtensionSlot.js","sourceRoot":"","sources":["../../src/components/ExtensionSlot.tsx"],"names":[],"mappings":"AAAA,OAAO,KAAK,KAAK,MAAM,OAAO,CAAC;AAC/B,OAAO,EAAE,MAAM,EAAE,MAAM,YAAY,CAAC;AACpC,OAAO,EAAE,aAAa,EAAE,MAAM,iBAAiB,CAAC;AAChD,OAAO,EAAE,cAAc,EAAE,qBAAqB,EAAE,MAAM,UAAU,CAAC;AACjE,OAAO,EAAE,aAAa,EAAE,IAAI,EAAE,MAAM,UAAU,CAAC;AAG/C,MAAM,gBAAgB,GAA4B;IAChD;QACE,SAAS,EAAE,CAAC,KAAK,EAAE,EAAE;YACnB,MAAM,OAAO,GAAG,qBAAqB,EAAE,CAAC;YACxC,MAAM,UAAU,GAAG,OAAO,CAAC,UAAU,CAAC;YACtC,MAAM,KAAK,GAAG,OAAO,CAAC,IAAI,CAAC,CAAC,CAAC;YAC7B,MAAM,EAAE,SAAS,EAAE,KAAK,EAAE,IAAI,EAAE,GAAG,K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ACH,MAAM,UAAU,aAAa,CAAmB,KAA4B;IAC1E,MAAM,EAAE,IAAI,EAAE,MAAM,GAAG,aAAa,EAAE,KAAK,EAAE,MAAM,EAAE,QAAQ,EAAE,GAAG,KAAK,CAAC;IACxE,MAAM,UAAU,GAAG,cAAc,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC,CAAC,QAAQ,CAAC,UAAU,CAAC,IAAI,CAAC,IAAI,IAAI,CAAC,CAAC,CAAC,gBAAgB,CAAC,CAAC,CAAC;IAC1G,OAAO,MAAM,CACX,UAAU,CAAC,MAAM,KAAK,CAAC,IAAI,MAAM,CAAC,KAAK,CAAC;QACtC,CAAC,CAAC,CAAC,aAAa,CAAC,KAAK,EAAE,EAAE,OAAO,CAAC,CAAC;QACnC,CAAC,CAAC,UAAU,CAAC,GAAG,CAAC,CAAC,EAAE,SAAS,EAAE,SAAS,EAAE,SAAS,EAAE,QAAQ,GAAG,EAAE,EAAE,EAAE,CAAC,EAAE,EAAE,CAAC,CACxE,oBAAC,SAAS,IACR,GAAG,EAAE,GAAG,CAAA,SAAS,aAAT,SAAS,uBAAT,SAAS,CAAE,WAAW,KAAI,GAAG,GAAG,CAAC,EAAE,EAC3C,QAAQ,EAAE,QAAQ,EAClB,MAAM,kCACD,QAAQ,GACR,CAAC,MAAM,IAAI,EAAE,CAAC,IAEnB,CACH,CAAC,CACP,CAAC;AACJ,CAAC;AAED,aAAa,CAAC,WAAW,GAAG,eAAe,CAAC"}
@@ -67,17 +67,20 @@ if (typeof window !== 'undefined' && 'customElements' in window) {
67
67
  customElements.define('piral-extension', PiralExtension);
68
68
  }
69
69
  export function renderElement(context, element, props) {
70
- let [id, portal] = renderInDom(context, element, ExtensionSlot, props);
71
- const evName = 'extension-props-changed';
72
- const handler = (ev) => update(ev.detail);
73
- const dispose = () => {
74
- context.hidePortal(id, portal);
75
- element.removeEventListener(evName, handler);
76
- };
77
- const update = (newProps) => {
78
- [id, portal] = changeDomPortal(id, portal, context, element, ExtensionSlot, newProps);
79
- };
80
- element.addEventListener(evName, handler);
81
- return [dispose, update];
70
+ if (typeof window !== 'undefined') {
71
+ let [id, portal] = renderInDom(context, element, ExtensionSlot, props);
72
+ const evName = 'extension-props-changed';
73
+ const handler = (ev) => update(ev.detail);
74
+ const dispose = () => {
75
+ context.hidePortal(id, portal);
76
+ element.removeEventListener(evName, handler);
77
+ };
78
+ const update = (newProps) => {
79
+ [id, portal] = changeDomPortal(id, portal, context, element, ExtensionSlot, newProps);
80
+ };
81
+ element.addEventListener(evName, handler);
82
+ return [dispose, update];
83
+ }
84
+ return [noop, noop];
82
85
  }
83
86
  //# sourceMappingURL=element.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"element.js","sourceRoot":"","sources":["../../src/modules/element.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,aAAa,EAAE,MAAM,eAAe,CAAC;AAC9C,OAAO,EAAE,YAAY,EAAE,IAAI,EAAE,eAAe,EAAE,WAAW,EAAE,eAAe,EAAE,MAAM,UAAU,CAAC;AAO7F,IAAI,OAAO,MAAM,KAAK,WAAW,IAAI,gBAAgB,IAAI,MAAM,EAAE;IAC/D,MAAM,cAAe,SAAQ,WAAW;QAAxC;;YACE,YAAO,GAAe,IAAI,CAAC;YAC3B,WAAM,GAAc,IAAI,CAAC;YACzB,UAAK,GAAG;gBACN,IAAI,EAAE,IAAI,CAAC,YAAY,CAAC,MAAM,CAAC;gBAC/B,MAAM,EAAE,YAAY,CAAC,IAAI,CAAC,YAAY,CAAC,QAAQ,CAAC,CAAC;gBACjD,KAAK,EAAE,SAAS;gBAChB,QAAQ,EAAE,eAAe,CAAC,IAAI,CAAC,UAAU,CAAC;aAC3C,CAAC;QA+DJ,CAAC;QA7DC,IAAI,MAAM;YACR,OAAO,IAAI,CAAC,KAAK,CAAC,MAAM,CAAC;QAC3B,CAAC;QAED,IAAI,MAAM,CAAC,KAAK;YACd,IAAI,CAAC,KAAK,CAAC,MA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M,GAAc,CAAC,QAAQ,EAAE,EAAE;YACrC,CAAC,EAAE,EAAE,MAAM,CAAC,GAAG,eAAe,CAAC,EAAE,EAAE,MAAM,EAAE,OAAO,EAAE,OAAO,EAAE,aAAa,EAAE,QAAQ,CAAC,CAAC;QACxF,CAAC,CAAC;QACF,OAAO,CAAC,gBAAgB,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC;QAC1C,OAAO,CAAC,OAAO,EAAE,MAAM,CAAC,CAAC;KAC1B;IAED,OAAO,CAAC,IAAI,EAAE,IAAI,CAAC,CAAC;AACtB,CAAC"}
@@ -6,6 +6,7 @@ const piral_base_1 = require("piral-base");
6
6
  const wrapComponent_1 = require("./wrapComponent");
7
7
  const hooks_1 = require("../hooks");
8
8
  const utils_1 = require("../utils");
9
+ const wrapper = ({ children }) => (0, utils_1.defaultRender)(children);
9
10
  const renderExtensions = [
10
11
  {
11
12
  component: (props) => {
@@ -13,7 +14,7 @@ const renderExtensions = [
13
14
  const converters = context.converters;
14
15
  const piral = context.apis._;
15
16
  const { component, props: args } = props.params;
16
- const Component = React.useMemo(() => (0, wrapComponent_1.wrapComponent)(converters, component, { piral }, utils_1.defaultRender), [component]);
17
+ const Component = React.useMemo(() => (0, wrapComponent_1.wrapComponent)(converters, component, { piral }, wrapper), [component]);
17
18
  return React.createElement(Component, Object.assign({}, args));
18
19
  },
19
20
  defaults: {},
@@ -1 +1 @@
1
- {"version":3,"file":"ExtensionSlot.js","sourceRoot":"","sources":["../../src/components/ExtensionSlot.tsx"],"names":[],"mappings":";;;AAAA,+BAA+B;AAC/B,2CAAoC;AACpC,mDAAgD;AAChD,oCAAiE;AACjE,oCAA+C;AAG/C,MAAM,gBAAgB,GAA4B;IAChD;QACE,SAAS,EAAE,CAAC,KAAK,EAAE,EAAE;YACnB,MAAM,OAAO,GAAG,IAAA,6BAAqB,GAAE,CAAC;YACxC,MAAM,UAAU,GAAG,OAAO,CAAC,UAAU,CAAC;YACtC,MAAM,KAAK,GAAG,OAA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IAC1E,MAAM,EAAE,IAAI,EAAE,MAAM,GAAG,qBAAa,EAAE,KAAK,EAAE,MAAM,EAAE,QAAQ,EAAE,GAAG,KAAK,CAAC;IACxE,MAAM,UAAU,GAAG,IAAA,sBAAc,EAAC,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC,CAAC,QAAQ,CAAC,UAAU,CAAC,IAAI,CAAC,IAAI,YAAI,CAAC,CAAC,CAAC,gBAAgB,CAAC,CAAC,CAAC;IAC1G,OAAO,MAAM,CACX,UAAU,CAAC,MAAM,KAAK,CAAC,IAAI,IAAA,mBAAM,EAAC,KAAK,CAAC;QACtC,CAAC,CAAC,CAAC,IAAA,qBAAa,EAAC,KAAK,EAAE,EAAE,OAAO,CAAC,CAAC;QACnC,CAAC,CAAC,UAAU,CAAC,GAAG,CAAC,CAAC,EAAE,SAAS,EAAE,SAAS,EAAE,SAAS,EAAE,QAAQ,GAAG,EAAE,EAAE,EAAE,CAAC,EAAE,EAAE,CAAC,CACxE,oBAAC,SAAS,IACR,GAAG,EAAE,GAAG,CAAA,SAAS,aAAT,SAAS,uBAAT,SAAS,CAAE,WAAW,KAAI,GAAG,GAAG,CAAC,EAAE,EAC3C,QAAQ,EAAE,QAAQ,EAClB,MAAM,kCACD,QAAQ,GACR,CAAC,MAAM,IAAI,EAAE,CAAC,IAEnB,CACH,CAAC,CACP,CAAC;AACJ,CAAC;AAjBD,sCAiBC;AAED,aAAa,CAAC,WAAW,GAAG,eAAe,CAAC"}
@@ -70,18 +70,21 @@ if (typeof window !== 'undefined' && 'customElements' in window) {
70
70
  customElements.define('piral-extension', PiralExtension);
71
71
  }
72
72
  function renderElement(context, element, props) {
73
- let [id, portal] = (0, utils_1.renderInDom)(context, element, components_1.ExtensionSlot, props);
74
- const evName = 'extension-props-changed';
75
- const handler = (ev) => update(ev.detail);
76
- const dispose = () => {
77
- context.hidePortal(id, portal);
78
- element.removeEventListener(evName, handler);
79
- };
80
- const update = (newProps) => {
81
- [id, portal] = (0, utils_1.changeDomPortal)(id, portal, context, element, components_1.ExtensionSlot, newProps);
82
- };
83
- element.addEventListener(evName, handler);
84
- return [dispose, update];
73
+ if (typeof window !== 'undefined') {
74
+ let [id, portal] = (0, utils_1.renderInDom)(context, element, components_1.ExtensionSlot, props);
75
+ const evName = 'extension-props-changed';
76
+ const handler = (ev) => update(ev.detail);
77
+ const dispose = () => {
78
+ context.hidePortal(id, portal);
79
+ element.removeEventListener(evName, handler);
80
+ };
81
+ const update = (newProps) => {
82
+ [id, portal] = (0, utils_1.changeDomPortal)(id, portal, context, element, components_1.ExtensionSlot, newProps);
83
+ };
84
+ element.addEventListener(evName, handler);
85
+ return [dispose, update];
86
+ }
87
+ return [utils_1.noop, utils_1.noop];
85
88
  }
86
89
  exports.renderElement = renderElement;
87
90
  //# sourceMappingURL=element.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"element.js","sourceRoot":"","sources":["../../src/modules/element.ts"],"names":[],"mappings":";;;AAAA,8CAA8C;AAC9C,oCAA6F;AAO7F,IAAI,OAAO,MAAM,KAAK,WAAW,IAAI,gBAAgB,IAAI,MAAM,EAAE;IAC/D,MAAM,cAAe,SAAQ,WAAW;QAAxC;;YACE,YAAO,GAAe,YAAI,CAAC;YAC3B,WAAM,GAAc,YAAI,CAAC;YACzB,UAAK,GAAG;gBACN,IAAI,EAAE,IAAI,CAAC,YAAY,CAAC,MAAM,CAAC;gBAC/B,MAAM,EAAE,IAAA,oBAAY,EAAC,IAAI,CAAC,YAAY,CAAC,QAAQ,CAAC,CAAC;gBACjD,KAAK,EAAE,SAAS;gBAChB,QAAQ,EAAE,IAAA,uBAAe,EAAC,IAAI,CAAC,UAAU,CAAC;aAC3C,CAAC;QA+DJ,CAAC;QA7DC,IAAI,MAAM;YACR,OAAO,IAAI,CAAC,KAAK,CAAC,MAAM,CAAC;QAC3B,CAAC;QAED,IAAI,MAAM,CAAC,KAAK;YACd,IAAI,CAAC,KAAK,CAAC,MA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AAE,MAAM,CAAC,GAAG,IAAA,uBAAe,EAAC,EAAE,EAAE,MAAM,EAAE,OAAO,EAAE,OAAO,EAAE,0BAAa,EAAE,QAAQ,CAAC,CAAC;QACxF,CAAC,CAAC;QACF,OAAO,CAAC,gBAAgB,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC;QAC1C,OAAO,CAAC,OAAO,EAAE,MAAM,CAAC,CAAC;KAC1B;IAED,OAAO,CAAC,YAAI,EAAE,YAAI,CAAC,CAAC;AACtB,CAAC;AArBD,sCAqBC"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "piral-core",
3
- "version": "0.15.0-alpha.3975",
3
+ "version": "0.15.0-alpha.4005",
4
4
  "description": "The core library for creating a Piral instance.",
5
5
  "keywords": [
6
6
  "portal",
@@ -48,8 +48,8 @@
48
48
  },
49
49
  "dependencies": {
50
50
  "@dbeining/react-atom": "^4.0.0",
51
- "piral-base": "0.15.0-alpha.3975",
52
- "piral-debug-utils": "0.15.0-alpha.3975"
51
+ "piral-base": "0.15.0-alpha.4005",
52
+ "piral-debug-utils": "0.15.0-alpha.4005"
53
53
  },
54
54
  "peerDependencies": {
55
55
  "react": ">=16.8.0",
@@ -79,5 +79,5 @@
79
79
  "@libre/atom",
80
80
  "@dbeining/react-atom"
81
81
  ],
82
- "gitHead": "461d63cd1957359472018b32a56778da716d3406"
82
+ "gitHead": "612f2072dea6b5d02e3672be3972e850ae95d446"
83
83
  }
@@ -0,0 +1,45 @@
1
+ import * as React from 'react';
2
+ import { render, unmountComponentAtNode } from 'react-dom';
3
+ import { act } from 'react-dom/test-utils';
4
+ import { RootListener } from './RootListener';
5
+
6
+ jest.mock('./hooks/globalState', () => ({
7
+ useGlobalStateContext: () => ({
8
+ showPortal() {},
9
+ }),
10
+ }));
11
+
12
+ describe('RootListener Component', () => {
13
+ it('renders the RootListener instance with default settings', async () => {
14
+ const element = document.createElement('div');
15
+ const removed = jest.fn();
16
+ document.body.appendChild(element);
17
+ const container = document.body.appendChild(document.createElement('div'));
18
+ render(<RootListener />, container);
19
+ document.body.removeEventListener = removed;
20
+ await act(() => {
21
+ const event = new CustomEvent('render-html', {
22
+ bubbles: true,
23
+ detail: {
24
+ target: element,
25
+ props: {},
26
+ }
27
+ });
28
+ element.dispatchEvent(event);
29
+ return Promise.resolve();
30
+ });
31
+ await act(() => Promise.resolve());
32
+ expect(removed).not.toHaveBeenCalled();
33
+ });
34
+
35
+ it('removes the RootListener successfully', async () => {
36
+ const container = document.body.appendChild(document.createElement('div'));
37
+ const removed = jest.fn();
38
+ render(<RootListener />, container);
39
+ document.body.removeEventListener = removed;
40
+ await act(() => Promise.resolve());
41
+ unmountComponentAtNode(container);
42
+ await act(() => Promise.resolve());
43
+ expect(removed).toHaveBeenCalled();
44
+ });
45
+ });
@@ -1,9 +1,26 @@
1
1
  import { createElement } from 'react';
2
2
  import { Atom, deref } from '@dbeining/react-atom';
3
- import { createListener } from 'piral-base';
4
- import { changeLayout, includeProvider } from './app';
3
+ import { createListener, Pilet } from 'piral-base';
4
+ import {
5
+ changeLayout,
6
+ includeProvider,
7
+ initialize,
8
+ injectPilet,
9
+ removePilet,
10
+ setComponent,
11
+ setErrorComponent,
12
+ setRoute,
13
+ } from './app';
5
14
  import { createActions } from '../state';
6
15
  import { mount } from 'enzyme';
16
+ import { RootListener } from '../RootListener';
17
+
18
+ const pilet: Pilet = {
19
+ name: 'my-pilet',
20
+ version: '1.0.0',
21
+ link: undefined,
22
+ custom: undefined,
23
+ };
7
24
 
8
25
  describe('App Actions Module', () => {
9
26
  it('changeLayout changes the current layout', () => {
@@ -23,6 +40,77 @@ describe('App Actions Module', () => {
23
40
  });
24
41
  });
25
42
 
43
+ it('initialize initializes state data', () => {
44
+ const state = Atom.of({
45
+ app: {},
46
+ });
47
+ const ctx = createActions(state, createListener({}));
48
+ const modules = ['pilet 1', 'pilet 2', 'pilet 3'];
49
+ initialize(ctx, false, undefined, modules);
50
+ expect(deref(state)).toEqual({
51
+ app: { error: undefined, loading: false },
52
+ modules: ['pilet 1', 'pilet 2', 'pilet 3'],
53
+ });
54
+ });
55
+
56
+ it('removePilet removes pilet', () => {
57
+ const state = Atom.of({
58
+ app: {},
59
+ modules: [pilet],
60
+ registry: { 'my-pilet': pilet },
61
+ });
62
+ const ctx = createActions(state, createListener({}));
63
+ removePilet(ctx, 'my-pilet');
64
+ expect(deref(state)).toEqual({ app: {}, modules: [], registry: { 'my-pilet': pilet } });
65
+ });
66
+
67
+ it('injectPilet injects pilet', () => {
68
+ const pilet2: Pilet = {
69
+ name: 'my-pilet2',
70
+ version: '1.0.0',
71
+ link: undefined,
72
+ custom: undefined,
73
+ };
74
+ const state = Atom.of({
75
+ app: {},
76
+ modules: [pilet2],
77
+ registry: { pilet2 },
78
+ });
79
+ const ctx = createActions(state, createListener({}));
80
+ injectPilet(ctx, pilet);
81
+ expect(deref(state)).toEqual({ app: {}, modules: [pilet2, pilet], registry: { pilet2 } });
82
+ });
83
+
84
+ it('setComponent set component', () => {
85
+ const state = Atom.of({
86
+ components: {},
87
+ });
88
+ const ctx = createActions(state, createListener({}));
89
+ const node = RootListener;
90
+ setComponent(ctx, 'ComponentName', node);
91
+ expect(deref(state)).toEqual({ components: { ComponentName: RootListener } });
92
+ });
93
+
94
+ it('setErrorComponent set error component', () => {
95
+ const state = Atom.of({
96
+ errorComponents: {},
97
+ });
98
+ const ctx = createActions(state, createListener({}));
99
+ const node = RootListener;
100
+ setErrorComponent(ctx, 'ComponentName', node);
101
+ expect(deref(state)).toEqual({ errorComponents: { ComponentName: RootListener } });
102
+ });
103
+
104
+ it('setRoute sets route', () => {
105
+ const state = Atom.of({
106
+ routes: {},
107
+ });
108
+ const ctx = createActions(state, createListener({}));
109
+ const node = RootListener;
110
+ setRoute(ctx, './dist', RootListener);
111
+ expect(deref(state)).toEqual({ routes: { './dist': RootListener } });
112
+ });
113
+
26
114
  it('allows using includeProvider once', () => {
27
115
  const state = Atom.of({
28
116
  provider: undefined,
@@ -3,18 +3,33 @@ import { mount } from 'enzyme';
3
3
  import { ExtensionSlot } from './ExtensionSlot';
4
4
 
5
5
  jest.mock('../hooks/globalState', () => ({
6
- useGlobalState(select: any) {
7
- return select(state);
8
- },
6
+ useGlobalState: (select: any) => select(state),
7
+ useGlobalStateContext: () => ({
8
+ converters: {
9
+ html: ({ component }) => component,
10
+ },
11
+ apis: {
12
+ _: {
13
+ meta: {
14
+ name: 'PiletName',
15
+ },
16
+ },
17
+ },
18
+ }),
9
19
  }));
10
20
 
21
+ (React as any).useMemo = (cb) => cb();
22
+
11
23
  const StubComponent1: React.FC = (props) => <div children={props.children} />;
12
24
  StubComponent1.displayName = 'StubComponent1';
13
25
 
14
26
  const StubComponent2: React.FC = (props) => <div children={props.children} />;
15
27
  StubComponent2.displayName = 'StubComponent2';
16
28
 
29
+ const StubComponent3: React.FC = (props) => <div children={props.children} />;
30
+
17
31
  const state = {
32
+ portals: {},
18
33
  registry: {
19
34
  extensions: {
20
35
  foo: [],
@@ -29,13 +44,41 @@ const state = {
29
44
  component: StubComponent2,
30
45
  },
31
46
  ],
47
+ bla: [
48
+ {
49
+ component: StubComponent3,
50
+ },
51
+ ],
32
52
  },
33
53
  },
34
54
  };
35
55
 
36
- (React as any).useMemo = (cb) => cb();
37
-
38
56
  describe('Extension Module', () => {
57
+ it('is able to default render not available extension with no name', () => {
58
+ const node = mount(<ExtensionSlot />);
59
+ expect(node.at(0).exists()).toBe(true);
60
+ expect(node.find(StubComponent1).length).toBe(0);
61
+ expect(node.find('div').length).toBe(0);
62
+ });
63
+
64
+ it('is able to default render given component with no name', () => {
65
+ const component = {
66
+ type: 'html',
67
+ component: {
68
+ mount(element) {
69
+ const container = document.createElement('div');
70
+ container.textContent = 'Hello!';
71
+ element.appendChild(container);
72
+ },
73
+ },
74
+ };
75
+ const node = mount(<ExtensionSlot params={{ component }} />);
76
+ expect(node.at(0).exists()).toBe(true);
77
+ expect(node.find(StubComponent1).length).toBe(0);
78
+ expect(node.find('div').length).toBe(1);
79
+ expect(node.text()).toContain('Hello!');
80
+ });
81
+
39
82
  it('is able to default render not available extension', () => {
40
83
  const node = mount(<ExtensionSlot name="qxz" />);
41
84
  expect(node.at(0).exists()).toBe(true);
@@ -62,6 +105,14 @@ describe('Extension Module', () => {
62
105
  const node = mount(<ExtensionSlot name="bar" />);
63
106
  expect(node.find(StubComponent1).length).toBe(2);
64
107
  expect(node.find(StubComponent2).length).toBe(1);
108
+ expect(node.find(StubComponent3).length).toBe(0);
109
+ });
110
+
111
+ it('is able to render extension without displayName', () => {
112
+ const node = mount(<ExtensionSlot name="bla" />);
113
+ expect(node.find(StubComponent1).length).toBe(0);
114
+ expect(node.find(StubComponent2).length).toBe(0);
115
+ expect(node.find(StubComponent3).length).toBe(1);
65
116
  });
66
117
 
67
118
  it('overrides the empty renderer on not available extension', () => {
@@ -5,6 +5,8 @@ import { useGlobalState, useGlobalStateContext } from '../hooks';
5
5
  import { defaultRender, none } from '../utils';
6
6
  import { ExtensionRegistration, ExtensionSlotProps } from '../types';
7
7
 
8
+ const wrapper = ({ children }) => defaultRender(children);
9
+
8
10
  const renderExtensions: [ExtensionRegistration] = [
9
11
  {
10
12
  component: (props) => {
@@ -12,10 +14,7 @@ const renderExtensions: [ExtensionRegistration] = [
12
14
  const converters = context.converters;
13
15
  const piral = context.apis._;
14
16
  const { component, props: args } = props.params;
15
- const Component = React.useMemo(
16
- () => wrapComponent(converters, component, { piral }, defaultRender),
17
- [component],
18
- );
17
+ const Component = React.useMemo(() => wrapComponent(converters, component, { piral }, wrapper), [component]);
19
18
  return <Component {...args} />;
20
19
  },
21
20
  defaults: {},
@@ -0,0 +1,119 @@
1
+ import * as React from 'react';
2
+ import { render, unmountComponentAtNode } from 'react-dom';
3
+ import { ForeignComponentContainer } from './ForeignComponentContainer';
4
+
5
+ describe('ForeignComponentContainer component', () => {
6
+ it('mounts an HTML component', () => {
7
+ const container = document.body.appendChild(document.createElement('div'));
8
+ const mount = jest.fn();
9
+ const component = { mount };
10
+ render(
11
+ <ForeignComponentContainer $component={component} $context={undefined} $portalId="foo" innerProps={{}} />,
12
+ container,
13
+ );
14
+ expect(mount).toHaveBeenCalled();
15
+ container.remove();
16
+ });
17
+
18
+ it('unmounts an HTML component', () => {
19
+ const container = document.body.appendChild(document.createElement('div'));
20
+ const mount = jest.fn();
21
+ const unmount = jest.fn();
22
+ const component = { mount, unmount };
23
+ render(
24
+ <ForeignComponentContainer $component={component} $context={undefined} $portalId="foo" innerProps={{}} />,
25
+ container,
26
+ );
27
+ expect(mount).toHaveBeenCalled();
28
+ expect(unmount).not.toHaveBeenCalled();
29
+ unmountComponentAtNode(container);
30
+ expect(unmount).toHaveBeenCalled();
31
+ container.remove();
32
+ });
33
+
34
+ it('updates an HTML component', () => {
35
+ const container = document.body.appendChild(document.createElement('div'));
36
+ const mount = jest.fn();
37
+ const update = jest.fn();
38
+ const component = { mount, update };
39
+ render(
40
+ <ForeignComponentContainer
41
+ $component={component}
42
+ $context={undefined}
43
+ $portalId="foo"
44
+ innerProps={{ a: 'bar' }}
45
+ />,
46
+ container,
47
+ );
48
+ expect(mount).toHaveBeenCalled();
49
+ expect(update).not.toHaveBeenCalled();
50
+ render(
51
+ <ForeignComponentContainer
52
+ $component={component}
53
+ $context={undefined}
54
+ $portalId="foo"
55
+ innerProps={{ a: 'foo' }}
56
+ />,
57
+ container,
58
+ );
59
+ expect(update).toHaveBeenCalled();
60
+ container.remove();
61
+ });
62
+
63
+ it('forces re-rendering of an HTML component', () => {
64
+ const container = document.body.appendChild(document.createElement('div'));
65
+ const componentDidMount = ForeignComponentContainer.prototype.componentDidMount;
66
+ ForeignComponentContainer.prototype.componentDidMount = function () {
67
+ componentDidMount.call(this);
68
+ this.previous = {
69
+ removeEventListener() {},
70
+ };
71
+ };
72
+ const mount = jest.fn();
73
+ const update = jest.fn();
74
+ const unmount = jest.fn();
75
+ const component = { mount, update, unmount };
76
+ render(
77
+ <ForeignComponentContainer
78
+ $component={component}
79
+ $context={undefined}
80
+ $portalId="foo"
81
+ innerProps={{ a: 'bar' }}
82
+ />,
83
+ container,
84
+ );
85
+ expect(mount).toHaveBeenCalled();
86
+ expect(unmount).not.toHaveBeenCalled();
87
+ expect(update).not.toHaveBeenCalled();
88
+ render(
89
+ <ForeignComponentContainer
90
+ $component={component}
91
+ $context={undefined}
92
+ $portalId="foo"
93
+ innerProps={{ a: 'foo' }}
94
+ />,
95
+ container,
96
+ );
97
+ expect(update).not.toHaveBeenCalled();
98
+ expect(unmount).toHaveBeenCalled();
99
+ container.remove();
100
+ });
101
+
102
+ it('listens to render-html', () => {
103
+ const container = document.body.appendChild(document.createElement('div'));
104
+ const mount = jest.fn();
105
+ const renderHtmlExtension = jest.fn();
106
+ const component = { mount };
107
+ const props = { piral: { renderHtmlExtension }, meta: {} };
108
+ render(
109
+ <ForeignComponentContainer $component={component} $context={undefined} $portalId="foo" innerProps={props} />,
110
+ container,
111
+ );
112
+ expect(mount).toHaveBeenCalled();
113
+ const node = document.querySelector('[data-portal-id=foo]');
114
+ expect(renderHtmlExtension).not.toHaveBeenCalled();
115
+ node.dispatchEvent(new CustomEvent('render-html', { detail: {} }));
116
+ expect(renderHtmlExtension).toHaveBeenCalled();
117
+ container.remove();
118
+ });
119
+ });
@@ -0,0 +1,60 @@
1
+ /**
2
+ * @jest-environment node
3
+ */
4
+
5
+ import * as React from 'react';
6
+ import * as hooks from '../hooks';
7
+ import * as routes from './PiralRoutes';
8
+ import { render } from 'enzyme';
9
+ import { PiralView } from './PiralView';
10
+
11
+ const StubDashboard: React.FC = () => <div />;
12
+ StubDashboard.displayName = 'StubDashboard';
13
+
14
+ const StubErrorInfo: React.FC = () => <div />;
15
+ StubErrorInfo.displayName = 'StubErrorInfo';
16
+
17
+ const StubLoader: React.FC = () => <div />;
18
+ StubLoader.displayName = 'StubLoader';
19
+
20
+ const StubRouter: React.FC = ({ children }) => <div>{children}</div>;
21
+ StubRouter.displayName = 'StubRouter';
22
+
23
+ const StubLayout: React.FC = ({ children }) => <div>{children}</div>;
24
+ StubLayout.displayName = 'StubLayout';
25
+
26
+ jest.mock('../hooks');
27
+ jest.mock('./PiralRoutes');
28
+
29
+ const state = {
30
+ app: {
31
+ error: undefined,
32
+ loading: true,
33
+ },
34
+ components: {
35
+ ErrorInfo: StubErrorInfo,
36
+ LoadingIndicator: StubLoader,
37
+ Router: StubRouter,
38
+ Layout: StubLayout,
39
+ },
40
+ registry: {
41
+ pages: {},
42
+ extensions: {},
43
+ },
44
+ routes: {},
45
+ provider: undefined,
46
+ };
47
+
48
+ (hooks as any).useGlobalState = (select: any) => select(state);
49
+
50
+ (routes as any).PiralRoutes = ({ }) => <StubDashboard />;
51
+
52
+ describe('Portal Module', () => {
53
+ it('In this test window should be undefined', () => {
54
+ state.app.loading = false;
55
+ state.app.error = undefined;
56
+ const node = render(<PiralView />);
57
+ expect(typeof window).toBe("undefined")
58
+ expect(node.length).toBe(1);
59
+ });
60
+ });
@@ -0,0 +1,38 @@
1
+ import * as React from 'react';
2
+ import { mount } from 'enzyme';
3
+ import { SwitchErrorInfo } from './SwitchErrorInfo';
4
+
5
+ jest.mock('../hooks/globalState', () => ({
6
+ useGlobalState(select: any) {
7
+ return select(state);
8
+ },
9
+ }));
10
+
11
+ const StubComponent1: React.FC = (props) => <div children={props.children} />;
12
+ const Unknown: React.FC = (props) => <div children={props.children} />;
13
+
14
+ const state = {
15
+ registry: {
16
+ extensions: {},
17
+ },
18
+ errorComponents: {
19
+ stubComponent1: StubComponent1,
20
+ unknown: Unknown,
21
+ },
22
+ };
23
+
24
+ (React as any).useMemo = (cb) => cb();
25
+
26
+ describe('SwitchErrorInfo Module', () => {
27
+ it('is able to render StubComponent1 component', () => {
28
+ const node = mount(<SwitchErrorInfo type="stubComponent1" />);
29
+ expect(node.at(0).exists()).toBe(true);
30
+ expect(node.find(StubComponent1).length).toBe(1);
31
+ });
32
+
33
+ it('is able to default render Unknow component if the compenent name not available in state data', () => {
34
+ const node = mount(<SwitchErrorInfo type="notRealComponent" />);
35
+ expect(node.at(0).exists()).toBe(true);
36
+ expect(node.find(Unknown).length).toBe(1);
37
+ });
38
+ })
@@ -12,8 +12,13 @@ describe('Piral-Core createInstance module', () => {
12
12
  expect(instance.options.strategy).toBe(blazingStrategy);
13
13
  });
14
14
 
15
- it('createInstance with empty actions uses the standard strategy', () => {
16
- const instance = createInstance({ actions: {} });
15
+ it('createInstance with empty actions and plugins uses the standard strategy', () => {
16
+ const instance = createInstance({ plugins: {}, actions: {} });
17
17
  expect(instance.options.strategy).toBe(standardStrategy);
18
18
  })
19
+
20
+ it('createInstance with async function uses the blazing strategy', () => {
21
+ const instance = createInstance({ async: () => { } });
22
+ expect(instance.options.strategy).not.toBe(blazingStrategy);
23
+ })
19
24
  });
@@ -0,0 +1,22 @@
1
+ /**
2
+ * @jest-environment node
3
+ */
4
+
5
+ import * as React from 'react';
6
+ import { renderToString } from 'react-dom/server';
7
+ import { useSetter } from './setter';
8
+
9
+ describe('UseSetter Hook Module', () => {
10
+ it('UseSetter', () => {
11
+ const cb = jest.fn();
12
+
13
+ const MyComponent = () => {
14
+ useSetter(cb);
15
+ return null;
16
+ };
17
+
18
+ const result = renderToString(React.createElement(MyComponent));
19
+ expect(result).toEqual('');
20
+ expect(cb).toHaveBeenCalled();
21
+ });
22
+ });
@@ -0,0 +1,19 @@
1
+ import * as React from 'react';
2
+ import { act } from 'react-dom/test-utils';
3
+ import { render } from 'react-dom';
4
+ import { useSetter } from './setter';
5
+
6
+ describe('UseSetter Hook Module', () => {
7
+ it('UseSetter', async () => {
8
+ const cb = jest.fn();
9
+
10
+ const MyComponent = () => {
11
+ useSetter(cb);
12
+ return null;
13
+ };
14
+
15
+ render(React.createElement(MyComponent), document.body.appendChild(document.createElement('div')));
16
+ await act(() => Promise.resolve());
17
+ expect(cb).toHaveBeenCalled();
18
+ });
19
+ });
@@ -0,0 +1,29 @@
1
+ /**
2
+ * @jest-environment node
3
+ */
4
+
5
+ import { Atom, deref } from '@dbeining/react-atom';
6
+ import { createListener } from 'piral-base';
7
+ import { createActions } from '../state';
8
+ import { renderElement } from './element';
9
+
10
+ function createMockContext(): [any, any] {
11
+ const state = Atom.of({
12
+ portals: {
13
+ root: [],
14
+ },
15
+ });
16
+ const context = createActions(state, createListener({}));
17
+ return [context, state];
18
+ }
19
+
20
+ describe('Elements Module from SSR', () => {
21
+ it('Should not have piral-extensions web component', () => {
22
+ const [context, state] = createMockContext();
23
+ const element: any = {
24
+ addEventListener() {},
25
+ };
26
+ renderElement(context, element, {});
27
+ expect(deref(state)['portals']['root'].length).toBe(0);
28
+ });
29
+ });
@@ -0,0 +1,77 @@
1
+ import { Atom, deref } from '@dbeining/react-atom';
2
+ import { createListener } from 'piral-base';
3
+ import { createActions } from '../state';
4
+ import { renderElement } from './element';
5
+
6
+ declare global {
7
+ interface HTMLElementTagNameMap {
8
+ "piral-extension": HTMLElement & {
9
+ params: any;
10
+ name: string;
11
+ empty: any;
12
+ };
13
+ }
14
+ }
15
+
16
+ function createMockContext(): [any, any] {
17
+ const state = Atom.of({
18
+ portals: {},
19
+ });
20
+ const context = createActions(state, createListener({}));
21
+ return [context, state];
22
+ }
23
+
24
+ describe('Elements Module', () => {
25
+ it('testing basic renderElement functionality of piral-extension web component', () => {
26
+ const [context, state] = createMockContext();
27
+ const element = document.createElement('piral-extension');
28
+ const event = new Event('extension-props-changed');
29
+ document.body.appendChild(element);
30
+ renderElement(context, element, {});
31
+ element.dispatchEvent(event);
32
+ document.body.removeChild(element);
33
+ (element as any).connectedCallback();
34
+ expect(deref(state)['portals']['root'].length).toBe(1);
35
+ });
36
+
37
+ it('disposing piral-extension web component', () => {
38
+ const [context, state] = createMockContext();
39
+ const element = document.createElement('piral-extension');
40
+ document.body.appendChild(element);
41
+ const [dispose] = renderElement(context, element, {});
42
+ expect(deref(state)['portals']['root'].length).toBe(1);
43
+ dispose();
44
+ expect(deref(state)['portals']['root'].length).toBe(0);
45
+ });
46
+
47
+ it('testing setters and getters in piral-extension web component', () => {
48
+ const [context] = createMockContext();
49
+ const element = document.createElement('piral-extension');
50
+ document.body.appendChild(element);
51
+ renderElement(context, element, {});
52
+ expect(element.params).toEqual(null);
53
+ expect(element.name).toEqual(null);
54
+ expect(element.empty).toEqual(undefined);
55
+ element.params = 'anything';
56
+ element.name = 'foo';
57
+ element.empty = 'anything';
58
+ expect(element.params).toEqual('anything');
59
+ expect(element.name).toEqual('foo');
60
+ expect(element.empty).toEqual('anything');
61
+ element.setAttribute('name', 'bar');
62
+ element.setAttribute('params', '{}');
63
+ expect(element.params).toEqual({});
64
+ expect(element.name).toEqual('bar');
65
+ });
66
+
67
+ it('testing attributes of piral-extension web component', () => {
68
+ const [context] = createMockContext();
69
+ const element = document.createElement('piral-extension');
70
+ document.body.appendChild(element);
71
+ renderElement(context, element, {});
72
+ element.setAttribute('name', 'bar');
73
+ element.setAttribute('params', '{}');
74
+ expect(element.params).toEqual({});
75
+ expect(element.name).toEqual('bar');
76
+ });
77
+ });
@@ -88,16 +88,20 @@ export function renderElement(
88
88
  element: HTMLElement | ShadowRoot,
89
89
  props: any,
90
90
  ): [Disposable, Updatable] {
91
- let [id, portal] = renderInDom(context, element, ExtensionSlot, props);
92
- const evName = 'extension-props-changed';
93
- const handler = (ev: CustomEvent) => update(ev.detail);
94
- const dispose: Disposable = () => {
95
- context.hidePortal(id, portal);
96
- element.removeEventListener(evName, handler);
97
- };
98
- const update: Updatable = (newProps) => {
99
- [id, portal] = changeDomPortal(id, portal, context, element, ExtensionSlot, newProps);
100
- };
101
- element.addEventListener(evName, handler);
102
- return [dispose, update];
91
+ if (typeof window !== 'undefined') {
92
+ let [id, portal] = renderInDom(context, element, ExtensionSlot, props);
93
+ const evName = 'extension-props-changed';
94
+ const handler = (ev: CustomEvent) => update(ev.detail);
95
+ const dispose: Disposable = () => {
96
+ context.hidePortal(id, portal);
97
+ element.removeEventListener(evName, handler);
98
+ };
99
+ const update: Updatable = (newProps) => {
100
+ [id, portal] = changeDomPortal(id, portal, context, element, ExtensionSlot, newProps);
101
+ };
102
+ element.addEventListener(evName, handler);
103
+ return [dispose, update];
104
+ }
105
+
106
+ return [noop, noop];
103
107
  }
@@ -6,6 +6,29 @@ import { withApi } from './withApi';
6
6
  import { StateContext } from '../state';
7
7
 
8
8
  function createMockContainer() {
9
+ const state = Atom.of({
10
+ portals: {},
11
+ });
12
+ return {
13
+ context: {
14
+ converters: {},
15
+ readState(cb) {
16
+ return cb({
17
+ registry: {
18
+ wrappers: { "feed": "test", "*": "test" },
19
+ },
20
+ });
21
+ },
22
+ on: jest.fn(),
23
+ off: jest.fn(),
24
+ emit: jest.fn(),
25
+ state,
26
+ destroyPortal: (id) => { },
27
+ } as any,
28
+ };
29
+ }
30
+
31
+ function createMockContainerWithNoWrappers() {
9
32
  const state = Atom.of({
10
33
  portals: {},
11
34
  });
@@ -23,7 +46,7 @@ function createMockContainer() {
23
46
  off: jest.fn(),
24
47
  emit: jest.fn(),
25
48
  state,
26
- destroyPortal: (id) => {},
49
+ destroyPortal: (id) => { },
27
50
  } as any,
28
51
  };
29
52
  }
@@ -103,11 +126,9 @@ describe('withApi Module', () => {
103
126
  };
104
127
  const { context } = createMockContainer();
105
128
  context.converters = {
106
- html: (component) => {
107
- return component.component;
108
- },
129
+ html: ({ component }) => component,
109
130
  };
110
- const Component = withApi(context, { type: 'html', component: { mount: () => {} } }, api, 'unknown');
131
+ const Component = withApi(context, { type: 'html', component: { mount: () => { } } }, api, 'unknown');
111
132
 
112
133
  const node = mount(
113
134
  <StateContext.Provider value={context}>
@@ -124,11 +145,9 @@ describe('withApi Module', () => {
124
145
  name: 'foo',
125
146
  },
126
147
  };
127
- const { context } = createMockContainer();
148
+ const { context } = createMockContainerWithNoWrappers();
128
149
  context.converters = {
129
- html: (component) => {
130
- return component.component;
131
- },
150
+ html: ({ component }) => component,
132
151
  };
133
152
  const Component = withApi(context, null, api, 'unknown');
134
153
 
@@ -1,6 +1,7 @@
1
1
  import * as React from 'react';
2
2
  import { mount } from 'enzyme';
3
- import { toExtension } from './extension';
3
+ import { reactifyContent, toExtension } from './extension';
4
+
4
5
 
5
6
  describe('Util Extension.', () => {
6
7
  it('Convert some component to an extension component.', () => {
@@ -9,4 +10,13 @@ describe('Util Extension.', () => {
9
10
  const node = mount(<Extension piral={undefined} params={{ title: 'Foo' }} />);
10
11
  expect(node.find('b').length).toBe(1);
11
12
  });
12
- });
13
+
14
+ it('reactifyContent.', async () => {
15
+ const container = document.body.appendChild(document.createElement('div'));
16
+ container.innerHTML = `<div>FOO<</div>`;
17
+ const result = reactifyContent(container.childNodes) as React.ReactElement;
18
+ const node = await mount(result)
19
+ expect(node.find("slot").length).toBe(1);
20
+ });
21
+ });
22
+
@@ -1,12 +1,30 @@
1
- import { createElement } from 'react';
2
- import { convertComponent, renderInDom } from './foreign';
1
+ import * as React from 'react';
2
+ import { changeDomPortal, convertComponent, renderInDom } from './foreign';
3
3
  import { ForeignComponent } from '../types';
4
4
  import { DefaultLoadingIndicator } from '../components/DefaultLoader';
5
5
 
6
+ // const StubComponent: React.FC = (props) => <div />;
7
+ // StubComponent.displayName = 'StubComponent';
8
+
6
9
  describe('Util Foreign.', () => {
10
+ it('changeDomPortal changes dom in portal', () => {
11
+ const children = React.createElement('div');
12
+ const current: React.ReactPortal = { key: 'current', children: { children }, type: 'div', props: null };
13
+
14
+ const context = {
15
+ updatePortal: jest.fn(),
16
+ } as any;
17
+ const portalId = 'data-portal-id';
18
+ const element = document.createElement('div') as HTMLDivElement;
19
+ element.setAttribute(portalId, '100');
20
+
21
+ const result = changeDomPortal(portalId, current, context, element, DefaultLoadingIndicator, {});
22
+ expect(result).not.toEqual({});
23
+ });
24
+
7
25
  it('Convert component function throws error due to missing converter function.', () => {
8
26
  const t = () => {
9
- convertComponent(null, createElement('div'));
27
+ convertComponent(null, React.createElement('div'));
10
28
  };
11
29
  expect(t).toThrow('No converter for component of type "div" registered.');
12
30
  });
@@ -17,7 +35,7 @@ describe('Util Foreign.', () => {
17
35
  };
18
36
  const result = convertComponent(() => {
19
37
  return fComponent;
20
- }, createElement('div'));
38
+ }, React.createElement('div'));
21
39
  expect(result).toEqual(fComponent);
22
40
  });
23
41
 
@@ -0,0 +1,39 @@
1
+ import * as hooks from '../hooks';
2
+ import { withAll, withRootExtension } from './state';
3
+ import { RootListener } from '../RootListener';
4
+ import { createGlobalState } from '../state';
5
+
6
+ describe('State Module', () => {
7
+ it('withRootExtension should create an extension key', () => {
8
+ const dispatch = withRootExtension('test', RootListener);
9
+ const result = dispatch({ registry: { extensions: {} } });
10
+ expect(result['registry']['extensions']['test']).toBeTruthy();
11
+ });
12
+
13
+ it('withAll should return identity state with no dispatcher', () => {
14
+ const dispatchers = withAll();
15
+ const result = dispatchers({ state: ['foo', 'boo'] });
16
+ expect(result).toEqual({ state: ['foo', 'boo'] });
17
+ });
18
+
19
+ it('withAll should return identity state with identity dispatcher', () => {
20
+ const dispatchers = withAll((s) => s);
21
+ const result = dispatchers({ state: ['foo', 'boo'] });
22
+ expect(result).toEqual({ state: ['foo', 'boo'] });
23
+ });
24
+
25
+ it('withAll should return empty state with blank dispatcher', () => {
26
+ const dispatchers = withAll((s) => ({}));
27
+ const result = dispatchers({ state: ['foo', 'boo'] });
28
+ expect(result).toEqual({});
29
+ });
30
+
31
+ it('withAll should return mutated state of all dispatchers', () => {
32
+ const dispatchers = withAll(
33
+ (s) => ({ ...s, foo: 'bar' }),
34
+ (s) => ({ ...s, bar: 'qxz' }),
35
+ );
36
+ const result = dispatchers({ state: ['foo', 'boo'] });
37
+ expect(result).toEqual({ state: ['foo', 'boo'], foo: 'bar', bar: 'qxz' });
38
+ });
39
+ });