fix(docs-infra): Handle search criteria from Chrome search providers (#30345)
fixes #30242 PR Close #30345
This commit is contained in:
parent
3aff79c251
commit
d70b1ff177
|
@ -44,6 +44,16 @@ describe('SearchBoxComponent', () => {
|
||||||
expect(host.searchHandler).toHaveBeenCalledWith('initial search');
|
expect(host.searchHandler).toHaveBeenCalledWith('initial search');
|
||||||
expect(component.searchBox.nativeElement.value).toEqual('initial search');
|
expect(component.searchBox.nativeElement.value).toEqual('initial search');
|
||||||
})));
|
})));
|
||||||
|
|
||||||
|
it('should decode the search query from the location service (chrome search provider format)',
|
||||||
|
fakeAsync(inject([LocationService], (location: MockLocationService) => {
|
||||||
|
location.search.and.returnValue({ search: 'initial+search' });
|
||||||
|
component.ngAfterViewInit();
|
||||||
|
expect(location.search).toHaveBeenCalled();
|
||||||
|
tick(300);
|
||||||
|
expect(host.searchHandler).toHaveBeenCalledWith('initial search');
|
||||||
|
expect(component.searchBox.nativeElement.value).toEqual('initial search');
|
||||||
|
})));
|
||||||
});
|
});
|
||||||
|
|
||||||
describe('onSearch', () => {
|
describe('onSearch', () => {
|
||||||
|
|
|
@ -43,7 +43,7 @@ export class SearchBoxComponent implements AfterViewInit {
|
||||||
ngAfterViewInit() {
|
ngAfterViewInit() {
|
||||||
const query = this.locationService.search()['search'];
|
const query = this.locationService.search()['search'];
|
||||||
if (query) {
|
if (query) {
|
||||||
this.query = query;
|
this.query = this.decodeQuery(query);
|
||||||
this.doSearch();
|
this.doSearch();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -60,6 +60,11 @@ export class SearchBoxComponent implements AfterViewInit {
|
||||||
this.searchBox.nativeElement.focus();
|
this.searchBox.nativeElement.focus();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private decodeQuery(query: string): string {
|
||||||
|
// `decodeURIComponent` does not handle `+` for spaces, replace via RexEx.
|
||||||
|
return query.replace(/\+/g, ' ');
|
||||||
|
}
|
||||||
|
|
||||||
private get query() { return this.searchBox.nativeElement.value; }
|
private get query() { return this.searchBox.nativeElement.value; }
|
||||||
private set query(value: string) { this.searchBox.nativeElement.value = value; }
|
private set query(value: string) { this.searchBox.nativeElement.value = value; }
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue