@worktile/planet 12.1.1 → 14.0.0-next.0
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/CHANGELOG.md +26 -0
- package/application/planet-application-loader.d.ts +73 -0
- package/application/planet-application-loader.d.ts.map +1 -0
- package/application/planet-application-ref.d.ts +36 -0
- package/application/planet-application-ref.d.ts.map +1 -0
- package/application/planet-application.service.d.ts +22 -0
- package/application/planet-application.service.d.ts.map +1 -0
- package/{packages/planet/src/application/portal-application.ts → application/portal-application.d.ts} +5 -18
- package/application/portal-application.d.ts.map +1 -0
- package/assets-loader.d.ts +36 -0
- package/assets-loader.d.ts.map +1 -0
- package/component/planet-component-loader.d.ts +31 -0
- package/component/planet-component-loader.d.ts.map +1 -0
- package/component/planet-component-ref.d.ts +8 -0
- package/component/planet-component-ref.d.ts.map +1 -0
- package/{packages/planet/src/component/plant-component.config.ts → component/plant-component.config.d.ts} +4 -4
- package/component/plant-component.config.d.ts.map +1 -0
- package/debug.d.ts +22 -0
- package/debug.d.ts.map +1 -0
- package/empty/empty.component.d.ts +6 -0
- package/empty/empty.component.d.ts.map +1 -0
- package/esm2020/application/planet-application-loader.mjs +454 -0
- package/esm2020/application/planet-application-ref.mjs +94 -0
- package/esm2020/application/planet-application.service.mjs +85 -0
- package/esm2020/application/portal-application.mjs +16 -0
- package/esm2020/assets-loader.mjs +216 -0
- package/esm2020/component/planet-component-loader.mjs +153 -0
- package/esm2020/component/planet-component-ref.mjs +3 -0
- package/esm2020/component/plant-component.config.mjs +7 -0
- package/esm2020/debug.mjs +33 -0
- package/esm2020/empty/empty.component.mjs +15 -0
- package/esm2020/global-event-dispatcher.mjs +70 -0
- package/esm2020/global-planet.mjs +53 -0
- package/esm2020/helpers.mjs +119 -0
- package/esm2020/module.mjs +31 -0
- package/esm2020/planet.class.mjs +9 -0
- package/esm2020/planet.mjs +91 -0
- package/esm2020/public-api.mjs +18 -0
- package/esm2020/sandbox/constants.mjs +7 -0
- package/esm2020/sandbox/exec.mjs +15 -0
- package/esm2020/sandbox/index.mjs +20 -0
- package/esm2020/sandbox/proxy/patches/document.mjs +12 -0
- package/esm2020/sandbox/proxy/patches/eventListener.mjs +41 -0
- package/esm2020/sandbox/proxy/patches/index.mjs +11 -0
- package/esm2020/sandbox/proxy/patches/storage.mjs +40 -0
- package/esm2020/sandbox/proxy/patches/timer.mjs +43 -0
- package/esm2020/sandbox/proxy/proxies/common.mjs +132 -0
- package/esm2020/sandbox/proxy/proxies/document.mjs +126 -0
- package/esm2020/sandbox/proxy/proxies/window.mjs +158 -0
- package/esm2020/sandbox/proxy/proxy-sandbox.mjs +49 -0
- package/esm2020/sandbox/proxy/types.mjs +2 -0
- package/esm2020/sandbox/sandbox.mjs +7 -0
- package/esm2020/sandbox/snapshot/snapshot-sandbox.mjs +12 -0
- package/esm2020/sandbox/types.mjs +2 -0
- package/esm2020/worktile-planet.mjs +5 -0
- package/fesm2015/worktile-planet.mjs +2049 -0
- package/fesm2015/worktile-planet.mjs.map +1 -0
- package/fesm2020/worktile-planet.mjs +2046 -0
- package/fesm2020/worktile-planet.mjs.map +1 -0
- package/global-event-dispatcher.d.ts +23 -0
- package/global-event-dispatcher.d.ts.map +1 -0
- package/global-planet.d.ts +23 -0
- package/global-planet.d.ts.map +1 -0
- package/helpers.d.ts +39 -0
- package/helpers.d.ts.map +1 -0
- package/index.d.ts +6 -0
- package/module.d.ts +12 -0
- package/module.d.ts.map +1 -0
- package/package.json +27 -120
- package/{packages/planet/src/planet.class.ts → planet.class.d.ts} +5 -26
- package/planet.class.d.ts.map +1 -0
- package/planet.d.ts +28 -0
- package/planet.d.ts.map +1 -0
- package/{packages/planet/src/public-api.ts → public-api.d.ts} +1 -4
- package/public-api.d.ts.map +1 -0
- package/sandbox/constants.d.ts +7 -0
- package/sandbox/constants.d.ts.map +1 -0
- package/sandbox/exec.d.ts +3 -0
- package/sandbox/exec.d.ts.map +1 -0
- package/sandbox/index.d.ts +7 -0
- package/sandbox/index.d.ts.map +1 -0
- package/sandbox/proxy/patches/document.d.ts +3 -0
- package/sandbox/proxy/patches/document.d.ts.map +1 -0
- package/sandbox/proxy/patches/eventListener.d.ts +3 -0
- package/sandbox/proxy/patches/eventListener.d.ts.map +1 -0
- package/sandbox/proxy/patches/index.d.ts +3 -0
- package/sandbox/proxy/patches/index.d.ts.map +1 -0
- package/sandbox/proxy/patches/storage.d.ts +15 -0
- package/sandbox/proxy/patches/storage.d.ts.map +1 -0
- package/sandbox/proxy/patches/timer.d.ts +3 -0
- package/sandbox/proxy/patches/timer.d.ts.map +1 -0
- package/sandbox/proxy/proxies/common.d.ts +13 -0
- package/sandbox/proxy/proxies/common.d.ts.map +1 -0
- package/sandbox/proxy/proxies/document.d.ts +14 -0
- package/sandbox/proxy/proxies/document.d.ts.map +1 -0
- package/sandbox/proxy/proxies/window.d.ts +13 -0
- package/sandbox/proxy/proxies/window.d.ts.map +1 -0
- package/sandbox/proxy/proxy-sandbox.d.ts +16 -0
- package/sandbox/proxy/proxy-sandbox.d.ts.map +1 -0
- package/{packages/planet/src/sandbox/proxy/types.ts → sandbox/proxy/types.d.ts} +2 -8
- package/sandbox/proxy/types.d.ts.map +1 -0
- package/sandbox/sandbox.d.ts +12 -0
- package/sandbox/sandbox.d.ts.map +1 -0
- package/sandbox/snapshot/snapshot-sandbox.d.ts +9 -0
- package/sandbox/snapshot/snapshot-sandbox.d.ts.map +1 -0
- package/sandbox/types.d.ts +2 -0
- package/sandbox/types.d.ts.map +1 -0
- package/worktile-planet.d.ts.map +1 -0
- package/.all-contributorsrc +0 -84
- package/.circleci/config.yml +0 -17
- package/.coveralls.yml +0 -1
- package/.docgeni/public/assets/favicon.ico +0 -0
- package/.docgeni/public/index.html +0 -13
- package/.docgenirc.js +0 -35
- package/.dockerignore +0 -1
- package/.editorconfig +0 -22
- package/.github/FUNDING.yml +0 -12
- package/.github/ISSUE_TEMPLATE/bug_report.md +0 -38
- package/.github/ISSUE_TEMPLATE/feature_request.md +0 -20
- package/.prettierignore +0 -7
- package/.prettierrc +0 -28
- package/.travis.yml +0 -26
- package/.wpmrc.js +0 -11
- package/CODE_OF_CONDUCT.md +0 -76
- package/Dockerfile +0 -11
- package/README.zh-CN.md +0 -307
- package/SECURITY.md +0 -21
- package/angular.json +0 -373
- package/commitlint.config.js +0 -6
- package/docs/api/defineApplication.md +0 -46
- package/docs/api/globalEventDispatcher.md +0 -51
- package/docs/api/index.md +0 -5
- package/docs/api/planet.md +0 -117
- package/docs/guides/getting-started.md +0 -174
- package/docs/guides/index.md +0 -5
- package/docs/guides/intro.md +0 -216
- package/examples/app1/browserslist +0 -11
- package/examples/app1/extra-webpack.config.js +0 -33
- package/examples/app1/karma.conf.js +0 -31
- package/examples/app1/postcss.config.js +0 -1
- package/examples/app1/src/app/app.module.ts +0 -44
- package/examples/app1/src/app/app.routing.ts +0 -49
- package/examples/app1/src/app/counter.service.ts +0 -16
- package/examples/app1/src/app/dashboard/dashboard.component.html +0 -51
- package/examples/app1/src/app/dashboard/dashboard.component.ts +0 -70
- package/examples/app1/src/app/detail/detail.component.html +0 -8
- package/examples/app1/src/app/detail/detail.component.ts +0 -18
- package/examples/app1/src/app/overlay.ts +0 -26
- package/examples/app1/src/app/projects/dialog/projects-dialog.component.html +0 -10
- package/examples/app1/src/app/projects/dialog/projects-dialog.component.ts +0 -41
- package/examples/app1/src/app/projects/projects.component.ts +0 -33
- package/examples/app1/src/app/root/root.component.css +0 -3
- package/examples/app1/src/app/root/root.component.html +0 -16
- package/examples/app1/src/app/root/root.component.ts +0 -35
- package/examples/app1/src/app/services/initialized-data.resolver.ts +0 -15
- package/examples/app1/src/app/shared.module.ts +0 -57
- package/examples/app1/src/app/user/detail/user-detail.component.html +0 -5
- package/examples/app1/src/app/user/detail/user-detail.component.ts +0 -20
- package/examples/app1/src/app/user/user-list.component.html +0 -7
- package/examples/app1/src/app/user/user-list.component.ts +0 -20
- package/examples/app1/src/app/user/user.module.ts +0 -31
- package/examples/app1/src/assets/.gitkeep +0 -0
- package/examples/app1/src/assets/github.png +0 -0
- package/examples/app1/src/assets/main.css +0 -3
- package/examples/app1/src/environments/environment.prod.ts +0 -3
- package/examples/app1/src/environments/environment.ts +0 -16
- package/examples/app1/src/favicon.ico +0 -0
- package/examples/app1/src/index.html +0 -14
- package/examples/app1/src/main.ts +0 -35
- package/examples/app1/src/polyfills.ts +0 -84
- package/examples/app1/src/styles.scss +0 -35
- package/examples/app1/src/test.ts +0 -14
- package/examples/app1/temp.js +0 -221
- package/examples/app1/tsconfig.app.json +0 -10
- package/examples/app1/tsconfig.spec.json +0 -18
- package/examples/app1/tslint.json +0 -17
- package/examples/app1/webpack.config.js +0 -127
- package/examples/app2/browserslist +0 -11
- package/examples/app2/extra-webpack.config.js +0 -32
- package/examples/app2/karma.conf.js +0 -31
- package/examples/app2/src/app/app.module.ts +0 -90
- package/examples/app2/src/app/dashboard/dashboard.component.html +0 -21
- package/examples/app2/src/app/dashboard/dashboard.component.ts +0 -27
- package/examples/app2/src/app/overlay.ts +0 -26
- package/examples/app2/src/app/projects/detail/detail.component.html +0 -16
- package/examples/app2/src/app/projects/detail/detail.component.ts +0 -21
- package/examples/app2/src/app/projects/project-list.component.html +0 -29
- package/examples/app2/src/app/projects/project-list.component.ts +0 -58
- package/examples/app2/src/app/projects/project.resolver.ts +0 -15
- package/examples/app2/src/app/projects/projects.service.ts +0 -28
- package/examples/app2/src/app/projects/tasks/tasks.component.html +0 -10
- package/examples/app2/src/app/projects/tasks/tasks.component.ts +0 -16
- package/examples/app2/src/app/projects/view/view.component.html +0 -1
- package/examples/app2/src/app/projects/view/view.component.ts +0 -20
- package/examples/app2/src/app/root/root.component.html +0 -14
- package/examples/app2/src/app/root/root.component.scss +0 -12
- package/examples/app2/src/app/root/root.component.ts +0 -28
- package/examples/app2/src/app/shared.module.ts +0 -59
- package/examples/app2/src/assets/.gitkeep +0 -0
- package/examples/app2/src/environments/environment.prod.ts +0 -3
- package/examples/app2/src/environments/environment.ts +0 -16
- package/examples/app2/src/favicon.ico +0 -0
- package/examples/app2/src/index.html +0 -14
- package/examples/app2/src/main.ts +0 -36
- package/examples/app2/src/polyfills.ts +0 -84
- package/examples/app2/src/styles.scss +0 -28
- package/examples/app2/src/test.ts +0 -14
- package/examples/app2/tsconfig.app.json +0 -10
- package/examples/app2/tsconfig.spec.json +0 -18
- package/examples/app2/tslint.json +0 -7
- package/examples/app2/webpack.config.js +0 -92
- package/examples/common/app-root-context.ts +0 -10
- package/examples/common/cache.ts +0 -82
- package/examples/common/index.ts +0 -13
- package/examples/common/module.ts +0 -10
- package/examples/common/overlay-container.service.ts +0 -28
- package/examples/common/section-card/section-card.component.html +0 -5
- package/examples/common/section-card/section-card.component.scss +0 -15
- package/examples/common/section-card/section-card.component.ts +0 -11
- package/examples/common/utils.ts +0 -0
- package/examples/portal/src/app/a-detail/a-detail.component.html +0 -8
- package/examples/portal/src/app/a-detail/a-detail.component.ts +0 -18
- package/examples/portal/src/app/about/about.component.html +0 -27
- package/examples/portal/src/app/about/about.component.scss +0 -0
- package/examples/portal/src/app/about/about.component.spec.ts +0 -26
- package/examples/portal/src/app/about/about.component.ts +0 -26
- package/examples/portal/src/app/app-routing.module.ts +0 -57
- package/examples/portal/src/app/app.component.html +0 -73
- package/examples/portal/src/app/app.component.scss +0 -58
- package/examples/portal/src/app/app.component.spec.ts +0 -33
- package/examples/portal/src/app/app.component.ts +0 -111
- package/examples/portal/src/app/app.module.ts +0 -64
- package/examples/portal/src/app/custom-settings.service.ts +0 -44
- package/examples/portal/src/app/overlay.ts +0 -26
- package/examples/portal/src/app/settings/settings.component.html +0 -31
- package/examples/portal/src/app/settings/settings.component.scss +0 -3
- package/examples/portal/src/app/settings/settings.component.ts +0 -43
- package/examples/portal/src/assets/.gitkeep +0 -0
- package/examples/portal/src/assets/apps.json +0 -29
- package/examples/portal/src/assets/icons/sprite.defs.svg +0 -1
- package/examples/portal/src/assets/images/logo.svg +0 -16
- package/examples/portal/src/assets/ngx-planet-micro-front-end.gif +0 -0
- package/examples/portal/src/browserslist +0 -11
- package/examples/portal/src/environments/environment.prod.ts +0 -3
- package/examples/portal/src/environments/environment.ts +0 -16
- package/examples/portal/src/extra-webpack.config.js +0 -32
- package/examples/portal/src/favicon.ico +0 -0
- package/examples/portal/src/index.html +0 -14
- package/examples/portal/src/karma.conf.js +0 -31
- package/examples/portal/src/main.ts +0 -18
- package/examples/portal/src/polyfills.ts +0 -84
- package/examples/portal/src/reboot.scss +0 -14
- package/examples/portal/src/styles.scss +0 -14
- package/examples/portal/src/test.ts +0 -14
- package/examples/portal/src/tsconfig.app.json +0 -10
- package/examples/portal/src/tsconfig.spec.json +0 -9
- package/examples/portal/src/tslint.json +0 -7
- package/extra-webpack.config.js +0 -5
- package/nginx.conf +0 -17
- package/packages/planet/karma.conf.js +0 -37
- package/packages/planet/ng-package.json +0 -7
- package/packages/planet/package.json +0 -10
- package/packages/planet/src/application/planet-application-loader.spec.ts +0 -1102
- package/packages/planet/src/application/planet-application-loader.ts +0 -549
- package/packages/planet/src/application/planet-application-ref.spec.ts +0 -233
- package/packages/planet/src/application/planet-application-ref.ts +0 -131
- package/packages/planet/src/application/planet-application.service.spec.ts +0 -145
- package/packages/planet/src/application/planet-application.service.ts +0 -88
- package/packages/planet/src/application/portal-application.spec.ts +0 -53
- package/packages/planet/src/assets-loader.spec.ts +0 -689
- package/packages/planet/src/assets-loader.ts +0 -247
- package/packages/planet/src/component/planet-component-loader.spec.ts +0 -187
- package/packages/planet/src/component/planet-component-loader.ts +0 -173
- package/packages/planet/src/component/planet-component-ref.ts +0 -8
- package/packages/planet/src/debug.spec.ts +0 -58
- package/packages/planet/src/debug.ts +0 -66
- package/packages/planet/src/empty/empty.component.spec.ts +0 -34
- package/packages/planet/src/empty/empty.component.ts +0 -7
- package/packages/planet/src/global-event-dispatcher.spec.ts +0 -81
- package/packages/planet/src/global-event-dispatcher.ts +0 -82
- package/packages/planet/src/global-planet.spec.ts +0 -39
- package/packages/planet/src/global-planet.ts +0 -73
- package/packages/planet/src/helpers.spec.ts +0 -242
- package/packages/planet/src/helpers.ts +0 -125
- package/packages/planet/src/module.spec.ts +0 -79
- package/packages/planet/src/module.ts +0 -25
- package/packages/planet/src/planet.spec.ts +0 -226
- package/packages/planet/src/planet.ts +0 -113
- package/packages/planet/src/sandbox/constants.ts +0 -6
- package/packages/planet/src/sandbox/exec.ts +0 -22
- package/packages/planet/src/sandbox/index.ts +0 -24
- package/packages/planet/src/sandbox/proxy/patches/document.ts +0 -13
- package/packages/planet/src/sandbox/proxy/patches/eventListener.ts +0 -49
- package/packages/planet/src/sandbox/proxy/patches/index.ts +0 -13
- package/packages/planet/src/sandbox/proxy/patches/storage.ts +0 -53
- package/packages/planet/src/sandbox/proxy/patches/timer.ts +0 -50
- package/packages/planet/src/sandbox/proxy/proxies/common.ts +0 -137
- package/packages/planet/src/sandbox/proxy/proxies/document.ts +0 -140
- package/packages/planet/src/sandbox/proxy/proxies/window.ts +0 -176
- package/packages/planet/src/sandbox/proxy/proxy-sandbox.ts +0 -59
- package/packages/planet/src/sandbox/sandbox.ts +0 -20
- package/packages/planet/src/sandbox/snapshot/snapshot-sandbox.ts +0 -12
- package/packages/planet/src/sandbox/types.ts +0 -1
- package/packages/planet/src/test.ts +0 -16
- package/packages/planet/src/testing/app1.module.ts +0 -34
- package/packages/planet/src/testing/app2.module.ts +0 -24
- package/packages/planet/src/testing/applications.ts +0 -58
- package/packages/planet/src/testing/index.ts +0 -2
- package/packages/planet/src/testing/utils.ts +0 -31
- package/packages/planet/tsconfig.lib.json +0 -27
- package/packages/planet/tsconfig.lib.prod.json +0 -9
- package/packages/planet/tsconfig.spec.json +0 -17
- package/packages/planet/tslint.json +0 -7
- package/postcss.config.js +0 -3
- package/proxy.conf.js +0 -15
- package/tsconfig.json +0 -23
- package/tslint.json +0 -80
|
@@ -1,233 +0,0 @@
|
|
|
1
|
-
import { PlanetPortalApplication } from './portal-application';
|
|
2
|
-
import { NgModule, Compiler, Injector, Component, NgZone, Type } from '@angular/core';
|
|
3
|
-
import { Router } from '@angular/router';
|
|
4
|
-
import { TestBed, inject, tick, fakeAsync, flush } from '@angular/core/testing';
|
|
5
|
-
import { defineApplication, getPlanetApplicationRef, clearGlobalPlanet } from '../global-planet';
|
|
6
|
-
import { Subject } from 'rxjs';
|
|
7
|
-
import { PlanetApplicationRef } from './planet-application-ref';
|
|
8
|
-
import { RouterTestingModule } from '@angular/router/testing';
|
|
9
|
-
|
|
10
|
-
@Component({
|
|
11
|
-
selector: 'app-root',
|
|
12
|
-
template: `
|
|
13
|
-
<router-outlet></router-outlet>
|
|
14
|
-
`
|
|
15
|
-
})
|
|
16
|
-
class EmptyComponent {}
|
|
17
|
-
@NgModule({
|
|
18
|
-
declarations: [EmptyComponent],
|
|
19
|
-
imports: [
|
|
20
|
-
RouterTestingModule.withRoutes([
|
|
21
|
-
{
|
|
22
|
-
path: 'app1',
|
|
23
|
-
component: EmptyComponent
|
|
24
|
-
},
|
|
25
|
-
{
|
|
26
|
-
path: 'app1/test',
|
|
27
|
-
component: EmptyComponent
|
|
28
|
-
}
|
|
29
|
-
])
|
|
30
|
-
]
|
|
31
|
-
})
|
|
32
|
-
class AppModule {}
|
|
33
|
-
|
|
34
|
-
describe('PlanetApplicationRef', () => {
|
|
35
|
-
afterEach(() => {
|
|
36
|
-
clearGlobalPlanet();
|
|
37
|
-
});
|
|
38
|
-
|
|
39
|
-
describe('getPlanetApplicationRef', () => {
|
|
40
|
-
it('should get planet application ref success', () => {
|
|
41
|
-
defineApplication('app1', {
|
|
42
|
-
template: '<app1-root></app1-root>',
|
|
43
|
-
bootstrap: (portalApp?: PlanetPortalApplication) => {
|
|
44
|
-
return new Promise(() => {});
|
|
45
|
-
}
|
|
46
|
-
});
|
|
47
|
-
const planetAppRef = getPlanetApplicationRef('app1');
|
|
48
|
-
expect(planetAppRef).toBeTruthy();
|
|
49
|
-
expect(planetAppRef).toBe(window['planet'].apps['app1']);
|
|
50
|
-
});
|
|
51
|
-
|
|
52
|
-
it('should not get planet appRef which has not exist', () => {
|
|
53
|
-
defineApplication('app1', {
|
|
54
|
-
template: '<app1-root></app1-root>',
|
|
55
|
-
bootstrap: (portalApp?: PlanetPortalApplication) => {
|
|
56
|
-
return new Promise(() => {});
|
|
57
|
-
}
|
|
58
|
-
});
|
|
59
|
-
const planetAppRef = getPlanetApplicationRef('app2');
|
|
60
|
-
expect(planetAppRef).toBeFalsy();
|
|
61
|
-
});
|
|
62
|
-
});
|
|
63
|
-
|
|
64
|
-
describe('ApplicationRef', () => {
|
|
65
|
-
let compiler: Compiler;
|
|
66
|
-
let injector: Injector;
|
|
67
|
-
|
|
68
|
-
function bootstrapApp1<T>(moduleType?: Type<T>) {
|
|
69
|
-
const portalApplication = new PlanetPortalApplication();
|
|
70
|
-
const ngModuleFactory = compiler.compileModuleSync(moduleType ? moduleType : AppModule);
|
|
71
|
-
const ngModuleRef = ngModuleFactory.create(injector);
|
|
72
|
-
const router = ngModuleRef.injector.get(Router);
|
|
73
|
-
defineApplication('app1', {
|
|
74
|
-
template: '<app1-root></app1-root>',
|
|
75
|
-
bootstrap: (portalApp?: PlanetPortalApplication) => {
|
|
76
|
-
return new Promise(resolve => {
|
|
77
|
-
expect(portalApp).toBe(portalApplication);
|
|
78
|
-
resolve(ngModuleRef);
|
|
79
|
-
});
|
|
80
|
-
}
|
|
81
|
-
});
|
|
82
|
-
|
|
83
|
-
const appRef = getPlanetApplicationRef('app1');
|
|
84
|
-
appRef.bootstrap(portalApplication).subscribe();
|
|
85
|
-
|
|
86
|
-
flush();
|
|
87
|
-
return {
|
|
88
|
-
router,
|
|
89
|
-
appRef
|
|
90
|
-
};
|
|
91
|
-
}
|
|
92
|
-
|
|
93
|
-
beforeEach(() => {
|
|
94
|
-
TestBed.configureTestingModule({});
|
|
95
|
-
});
|
|
96
|
-
|
|
97
|
-
beforeEach(inject([Compiler, Injector], (_compiler: Compiler, _injector: Injector) => {
|
|
98
|
-
compiler = _compiler;
|
|
99
|
-
injector = _injector;
|
|
100
|
-
}));
|
|
101
|
-
|
|
102
|
-
it(`should bootstrap application ref`, fakeAsync(() => {
|
|
103
|
-
const portalApplication = new PlanetPortalApplication();
|
|
104
|
-
const ngModuleFactory = compiler.compileModuleSync(AppModule);
|
|
105
|
-
const ngModuleRef = ngModuleFactory.create(injector);
|
|
106
|
-
defineApplication('app1', {
|
|
107
|
-
template: '<app1-root></app1-root>',
|
|
108
|
-
bootstrap: (portalApp?: PlanetPortalApplication) => {
|
|
109
|
-
return new Promise(resolve => {
|
|
110
|
-
expect(portalApp).toBe(portalApplication);
|
|
111
|
-
resolve(ngModuleRef);
|
|
112
|
-
});
|
|
113
|
-
}
|
|
114
|
-
});
|
|
115
|
-
const appRef = getPlanetApplicationRef('app1');
|
|
116
|
-
expect(appRef).toBeTruthy();
|
|
117
|
-
const bootstrapSpy = jasmine.createSpy('bootstrap spy');
|
|
118
|
-
appRef.bootstrap(portalApplication).subscribe(bootstrapSpy);
|
|
119
|
-
expect(appRef.bootstrapped).toEqual(false);
|
|
120
|
-
flush();
|
|
121
|
-
expect(appRef.bootstrapped).toEqual(true);
|
|
122
|
-
expect(appRef.appModuleRef).toEqual(ngModuleRef);
|
|
123
|
-
expect(appRef.appModuleRef.instance.appName).toEqual('app1');
|
|
124
|
-
expect(bootstrapSpy.calls.count()).toEqual(1);
|
|
125
|
-
expect(bootstrapSpy).toHaveBeenCalled();
|
|
126
|
-
expect(bootstrapSpy).toHaveBeenCalledWith(appRef);
|
|
127
|
-
}));
|
|
128
|
-
|
|
129
|
-
it(`should destroy application ref success`, fakeAsync(() => {
|
|
130
|
-
const portalApplication = new PlanetPortalApplication();
|
|
131
|
-
const ngModuleFactory = compiler.compileModuleSync(AppModule);
|
|
132
|
-
const ngModuleRef = ngModuleFactory.create(injector);
|
|
133
|
-
const router = ngModuleRef.injector.get(Router);
|
|
134
|
-
defineApplication('app1', {
|
|
135
|
-
template: '<app1-root></app1-root>',
|
|
136
|
-
bootstrap: (portalApp?: PlanetPortalApplication) => {
|
|
137
|
-
return new Promise(resolve => {
|
|
138
|
-
expect(portalApp).toBe(portalApplication);
|
|
139
|
-
resolve(ngModuleRef);
|
|
140
|
-
});
|
|
141
|
-
}
|
|
142
|
-
});
|
|
143
|
-
|
|
144
|
-
const appRef = getPlanetApplicationRef('app1');
|
|
145
|
-
appRef.bootstrap(portalApplication).subscribe();
|
|
146
|
-
|
|
147
|
-
flush();
|
|
148
|
-
expect(appRef.bootstrapped).toEqual(true);
|
|
149
|
-
expect(appRef.appModuleRef).toEqual(ngModuleRef);
|
|
150
|
-
|
|
151
|
-
appRef.destroy();
|
|
152
|
-
expect(appRef.bootstrapped).toEqual(false);
|
|
153
|
-
expect(appRef.appModuleRef).toEqual(undefined);
|
|
154
|
-
}));
|
|
155
|
-
|
|
156
|
-
it(`should get router success`, fakeAsync(() => {
|
|
157
|
-
const { appRef, router } = bootstrapApp1();
|
|
158
|
-
expect(appRef.getRouter()).toBeTruthy();
|
|
159
|
-
expect(appRef.getRouter()).toEqual(router);
|
|
160
|
-
}));
|
|
161
|
-
|
|
162
|
-
it(`should navigate to url success and get correct current router state url `, fakeAsync(() => {
|
|
163
|
-
const routerSpy = {
|
|
164
|
-
navigateByUrl: jasmine.createSpy('navigateByUrl syp'),
|
|
165
|
-
events: new Subject(),
|
|
166
|
-
routerState: {
|
|
167
|
-
snapshot: {
|
|
168
|
-
url: 'app1/hello'
|
|
169
|
-
}
|
|
170
|
-
}
|
|
171
|
-
};
|
|
172
|
-
@NgModule({
|
|
173
|
-
declarations: [],
|
|
174
|
-
imports: [],
|
|
175
|
-
providers: [
|
|
176
|
-
{
|
|
177
|
-
provide: Router,
|
|
178
|
-
useValue: routerSpy
|
|
179
|
-
}
|
|
180
|
-
]
|
|
181
|
-
})
|
|
182
|
-
class AppModuleWithSpyRouter {}
|
|
183
|
-
const { appRef } = bootstrapApp1(AppModuleWithSpyRouter);
|
|
184
|
-
expect(appRef.getCurrentRouterStateUrl()).toEqual('app1/hello');
|
|
185
|
-
|
|
186
|
-
expect(routerSpy.navigateByUrl).not.toHaveBeenCalled();
|
|
187
|
-
|
|
188
|
-
const toUrl = 'app2/to-url';
|
|
189
|
-
appRef.navigateByUrl('app2/to-url');
|
|
190
|
-
|
|
191
|
-
expect(routerSpy.navigateByUrl).toHaveBeenCalled();
|
|
192
|
-
expect(routerSpy.navigateByUrl).toHaveBeenCalledWith(toUrl);
|
|
193
|
-
}));
|
|
194
|
-
|
|
195
|
-
it(`should throw error when app is not defined`, () => {
|
|
196
|
-
expect(() => {
|
|
197
|
-
const appRef = new PlanetApplicationRef('app3', {} as any);
|
|
198
|
-
appRef.bootstrap(undefined);
|
|
199
|
-
}).toThrowError(`app(app3) is not defined`);
|
|
200
|
-
});
|
|
201
|
-
|
|
202
|
-
it(`should sync portal route change when sub app(app1) route navigate`, fakeAsync(() => {
|
|
203
|
-
const portalApplication = new PlanetPortalApplication();
|
|
204
|
-
portalApplication.router = { navigateByUrl: () => {} } as any;
|
|
205
|
-
const navigateByUrlSpy = spyOn(portalApplication.router, 'navigateByUrl');
|
|
206
|
-
const ngModuleFactory = compiler.compileModuleSync(AppModule);
|
|
207
|
-
const ngModuleRef = ngModuleFactory.create(injector);
|
|
208
|
-
defineApplication('app1', {
|
|
209
|
-
template: '<app1-root></app1-root>',
|
|
210
|
-
bootstrap: (portalApp?: PlanetPortalApplication) => {
|
|
211
|
-
return new Promise(resolve => {
|
|
212
|
-
expect(portalApp).toBe(portalApplication);
|
|
213
|
-
resolve(ngModuleRef);
|
|
214
|
-
});
|
|
215
|
-
}
|
|
216
|
-
});
|
|
217
|
-
const appRef = getPlanetApplicationRef('app1');
|
|
218
|
-
expect(appRef).toBeTruthy();
|
|
219
|
-
appRef.bootstrap(portalApplication);
|
|
220
|
-
|
|
221
|
-
const router = ngModuleRef.injector.get(Router);
|
|
222
|
-
const ngZone = ngModuleRef.injector.get(NgZone);
|
|
223
|
-
ngZone.run(() => {
|
|
224
|
-
router.navigateByUrl('/app1');
|
|
225
|
-
});
|
|
226
|
-
expect(navigateByUrlSpy).not.toHaveBeenCalled();
|
|
227
|
-
ngZone.onStable.next();
|
|
228
|
-
tick();
|
|
229
|
-
expect(navigateByUrlSpy).toHaveBeenCalled();
|
|
230
|
-
expect(navigateByUrlSpy).toHaveBeenCalledWith('/app1');
|
|
231
|
-
}));
|
|
232
|
-
});
|
|
233
|
-
});
|
|
@@ -1,131 +0,0 @@
|
|
|
1
|
-
import { NgModuleRef, NgZone } from '@angular/core';
|
|
2
|
-
import { Router, NavigationEnd } from '@angular/router';
|
|
3
|
-
import { take } from 'rxjs/operators';
|
|
4
|
-
import { Observable, from } from 'rxjs';
|
|
5
|
-
import { PlanetPortalApplication } from './portal-application';
|
|
6
|
-
import { PlantComponentConfig } from '../component/plant-component.config';
|
|
7
|
-
import { PlanetComponentRef } from '../component/planet-component-ref';
|
|
8
|
-
import { getTagNameByTemplate } from '../helpers';
|
|
9
|
-
import { getSandboxInstance, Sandbox } from '../sandbox/';
|
|
10
|
-
|
|
11
|
-
export interface BootstrapOptions {
|
|
12
|
-
template: string;
|
|
13
|
-
bootstrap: BootstrapAppModule;
|
|
14
|
-
}
|
|
15
|
-
|
|
16
|
-
export type BootstrapAppModule = (portalApp: PlanetPortalApplication) => Promise<NgModuleRef<any> | undefined | null>;
|
|
17
|
-
|
|
18
|
-
export type PlantComponentFactory = <TData, TComp>(
|
|
19
|
-
componentName: string,
|
|
20
|
-
config: PlantComponentConfig<TData>
|
|
21
|
-
) => PlanetComponentRef<TComp>;
|
|
22
|
-
|
|
23
|
-
export class PlanetApplicationRef {
|
|
24
|
-
public appModuleRef?: NgModuleRef<any>;
|
|
25
|
-
public template?: string;
|
|
26
|
-
private innerSelector?: string;
|
|
27
|
-
private name: string;
|
|
28
|
-
private portalApp!: PlanetPortalApplication;
|
|
29
|
-
private appModuleBootstrap?: BootstrapAppModule;
|
|
30
|
-
private componentFactory?: PlantComponentFactory;
|
|
31
|
-
|
|
32
|
-
public get selector() {
|
|
33
|
-
return this.innerSelector;
|
|
34
|
-
}
|
|
35
|
-
|
|
36
|
-
public get bootstrapped() {
|
|
37
|
-
return !!this.appModuleRef;
|
|
38
|
-
}
|
|
39
|
-
|
|
40
|
-
public get ngZone(): NgZone | undefined {
|
|
41
|
-
return this.appModuleRef?.injector.get(NgZone);
|
|
42
|
-
}
|
|
43
|
-
|
|
44
|
-
public get sandbox(): Sandbox {
|
|
45
|
-
return getSandboxInstance();
|
|
46
|
-
}
|
|
47
|
-
|
|
48
|
-
constructor(name: string, options?: BootstrapOptions) {
|
|
49
|
-
this.name = name;
|
|
50
|
-
if (options) {
|
|
51
|
-
this.template = options.template;
|
|
52
|
-
this.innerSelector = this.template ? getTagNameByTemplate(this.template) : '';
|
|
53
|
-
this.appModuleBootstrap = options.bootstrap;
|
|
54
|
-
}
|
|
55
|
-
// This is a hack, since NgZone doesn't allow you to configure the property that identifies your zone.
|
|
56
|
-
// See https://github.com/PlaceMe-SAS/single-spa-angular-cli/issues/33,
|
|
57
|
-
NgZone.isInAngularZone = () => {
|
|
58
|
-
// @ts-ignore
|
|
59
|
-
return window.Zone.current._properties[`ngx-planet-${name}`] === true;
|
|
60
|
-
};
|
|
61
|
-
}
|
|
62
|
-
|
|
63
|
-
// 子应用路由变化后同步修改 portal 的 Route
|
|
64
|
-
private syncPortalRouteWhenNavigationEnd() {
|
|
65
|
-
const router = this.appModuleRef?.injector.get(Router);
|
|
66
|
-
if (router) {
|
|
67
|
-
router.events.subscribe(event => {
|
|
68
|
-
if (event instanceof NavigationEnd) {
|
|
69
|
-
this.ngZone?.onStable
|
|
70
|
-
.asObservable()
|
|
71
|
-
.pipe(take(1))
|
|
72
|
-
.subscribe(() => {
|
|
73
|
-
this.portalApp.router!.navigateByUrl(event.url);
|
|
74
|
-
});
|
|
75
|
-
}
|
|
76
|
-
});
|
|
77
|
-
}
|
|
78
|
-
}
|
|
79
|
-
|
|
80
|
-
bootstrap(app: PlanetPortalApplication): Observable<this> {
|
|
81
|
-
if (!this.appModuleBootstrap) {
|
|
82
|
-
throw new Error(`app(${this.name}) is not defined`);
|
|
83
|
-
}
|
|
84
|
-
this.portalApp = app;
|
|
85
|
-
return from(
|
|
86
|
-
this.appModuleBootstrap(app).then(appModuleRef => {
|
|
87
|
-
this.appModuleRef = appModuleRef!;
|
|
88
|
-
this.appModuleRef.instance.appName = this.name;
|
|
89
|
-
this.syncPortalRouteWhenNavigationEnd();
|
|
90
|
-
return this;
|
|
91
|
-
})
|
|
92
|
-
);
|
|
93
|
-
}
|
|
94
|
-
|
|
95
|
-
getRouter() {
|
|
96
|
-
return this.appModuleRef?.injector.get(Router);
|
|
97
|
-
}
|
|
98
|
-
|
|
99
|
-
getCurrentRouterStateUrl() {
|
|
100
|
-
return this.getRouter()?.routerState.snapshot.url;
|
|
101
|
-
}
|
|
102
|
-
|
|
103
|
-
navigateByUrl(url: string): void {
|
|
104
|
-
const router = this.getRouter();
|
|
105
|
-
this.ngZone?.run(() => {
|
|
106
|
-
router?.navigateByUrl(url);
|
|
107
|
-
});
|
|
108
|
-
}
|
|
109
|
-
|
|
110
|
-
getComponentFactory() {
|
|
111
|
-
return this.componentFactory;
|
|
112
|
-
}
|
|
113
|
-
|
|
114
|
-
registerComponentFactory(componentFactory: PlantComponentFactory) {
|
|
115
|
-
this.componentFactory = componentFactory;
|
|
116
|
-
}
|
|
117
|
-
|
|
118
|
-
destroy(): void {
|
|
119
|
-
if (this.appModuleRef) {
|
|
120
|
-
const router = this.appModuleRef.injector.get(Router);
|
|
121
|
-
if (router) {
|
|
122
|
-
router.dispose();
|
|
123
|
-
}
|
|
124
|
-
if (this.sandbox) {
|
|
125
|
-
this.sandbox.destroy();
|
|
126
|
-
}
|
|
127
|
-
this.appModuleRef.destroy();
|
|
128
|
-
this.appModuleRef = undefined;
|
|
129
|
-
}
|
|
130
|
-
}
|
|
131
|
-
}
|
|
@@ -1,145 +0,0 @@
|
|
|
1
|
-
import { TestBed } from '@angular/core/testing';
|
|
2
|
-
import { HttpClientTestingModule, HttpTestingController } from '@angular/common/http/testing';
|
|
3
|
-
import { PlanetApplicationService } from './planet-application.service';
|
|
4
|
-
import { SwitchModes } from '../planet.class';
|
|
5
|
-
import { HttpClient } from '@angular/common/http';
|
|
6
|
-
import { app1, app2, app2WithPreload } from '../testing/applications';
|
|
7
|
-
import { AssetsLoader } from 'ngx-planet/assets-loader';
|
|
8
|
-
import { Planet } from 'ngx-planet/planet';
|
|
9
|
-
|
|
10
|
-
describe('PlanetApplicationService', () => {
|
|
11
|
-
let planetApplicationService: PlanetApplicationService;
|
|
12
|
-
beforeEach(() => {
|
|
13
|
-
TestBed.configureTestingModule({
|
|
14
|
-
imports: [HttpClientTestingModule],
|
|
15
|
-
providers: []
|
|
16
|
-
});
|
|
17
|
-
planetApplicationService = TestBed.inject(PlanetApplicationService);
|
|
18
|
-
});
|
|
19
|
-
|
|
20
|
-
it(`should throw error when repeat PlanetApplicationService injection`, () => {
|
|
21
|
-
window['planet'].applicationService = TestBed.inject(PlanetApplicationService);
|
|
22
|
-
expect(() => {
|
|
23
|
-
return new PlanetApplicationService(TestBed.inject(HttpClient), TestBed.inject(AssetsLoader));
|
|
24
|
-
}).toThrowError('PlanetApplicationService has been injected in the portal, repeated injection is not allowed');
|
|
25
|
-
window['planet'].applicationService = null;
|
|
26
|
-
});
|
|
27
|
-
|
|
28
|
-
describe('register', () => {
|
|
29
|
-
it('should register signal app1 success', () => {
|
|
30
|
-
planetApplicationService.register(app1);
|
|
31
|
-
expect(planetApplicationService.getApps()).toEqual([app1]);
|
|
32
|
-
});
|
|
33
|
-
|
|
34
|
-
it('should throw error when register exist app1 ', () => {
|
|
35
|
-
planetApplicationService.register(app1);
|
|
36
|
-
expect(() => {
|
|
37
|
-
planetApplicationService.register(app1);
|
|
38
|
-
}).toThrowError('app1 has be registered.');
|
|
39
|
-
});
|
|
40
|
-
|
|
41
|
-
it('should register multiple apps contains app1 and app2 success', () => {
|
|
42
|
-
planetApplicationService.register([app1, app2]);
|
|
43
|
-
expect(planetApplicationService.getApps()).toEqual([app1, app2]);
|
|
44
|
-
});
|
|
45
|
-
|
|
46
|
-
describe('registerByUrl', () => {
|
|
47
|
-
let httpClient: HttpClient;
|
|
48
|
-
let httpTestingController: HttpTestingController;
|
|
49
|
-
beforeEach(() => {
|
|
50
|
-
httpClient = TestBed.inject(HttpClient);
|
|
51
|
-
httpTestingController = TestBed.inject(HttpTestingController);
|
|
52
|
-
});
|
|
53
|
-
|
|
54
|
-
afterEach(() => {
|
|
55
|
-
// After every test, assert that there are no more pending requests.
|
|
56
|
-
httpTestingController.verify();
|
|
57
|
-
});
|
|
58
|
-
|
|
59
|
-
it('should register multiple apps by url', () => {
|
|
60
|
-
planetApplicationService.registerByUrl('/static/apps.json');
|
|
61
|
-
const req = httpTestingController.expectOne('/static/apps.json');
|
|
62
|
-
|
|
63
|
-
// Assert that the request is a GET.
|
|
64
|
-
expect(req.request.method).toEqual('GET');
|
|
65
|
-
|
|
66
|
-
// Respond with mock data, causing Observable to resolve.
|
|
67
|
-
// Subscribe callback asserts that correct data was returned.
|
|
68
|
-
req.flush([app1, app2]);
|
|
69
|
-
|
|
70
|
-
expect(planetApplicationService.getApps()).toEqual([app1, app2]);
|
|
71
|
-
});
|
|
72
|
-
|
|
73
|
-
it('should register one app by url', () => {
|
|
74
|
-
planetApplicationService.registerByUrl('/static/apps.json');
|
|
75
|
-
const req = httpTestingController.expectOne('/static/apps.json');
|
|
76
|
-
expect(req.request.method).toEqual('GET');
|
|
77
|
-
req.flush(app1);
|
|
78
|
-
expect(planetApplicationService.getApps()).toEqual([app1]);
|
|
79
|
-
});
|
|
80
|
-
});
|
|
81
|
-
});
|
|
82
|
-
|
|
83
|
-
describe('unregister', () => {
|
|
84
|
-
it('should unregister app1 success', () => {
|
|
85
|
-
planetApplicationService.register(app1);
|
|
86
|
-
expect(planetApplicationService.getApps()).toEqual([app1]);
|
|
87
|
-
planetApplicationService.unregister(app1.name);
|
|
88
|
-
expect(planetApplicationService.getApps()).toEqual([]);
|
|
89
|
-
});
|
|
90
|
-
});
|
|
91
|
-
|
|
92
|
-
describe('getAppsByMatchedUrl', () => {
|
|
93
|
-
it('should get matched apps(app1) by url app1/dashboard', () => {
|
|
94
|
-
planetApplicationService.register(app1);
|
|
95
|
-
planetApplicationService.register(app2);
|
|
96
|
-
const apps = planetApplicationService.getAppsByMatchedUrl('/app1/dashboard');
|
|
97
|
-
expect(apps).toEqual([app1]);
|
|
98
|
-
});
|
|
99
|
-
|
|
100
|
-
it('should get matched apps by url when apps has same routerPathPrefix', () => {
|
|
101
|
-
planetApplicationService.register(app1);
|
|
102
|
-
const app2SameApp1 = { ...app2, routerPathPrefix: '/app1' };
|
|
103
|
-
planetApplicationService.register(app2SameApp1);
|
|
104
|
-
const apps = planetApplicationService.getAppsByMatchedUrl('/app1/dashboard');
|
|
105
|
-
expect(apps).toEqual([app1, app2SameApp1]);
|
|
106
|
-
});
|
|
107
|
-
|
|
108
|
-
it('should get empty apps by url __/dashboard/app1 without start with app1', () => {
|
|
109
|
-
planetApplicationService.register(app1);
|
|
110
|
-
planetApplicationService.register(app2);
|
|
111
|
-
const apps = planetApplicationService.getAppsByMatchedUrl('/__/dashboard/app1');
|
|
112
|
-
expect(apps).toEqual([]);
|
|
113
|
-
});
|
|
114
|
-
|
|
115
|
-
it('should get matched apps which rule is RegExp("(a\\wp3)|app4") by url app3/dashboard', () => {
|
|
116
|
-
planetApplicationService.register(app1);
|
|
117
|
-
planetApplicationService.register(app2);
|
|
118
|
-
const app3 = {
|
|
119
|
-
...app1,
|
|
120
|
-
name: 'app3',
|
|
121
|
-
routerPathPrefix: new RegExp('(a\\wp3)|app4')
|
|
122
|
-
};
|
|
123
|
-
planetApplicationService.register(app3);
|
|
124
|
-
const apps = planetApplicationService.getAppsByMatchedUrl('/app3/dashboard');
|
|
125
|
-
expect(apps).toBeTruthy('app is not found');
|
|
126
|
-
expect(apps[0]).toBe(app3);
|
|
127
|
-
});
|
|
128
|
-
});
|
|
129
|
-
|
|
130
|
-
describe('getAppsToPreload', () => {
|
|
131
|
-
it('should get correct preload apps', () => {
|
|
132
|
-
planetApplicationService.register(app1);
|
|
133
|
-
planetApplicationService.register(app2WithPreload);
|
|
134
|
-
const appsToPreload = planetApplicationService.getAppsToPreload();
|
|
135
|
-
expect(appsToPreload).toEqual([app2WithPreload]);
|
|
136
|
-
});
|
|
137
|
-
|
|
138
|
-
it('should get correct preload apps exclude app names', () => {
|
|
139
|
-
planetApplicationService.register(app1);
|
|
140
|
-
planetApplicationService.register(app2WithPreload);
|
|
141
|
-
const appsToPreload = planetApplicationService.getAppsToPreload(['app2']);
|
|
142
|
-
expect(appsToPreload).toEqual([]);
|
|
143
|
-
});
|
|
144
|
-
});
|
|
145
|
-
});
|
|
@@ -1,88 +0,0 @@
|
|
|
1
|
-
import { PlanetApplication } from '../planet.class';
|
|
2
|
-
import { Injectable } from '@angular/core';
|
|
3
|
-
import { HttpClient } from '@angular/common/http';
|
|
4
|
-
import { shareReplay, map } from 'rxjs/operators';
|
|
5
|
-
import { coerceArray } from '../helpers';
|
|
6
|
-
import { Observable } from 'rxjs';
|
|
7
|
-
import { AssetsLoader } from '../assets-loader';
|
|
8
|
-
import { getApplicationService } from '../global-planet';
|
|
9
|
-
|
|
10
|
-
@Injectable({
|
|
11
|
-
providedIn: 'root'
|
|
12
|
-
})
|
|
13
|
-
export class PlanetApplicationService {
|
|
14
|
-
private apps: PlanetApplication[] = [];
|
|
15
|
-
|
|
16
|
-
private appsMap: { [key: string]: PlanetApplication } = {};
|
|
17
|
-
|
|
18
|
-
constructor(private http: HttpClient, private assetsLoader: AssetsLoader) {
|
|
19
|
-
if (getApplicationService()) {
|
|
20
|
-
throw new Error(
|
|
21
|
-
'PlanetApplicationService has been injected in the portal, repeated injection is not allowed'
|
|
22
|
-
);
|
|
23
|
-
}
|
|
24
|
-
}
|
|
25
|
-
|
|
26
|
-
register<TExtra>(appOrApps: PlanetApplication<TExtra> | PlanetApplication<TExtra>[]) {
|
|
27
|
-
const apps = coerceArray(appOrApps);
|
|
28
|
-
apps.forEach(app => {
|
|
29
|
-
if (this.appsMap[app.name]) {
|
|
30
|
-
throw new Error(`${app.name} has be registered.`);
|
|
31
|
-
}
|
|
32
|
-
this.apps.push(app);
|
|
33
|
-
this.appsMap[app.name] = app;
|
|
34
|
-
});
|
|
35
|
-
}
|
|
36
|
-
|
|
37
|
-
registerByUrl(url: string): Observable<void> {
|
|
38
|
-
const result = this.http.get(`${url}`).pipe(
|
|
39
|
-
map(apps => {
|
|
40
|
-
if (apps && Array.isArray(apps)) {
|
|
41
|
-
this.register(apps);
|
|
42
|
-
} else {
|
|
43
|
-
this.register(apps as PlanetApplication);
|
|
44
|
-
}
|
|
45
|
-
}),
|
|
46
|
-
shareReplay()
|
|
47
|
-
);
|
|
48
|
-
result.subscribe();
|
|
49
|
-
return result;
|
|
50
|
-
}
|
|
51
|
-
|
|
52
|
-
unregister(name: string) {
|
|
53
|
-
if (this.appsMap[name]) {
|
|
54
|
-
delete this.appsMap[name];
|
|
55
|
-
this.apps = this.apps.filter(app => {
|
|
56
|
-
return app.name !== name;
|
|
57
|
-
});
|
|
58
|
-
}
|
|
59
|
-
}
|
|
60
|
-
|
|
61
|
-
getAppsByMatchedUrl<TExtra = unknown>(url: string): PlanetApplication<TExtra>[] {
|
|
62
|
-
return this.getApps().filter(app => {
|
|
63
|
-
if (app.routerPathPrefix instanceof RegExp) {
|
|
64
|
-
return app.routerPathPrefix.test(url);
|
|
65
|
-
} else {
|
|
66
|
-
return url.startsWith(app.routerPathPrefix);
|
|
67
|
-
}
|
|
68
|
-
});
|
|
69
|
-
}
|
|
70
|
-
|
|
71
|
-
getAppByName(name: string) {
|
|
72
|
-
return this.appsMap[name];
|
|
73
|
-
}
|
|
74
|
-
|
|
75
|
-
getAppsToPreload(excludeAppNames?: string[]) {
|
|
76
|
-
return this.getApps().filter(app => {
|
|
77
|
-
if (excludeAppNames) {
|
|
78
|
-
return app.preload && !excludeAppNames.includes(app.name);
|
|
79
|
-
} else {
|
|
80
|
-
return app.preload;
|
|
81
|
-
}
|
|
82
|
-
});
|
|
83
|
-
}
|
|
84
|
-
|
|
85
|
-
getApps() {
|
|
86
|
-
return this.apps;
|
|
87
|
-
}
|
|
88
|
-
}
|
|
@@ -1,53 +0,0 @@
|
|
|
1
|
-
import { TestBed } from '@angular/core/testing';
|
|
2
|
-
import { Router } from '@angular/router';
|
|
3
|
-
import { PlanetPortalApplication } from './portal-application';
|
|
4
|
-
import { NgZone, ApplicationRef } from '@angular/core';
|
|
5
|
-
import { RouterTestingModule } from '@angular/router/testing';
|
|
6
|
-
|
|
7
|
-
describe('PlanetPortalApplication', () => {
|
|
8
|
-
let router: Router;
|
|
9
|
-
let planetPortalApplication: PlanetPortalApplication;
|
|
10
|
-
beforeEach(() => {
|
|
11
|
-
TestBed.configureTestingModule({
|
|
12
|
-
imports: [RouterTestingModule.withRoutes([])]
|
|
13
|
-
});
|
|
14
|
-
router = TestBed.inject(Router);
|
|
15
|
-
planetPortalApplication = new PlanetPortalApplication();
|
|
16
|
-
planetPortalApplication.ngZone = TestBed.inject(NgZone);
|
|
17
|
-
planetPortalApplication.applicationRef = TestBed.inject(ApplicationRef);
|
|
18
|
-
planetPortalApplication.router = TestBed.inject(Router);
|
|
19
|
-
});
|
|
20
|
-
|
|
21
|
-
it(`should create PlanetPortalApplication`, () => {
|
|
22
|
-
expect(planetPortalApplication).toBeTruthy();
|
|
23
|
-
});
|
|
24
|
-
|
|
25
|
-
it(`should run function`, () => {
|
|
26
|
-
const spy = jasmine.createSpy('spy');
|
|
27
|
-
expect(spy).not.toHaveBeenCalled();
|
|
28
|
-
planetPortalApplication.run(spy);
|
|
29
|
-
expect(spy).toHaveBeenCalled();
|
|
30
|
-
});
|
|
31
|
-
|
|
32
|
-
it(`should run function in ngZone`, () => {
|
|
33
|
-
const ngZoneRunSpy = spyOn(planetPortalApplication.ngZone, 'run');
|
|
34
|
-
expect(ngZoneRunSpy).not.toHaveBeenCalled();
|
|
35
|
-
planetPortalApplication.run(() => {});
|
|
36
|
-
expect(ngZoneRunSpy).toHaveBeenCalled();
|
|
37
|
-
});
|
|
38
|
-
|
|
39
|
-
it(`should run tick`, () => {
|
|
40
|
-
const tickSpy = spyOn(planetPortalApplication.applicationRef, 'tick');
|
|
41
|
-
expect(tickSpy).not.toHaveBeenCalled();
|
|
42
|
-
planetPortalApplication.tick();
|
|
43
|
-
expect(tickSpy).toHaveBeenCalled();
|
|
44
|
-
});
|
|
45
|
-
|
|
46
|
-
it(`should run navigateByUrl`, () => {
|
|
47
|
-
const navigateByUrlSpy = spyOn(planetPortalApplication.router, 'navigateByUrl');
|
|
48
|
-
expect(navigateByUrlSpy).not.toHaveBeenCalled();
|
|
49
|
-
planetPortalApplication.navigateByUrl('/app1/dashboard', { skipLocationChange: true });
|
|
50
|
-
expect(navigateByUrlSpy).toHaveBeenCalled();
|
|
51
|
-
expect(navigateByUrlSpy).toHaveBeenCalledWith('/app1/dashboard', { skipLocationChange: true });
|
|
52
|
-
});
|
|
53
|
-
});
|