diff --git a/aio/src/app/app.component.spec.ts b/aio/src/app/app.component.spec.ts index 7388c4f7ca..14ff9fdf96 100644 --- a/aio/src/app/app.component.spec.ts +++ b/aio/src/app/app.component.spec.ts @@ -401,6 +401,22 @@ describe('AppComponent', () => { expect(scrollSpy.calls.count()).toBe(2); }); + it('should scroll when nav to the same path', () => { + locationService.go('guide/pipes'); + scrollSpy.calls.reset(); + + locationService.go('guide/pipes'); + expect(scrollSpy).toHaveBeenCalledTimes(1); + }); + + it('should scroll when e-nav to the empty path', () => { + locationService.go(''); + scrollSpy.calls.reset(); + + locationService.go(''); + expect(scrollSpy).toHaveBeenCalledTimes(1); + }); + it('should scroll after a delay when call onDocRendered directly', fakeAsync(() => { component.onDocRendered(); expect(scrollSpy).not.toHaveBeenCalled(); @@ -650,6 +666,20 @@ describe('AppComponent', () => { expect(getProgressBar()).toBeFalsy(); })); + it('should not be shown when re-navigating to the empty path', fakeAsync(() => { + initializeAndCompleteNavigation(); + locationService.urlSubject.next(''); + triggerDocRendered(); + + locationService.urlSubject.next(''); + + tick(SHOW_DELAY); + fixture.detectChanges(); + expect(getProgressBar()).toBeFalsy(); + + tick(HIDE_DELAY); // Fire the remaining timer or `fakeAsync()` complains. + })); + it('should not be shown if the doc is rendered quickly', fakeAsync(() => { initializeAndCompleteNavigation(); locationService.urlSubject.next('c/d'); diff --git a/aio/src/app/app.component.ts b/aio/src/app/app.component.ts index f23eb9c41a..185b51fa4e 100644 --- a/aio/src/app/app.component.ts +++ b/aio/src/app/app.component.ts @@ -123,7 +123,7 @@ export class AppComponent implements OnInit { }); this.locationService.currentPath.subscribe(path => { - if (this.currentPath && path === this.currentPath) { + if (path === this.currentPath) { // scroll only if on same page (most likely a change to the hash) this.autoScroll(); } else {