Commit cae78b8f authored by Tifenn Guillas's avatar Tifenn Guillas
Browse files

Update tests + ngOnDestroy for Search results

parent c2702ff2
...@@ -61,4 +61,4 @@ export function reducer(state: State = initialState, action: actions.Actions): S ...@@ -61,4 +61,4 @@ export function reducer(state: State = initialState, action: actions.Actions): S
export const getAttributeList = (state: State) => state.attributeList; export const getAttributeList = (state: State) => state.attributeList;
export const getObjectIsLoading = (state: State) => state.objectIsLoading; export const getObjectIsLoading = (state: State) => state.objectIsLoading;
export const getObjectIsLoaded = (state: State) => state.objectIsLoaded; export const getObjectIsLoaded = (state: State) => state.objectIsLoaded;
export const getObject = (state: State) => state.object; export const getObject = (state: State) => state.object;
\ No newline at end of file
<div class="form-group row"> <div class="form-group row">
<label class="col-3 col-form-label">{{label}}</label> <label class="col-3 col-form-label">{{ label }}</label>
<div class="col"> <div class="col">
<div *ngFor="let cb of checkboxes.controls; let i=index" class="form-check form-check-inline"> <div *ngFor="let cb of checkboxes.controls; let i=index" class="form-check form-check-inline">
<input class="form-check-input" type="checkbox" id="cb_{{optionList[i].value}}" [formControl]="cb"> <input class="form-check-input" type="checkbox" id="cb_{{optionList[i].value}}" [formControl]="cb">
<label class="form-check-label" for="cb_{{optionList[i].value}}">{{optionList[i].label}}</label> <label class="form-check-label" for="cb_{{optionList[i].value}}">{{ optionList[i].label }}</label>
</div> </div>
</div> </div>
<div class="col-2 text-center"> <div class="col-2 text-center">
<button class="btn btn-outline-success" *ngIf="!checkboxes.disabled" [hidden]="!isChecked()" (click)="emitAdd()"> <button *ngIf="!checkboxes.disabled" class="btn btn-outline-success" [hidden]="!isChecked()"
(click)="emitAdd()">
<span class="fas fa-plus fa-fw"></span> <span class="fas fa-plus fa-fw"></span>
</button> </button>
<button class="btn btn-outline-danger" *ngIf="checkboxes.disabled" (click)="emiteDelete()"> <button *ngIf="checkboxes.disabled" class="btn btn-outline-danger" (click)="emiteDelete()">
<span class="fa fa-times fa-fw"></span> <span class="fa fa-times fa-fw"></span>
</button> </button>
</div> </div>
......
...@@ -30,8 +30,11 @@ describe('[Search][Criteria][SearchType] Component: CheckboxComponent', () => { ...@@ -30,8 +30,11 @@ describe('[Search][Criteria][SearchType] Component: CheckboxComponent', () => {
{label: 'Three', value: 'three', display: 3} {label: 'Three', value: 'three', display: 3}
]; ];
component.setCheckboxes(options); component.setCheckboxes(options);
// console.log(component.checkboxes.controls[0].value);
expect(component.checkboxes.length).toEqual(3); expect(component.checkboxes.length).toEqual(3);
expect(component.checkboxesFormControls.length).toEqual(3);
expect(component.checkboxesFormControls[0].value).toMatch('one');
expect(component.checkboxesFormControls[1].value).toMatch('two');
expect(component.checkboxesFormControls[2].value).toMatch('three');
}); });
// it('#getDefault() should not fill and enable form if criterion not defined', () => { // it('#getDefault() should not fill and enable form if criterion not defined', () => {
...@@ -78,12 +81,13 @@ describe('[Search][Criteria][SearchType] Component: CheckboxComponent', () => { ...@@ -78,12 +81,13 @@ describe('[Search][Criteria][SearchType] Component: CheckboxComponent', () => {
// it('raises the add criterion event when clicked', () => { // it('raises the add criterion event when clicked', () => {
// component.id = 1; // component.id = 1;
// const values: Option[] = [ // const options: Option[] = [
// {label: 'One', value: 'one', display: 1}, // {label: 'One', value: 'one', display: 1},
// {label: 'Two', value: 'two', display: 2}, // {label: 'Two', value: 'two', display: 2},
// {label: 'Three', value: 'three', display: 3} // {label: 'Three', value: 'three', display: 3}
// ]; // ];
// const expectedCriterion = new SelectMultipleCriterion(component.id, values); // component.setCheckboxes(options);
// const expectedCriterion = new SelectMultipleCriterion(component.id, options);
// component.addCriterion.subscribe((event: SelectMultipleCriterion) => expect(event).toEqual(expectedCriterion)); // component.addCriterion.subscribe((event: SelectMultipleCriterion) => expect(event).toEqual(expectedCriterion));
// component.emitAdd(); // component.emitAdd();
// }); // });
......
...@@ -50,7 +50,6 @@ export class CheckboxComponent { ...@@ -50,7 +50,6 @@ export class CheckboxComponent {
this.checkboxesFormControls.push({ value: option.value, control }); this.checkboxesFormControls.push({ value: option.value, control });
return control; return control;
})); }));
console.log(this.checkboxesFormControls);
} }
getDefault(criterion: Criterion): void { getDefault(criterion: Criterion): void {
......
import { Component, OnInit, Query } from '@angular/core'; import { Component, OnInit, OnDestroy } from '@angular/core';
import { Observable } from 'rxjs'; import { Observable } from 'rxjs';
import { Store } from '@ngrx/store'; import { Store } from '@ngrx/store';
...@@ -22,7 +22,7 @@ interface StoreState { ...@@ -22,7 +22,7 @@ interface StoreState {
selector: 'app-result', selector: 'app-result',
templateUrl: 'result.component.html' templateUrl: 'result.component.html'
}) })
export class ResultComponent implements OnInit { export class ResultComponent implements OnInit, OnDestroy {
public datasetSearchMetaIsLoading: Observable<boolean>; public datasetSearchMetaIsLoading: Observable<boolean>;
public datasetSearchMetaIsLoaded: Observable<boolean>; public datasetSearchMetaIsLoaded: Observable<boolean>;
public attributeSearchMetaIsLoading: Observable<boolean>; public attributeSearchMetaIsLoading: Observable<boolean>;
...@@ -91,4 +91,8 @@ export class ResultComponent implements OnInit { ...@@ -91,4 +91,8 @@ export class ResultComponent implements OnInit {
executeProcess(typeProcess: string): void { executeProcess(typeProcess: string): void {
this.store.dispatch(new searchActions.ExecuteProcessAction(typeProcess)); this.store.dispatch(new searchActions.ExecuteProcessAction(typeProcess));
} }
ngOnDestroy() {
this.store.dispatch(new searchActions.DestroyResultsAction());
}
} }
...@@ -25,6 +25,7 @@ export const EXECUTE_PROCESS = '[Search] Execute Process'; ...@@ -25,6 +25,7 @@ export const EXECUTE_PROCESS = '[Search] Execute Process';
export const EXECUTE_PROCESS_WIP = '[Search] Execute Process WIP'; export const EXECUTE_PROCESS_WIP = '[Search] Execute Process WIP';
export const EXECUTE_PROCESS_SUCCESS = '[Search] Execute Process Success'; export const EXECUTE_PROCESS_SUCCESS = '[Search] Execute Process Success';
export const EXECUTE_PROCESS_FAIL = '[Search] Execute Process Fail'; export const EXECUTE_PROCESS_FAIL = '[Search] Execute Process Fail';
export const DESTROY_RESULTS = '[Search] Destroy Results';
export class InitSearchByUrl implements Action { export class InitSearchByUrl implements Action {
type = INIT_SEARCH_BY_URL; type = INIT_SEARCH_BY_URL;
...@@ -164,6 +165,12 @@ export class ExecuteProcessFailAction implements Action { ...@@ -164,6 +165,12 @@ export class ExecuteProcessFailAction implements Action {
constructor(public payload: {} = null) { } constructor(public payload: {} = null) { }
} }
export class DestroyResultsAction implements Action {
type = DESTROY_RESULTS;
constructor(public payload: {} = null) { }
}
export type Actions export type Actions
= InitSearchByUrl = InitSearchByUrl
| ChangeStepAction | ChangeStepAction
...@@ -187,4 +194,5 @@ export type Actions ...@@ -187,4 +194,5 @@ export type Actions
| ExecuteProcessAction | ExecuteProcessAction
| ExecuteProcessWipAction | ExecuteProcessWipAction
| ExecuteProcessSuccessAction | ExecuteProcessSuccessAction
| ExecuteProcessFailAction; | ExecuteProcessFailAction
| DestroyResultsAction;
...@@ -193,6 +193,14 @@ export function reducer(state: State = initialState, action: actions.Actions): S ...@@ -193,6 +193,14 @@ export function reducer(state: State = initialState, action: actions.Actions): S
processId: null processId: null
}; };
case actions.DESTROY_RESULTS:
return {
...state,
searchMetaIsLoaded: false,
searchMeta: null,
searchData: null,
};
default: default:
return state; return state;
} }
......
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