Commits

Art Lowel authored 32fc28ec54a
fix dev mode issue where retrieving the login options fails
No tags

src/app/core/server-check/server-check.guard.spec.ts

Modified
13 13 let rootDataServiceStub: SpyObj<RootDataService>;
14 14 let testScheduler: TestScheduler;
15 15 let redirectUrlTree: UrlTree;
16 16
17 17 beforeEach(() => {
18 18 testScheduler = new TestScheduler((actual, expected) => {
19 19 expect(actual).toEqual(expected);
20 20 });
21 21 rootDataServiceStub = jasmine.createSpyObj('RootDataService', {
22 22 checkServerAvailability: jasmine.createSpy('checkServerAvailability'),
23 - invalidateRootCache: jasmine.createSpy('invalidateRootCache')
23 + invalidateRootCache: jasmine.createSpy('invalidateRootCache'),
24 + findRoot: jasmine.createSpy('findRoot')
24 25 });
25 26 redirectUrlTree = new UrlTree();
26 27 router = {
27 28 events: eventSubject.asObservable(),
28 29 navigateByUrl: jasmine.createSpy('navigateByUrl'),
29 30 parseUrl: jasmine.createSpy('parseUrl').and.returnValue(redirectUrlTree)
30 31 } as any;
31 32 guard = new ServerCheckGuard(router, rootDataServiceStub);
32 33 });
33 34
56 57 it('should return a UrlTree with the route to the 500 error page', () => {
57 58 testScheduler.run(({ expectObservable }) => {
58 59 const result$ = guard.canActivateChild({} as any, {} as any);
59 60 expectObservable(result$).toBe('(b|)', { b: redirectUrlTree });
60 61 });
61 62 expect(router.parseUrl).toHaveBeenCalledWith('/500');
62 63 });
63 64 });
64 65
65 66 describe(`listenForRouteChanges`, () => {
66 - it(`should invalidate the root cache when the method is first called, and then on every NavigationStart event`, () => {
67 + it(`should retrieve the root endpoint, without using the cache, when the method is first called`, () => {
67 68 testScheduler.run(() => {
68 69 guard.listenForRouteChanges();
69 - expect(rootDataServiceStub.invalidateRootCache).toHaveBeenCalledTimes(1);
70 + expect(rootDataServiceStub.findRoot).toHaveBeenCalledWith(false);
71 + });
72 + });
70 73
74 + it(`should invalidate the root cache on every NavigationStart event`, () => {
75 + testScheduler.run(() => {
76 + guard.listenForRouteChanges();
71 77 eventSubject.next(new NavigationStart(1,''));
72 78 eventSubject.next(new NavigationEnd(1,'', ''));
73 79 eventSubject.next(new NavigationStart(2,''));
74 80 eventSubject.next(new NavigationEnd(2,'', ''));
75 81 eventSubject.next(new NavigationStart(3,''));
76 82 });
77 - expect(rootDataServiceStub.invalidateRootCache).toHaveBeenCalledTimes(4);
83 + expect(rootDataServiceStub.invalidateRootCache).toHaveBeenCalledTimes(3);
78 84 });
79 85 });
80 86 });

Everything looks good. We'll let you know here if there's anything you should know about.

Add shortcut