Skip to content

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

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
May 25, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
30 changes: 30 additions & 0 deletions aio/src/app/app.component.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down Expand Up @@ -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');
Expand Down
2 changes: 1 addition & 1 deletion aio/src/app/app.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down