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

fix: Fix test and bugs. Minor fixes. GNP-4309

parent 65e576f7
......@@ -11,7 +11,7 @@
</ng-template>
</ng-template>
<ng-container *ngIf="facet.terms.length && facet.terms.length > 8">
<ng-container *ngIf="facet.terms.length && facet.terms.length >8">
<div class="card mb-1">
<div class="card-body">
......@@ -23,7 +23,7 @@
style="font-size: smaller"
*ngFor="let term of selectedTerms[facet.field]"
(keydown.delete)="removeKey(term)"
(keydown.backspace)="removeKey(term)"> {{ displaySourceName(term) }}
(keydown.backspace)="removeKey(term)"> {{ displaySourceName(term) }}
<button tabindex="-1" type="button" class="btn btn-link"
(click)="removeKey(term)">&times;</button>
</span>
......@@ -38,6 +38,7 @@
</div>
<faidare-switch-button
*ngIf="!criteriaIsEmpty"
style="margin-top: -10px; margin-left: 25px"
[criteria$]=criteria$
[displayGermplasmResult$]="displayGermplasmResult$"
......
......@@ -5,12 +5,16 @@ import {
DataDiscoveryCriteriaUtils,
DataDiscoveryFacet
} from '../../models/data-discovery.model';
import { NgbTypeaheadModule } from '@ng-bootstrap/ng-bootstrap';
import {
NgbPopoverModule,
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 { SwitchButtonComponent } from '../switch-button/switch-button.component';
describe('LargeFacetsComponent', () => {
......@@ -84,8 +88,8 @@ describe('LargeFacetsComponent', () => {
beforeEach(async(() => {
TestBed.configureTestingModule({
imports: [NgbTypeaheadModule, ReactiveFormsModule, HttpClientTestingModule ],
declarations: [LargeFacetsComponent]
imports: [NgbTypeaheadModule, ReactiveFormsModule, HttpClientTestingModule, NgbPopoverModule],
declarations: [LargeFacetsComponent, SwitchButtonComponent]
})
.compileComponents();
......@@ -95,6 +99,7 @@ describe('LargeFacetsComponent', () => {
component.criteria$ = new BehaviorSubject<DataDiscoveryCriteria>(DataDiscoveryCriteriaUtils.emptyCriteria());
component.germplasmSearchCriteria$ = new BehaviorSubject<GermplasmSearchCriteria>(DataDiscoveryCriteriaUtils
.emptyGermplasmSearchCriteria());
component.displayGermplasmResult$ = new BehaviorSubject<boolean>(false);
component.facet = largeFacet;
fixture.detectChanges();
}));
......@@ -106,6 +111,7 @@ describe('LargeFacetsComponent', () => {
it ('should display search box', () => {
const tester = new LargeFacetsComponentTester();
component = tester.componentInstance;
component.displayGermplasmResult$ = new BehaviorSubject<boolean>(false);
component.facet = largeFacet;
tester.detectChanges();
......
......@@ -42,7 +42,7 @@ export class LargeFacetsComponent implements OnInit {
criterion = new FormControl('');
sources: DataDiscoverySource[];
criteriaIsEmpty = true;
displayGermplasmCurrentState = false;
germplasmDisplayCurrentState = false;
constructor(private gnpisService: GnpisService) {
}
......@@ -53,7 +53,9 @@ export class LargeFacetsComponent implements OnInit {
this.sources = sources;
});
this.displayGermplasmResult$.subscribe(status => this.displayGermplasmCurrentState = status);
this.displayGermplasmResult$.subscribe(status => {
this.germplasmDisplayCurrentState = status;
});
if (this.criteria$) {
this.criteria$.pipe(filter(c => c !== this.localCriteria))
......@@ -64,7 +66,7 @@ export class LargeFacetsComponent implements OnInit {
});
}
if (this.germplasmSearchCriteria$ && this.displayGermplasmCurrentState) {
if (this.germplasmSearchCriteria$ && this.germplasmDisplayCurrentState) {
this.germplasmSearchCriteria$.pipe(filter(c => c !== this.germplasmLocalCriteria))
.subscribe(germplasmCriteria => {
this.germplasmLocalCriteria = germplasmCriteria;
......@@ -118,14 +120,14 @@ export class LargeFacetsComponent implements OnInit {
if (selected !== 'REFINE') {
// the item field of the event contains the facet term
// we push the selected key to our collection of keys
if (this.criteria$ && !this.displayGermplasmCurrentState) {
if (this.criteria$) {
if (this.localCriteria[this.facet.field]) {
this.localCriteria[this.facet.field].push(event.item.term);
} else {
this.localCriteria[this.facet.field] = [event.item.term];
}
}
if (this.germplasmSearchCriteria$ && this.displayGermplasmCurrentState) {
if (this.germplasmSearchCriteria$ && this.germplasmDisplayCurrentState) {
if (event.item.term !== 'Germplasm' && this.facet.field === 'types') {
if (this.localCriteria[this.facet.field]) {
......@@ -148,10 +150,10 @@ export class LargeFacetsComponent implements OnInit {
}
emitChanges() {
if (this.criteria$ && !this.displayGermplasmCurrentState) {
if (this.criteria$) {
this.criteria$.next(this.localCriteria);
}
if (this.germplasmSearchCriteria$ && this.displayGermplasmCurrentState) {
if (this.germplasmSearchCriteria$ && this.germplasmDisplayCurrentState) {
this.germplasmSearchCriteria$.next(this.germplasmLocalCriteria);
}
}
......@@ -159,11 +161,11 @@ export class LargeFacetsComponent implements OnInit {
removeKey(key: string) {
this.selectedTerms[this.facet.field] =
this.removeFromList(this.selectedTerms[this.facet.field], key);
if (this.criteria$ && !this.displayGermplasmCurrentState) {
if (this.criteria$ && !this.germplasmDisplayCurrentState) {
this.localCriteria[this.facet.field] =
this.removeFromList(this.localCriteria[this.facet.field], key);
}
if (this.germplasmSearchCriteria$ && this.displayGermplasmCurrentState) {
if (this.germplasmSearchCriteria$ && this.germplasmDisplayCurrentState) {
if (key === 'Germplasm') {
this.switchGermplasmResult();
}
......@@ -181,7 +183,7 @@ export class LargeFacetsComponent implements OnInit {
}
switchGermplasmResult() {
if (!this.displayGermplasmCurrentState) {
if (!this.germplasmDisplayCurrentState) {
this.localCriteria = {
...this.localCriteria,
facetFields: ['types']
......@@ -193,6 +195,6 @@ export class LargeFacetsComponent implements OnInit {
};
}
this.criteria$.next(this.localCriteria);
this.displayGermplasmResult$.next(!this.displayGermplasmCurrentState);
this.displayGermplasmResult$.next(!this.germplasmDisplayCurrentState);
}
}
......@@ -25,7 +25,7 @@
<faidare-switch-button
style="margin-top: 5px"
*ngIf="term.term == 'Germplasm'"
*ngIf="term.term == 'Germplasm' && !criteriaIsEmpty"
[criteria$]=criteria$
[displayGermplasmResult$]="displayGermplasmResult$"
[facetFiled]="facet.field"
......
......@@ -12,6 +12,7 @@ import { BehaviorSubject } from 'rxjs';
import { take } from 'rxjs/operators';
import { NO_ERRORS_SCHEMA } from '@angular/core';
import { GermplasmSearchCriteria } from '../../models/gnpis.model';
import { SwitchButtonComponent } from '../switch-button/switch-button.component';
describe('SmallFacetsComponent', () => {
class FacetsComponentTester extends ComponentTester<SmallFacetsComponent> {
......@@ -65,7 +66,7 @@ describe('SmallFacetsComponent', () => {
beforeEach(() => TestBed.configureTestingModule({
imports: [ReactiveFormsModule],
declarations: [SmallFacetsComponent],
declarations: [SmallFacetsComponent, SwitchButtonComponent],
schemas: [NO_ERRORS_SCHEMA]
}));
......
......@@ -33,7 +33,7 @@ export class SmallFacetsComponent implements OnInit {
queryParams: Params;
checkBoxes: FormGroup = new FormGroup({});
displayAdvanceGermplasmSearchButton: boolean;
displayGermplasmCurrentState = false;
germplasmDisplayCurrentState = false;
constructor() {
}
......@@ -49,7 +49,7 @@ export class SmallFacetsComponent implements OnInit {
}
this.displayGermplasmResult$.subscribe(value => {
this.displayGermplasmCurrentState = value;
this.germplasmDisplayCurrentState = value;
});
if (this.criteria$) {
......@@ -58,29 +58,36 @@ export class SmallFacetsComponent implements OnInit {
this.localCriteria = criteria;
this.getSelectedTerms(criteria);
this.criteriaIsEmpty = DataDiscoveryCriteriaUtils.checkCriteriaIsEmpty(criteria);
if (criteria.types) {
this.showAndHideAdvanceGermplasmSearch(criteria.types);
}
});
}
if (this.germplasmSearchCriteria$) {
if (this.germplasmSearchCriteria$ && this.germplasmDisplayCurrentState) {
this.germplasmSearchCriteria$.pipe(filter(c => c !== this.germplasmLocalCriteria))
.subscribe(germplasmCriteria => {
this.germplasmLocalCriteria = germplasmCriteria;
if (this.displayGermplasmCurrentState) {
if (this.germplasmDisplayCurrentState) {
this.getSelectedTerms(germplasmCriteria);
}
});
}
this.checkBoxes.valueChanges.subscribe(values => {
const selectedTerms = Object.keys(values).filter(key => values[key]);
const multiSelection = Object.keys(values).filter(key => values[key] && key !== 'Germplasm');
const unselectGermplasm = Object.keys(values).filter(key => key === 'Germplasm' && !values[key]);
this.checkBoxes.valueChanges.subscribe(checkBoxesValue => {
const selectedTerms = Object.keys(checkBoxesValue).filter(key => checkBoxesValue[key]);
const multiSelection = Object.keys(checkBoxesValue).filter(key => checkBoxesValue[key] && key !== 'Germplasm');
const unselectGermplasm = Object.keys(checkBoxesValue).filter(key => key === 'Germplasm' && !checkBoxesValue[key]);
if ((multiSelection.length > 0 && this.facet.field === 'types') || unselectGermplasm.length > 0) {
this.switchGermplasmResult();
this.localCriteria = {
...this.localCriteria,
facetFields: ['types', 'sources'],
[this.facet.field]: selectedTerms
};
this.criteria$.next(this.localCriteria);
this.displayGermplasmResult$.next(false);
}
this.showAndHideAdvanceGermplasmSearch(selectedTerms);
......@@ -91,7 +98,7 @@ export class SmallFacetsComponent implements OnInit {
};
this.criteria$.next(this.localCriteria);
}
if (this.germplasmSearchCriteria$) {
if (this.germplasmSearchCriteria$ && this.germplasmDisplayCurrentState) {
this.germplasmLocalCriteria = {
...this.germplasmLocalCriteria,
[this.facet.field]: selectedTerms
......@@ -117,21 +124,4 @@ export class SmallFacetsComponent implements OnInit {
const GermplasmSelected = typeList.includes('Germplasm');
this.displayAdvanceGermplasmSearchButton = facetIsTypes && GermplasmSelected;
}
switchGermplasmResult() {
if (!this.displayGermplasmCurrentState) {
this.localCriteria = {
...this.localCriteria,
facetFields: ['types']
};
} else {
this.localCriteria = {
...this.localCriteria,
facetFields: ['types', 'sources']
};
}
this.criteria$.next(this.localCriteria);
this.displayGermplasmResult$.next(!this.displayGermplasmCurrentState);
}
}
......@@ -7,7 +7,7 @@
</label>
<label class="switch" id="switchButton">
<input type="checkbox" id="selectSwitchButton"
[checked]="displayGermplasmCurrentState"
[checked]="germplasmDisplayCurrentState"
(change)="switchGermplasmResult()">
<span class="slider round"></span>
</label>
......
import { async, ComponentFixture, TestBed } from '@angular/core/testing';
import { SwitchButtonComponent } from './switch-button.component';
import { NgbPopoverModule } from '@ng-bootstrap/ng-bootstrap';
import {
DataDiscoveryCriteria,
DataDiscoveryCriteriaUtils
} from '../../models/data-discovery.model';
import { BehaviorSubject } from 'rxjs';
describe('SwitchButtonComponent', () => {
let component: SwitchButtonComponent;
let fixture: ComponentFixture<SwitchButtonComponent>;
let component: SwitchButtonComponent;
let fixture: ComponentFixture<SwitchButtonComponent>;
beforeEach(async(() => {
TestBed.configureTestingModule({
declarations: [ SwitchButtonComponent ]
})
.compileComponents();
}));
beforeEach(async(() => {
TestBed.configureTestingModule({
imports: [NgbPopoverModule],
declarations: [SwitchButtonComponent]
})
.compileComponents();
}));
beforeEach(() => {
fixture = TestBed.createComponent(SwitchButtonComponent);
component = fixture.componentInstance;
fixture.detectChanges();
});
it('should create', () => {
expect(component).toBeTruthy();
});
it('should create', () => {
fixture = TestBed.createComponent(SwitchButtonComponent);
component = fixture.componentInstance;
component.displayGermplasmResult$ = new BehaviorSubject<boolean>(false);
component.criteria$ = new BehaviorSubject<DataDiscoveryCriteria>(DataDiscoveryCriteriaUtils.emptyCriteria());
fixture.detectChanges();
expect(component).toBeTruthy();
});
});
import { Component, Input, OnInit } from '@angular/core';
import {
DataDiscoveryCriteria,
DataDiscoveryCriteriaUtils,
DataDiscoverySource
} from '../../models/data-discovery.model';
import { BehaviorSubject } from 'rxjs';
......@@ -21,7 +22,7 @@ export class SwitchButtonComponent implements OnInit {
localCriteria: DataDiscoveryCriteria;
sources: DataDiscoverySource[];
criteriaIsEmpty = true;
displayGermplasmCurrentState = false;
germplasmDisplayCurrentState = false;
constructor() {
}
......@@ -29,12 +30,19 @@ export class SwitchButtonComponent implements OnInit {
ngOnInit() {
this.displayGermplasmResult$.subscribe(value => {
this.displayGermplasmCurrentState = value;
this.germplasmDisplayCurrentState = value;
});
if (this.criteria$) {
this.criteria$.subscribe(criteria => {
this.localCriteria = criteria;
this.criteriaIsEmpty = DataDiscoveryCriteriaUtils.checkCriteriaIsEmpty(criteria);
});
}
}
switchGermplasmResult() {
if (!this.displayGermplasmCurrentState) {
if (!this.germplasmDisplayCurrentState) {
this.localCriteria = {
...this.localCriteria,
facetFields: ['types']
......@@ -46,6 +54,6 @@ export class SwitchButtonComponent implements OnInit {
};
}
this.criteria$.next(this.localCriteria);
this.displayGermplasmResult$.next(!this.displayGermplasmCurrentState);
this.displayGermplasmResult$.next(!this.germplasmDisplayCurrentState);
}
}
......@@ -153,7 +153,7 @@ describe('GnpisService', () => {
geneticNature: null,
holdingInstitute: null,
sources: null,
types: 'Germplasm',
types: ['Germplasm'],
facetFields: null,
sortBy: null,
......
......@@ -103,10 +103,6 @@ export class ResultPageComponent implements OnInit {
relativeTo: this.route,
queryParams: DataDiscoveryCriteriaUtils.toQueryParams(newCriteria)
});
this.displayGermplasmResult$.subscribe(value => {
this.displayGermplasmResult = value;
});
this.displayGermplasmResult$.next(this.displayGermplasmResult);
});
this.germplasmfacets$.subscribe(facets => {
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment