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
This commit is contained in:
Pete Bacon Darwin 2018-09-21 14:46:27 +01:00 committed by Kara Erickson
parent 026b60cd70
commit a880686081
2 changed files with 10 additions and 1 deletions

View File

@ -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();

View File

@ -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() {