fix(aio): correctly handle re-navigation to the empty path (#16997)

This commit is contained in:
George Kalpakas 2017-05-26 02:43:34 +03:00 committed by Chuck Jazdzewski
parent 573b8611bc
commit e10d763446
2 changed files with 31 additions and 1 deletions

View File

@ -401,6 +401,22 @@ describe('AppComponent', () => {
expect(scrollSpy.calls.count()).toBe(2); 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(() => { it('should scroll after a delay when call onDocRendered directly', fakeAsync(() => {
component.onDocRendered(); component.onDocRendered();
expect(scrollSpy).not.toHaveBeenCalled(); expect(scrollSpy).not.toHaveBeenCalled();
@ -650,6 +666,20 @@ describe('AppComponent', () => {
expect(getProgressBar()).toBeFalsy(); 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(() => { it('should not be shown if the doc is rendered quickly', fakeAsync(() => {
initializeAndCompleteNavigation(); initializeAndCompleteNavigation();
locationService.urlSubject.next('c/d'); locationService.urlSubject.next('c/d');

View File

@ -123,7 +123,7 @@ export class AppComponent implements OnInit {
}); });
this.locationService.currentPath.subscribe(path => { 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) // scroll only if on same page (most likely a change to the hash)
this.autoScroll(); this.autoScroll();
} else { } else {