Skip to content
Permalink
Browse files
fix: gravsearch results now appear after page refresh (#542)
  • Loading branch information
mdelez committed Sep 22, 2021
1 parent 0eb621b commit a88dd790e6bf35931e9443a6745a5d75f47ce502
Showing with 7 additions and 25 deletions.
  1. +2 −20 src/app/workspace/results/list-view/list-view.component.spec.ts
  2. +5 −5 src/app/workspace/results/list-view/list-view.component.ts
@@ -7,7 +7,6 @@ import { MatSnackBarModule } from '@angular/material/snack-bar';
import { CountQueryResponse, IFulltextSearchParams, MockResource, ReadResourceSequence, SearchEndpointV2 } from '@dasch-swiss/dsp-js';
import { of } from 'rxjs';
import { DspApiConnectionToken } from 'src/app/main/declarations/dsp-api-tokens';
import { AdvancedSearchParams, AdvancedSearchParamsService } from '../../search/services/advanced-search-params.service';
import { ListViewComponent, SearchParams } from './list-view.component';

/**
@@ -80,7 +79,7 @@ class TestParentComponent implements OnInit {
};

this.gravsearch = {
query: 'fake query',
query: 'fake query OFFSET 0',
mode: 'gravsearch'
};
}
@@ -96,8 +95,6 @@ describe('ListViewComponent', () => {
let testHostComponent: TestParentComponent;
let testHostFixture: ComponentFixture<TestParentComponent>;

let searchParamsServiceSpy: jasmine.SpyObj<AdvancedSearchParamsService>;

beforeEach(waitForAsync(() => {

const searchSpyObj = {
@@ -106,8 +103,6 @@ describe('ListViewComponent', () => {
}
};

const searchParamsSpyObj = jasmine.createSpyObj('SearchParamsService', ['getSearchParams']);

TestBed.configureTestingModule({
declarations: [
ListViewComponent,
@@ -127,23 +122,13 @@ describe('ListViewComponent', () => {
provide: DspApiConnectionToken,
useValue: searchSpyObj
},
{
provide: AdvancedSearchParamsService,
useValue: searchParamsSpyObj
}
]
})
.compileComponents();
}));

beforeEach(() => {

searchParamsServiceSpy = TestBed.inject(AdvancedSearchParamsService) as jasmine.SpyObj<AdvancedSearchParamsService>;

const generateFakeQuery = (offset: number) => 'fake query OFFSET ' + offset;

searchParamsServiceSpy.getSearchParams.and.callFake((): AdvancedSearchParams => new AdvancedSearchParams(generateFakeQuery));

const searchSpy = TestBed.inject(DspApiConnectionToken);

(searchSpy.v2.search as jasmine.SpyObj<SearchEndpointV2>).doFulltextSearchCountQuery.and.callFake(
@@ -215,10 +200,7 @@ describe('ListViewComponent', () => {
const searchSpy = TestBed.inject(DspApiConnectionToken);

// do advanced search count query
expect(searchSpy.v2.search.doExtendedSearchCountQuery).toHaveBeenCalledWith('fake query');

// generate gravesearch query
expect(searchParamsServiceSpy.getSearchParams).toHaveBeenCalled();
expect(searchSpy.v2.search.doExtendedSearchCountQuery).toHaveBeenCalledWith('fake query OFFSET 0');

// do advanced search
expect(searchSpy.v2.search.doExtendedSearch).toHaveBeenCalledWith('fake query OFFSET 0');
@@ -4,7 +4,6 @@ import { ApiResponseError, CountQueryResponse, IFulltextSearchParams, KnoraApiCo
import { DspApiConnectionToken } from 'src/app/main/declarations/dsp-api-tokens';
import { ComponentCommunicationEventService, EmitEvent, Events } from 'src/app/main/services/component-communication-event.service';
import { NotificationService } from 'src/app/main/services/notification.service';
import { AdvancedSearchParamsService } from '../../search/services/advanced-search-params.service';

/**
* query: search query. It can be gravserch query or fulltext string query.
@@ -117,7 +116,6 @@ export class ListViewComponent implements OnChanges {

constructor(
@Inject(DspApiConnectionToken) private _dspApiConnection: KnoraApiConnection,
private _advancedSearchParamsService: AdvancedSearchParamsService,
private _notification: NotificationService,
private _componentCommsService: ComponentCommunicationEventService,
) { }
@@ -231,10 +229,12 @@ export class ListViewComponent implements OnChanges {
);
}

// perform advanced search
const gravsearch = this._advancedSearchParamsService.getSearchParams().generateGravsearch(this.pageEvent.pageIndex);
let gravsearch: string;

if (typeof gravsearch === 'string') {
if (this.search.query !== undefined) {
gravsearch = this.search.query;
gravsearch = gravsearch.substring(0, gravsearch.search('OFFSET'));
gravsearch = gravsearch + 'OFFSET ' + this.pageEvent.pageIndex;
this._dspApiConnection.v2.search.doExtendedSearch(gravsearch).subscribe(
(response: ReadResourceSequence) => {
// if the response does not contain any resources even the search count is greater than 0,

0 comments on commit a88dd79

Please sign in to comment.