Commit fe275ed5 authored by Jérémy Destin's avatar Jérémy Destin
Browse files

fix: Fix the fronted test and implement new tests for germplasm-result-page...

fix: Fix the fronted test and implement new tests for germplasm-result-page and the facets management. GNP-4309
parent 51c7f314
......@@ -7,5 +7,27 @@
</content>
<orderEntry type="inheritedJdk" />
<orderEntry type="sourceFolder" forTests="false" />
<orderEntry type="library" name="Gradle: io.swagger:swagger-annotations:1.5.21" level="project" />
<orderEntry type="library" name="Gradle: org.springframework:spring-beans:5.1.4.RELEASE" level="project" />
<orderEntry type="library" name="Gradle: org.springframework:spring-web:5.1.4.RELEASE" level="project" />
<orderEntry type="library" name="Gradle: io.springfox:springfox-core:2.9.2" level="project" />
<orderEntry type="library" name="Gradle: io.springfox:springfox-spring-web:2.9.2" level="project" />
<orderEntry type="library" name="Gradle: javax.validation:validation-api:2.0.1.Final" level="project" />
<orderEntry type="library" name="Gradle: com.google.guava:guava:27.0.1-jre" level="project" />
<orderEntry type="library" name="Gradle: commons-collections:commons-collections:3.2.2" level="project" />
<orderEntry type="library" name="Gradle: org.apache.httpcomponents:httpcore:4.4.10" level="project" />
<orderEntry type="library" name="Gradle: org.elasticsearch.client:elasticsearch-rest-client:6.4.3" level="project" />
<orderEntry type="library" name="Gradle: org.apache.httpcomponents:httpcore-nio:4.4.10" level="project" />
<orderEntry type="library" name="Gradle: org.springframework.boot:spring-boot-autoconfigure:2.1.2.RELEASE" level="project" />
<orderEntry type="library" name="Gradle: org.springframework:spring-context:5.1.4.RELEASE" level="project" />
<orderEntry type="library" name="Gradle: com.fasterxml.jackson.core:jackson-databind:2.9.8" level="project" />
<orderEntry type="library" name="Gradle: org.springframework.boot:spring-boot:2.1.2.RELEASE" level="project" />
<orderEntry type="library" name="Gradle: org.springframework.security:spring-security-config:5.1.3.RELEASE" level="project" />
<orderEntry type="library" name="Gradle: io.springfox:springfox-spi:2.9.2" level="project" />
<orderEntry type="library" name="Gradle: io.springfox:springfox-swagger2:2.9.2" level="project" />
<orderEntry type="library" name="Gradle: org.elasticsearch:elasticsearch:6.5.4" level="project" />
<orderEntry type="library" name="Gradle: org.slf4j:slf4j-api:1.7.25" level="project" />
<orderEntry type="library" name="Gradle: org.elasticsearch.client:elasticsearch-rest-high-level-client:6.5.4" level="project" />
<orderEntry type="library" name="Gradle: org.elasticsearch:elasticsearch-core:6.5.4" level="project" />
</component>
</module>
\ No newline at end of file
This diff is collapsed.
......@@ -299,7 +299,8 @@ describe('BrapiService', () => {
distributors: [origin],
panel: [germplasmSet],
collection: [germplasmSet],
population: [germplasmSet]
population: [germplasmSet],
'schema:includedInDataCatalog': null
};
let brapiService: BrapiService;
......
import { async, ComponentFixture, TestBed } from '@angular/core/testing';
import { FacetsComponent } from './facets.component';
import { BehaviorSubject } from 'rxjs';
import {
DataDiscoveryCriteria,
DataDiscoveryCriteriaUtils
} from '../models/data-discovery.model';
import { GermplasmSearchCriteria } from '../models/gnpis.model';
import { SmallFacetsComponent } from './small-facets/small-facets.component';
import { LargeFacetsComponent } from './large-facets/large-facets.component';
import { MockComponents } from 'ng-mocks';
describe('LargeFacetsComponent', () => {
describe('FacetsComponent', () => {
let component: FacetsComponent;
let fixture: ComponentFixture<FacetsComponent>;
beforeEach(async(() => {
TestBed.configureTestingModule({
declarations: [FacetsComponent]
declarations: [FacetsComponent, MockComponents(SmallFacetsComponent), MockComponents(LargeFacetsComponent)]
})
.compileComponents();
}));
beforeEach(() => {
fixture = TestBed.createComponent(FacetsComponent);
component = fixture.componentInstance;
component.criteria$ = new BehaviorSubject<DataDiscoveryCriteria>(DataDiscoveryCriteriaUtils.emptyCriteria());
component.germplasmSearchCriteria$ = new BehaviorSubject<GermplasmSearchCriteria>(DataDiscoveryCriteriaUtils
.emptyGermplasmSearchCriteria());
component.displayGermplasmResult$ = new BehaviorSubject<boolean>(false);
fixture.detectChanges();
});
}));
it('should create', () => {
expect(component).toBeTruthy();
......
......@@ -11,7 +11,7 @@
</ng-template>
</ng-template>
<ng-container *ngIf="facet.terms.length && facet.terms.length > 8">
<ng-container>
<div class="mb-2">
<span class="badge badge-pill badge-secondary mr-1"
*ngFor="let term of selectedTerms[facet.field]" tabindex="0"
......
import { LargeFacetsComponent } from './large-facets.component';
import { async, ComponentFixture, TestBed } from '@angular/core/testing';
import {
DataDiscoveryCriteria, DataDiscoveryCriteriaUtils,
DataDiscoveryFacet
} from '../../models/data-discovery.model';
import { NgbTypeaheadModule } from '@ng-bootstrap/ng-bootstrap';
import { ReactiveFormsModule } from '@angular/forms';
import { HttpClientTestingModule } from '@angular/common/http/testing';
import { BehaviorSubject } from 'rxjs';
import { GermplasmSearchCriteria } from '../../models/gnpis.model';
import { ComponentTester } from 'ngx-speculoos';
import { LargeFacetsComponent } from './large-facets.component';
describe('LargeFacetsComponent', () => {
let component: LargeFacetsComponent;
let fixture: ComponentFixture<LargeFacetsComponent>;
class LargeFacetsComponentTester extends ComponentTester<LargeFacetsComponent> {
constructor() {
super(LargeFacetsComponent);
}
get facetTitle() {
return this.element('h3')
}
get facetInput() {
return this.element('input')
}
}
const largeFacet: DataDiscoveryFacet = {
field: 'large Facet',
terms: [
{
term: 'source 1',
label: 'SOURCE 1',
count: 10
}, {
term: 'source 2',
label: 'SOURCE 2',
count: 20
}, {
term: 'Germplasm',
label: 'GERMPLASM',
count: 10
},{
term: 'Traditional cultivar/landrace',
label: 'Traditional cultivar/landrace',
count: 74
}, {
term: 'Wild',
label: 'Wild',
count: 7095
}, {
term: 'Hybrid',
label: 'Hybrid',
count: 478
},{
term: 'INRA',
label: 'INRA',
count: 74
}, {
term: 'INRA-ONF',
label: 'INRA-ONF',
count: 8282
}, {
term: 'USDA',
label: 'USDA',
count: 3871
}, {
term: 'IPK',
label: 'IPK',
count: 2606
}, {
term: 'INRA, CNRS',
label: 'INRA, CNRS',
count: 2170
}
]
};
beforeEach(async(() => {
TestBed.configureTestingModule({
imports: [NgbTypeaheadModule, ReactiveFormsModule, HttpClientTestingModule ],
declarations: [LargeFacetsComponent]
})
.compileComponents();
}));
beforeEach(() => {
fixture = TestBed.createComponent(LargeFacetsComponent);
component = fixture.componentInstance;
component.criteria$ = new BehaviorSubject<DataDiscoveryCriteria>(DataDiscoveryCriteriaUtils.emptyCriteria());
component.germplasmSearchCriteria$ = new BehaviorSubject<GermplasmSearchCriteria>(DataDiscoveryCriteriaUtils
.emptyGermplasmSearchCriteria());
component.facet = largeFacet;
fixture.detectChanges();
});
}));
it('should create', () => {
expect(component).toBeTruthy();
});
it ('should display search box', () => {
const tester = new LargeFacetsComponentTester();
const component = tester.componentInstance;
component.facet = largeFacet;
tester.detectChanges();
expect(tester.facetTitle.textContent).toEqual('Large Facet');
expect(tester.facetInput).toBeTruthy();
});
});
......@@ -30,8 +30,8 @@ describe('SmallFacetsComponent', () => {
return this.elements('input');
}
get advanceSearchButton() {
return this.elements('button');
get switchButton() {
return this.elements('label#switchTitle');
}
}
......@@ -76,6 +76,7 @@ describe('SmallFacetsComponent', () => {
const component = tester.componentInstance;
component.facet = exampleFacet1;
component.criteria$ = new BehaviorSubject<DataDiscoveryCriteria>(DataDiscoveryCriteriaUtils.emptyCriteria());
component.displayGermplasmResult$ = new BehaviorSubject<boolean>(false);
tester.detectChanges();
expect(tester.title).toContainText('Sources');
......@@ -100,6 +101,7 @@ describe('SmallFacetsComponent', () => {
sources: ['source 2']
};
component.criteria$ = new BehaviorSubject<DataDiscoveryCriteria>(criteria);
component.displayGermplasmResult$ = new BehaviorSubject<boolean>(false);
tester.detectChanges();
......@@ -114,6 +116,7 @@ describe('SmallFacetsComponent', () => {
const component = tester.componentInstance;
component.facet = exampleFacet1;
component.criteria$ = new BehaviorSubject<DataDiscoveryCriteria>(DataDiscoveryCriteriaUtils.emptyCriteria());
component.displayGermplasmResult$ = new BehaviorSubject<boolean>(false);
tester.detectChanges();
// No sources selected in criteria
......@@ -141,11 +144,12 @@ describe('SmallFacetsComponent', () => {
types: ['Germplasm']
};
component.criteria$ = new BehaviorSubject<DataDiscoveryCriteria>(criteria);
component.displayGermplasmResult$ = new BehaviorSubject<boolean>(true);
component.facet = exampleFacet2;
tester.detectChanges();
expect(tester.advanceSearchButton.length).toEqual(1);
expect(tester.advanceSearchButton[0]).toContainText('Advance search');
expect(tester.switchButton.length).toEqual(1);
expect(tester.switchButton[0]).toContainText('Focus');
});
......@@ -157,11 +161,12 @@ describe('SmallFacetsComponent', () => {
...DataDiscoveryCriteriaUtils.emptyCriteria(),
types: ['Germplasm', 'Phenotyping Study']
};
component.criteria$ = new BehaviorSubject<DataDiscoveryCriteria>(criteria);
component.criteria$ = new BehaviorSubject<DataDiscoveryCriteria>(DataDiscoveryCriteriaUtils.emptyCriteria());
component.displayGermplasmResult$ = new BehaviorSubject<boolean>(false);
component.facet = exampleFacet2;
tester.detectChanges();
expect(tester.advanceSearchButton).toEqual([]);
expect(tester.switchButton).toEqual([]);
});
});
......@@ -40,14 +40,6 @@ describe('GermplasmCardComponent', () => {
}
}
const gnpisSite: Site = {
latitude: null,
longitude: null,
siteId: null,
siteName: null,
siteType: null
};
const brapiSibling: BrapiSibling = {
germplasmDbId: 'frere1',
defaultDisplayName: 'frere1'
......
import { async, ComponentFixture, TestBed } from '@angular/core/testing';
import { GermplasmResultPageComponent } from './germplasm-result-page.component';
import { RouterTestingModule } from '@angular/router/testing';
import { LoadingSpinnerComponent } from '../loading-spinner/loading-spinner.component';
import { GnpisService } from '../gnpis.service';
import { BrapiGermplasm, GermplasmResults } from '../models/brapi.model';
import { CardSectionComponent } from '../card-section/card-section.component';
import { NO_ERRORS_SCHEMA } from '@angular/core';
import {
DataDiscoveryCriteria,
DataDiscoveryCriteriaUtils,
DataDiscoveryFacet,
DEFAULT_PAGE_SIZE,
MAX_RESULTS
} from '../models/data-discovery.model';
import { GermplasmSearchCriteria } from '../models/gnpis.model';
import { BehaviorSubject, of } from 'rxjs';
describe('GermplasmResultPageComponent', () => {
let component: GermplasmResultPageComponent;
let fixture: ComponentFixture<GermplasmResultPageComponent>;
const pagination = {
startResult: 1,
endResult: DEFAULT_PAGE_SIZE,
totalResult: 2,
currentPage: 0,
pageSize: DEFAULT_PAGE_SIZE,
totalPages: 1,
totalCount: 2,
maxResults: MAX_RESULTS
};
const facets: DataDiscoveryFacet[] = [
{
field: 'holdingInstitute',
terms: [
{
term: 'INRA',
label: 'INRA',
count: 74
},
{
term: 'INRA-ONF',
label: 'INRA-ONF',
count: 8282
},
{
term: 'USDA',
label: 'USDA',
count: 3871
},
{
term: 'IPK',
label: 'IPK',
count: 2606
},
{
term: 'INRA, CNRS',
label: 'INRA, CNRS',
count: 2170
}
]
},
{
field: 'biologicalStatus',
terms: [
{
term: 'Traditional cultivar/landrace',
label: 'Traditional cultivar/landrace',
count: 74
},
{
term: 'Wild',
label: 'Wild',
count: 7095
},
{
term: 'Hybrid',
label: 'Hybrid',
count: 478
}
]
}
];
const germplasmSearchResult: GermplasmResults<BrapiGermplasm> = {
metadata: {
pagination: pagination
},
facets: facets,
result: {
data: [{
germplasmDbId: 'g1',
defaultDisplayName: 'germplam1',
accessionNumber: 'G_10',
germplasmName: 'germplam1',
germplasmPUI: 'urn_g1',
pedigree: null,
seedSource: 'Versaille Institute',
synonyms: null,
commonCropName: 'cheery',
instituteCode: '78',
instituteName: 'Versaille Institute',
biologicalStatusOfAccessionCode: null,
countryOfOriginCode: 'FR',
typeOfGermplasmStorageCode: null,
taxonIds: null,
genus: 'Populus',
species: 'x generosa',
speciesAuthority: 'Pop',
subtaxa: 'subsp',
subtaxaAuthority: '',
donors: null,
acquisitionDate: 'yesterday'
}, {
germplasmDbId: 'g2',
defaultDisplayName: 'germplam2',
accessionNumber: 'G_20',
germplasmName: 'germplam2',
germplasmPUI: 'urn_g2',
pedigree: null,
seedSource: 'Versaille Institute',
synonyms: null,
commonCropName: 'cheery',
instituteCode: '78',
instituteName: 'Versaille Institute',
biologicalStatusOfAccessionCode: null,
countryOfOriginCode: 'FR',
typeOfGermplasmStorageCode: null,
taxonIds: null,
genus: 'Triticum',
species: 'aestivum',
speciesAuthority: 'Trit',
subtaxa: 'subsp',
subtaxaAuthority: '',
donors: null,
acquisitionDate: 'today'
}],
}
};
const criteria: GermplasmSearchCriteria = {
accessionNumbers: ['G_20'],
germplasmDbIds: null,
germplasmGenus: null,
germplasmNames: ['germplam1'],
germplasmPUIs: null,
germplasmSpecies: null,
synonyms: null,
panel: null,
collection: null,
population: null,
commonCropName: null,
species: null,
genusSpecies: null,
subtaxa: null,
genusSpeciesSubtaxa: null,
taxonSynonyms: null,
biologicalStatus: null,
geneticNature: null,
holdingInstitute: null,
sources: null,
facetFields: null,
sortBy: 'germplasmName',
sortOrder: null,
page: 1,
pageSize: 10,
};
const dataDiscoveryCriteria: DataDiscoveryCriteria = {
accessions: ['G_10', 'incisa', 'G_20'],
crops: ['cheery', 'prunus'],
facetFields: null,
germplasmLists: null,
observationVariableIds: null,
sources: ['URGI'],
types: null,
topSelectedTraitOntologyIds: null,
page: 1,
pageSize: 10
};
const gnpisService = jasmine.createSpyObj(
'GnpisService', [
'germplasmSearch'
]
);
gnpisService.germplasmSearch.and.returnValue(of(germplasmSearchResult));
beforeEach(async(() => {
TestBed.configureTestingModule({
declarations: [GermplasmResultPageComponent]
imports: [RouterTestingModule],
declarations: [GermplasmResultPageComponent, CardSectionComponent, LoadingSpinnerComponent],
providers: [
{ provide: GnpisService, useValue: gnpisService }
],
schemas: [NO_ERRORS_SCHEMA],
})
.compileComponents();
}));
beforeEach(() => {
fixture = TestBed.createComponent(GermplasmResultPageComponent);
component = fixture.componentInstance;
component.criteriaFromForm$ = new BehaviorSubject<DataDiscoveryCriteria>(DataDiscoveryCriteriaUtils
.emptyCriteria());
component.germplasmSearchCriteria$ = new BehaviorSubject<GermplasmSearchCriteria>(DataDiscoveryCriteriaUtils
.emptyGermplasmSearchCriteria());
component.germplasmFacets$ = new BehaviorSubject<DataDiscoveryFacet[]>(facets);
fixture.detectChanges();
});
}));
it('should create', () => {
expect(component).toBeTruthy();
});
it('should fecth the germplasm', () => {
component.germplasmSearchCriteria$.next(criteria);
expect(component.localCriteria).toEqual(criteria);
expect(gnpisService.germplasmSearch).toHaveBeenCalledWith(criteria);
expect(component.germplasm).toEqual(germplasmSearchResult.result.data);
});
it('should get criteria information from data discovery criteria', () => {
component.criteriaFromForm$.next(dataDiscoveryCriteria);
fixture.detectChanges();
expect(component.localCriteria.commonCropName).toContain('cheery');
expect(component.localCriteria.commonCropName).toContain('prunus');
expect(component.localCriteria.commonCropName).toContain('cheery');
expect(component.localCriteria.genusSpecies).toContain('prunus');
expect(component.localCriteria.genusSpeciesSubtaxa).toContain('prunus');
expect(component.localCriteria.germplasmNames).toContain('G_10');
expect(component.localCriteria.accessionNumbers).toContain('incisa');
expect(component.localCriteria.synonyms).toContain('G_20');
});
});
......@@ -51,7 +51,7 @@ export class GermplasmResultPageComponent implements OnInit {
maxResults: MAX_RESULTS
};
constructor(public service: GnpisService, private route: ActivatedRoute, private router: Router) {
constructor(public service: GnpisService, private route: ActivatedRoute) {
}
ngOnInit() {
......
......@@ -13,6 +13,7 @@ import {
Donor,
Germplasm,
GermplasmInstitute,
GermplasmSearchCriteria,
GermplasmSet,
Institute,
Site
......@@ -125,16 +126,38 @@ describe('GnpisService', () => {
distributors: [germplasmInstitute],
panel: [germplasmSet],
collection: [germplasmSet],
population: [germplasmSet]
population: [germplasmSet],
'schema:includedInDataCatalog': null
};
const germplasmExportCriteria: GermplasmExportCriteria = {
const germplasmExportCriteria: GermplasmSearchCriteria = {
accessionNumbers: ['VCR010'],
germplasmDbIds: [],
germplasmGenus: [],
germplasmNames