mirror of
https://github.com/DSpace/dspace-angular.git
synced 2025-10-07 01:54:15 +00:00
fix issue where invalidateRootCache didn't happen when the page first loaded
This commit is contained in:
@@ -63,16 +63,18 @@ describe('ServerCheckGuard', () => {
|
||||
});
|
||||
|
||||
describe(`listenForRouteChanges`, () => {
|
||||
it(`should invalidate the root cache on every NavigationStart event`, () => {
|
||||
it(`should invalidate the root cache when the method is first called, and then on every NavigationStart event`, () => {
|
||||
testScheduler.run(() => {
|
||||
guard.listenForRouteChanges();
|
||||
expect(rootDataServiceStub.invalidateRootCache).toHaveBeenCalledTimes(1);
|
||||
|
||||
eventSubject.next(new NavigationStart(1,''));
|
||||
eventSubject.next(new NavigationEnd(1,'', ''));
|
||||
eventSubject.next(new NavigationStart(2,''));
|
||||
eventSubject.next(new NavigationEnd(2,'', ''));
|
||||
eventSubject.next(new NavigationStart(3,''));
|
||||
});
|
||||
expect(rootDataServiceStub.invalidateRootCache).toHaveBeenCalledTimes(3);
|
||||
expect(rootDataServiceStub.invalidateRootCache).toHaveBeenCalledTimes(4);
|
||||
});
|
||||
});
|
||||
});
|
||||
|
@@ -52,6 +52,10 @@ export class ServerCheckGuard implements CanActivateChild {
|
||||
* operation, the cached version is used.
|
||||
*/
|
||||
listenForRouteChanges(): void {
|
||||
// we'll always be too late for the first NavigationStart event with the router subscribe below,
|
||||
// so this statement is for the very first route operation
|
||||
this.rootDataService.invalidateRootCache();
|
||||
|
||||
this.router.events.pipe(
|
||||
filter(event => event instanceof NavigationStart),
|
||||
).subscribe(() => {
|
||||
|
Reference in New Issue
Block a user