Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Browse files
Browse the repository at this point in the history
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
Showing
82 changed files
with
7,974 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
23 changes: 23 additions & 0 deletions
23
src/app/workspace/search/advanced-search/advanced-search.component.html
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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> |
Empty file.
179 changes: 179 additions & 0 deletions
179
src/app/workspace/search/advanced-search/advanced-search.component.spec.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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'); | ||
|
||
}); | ||
|
||
}); | ||
|
||
}); |
Oops, something went wrong.