diff --git a/client/src/app/instance/search/components/summary.component.spec.ts b/client/src/app/instance/search/components/summary.component.spec.ts new file mode 100644 index 0000000000000000000000000000000000000000..1b46e6ac5d7d5150701a7f9026c886b22ba2d973 --- /dev/null +++ b/client/src/app/instance/search/components/summary.component.spec.ts @@ -0,0 +1,186 @@ +import { ComponentFixture, TestBed } from '@angular/core/testing'; +import { BrowserAnimationsModule } from '@angular/platform-browser/animations'; + +import { AccordionModule } from 'ngx-bootstrap/accordion'; + +import { SummaryComponent } from './summary.component'; +import { TooltipModule } from 'ngx-bootstrap/tooltip'; +import { FieldCriterion } from '../../store/models/criterion'; + +describe('[Instance][Search][Component] SummaryComponent', () => { + let component: SummaryComponent; + let fixture: ComponentFixture<SummaryComponent>; + + beforeEach(() => { + TestBed.configureTestingModule({ + declarations: [SummaryComponent], + imports: [ + AccordionModule.forRoot(), + TooltipModule.forRoot(), + BrowserAnimationsModule + ] + }); + fixture = TestBed.createComponent(SummaryComponent); + component = fixture.componentInstance; + }); + + it('should create the component', () => { + expect(component).toBeTruthy(); + }); + + it('#getDataset() should return the dataset with the given name', () => { + component.datasetList = [ + { + name: 'myDataset', + table_ref: '', + label: '', + description: '', + display: 1, + data_path: '', + survey_name: '', + id_dataset_family: 1, + public: true, + full_data_path: '', + config: { + images: [], + survey: { + survey_enabled: true, + survey_label: '' + }, + cone_search: { + cone_search_enabled: true, + cone_search_opened: true, + cone_search_column_ra: 1, + cone_search_column_dec: 2, + cone_search_plot_enabled: true, + cone_search_sdss_enabled: true, + cone_search_sdss_display: 1, + cone_search_background: [] + }, + download: { + download_enabled: true, + download_opened: true, + download_csv: true, + download_ascii: true, + download_vo: true, + download_archive: true + }, + summary: { + summary_enabled: true, + summary_opened: true + }, + server_link: { + server_link_enabled: true, + server_link_opened: true + }, + samp: { + samp_enabled: true, + samp_opened: true + }, + datatable: { + datatable_enabled: true, + datatable_opened: true, + datatable_selectable_rows: true + } + } + }, + { + name: 'anotherDataset', + table_ref: '', + label: '', + description: '', + display: 1, + data_path: '', + survey_name: '', + id_dataset_family: 1, + public: true, + full_data_path: '', + config: { + images: [], + survey: { + survey_enabled: true, + survey_label: '' + }, + cone_search: { + cone_search_enabled: true, + cone_search_opened: true, + cone_search_column_ra: 1, + cone_search_column_dec: 2, + cone_search_plot_enabled: true, + cone_search_sdss_enabled: true, + cone_search_sdss_display: 1, + cone_search_background: [] + }, + download: { + download_enabled: true, + download_opened: true, + download_csv: true, + download_ascii: true, + download_vo: true, + download_archive: true + }, + summary: { + summary_enabled: true, + summary_opened: true + }, + server_link: { + server_link_enabled: true, + server_link_opened: true + }, + samp: { + samp_enabled: true, + samp_opened: true + }, + datatable: { + datatable_enabled: true, + datatable_opened: true, + datatable_selectable_rows: true + } + } + } + ]; + component.datasetSelected = 'myDataset'; + expect(component.getDataset()).toBe(component.datasetList[0]); + }); + + it('#noCriteria() should return if there is criteria or not', () => { + component.criteriaList = []; + expect(component.noCriteria()).toBeTruthy(); + component.criteriaList = [ + {id: 1, type: 'field', operator: 'eq', value: 'fd_crit_1'} as FieldCriterion, + {id: 2, type: 'field', operator: 'eq', value: 'fd_crit_2'} as FieldCriterion + ] + ; + expect(component.noCriteria()).toBeFalsy(); + component.coneSearch = { ra: 1, dec: 2, radius: 3 }; + expect(component.noCriteria()).toBeFalsy(); + component.criteriaList = []; + expect(component.noCriteria()).toBeFalsy(); + }); + + // it('#getAttribute() should return the attribute with the given id', () => { + // component.attributeList = ATTRIBUTE_LIST; + // expect(component.getAttribute(1).name).toBe('name_one'); + // }); + // + // it('#printCriterion() should return pretty criterion', () => { + // const criterion: Criterion = CRITERIA_LIST.find(c => c.id === 1); + // expect(component.printCriterion(criterion)).toBe('= fd_crit_1'); + // }); + // + // it('#getCategoryByFamilySortedByDisplay(idFamily) should sort by display categories belonging to idFamily', () => { + // component.categoryList = CATEGORY_LIST; + // const sortedCategoryList: Category[] = component.getCategoryByFamilySortedByDisplay(1); + // expect(sortedCategoryList.length).toBe(2); + // expect(sortedCategoryList[0].id).toBe(2); + // expect(sortedCategoryList[1].id).toBe(1); + // }); + // + // it('#getSelectedOutputByCategory() should return selected attributes belonging to the given category', () => { + // component.attributeList = ATTRIBUTE_LIST; + // component.outputList = [1]; + // expect(component.getSelectedOutputByCategory(1).length).toEqual(1); + // component.outputList = []; + // expect(component.getSelectedOutputByCategory(1).length).toEqual(0); + // }); +}); diff --git a/client/src/app/instance/search/components/summary.component.ts b/client/src/app/instance/search/components/summary.component.ts index 10170ce92de91aa238a7afd542a5e2ddc565fe4a..dffa980e1f1ce337b5f230426d58028702817094 100644 --- a/client/src/app/instance/search/components/summary.component.ts +++ b/client/src/app/instance/search/components/summary.component.ts @@ -12,16 +12,16 @@ import { ChangeDetectionStrategy, Component, Input, ViewEncapsulation } from '@a import { Criterion, ConeSearch, SearchQueryParams, getPrettyCriterion } from '../../store/models'; import { Attribute, Dataset, CriteriaFamily, OutputFamily, OutputCategory } from 'src/app/metamodel/models'; +/** + * @class + * @classdesc Search summary component. + */ @Component({ selector: 'app-summary', templateUrl: 'summary.component.html', changeDetection: ChangeDetectionStrategy.OnPush, encapsulation: ViewEncapsulation.None }) -/** - * @class - * @classdesc Search summary component. - */ export class SummaryComponent { @Input() currentStep: string; @Input() datasetSelected: string; @@ -63,7 +63,7 @@ export class SummaryComponent { * * @param {number} id - The attribute ID. * - * @return Attribute[] + * @return Attribute */ getAttribute(id: number): Attribute { return this.attributeList.find(attribute => attribute.id === id); @@ -85,7 +85,7 @@ export class SummaryComponent { * * @param {number} idFamily - The family ID. * - * @return Category[] + * @return OutputCategory[] */ getCategoryByFamilySortedByDisplay(idFamily: number): OutputCategory[] { return this.outputCategoryList.filter(category => category.id_output_family === idFamily)