Skip to content

Commit eb9c93a

Browse files
authored
feat(planet): add stop feature to planet service (#117)
1 parent b5413c1 commit eb9c93a

File tree

3 files changed

+46
-3
lines changed

3 files changed

+46
-3
lines changed

angular.json

+4-1
Original file line numberDiff line numberDiff line change
@@ -382,5 +382,8 @@
382382
}
383383
}
384384
},
385-
"defaultProject": "portal"
385+
"defaultProject": "portal",
386+
"cli": {
387+
"analytics": false
388+
}
386389
}

packages/planet/src/planet.spec.ts

+34
Original file line numberDiff line numberDiff line change
@@ -183,4 +183,38 @@ describe('Planet', () => {
183183
expect(rerouteSpy).toHaveBeenCalledTimes(2);
184184
expect(planetRouterEvent.url).toEqual('/users');
185185
}));
186+
187+
it('should reroute not be call when planet stop', fakeAsync(() => {
188+
const router: Router = TestBed.inject(Router);
189+
const ngZone: NgZone = TestBed.inject(NgZone);
190+
const rerouteSpy = spyOn(planetApplicationLoader, 'reroute');
191+
expect(rerouteSpy).not.toHaveBeenCalled();
192+
planet.start();
193+
expect(rerouteSpy).toHaveBeenCalledTimes(1);
194+
195+
ngZone.run(() => {
196+
router.navigateByUrl('/app1/dashboard');
197+
});
198+
199+
tick();
200+
201+
expect(rerouteSpy).toHaveBeenCalledTimes(2);
202+
expect(rerouteSpy).toHaveBeenCalledWith({
203+
url: '/app1/dashboard'
204+
});
205+
206+
planet.stop();
207+
208+
ngZone.run(() => {
209+
router.navigateByUrl('/app1/users');
210+
});
211+
tick();
212+
213+
// rerouteSpy should not be call
214+
// url should not change
215+
expect(rerouteSpy).toHaveBeenCalledTimes(2);
216+
expect(rerouteSpy).toHaveBeenCalledWith({
217+
url: '/app1/dashboard'
218+
});
219+
}));
186220
});

packages/planet/src/planet.ts

+8-2
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ import {
77
AppsLoadingStartEvent,
88
AppStatusChangeEvent
99
} from './application/planet-application-loader';
10-
import { Observable } from 'rxjs';
10+
import { Observable, Subscription } from 'rxjs';
1111
import { filter, startWith, distinctUntilChanged, map } from 'rxjs/operators';
1212
import {
1313
setPortalApplicationData,
@@ -41,6 +41,8 @@ export class Planet {
4141
return this.planetApplicationLoader.appsLoadingStart;
4242
}
4343

44+
private subscription: Subscription;
45+
4446
constructor(
4547
private injector: Injector,
4648
private router: Router,
@@ -83,7 +85,7 @@ export class Planet {
8385
}
8486

8587
start() {
86-
this.router.events
88+
this.subscription = this.router.events
8789
.pipe(
8890
filter(event => {
8991
return event instanceof NavigationEnd;
@@ -100,4 +102,8 @@ export class Planet {
100102
});
101103
});
102104
}
105+
106+
stop() {
107+
this.subscription.unsubscribe();
108+
}
103109
}

0 commit comments

Comments
 (0)