Skip to content
Open
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
19 changes: 19 additions & 0 deletions src/app/shared/search/search.component.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -300,6 +300,25 @@ describe('SearchComponent', () => {
expect(comp.resultFound.emit).toHaveBeenCalledWith(expectedResults);
}));

it('should use the cached version for a normal search', fakeAsync(() => {
fixture.detectChanges();
tick(100);
expect((searchServiceStub.search as jasmine.Spy).calls.mostRecent().args[2]).toBe(true);
}));

it('should re-run the search without cache and refresh filters on content change', fakeAsync(() => {
fixture.detectChanges();
tick(100);
spyOn(comp.refreshFilters, 'next');

comp.onContentChange(null);

const searchArgs = (searchServiceStub.search as jasmine.Spy).calls.mostRecent().args;
expect(searchArgs[0]).toEqual(jasmine.objectContaining({ configuration: 'default' }));
expect(searchArgs[2]).toBe(false);
expect(comp.refreshFilters.next).toHaveBeenCalledWith(true);
}));

describe('when the open sidebar button is clicked in mobile view', () => {

beforeEach(() => {
Expand Down
6 changes: 4 additions & 2 deletions src/app/shared/search/search.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -434,6 +434,7 @@ export class SearchComponent implements OnDestroy, OnInit {
* @param $event
*/
public onContentChange($event: any) {
this.retrieveSearchResults(this.lastSearchOptions, false);
this.retrieveFilters(this.lastSearchOptions);
this.refreshFilters.next(true);
}
Expand Down Expand Up @@ -470,9 +471,10 @@ export class SearchComponent implements OnDestroy, OnInit {
/**
* Retrieve search result by the given search options
* @param searchOptions
* @param useCachedVersionIfAvailable
* @protected
*/
protected retrieveSearchResults(searchOptions: PaginatedSearchOptions) {
protected retrieveSearchResults(searchOptions: PaginatedSearchOptions, useCachedVersionIfAvailable = this.useCachedVersionIfAvailable) {
this.resultsRD$.next(null);
this.lastSearchOptions = searchOptions;
let followLinks = [
Expand All @@ -498,7 +500,7 @@ export class SearchComponent implements OnDestroy, OnInit {
this.service.search(
searchOptionsWithHidden,
undefined,
this.useCachedVersionIfAvailable,
useCachedVersionIfAvailable,
true,
...followLinks
).pipe(getFirstCompletedRemoteData())
Expand Down
Loading