From 05d1b84f5254d2e9f65fa4b78ad85910e3ff6739 Mon Sep 17 00:00:00 2001 From: Pete Bacon Darwin Date: Fri, 21 Sep 2018 14:46:27 +0100 Subject: [PATCH] fix(docs-infra): ensure that only search is removed from URL on click (#26056) When we have navigated to the site via a URL that contains a search query param, the site shows the search results. We want to remove that query param from the URL when the search results are closed, but the current implementation is also removing other query params unnecessarily. Now only the search param is removed when the search results are closed. See https://github.com/angular/angular/pull/25479/files#r219497804 for more context. PR Close #26056 --- aio/src/app/app.component.spec.ts | 9 +++++++++ aio/src/app/app.component.ts | 2 +- 2 files changed, 10 insertions(+), 1 deletion(-) diff --git a/aio/src/app/app.component.spec.ts b/aio/src/app/app.component.spec.ts index b27951a1ff..ca60257b08 100644 --- a/aio/src/app/app.component.spec.ts +++ b/aio/src/app/app.component.spec.ts @@ -721,6 +721,15 @@ describe('AppComponent', () => { expect(component.showSearchResults).toBe(false); }); + it('should clear "only" the search query param from the URL', () => { + // Mock out the current state of the URL query params + locationService.search.and.returnValue({ a: 'some-A', b: 'some-B', search: 'some-C'}); + // docViewer is a commonly-clicked, non-search element + docViewer.click(); + // Check that the query params were updated correctly + expect(locationService.setSearch).toHaveBeenCalledWith('', { a: 'some-A', b: 'some-B', search: undefined }); + }); + it('should not intercept clicks on the searchResults', () => { component.showSearchResults = true; fixture.detectChanges(); diff --git a/aio/src/app/app.component.ts b/aio/src/app/app.component.ts index a15c4ca3fe..7353f7480c 100644 --- a/aio/src/app/app.component.ts +++ b/aio/src/app/app.component.ts @@ -384,7 +384,7 @@ export class AppComponent implements OnInit { hideSearchResults() { this.showSearchResults = false; - this.locationService.setSearch('', {}); + this.locationService.setSearch('', { ...this.locationService.search(), search: undefined }); } focusSearchBox() {