fix(docs-infra): don't call setSearch when not clicking in the searchBox and no searchResults ()

Fix to call locationService.setSearch less often to avoid unnecessary
downloading of favicons

Fixes 

PR Close 
This commit is contained in:
onlyflix 2018-10-19 16:09:28 +02:00 committed by Jason Aden
parent 30f12f2887
commit 4001bb44d2
2 changed files with 10 additions and 2 deletions

@ -742,7 +742,7 @@ describe('AppComponent', () => {
expect(component.showSearchResults).toBe(true); expect(component.showSearchResults).toBe(true);
}); });
it('should not intercept clicks om the searchBox', () => { it('should not intercept clicks on the searchBox', () => {
component.showSearchResults = true; component.showSearchResults = true;
fixture.detectChanges(); fixture.detectChanges();
@ -752,6 +752,11 @@ describe('AppComponent', () => {
expect(component.showSearchResults).toBe(true); expect(component.showSearchResults).toBe(true);
}); });
it('should not call `locationService.setSearch` when searchResults are not shown', () => {
docViewer.click();
expect(locationService.setSearch).not.toHaveBeenCalled();
});
}); });
describe('keyup handling', () => { describe('keyup handling', () => {

@ -389,7 +389,10 @@ export class AppComponent implements OnInit {
hideSearchResults() { hideSearchResults() {
this.showSearchResults = false; this.showSearchResults = false;
this.locationService.setSearch('', { ...this.locationService.search(), search: undefined }); const oldSearch = this.locationService.search();
if (oldSearch.search !== undefined) {
this.locationService.setSearch('', { ...oldSearch, search: undefined });
}
} }
focusSearchBox() { focusSearchBox() {