Skip to content
Permalink
Browse files
refactor(search): migrate search module (DSP-1851) (#510)
* refactor(search): migrates:
 - expert-search comp
 - fulltext-search comp
 - search-panel comp
 - _search.scss -> assets

* refactor(search): migrates advanced search
  • Loading branch information
mdelez committed Sep 1, 2021
1 parent 35f6e7b commit fc7ea5c5f1b6b225c20e41cbd3273aa8a1acc4d0
Show file tree
Hide file tree
Showing 82 changed files with 7,974 additions and 2 deletions.
@@ -1,3 +1,4 @@
/* eslint-disable max-len */
import { ClipboardModule } from '@angular/cdk/clipboard';
import { CommonModule } from '@angular/common';
import { HttpClient, HttpClientModule } from '@angular/common/http';
@@ -147,6 +148,24 @@ import { ListViewComponent } from './workspace/results/list-view/list-view.compo
import { ResourceGridComponent } from './workspace/results/list-view/resource-grid/resource-grid.component';
import { ResourceListComponent } from './workspace/results/list-view/resource-list/resource-list.component';
import { ComparisonComponent } from './workspace/comparison/comparison.component';
import { SearchPanelComponent } from './workspace/search/search-panel/search-panel.component';
import { FulltextSearchComponent } from './workspace/search/fulltext-search/fulltext-search.component';
import { ExpertSearchComponent } from './workspace/search/expert-search/expert-search.component';
import { AdvancedSearchComponent } from './workspace/search/advanced-search/advanced-search.component';
import { SearchBooleanValueComponent } from './workspace/search/advanced-search/resource-and-property-selection/search-select-property/specify-property-value/search-boolean-value/search-boolean-value.component';
import { SearchDateValueComponent } from './workspace/search/advanced-search/resource-and-property-selection/search-select-property/specify-property-value/search-date-value/search-date-value.component';
import { SearchDecimalValueComponent } from './workspace/search/advanced-search/resource-and-property-selection/search-select-property/specify-property-value/search-decimal-value/search-decimal-value.component';
import { SearchIntValueComponent } from './workspace/search/advanced-search/resource-and-property-selection/search-select-property/specify-property-value/search-int-value/search-int-value.component';
import { SearchLinkValueComponent } from './workspace/search/advanced-search/resource-and-property-selection/search-select-property/specify-property-value/search-link-value/search-link-value.component';
import { SearchListValueComponent } from './workspace/search/advanced-search/resource-and-property-selection/search-select-property/specify-property-value/search-list-value/search-list-value.component';
import { SearchDisplayListComponent } from './workspace/search/advanced-search/resource-and-property-selection/search-select-property/specify-property-value/search-list-value/search-display-list/search-display-list.component';
import { SearchTextValueComponent } from './workspace/search/advanced-search/resource-and-property-selection/search-select-property/specify-property-value/search-text-value/search-text-value.component';
import { SearchUriValueComponent } from './workspace/search/advanced-search/resource-and-property-selection/search-select-property/specify-property-value/search-uri-value/search-uri-value.component';
import { SpecifyPropertyValueComponent } from './workspace/search/advanced-search/resource-and-property-selection/search-select-property/specify-property-value/specify-property-value.component';
import { ResourceAndPropertySelectionComponent } from './workspace/search/advanced-search/resource-and-property-selection/resource-and-property-selection.component';
import { SearchSelectPropertyComponent } from './workspace/search/advanced-search/resource-and-property-selection/search-select-property/search-select-property.component';
import { SearchSelectResourceClassComponent } from './workspace/search/advanced-search/resource-and-property-selection/search-select-resource-class/search-select-resource-class.component';
import { SearchSelectOntologyComponent } from './workspace/search/advanced-search/search-select-ontology/search-select-ontology.component';

// translate: AoT requires an exported function for factories
export function httpLoaderFactory(httpClient: HttpClient) {
@@ -278,6 +297,24 @@ export function httpLoaderFactory(httpClient: HttpClient) {
ResourceGridComponent,
ResourceListComponent,
ComparisonComponent,
SearchPanelComponent,
FulltextSearchComponent,
ExpertSearchComponent,
AdvancedSearchComponent,
SearchBooleanValueComponent,
SearchDateValueComponent,
SearchDecimalValueComponent,
SearchIntValueComponent,
SearchLinkValueComponent,
SearchListValueComponent,
SearchDisplayListComponent,
SearchTextValueComponent,
SearchUriValueComponent,
SpecifyPropertyValueComponent,
ResourceAndPropertySelectionComponent,
SearchSelectPropertyComponent,
SearchSelectResourceClassComponent,
SearchSelectOntologyComponent,
],
imports: [
AppRoutingModule,
@@ -7,7 +7,7 @@ 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 { AdvancedSearchParams, AdvancedSearchParamsService } from '../../search/services/advanced-search-params.service';
import { ListViewComponent, SearchParams } from './list-view.component';

/**
@@ -3,7 +3,7 @@ import { PageEvent } from '@angular/material/paginator';
import { ApiResponseError, CountQueryResponse, IFulltextSearchParams, KnoraApiConnection, ReadResourceSequence } from '@dasch-swiss/dsp-js';
import { DspApiConnectionToken } from 'src/app/main/declarations/dsp-api-tokens';
import { NotificationService } from 'src/app/main/services/notification.service';
import { AdvancedSearchParamsService } from '../../../search/services/advanced-search-params.service';
import { AdvancedSearchParamsService } from '../../search/services/advanced-search-params.service';

/**
* query: search query. It can be gravserch query or fulltext string query.
@@ -0,0 +1,23 @@
<form *ngIf="!errorMessage" [formGroup]="form" (ngSubmit)="submit()" class="dsp-form-content">

<div *ngIf="ontologiesMetadata?.ontologies.length > 0">
<app-search-select-ontology [formGroup]="form" [ontologiesMetadata]="ontologiesMetadata"
(ontologySelected)="setActiveOntology($event)"></app-search-select-ontology>
</div>

<app-resource-and-property-selection *ngIf="activeOntology !== undefined" #resAndPropSel [formGroup]="form" [activeOntology]="activeOntology" [topLevel]="true">
</app-resource-and-property-selection>

<div class="dsp-form-action">
<button class="reset" mat-button type="button" (click)="resourceAndPropertySelection?.resetForm()" [disabled]="this.activeOntology === undefined">
Reset
</button>
<span class="fill-remaining-space"></span>
<button class="advanced-search-button" mat-raised-button color="primary" type="submit" [disabled]="!formValid">
Search
</button>
</div>

</form>

<app-message *ngIf="errorMessage" [apiError]="errorMessage" [size]="'medium'"></app-message>
@@ -0,0 +1,179 @@
import { HarnessLoader } from '@angular/cdk/testing';
import { TestbedHarnessEnvironment } from '@angular/cdk/testing/testbed';
import { Component, EventEmitter, Input, OnInit, Output, ViewChild } from '@angular/core';
import { ComponentFixture, TestBed, waitForAsync } from '@angular/core/testing';
import { FormGroup, ReactiveFormsModule } from '@angular/forms';
import { MatIconModule } from '@angular/material/icon';
import { MatSnackBarModule } from '@angular/material/snack-bar';
import { By } from '@angular/platform-browser';
import { BrowserAnimationsModule } from '@angular/platform-browser/animations';
import { OntologiesEndpointV2, OntologiesMetadata, OntologyMetadata } from '@dasch-swiss/dsp-js';
import { of } from 'rxjs';
import { DspApiConnectionToken } from 'src/app/main/declarations/dsp-api-tokens';
import { AdvancedSearchComponent } from './advanced-search.component';

/**
* test component to simulate select ontology component.
*/
@Component({
selector: 'app-search-select-ontology',
template: ''
})
class TestSearchSelectOntologyComponent implements OnInit {

@Input() formGroup: FormGroup;

@Input() ontologiesMetadata: OntologiesMetadata;

@Output() ontologySelected = new EventEmitter<string>();

ngOnInit() {

}

}

/**
* test component to simulate select resource class and property component.
*/
@Component({
selector: 'app-resource-and-property-selection',
template: ''
})
class TestSelectResourceClassAndPropertyComponent {

@Input() formGroup: FormGroup;

@Input() activeOntology: string;

@Input() resClassRestriction?: string;

@Input() topLevel: boolean;

}

/**
* test host component to simulate parent component.
*/
@Component({
template: `
<app-advanced-search #advSearch></app-advanced-search>`
})
class TestHostComponent implements OnInit {

@ViewChild('advSearch') advancedSearch: AdvancedSearchComponent;

ngOnInit() {
}

}

describe('AdvancedSearchComponent', () => {
let testHostComponent: TestHostComponent;
let testHostFixture: ComponentFixture<TestHostComponent>;

let loader: HarnessLoader;

beforeEach(waitForAsync(() => {

const dspConnSpy = {
v2: {
onto: jasmine.createSpyObj('onto', ['getOntologiesMetadata'])
}
};

TestBed.configureTestingModule({
declarations: [
AdvancedSearchComponent,
TestHostComponent,
TestSearchSelectOntologyComponent,
TestSelectResourceClassAndPropertyComponent
],
imports: [
ReactiveFormsModule,
BrowserAnimationsModule,
MatIconModule,
MatSnackBarModule
],
providers: [
{
provide: DspApiConnectionToken,
useValue: dspConnSpy
}
]
})
.compileComponents();
}));

describe('Ontology with resources', () => {
beforeEach(() => {

const dspConnSpy = TestBed.inject(DspApiConnectionToken);

(dspConnSpy.v2.onto as jasmine.SpyObj<OntologiesEndpointV2>).getOntologiesMetadata.and.callFake(
() => {

const ontoMetadata = new OntologiesMetadata();

const anythingOnto = new OntologyMetadata();
anythingOnto.id = 'anyid';
anythingOnto.label = 'anythingOnto';

ontoMetadata.ontologies = [anythingOnto];

return of(ontoMetadata);
}
);

testHostFixture = TestBed.createComponent(TestHostComponent);
testHostComponent = testHostFixture.componentInstance;

loader = TestbedHarnessEnvironment.loader(testHostFixture);

testHostFixture.detectChanges();
});

it('should create', () => {

expect(testHostComponent).toBeTruthy();
expect(testHostComponent.advancedSearch).toBeTruthy();

});

it('should get ontologies metadata on init', () => {

const dspConnSpy = TestBed.inject(DspApiConnectionToken);

expect(testHostComponent.advancedSearch.ontologiesMetadata).toBeDefined();
expect(testHostComponent.advancedSearch.ontologiesMetadata.ontologies.length).toEqual(1);

const hostCompDe = testHostFixture.debugElement;
const selectOntoComp = hostCompDe.query(By.directive(TestSearchSelectOntologyComponent));

expect((selectOntoComp.componentInstance as TestSearchSelectOntologyComponent).ontologiesMetadata).toBeDefined();
expect((selectOntoComp.componentInstance as TestSearchSelectOntologyComponent).ontologiesMetadata.ontologies.length).toEqual(1);

expect(dspConnSpy.v2.onto.getOntologiesMetadata).toHaveBeenCalledTimes(1);

expect((selectOntoComp.componentInstance as TestSearchSelectOntologyComponent).formGroup).toBeDefined();

});

it('should set the active ontology when an ontology is selected', () => {

const hostCompDe = testHostFixture.debugElement;
const selectOntoComp = hostCompDe.query(By.directive(TestSearchSelectOntologyComponent));

(selectOntoComp.componentInstance as TestSearchSelectOntologyComponent).ontologySelected.emit('http://0.0.0.0:3333/ontology/0001/anything/v2');

testHostFixture.detectChanges();

expect(testHostComponent.advancedSearch.activeOntology).toEqual('http://0.0.0.0:3333/ontology/0001/anything/v2');

expect(testHostComponent.advancedSearch.resourceAndPropertySelection.activeOntology).toEqual('http://0.0.0.0:3333/ontology/0001/anything/v2');

});

});

});

0 comments on commit fc7ea5c

Please sign in to comment.