diff --git a/client/src/app/instance/search/components/output/output-by-category.component.spec.ts b/client/src/app/instance/search/components/output/output-by-category.component.spec.ts new file mode 100644 index 0000000000000000000000000000000000000000..a5c5f09f3000a9389f627aa2be4f3effbbdfe2dc --- /dev/null +++ b/client/src/app/instance/search/components/output/output-by-category.component.spec.ts @@ -0,0 +1,120 @@ +import { ComponentFixture, TestBed } from '@angular/core/testing'; + +import { OutputByCategoryComponent } from './output-by-category.component'; + +describe('[Instance][Search][Component][Output] OutputByCategoryComponent', () => { + let component: OutputByCategoryComponent; + let fixture: ComponentFixture<OutputByCategoryComponent>; + + beforeEach(() => { + TestBed.configureTestingModule({ + declarations: [OutputByCategoryComponent] + }); + fixture = TestBed.createComponent(OutputByCategoryComponent); + component = fixture.componentInstance; + }); + + it('should create the component', () => { + expect(component).toBeTruthy(); + }); + + it('#isSelected(idOutput) should return true if output is selected', () => { + component.outputList = [1]; + expect(component.isSelected(1)).toBeTruthy(); + }); + + it('#isSelected(idOutput) should return false if output is not selected', () => { + component.outputList = [1]; + expect(component.isSelected(2)).toBeFalsy(); + }); + + it('#toggleSelection(idOutput) should remove idOutput from outputList and raise change event', () => { + component.outputList = [1]; + const idOutput = 1; + const expectedOutputList = []; + component.change.subscribe((event: number[]) => expect(event).toEqual(expectedOutputList)); + component.toggleSelection(idOutput); + }); + + it('#toggleSelection(idOutput) should add idOutput to outputList and raise change event', () => { + component.outputList = []; + const idOutput = 1; + const expectedOutputList = [1]; + component.change.subscribe((event: number[]) => expect(event).toEqual(expectedOutputList)); + component.toggleSelection(idOutput); + }); + + it('#selectAll() should add all outputs to outputList and raise change event', () => { + component.attributeList = [ + { + id: 2, + name: 'name_two', + label: 'label_two', + form_label: 'form_label_two', + description : 'description_two', + output_display: 1, + criteria_display: 1, + search_flag : 'SPECTRUM_1D', + search_type : 'field', + operator : '=', + type: '', + display_detail: 1 + }, + { + id: 1, + name: 'name_one', + label: 'label_one', + form_label: 'form_label_one', + description: 'description_one', + output_display: 2, + criteria_display: 2, + search_flag: 'ID', + search_type: 'field', + operator: '=', + type: 'integer', + display_detail: 2 + } + ]; + component.outputList = []; + const expectedOutputList = [1, 2]; + component.change.subscribe((event: number[]) => expect(event).toEqual(expectedOutputList)); + component.selectAll(); + }); + + it('#unselectAll() should remove all outputs to outputList and raise change event', () => { + component.attributeList = [ + { + id: 2, + name: 'name_two', + label: 'label_two', + form_label: 'form_label_two', + description : 'description_two', + output_display: 1, + criteria_display: 1, + search_flag : 'SPECTRUM_1D', + search_type : 'field', + operator : '=', + type: '', + display_detail: 1 + }, + { + id: 1, + name: 'name_one', + label: 'label_one', + form_label: 'form_label_one', + description: 'description_one', + output_display: 2, + criteria_display: 2, + search_flag: 'ID', + search_type: 'field', + operator: '=', + type: 'integer', + display_detail: 2 + } + ]; + component.outputList = [1, 2]; + const expectedOutputList = []; + component.change.subscribe((event: number[]) => expect(event).toEqual(expectedOutputList)); + component.unselectAll(); + }); +}); diff --git a/client/src/app/instance/search/components/output/output-by-category.component.ts b/client/src/app/instance/search/components/output/output-by-category.component.ts index 830f1495803575e40d45722c797581fa68ec7e56..84e593e1c6c898738b2c6702f4d7d7f64aca74f3 100644 --- a/client/src/app/instance/search/components/output/output-by-category.component.ts +++ b/client/src/app/instance/search/components/output/output-by-category.component.ts @@ -11,16 +11,16 @@ import { Component, Input, Output, EventEmitter, ChangeDetectionStrategy } from import { Attribute } from 'src/app/metamodel/models'; +/** + * @class + * @classdesc Search output by category component. + */ @Component({ selector: 'app-output-by-category', templateUrl: 'output-by-category.component.html', styleUrls: ['output-by-category.component.scss'], changeDetection: ChangeDetectionStrategy.OnPush }) -/** - * @class - * @classdesc Search output by category component. - */ export class OutputByCategoryComponent { @Input() categoryLabel: string; @Input() attributeList: Attribute[];