diff --git a/aio/src/app/app.component.spec.ts b/aio/src/app/app.component.spec.ts index e6d37a15d2a2e..1b5b6d7c6ec9c 100644 --- a/aio/src/app/app.component.spec.ts +++ b/aio/src/app/app.component.spec.ts @@ -394,6 +394,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(); @@ -643,6 +659,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 d6fce322375e3..61bc83aeeebee 100644 --- a/aio/src/app/app.component.ts +++ b/aio/src/app/app.component.ts @@ -119,7 +119,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 {