From 1294bb0e36640e1c82d188f2d82c98e5f2c074f5 Mon Sep 17 00:00:00 2001 From: Tifenn Guillas <tifenn.guillas@gmail.com> Date: Fri, 1 Oct 2021 15:37:41 +0200 Subject: [PATCH] WIP: Tests on result conponents --- .../components/progress-bar.component.spec.ts | 7 +- .../result/reminder.component.spec.ts | 416 ++++++++++++++++++ .../components/result/reminder.component.ts | 18 +- .../components/result/samp.component.spec.ts | 267 +++++++++++ .../components/result/samp.component.ts | 30 +- .../result/url-display.component.spec.ts | 288 ++++++++++++ .../result/url-display.component.ts | 13 +- 7 files changed, 1016 insertions(+), 23 deletions(-) create mode 100644 client/src/app/instance/search/components/result/reminder.component.spec.ts create mode 100644 client/src/app/instance/search/components/result/samp.component.spec.ts create mode 100644 client/src/app/instance/search/components/result/url-display.component.spec.ts diff --git a/client/src/app/instance/search/components/progress-bar.component.spec.ts b/client/src/app/instance/search/components/progress-bar.component.spec.ts index 3fe9d464..bd02e509 100644 --- a/client/src/app/instance/search/components/progress-bar.component.spec.ts +++ b/client/src/app/instance/search/components/progress-bar.component.spec.ts @@ -10,12 +10,7 @@ describe('[Instance][Search][Component] ProgressBarComponent', () => { beforeEach(() => { TestBed.configureTestingModule({ declarations: [ProgressBarComponent], - imports: [ - RouterTestingModule, - // AccordionModule.forRoot(), - // TooltipModule.forRoot(), - // BrowserAnimationsModule - ] + imports: [RouterTestingModule] }); fixture = TestBed.createComponent(ProgressBarComponent); component = fixture.componentInstance; diff --git a/client/src/app/instance/search/components/result/reminder.component.spec.ts b/client/src/app/instance/search/components/result/reminder.component.spec.ts new file mode 100644 index 00000000..9a639c1f --- /dev/null +++ b/client/src/app/instance/search/components/result/reminder.component.spec.ts @@ -0,0 +1,416 @@ +import { ComponentFixture, TestBed } from '@angular/core/testing'; +import { BrowserAnimationsModule } from '@angular/platform-browser/animations'; + +import { AccordionModule } from 'ngx-bootstrap/accordion'; + +import { ReminderComponent } from './reminder.component'; +import { FieldCriterion } from '../../../store/models/criterion'; +import { TabsModule } from 'ngx-bootstrap/tabs'; +import { Criterion } from '../../../store/models'; + +describe('[Instance][Search][Component][Result] ReminderComponent', () => { + let component: ReminderComponent; + let fixture: ComponentFixture<ReminderComponent>; + + beforeEach(() => { + TestBed.configureTestingModule({ + declarations: [ReminderComponent], + imports: [ + AccordionModule.forRoot(), + TabsModule.forRoot(), + BrowserAnimationsModule + ] + }); + fixture = TestBed.createComponent(ReminderComponent); + component = fixture.componentInstance; + }); + + it('should create the component', () => { + expect(component).toBeTruthy(); + }); + + it('#isSummaryActivated() should return if summary has to be enabled or not', () => { + component.datasetList = [ + { + name: 'myDataset', + table_ref: 'table', + label: 'my dataset', + description: 'This is my dataset', + display: 1, + data_path: '/path', + survey_name: 'mySurvey', + id_dataset_family: 1, + public: true, + full_data_path: '/data/path', + config: { + images: ['image1'], + survey: { + survey_enabled: true, + survey_label: 'More about this survey' + }, + 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: [{ id: 1, enabled: true, display: 1 }] + }, + download: { + download_enabled: true, + download_opened: true, + download_csv: true, + download_ascii: true, + download_vo: true, + download_archive: true + }, + summary: { + summary_enabled: false, + summary_opened: false + }, + server_link: { + server_link_enabled: false, + server_link_opened: true + }, + samp: { + samp_enabled: false, + samp_opened: false + }, + datatable: { + datatable_enabled: true, + datatable_opened: true, + datatable_selectable_rows: true + } + } + }, + { + name: 'anotherDataset', + table_ref: 'table', + label: 'another dataset', + description: 'This is another dataset', + display: 1, + data_path: '/path', + survey_name: 'mySurvey', + id_dataset_family: 1, + public: true, + full_data_path: '/data/path', + config: { + images: ['image1'], + survey: { + survey_enabled: true, + survey_label: 'More about this survey' + }, + 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: [{ id: 1, enabled: true, display: 1 }] + }, + 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.isSummaryActivated()).toBeFalsy(); + component.datasetSelected = 'anotherDataset'; + expect(component.isSummaryActivated()).toBeTruthy(); + }); + + it('#isSummaryOpened() should return if summary tab has to be opened or not', () => { + component.datasetList = [ + { + name: 'myDataset', + table_ref: 'table', + label: 'my dataset', + description: 'This is my dataset', + display: 1, + data_path: '/path', + survey_name: 'mySurvey', + id_dataset_family: 1, + public: true, + full_data_path: '/data/path', + config: { + images: ['image1'], + survey: { + survey_enabled: true, + survey_label: 'More about this survey' + }, + 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: [{ id: 1, enabled: true, display: 1 }] + }, + download: { + download_enabled: true, + download_opened: true, + download_csv: true, + download_ascii: true, + download_vo: true, + download_archive: true + }, + summary: { + summary_enabled: false, + summary_opened: false + }, + server_link: { + server_link_enabled: false, + server_link_opened: false + }, + samp: { + samp_enabled: false, + samp_opened: false + }, + datatable: { + datatable_enabled: true, + datatable_opened: true, + datatable_selectable_rows: true + } + } + }, + { + name: 'anotherDataset', + table_ref: 'table', + label: 'another dataset', + description: 'This is another dataset', + display: 1, + data_path: '/path', + survey_name: 'mySurvey', + id_dataset_family: 1, + public: true, + full_data_path: '/data/path', + config: { + images: ['image1'], + survey: { + survey_enabled: true, + survey_label: 'More about this survey' + }, + 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: [{ id: 1, enabled: true, display: 1 }] + }, + 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.isSummaryOpened()).toBeFalsy(); + component.datasetSelected = 'anotherDataset'; + expect(component.isSummaryOpened()).toBeTruthy(); + }); + + it('#nbCriteria() should return criteria amount', () => { + component.criteriaList = []; + expect(component.nbCriteria()).toEqual(0); + component.coneSearch = { ra: 1, dec: 2, radius: 3 }; + expect(component.nbCriteria()).toEqual(1); + }); + + it('#criteriaByFamily() should return criteria for the given family', () => { + 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_criteria_family: 2 + }, + { + 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, + id_criteria_family: 1 + } + ]; + component.criteriaList = [ + {'id':1,'type':'field','operator':'eq','value':'one'} as FieldCriterion, + {'id':2,'type':'field','operator':'eq','value':'two'} as FieldCriterion + ]; + expect(component.criteriaByFamily(1).length).toEqual(1); + expect(component.criteriaByFamily(1)[0].id).toEqual(1); + }); + + it('#getAttribute() should return the attribute with the given id', () => { + 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 + } + ]; + expect(component.getAttribute(1).name).toBe('name_one'); + }); + + it('#printCriterion() should return pretty criterion', () => { + const criterion: Criterion = {'id':1,'type':'field','operator':'eq','value':'one'} as FieldCriterion; + expect(component.printCriterion(criterion)).toBe('= one'); + }); + + it('#categoryListByFamily() should return output categories for the given output family', () => { + component.outputCategoryList = [ + { + id: 3, + label: 'The last output category', + display: 30, + id_output_family: 2 + }, + { + id: 1, + label: 'Another output category', + display: 10, + id_output_family: 1 + }, + { + id: 2, + label: 'Default output category', + display: 20, + id_output_family: 1 + } + ]; + expect(component.categoryListByFamily(1).length).toEqual(2); + expect(component.categoryListByFamily(1)[0].id).toEqual(1); + expect(component.categoryListByFamily(1)[1].id).toEqual(2); + }); + + it('#outputListByCategory() should return outputs for the given output category', () => { + 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_output_category: 2 + }, + { + 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, + id_output_category: 1 + } + ]; + component.outputList = [1, 2]; + expect(component.outputListByCategory(1).length).toEqual(1); + expect(component.outputListByCategory(1)[0]).toEqual(1); + }); +}); diff --git a/client/src/app/instance/search/components/result/reminder.component.ts b/client/src/app/instance/search/components/result/reminder.component.ts index 8e3d88ea..844b1f54 100644 --- a/client/src/app/instance/search/components/result/reminder.component.ts +++ b/client/src/app/instance/search/components/result/reminder.component.ts @@ -12,15 +12,15 @@ import { Component, Input } from '@angular/core'; import { Criterion, ConeSearch, getPrettyCriterion } from 'src/app/instance/store/models'; import { Dataset, Attribute, CriteriaFamily, OutputFamily, OutputCategory } from 'src/app/metamodel/models'; +/** + * @class + * @classdesc Search result reminder component. + */ @Component({ selector: 'app-reminder', templateUrl: 'reminder.component.html', styleUrls: ['reminder.component.scss'] }) -/** - * @class - * @classdesc Search result reminder component. - */ export class ReminderComponent { @Input() datasetSelected: string; @Input() datasetList: Dataset[]; @@ -32,11 +32,21 @@ export class ReminderComponent { @Input() coneSearch: ConeSearch; @Input() outputList: number[]; + /** + * Checks if reminder has to be display. + * + * @return boolean + */ isSummaryActivated(): boolean { const dataset = this.datasetList.find(dataset => dataset.name === this.datasetSelected); return dataset.config.summary.summary_enabled; } + /** + * Checks if reminder has to be open. + * + * @return boolean + */ isSummaryOpened(): boolean { const dataset = this.datasetList.find(dataset => dataset.name === this.datasetSelected); return dataset.config.summary.summary_opened; diff --git a/client/src/app/instance/search/components/result/samp.component.spec.ts b/client/src/app/instance/search/components/result/samp.component.spec.ts new file mode 100644 index 00000000..dfb4e4f0 --- /dev/null +++ b/client/src/app/instance/search/components/result/samp.component.spec.ts @@ -0,0 +1,267 @@ +import { ComponentFixture, TestBed } from '@angular/core/testing'; +import { BrowserAnimationsModule } from '@angular/platform-browser/animations'; + +import { AccordionModule } from 'ngx-bootstrap/accordion'; + +import { SampComponent } from './samp.component'; + +describe('[Instance][Search][Component][Result] SampComponent', () => { + let component: SampComponent; + let fixture: ComponentFixture<SampComponent>; + + beforeEach(() => { + TestBed.configureTestingModule({ + declarations: [SampComponent], + imports: [ + AccordionModule.forRoot(), + BrowserAnimationsModule + ] + }); + fixture = TestBed.createComponent(SampComponent); + component = fixture.componentInstance; + }); + + it('should create the component', () => { + expect(component).toBeTruthy(); + }); + + it('#isSampActivated() should return if SAMP has to be enabled or not', () => { + component.datasetList = [ + { + name: 'myDataset', + table_ref: 'table', + label: 'my dataset', + description: 'This is my dataset', + display: 1, + data_path: '/path', + survey_name: 'mySurvey', + id_dataset_family: 1, + public: true, + full_data_path: '/data/path', + config: { + images: ['image1'], + survey: { + survey_enabled: true, + survey_label: 'More about this survey' + }, + 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: [{ id: 1, enabled: true, display: 1 }] + }, + 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: false, + server_link_opened: true + }, + samp: { + samp_enabled: false, + samp_opened: false + }, + datatable: { + datatable_enabled: true, + datatable_opened: true, + datatable_selectable_rows: true + } + } + }, + { + name: 'anotherDataset', + table_ref: 'table', + label: 'another dataset', + description: 'This is another dataset', + display: 1, + data_path: '/path', + survey_name: 'mySurvey', + id_dataset_family: 1, + public: true, + full_data_path: '/data/path', + config: { + images: ['image1'], + survey: { + survey_enabled: true, + survey_label: 'More about this survey' + }, + 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: [{ id: 1, enabled: true, display: 1 }] + }, + 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.isSampActivated()).toBeFalsy(); + component.datasetSelected = 'anotherDataset'; + expect(component.isSampActivated()).toBeTruthy(); + }); + + it('#isSampOpened() should return if URL tab has to be opened or not', () => { + component.datasetList = [ + { + name: 'myDataset', + table_ref: 'table', + label: 'my dataset', + description: 'This is my dataset', + display: 1, + data_path: '/path', + survey_name: 'mySurvey', + id_dataset_family: 1, + public: true, + full_data_path: '/data/path', + config: { + images: ['image1'], + survey: { + survey_enabled: true, + survey_label: 'More about this survey' + }, + 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: [{ id: 1, enabled: true, display: 1 }] + }, + 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: false, + server_link_opened: false + }, + samp: { + samp_enabled: false, + samp_opened: false + }, + datatable: { + datatable_enabled: true, + datatable_opened: true, + datatable_selectable_rows: true + } + } + }, + { + name: 'anotherDataset', + table_ref: 'table', + label: 'another dataset', + description: 'This is another dataset', + display: 1, + data_path: '/path', + survey_name: 'mySurvey', + id_dataset_family: 1, + public: true, + full_data_path: '/data/path', + config: { + images: ['image1'], + survey: { + survey_enabled: true, + survey_label: 'More about this survey' + }, + 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: [{ id: 1, enabled: true, display: 1 }] + }, + 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.isSampOpened()).toBeFalsy(); + component.datasetSelected = 'anotherDataset'; + expect(component.isSampOpened()).toBeTruthy(); + }); + + it('#getColor() should return color button depending on SAMP registered or not', () => { + expect(component.getColor()).toEqual('red'); + component.sampRegistered = true; + expect(component.getColor()).toEqual('green'); + }); +}); diff --git a/client/src/app/instance/search/components/result/samp.component.ts b/client/src/app/instance/search/components/result/samp.component.ts index fb96f57e..8c830c41 100644 --- a/client/src/app/instance/search/components/result/samp.component.ts +++ b/client/src/app/instance/search/components/result/samp.component.ts @@ -11,15 +11,15 @@ import { Component, Input, ChangeDetectionStrategy, Output, EventEmitter } from import { Dataset } from 'src/app/metamodel/models'; +/** + * @class + * @classdesc Samp component. + */ @Component({ selector: 'app-samp', templateUrl: 'samp.component.html', changeDetection: ChangeDetectionStrategy.OnPush }) -/** - * @class - * @classdesc Samp component. - */ export class SampComponent { @Input() datasetSelected: string; @Input() datasetList: Dataset[]; @@ -27,21 +27,33 @@ export class SampComponent { @Output() sampRegister: EventEmitter<{}> = new EventEmitter(); @Output() sampUnregister: EventEmitter<{}> = new EventEmitter(); + /** + * Checks if SAMP has to be display. + * + * @return boolean + */ isSampActivated(): boolean { const dataset = this.datasetList.find(dataset => dataset.name === this.datasetSelected); return dataset.config.samp.samp_enabled; } + /** + * Checks if SAMP tab has to be opened. + * + * @return boolean + */ isSampOpened(): boolean { const dataset = this.datasetList.find(dataset => dataset.name === this.datasetSelected); return dataset.config.samp.samp_opened; } + /** + * Returns SAMP color button. + * + * @return boolean + */ getColor(): string { - if (this.sampRegistered) { - return 'green'; - } else { - return 'red'; - } + if (this.sampRegistered) return 'green'; + return 'red'; } } diff --git a/client/src/app/instance/search/components/result/url-display.component.spec.ts b/client/src/app/instance/search/components/result/url-display.component.spec.ts new file mode 100644 index 00000000..5d47e352 --- /dev/null +++ b/client/src/app/instance/search/components/result/url-display.component.spec.ts @@ -0,0 +1,288 @@ +import { ComponentFixture, TestBed } from '@angular/core/testing'; +import { BrowserAnimationsModule } from '@angular/platform-browser/animations'; + +import { AccordionModule } from 'ngx-bootstrap/accordion'; +import { ToastrService } from 'ngx-toastr'; + +import { UrlDisplayComponent } from './url-display.component'; +import { AppConfigService } from '../../../../app-config.service'; +import { FieldCriterion } from '../../../store/models/criterion'; + +describe('[Instance][Search][Component][Result] UrlDisplayComponent', () => { + let component: UrlDisplayComponent; + let fixture: ComponentFixture<UrlDisplayComponent>; + let appConfigServiceStub = new AppConfigService(); + + beforeEach(() => { + TestBed.configureTestingModule({ + declarations: [UrlDisplayComponent], + imports: [ + AccordionModule.forRoot(), + BrowserAnimationsModule + ], + providers: [ + { provide: AppConfigService, useValue: appConfigServiceStub }, + { provide: ToastrService, useValue: { }} + ] + }); + fixture = TestBed.createComponent(UrlDisplayComponent); + component = fixture.componentInstance; + }); + + it('should create the component', () => { + expect(component).toBeTruthy(); + }); + + it('#urlDisplayEnabled() should return if URL display has to be enabled or not', () => { + component.datasetList = [ + { + name: 'myDataset', + table_ref: 'table', + label: 'my dataset', + description: 'This is my dataset', + display: 1, + data_path: '/path', + survey_name: 'mySurvey', + id_dataset_family: 1, + public: true, + full_data_path: '/data/path', + config: { + images: ['image1'], + survey: { + survey_enabled: true, + survey_label: 'More about this survey' + }, + 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: [{ id: 1, enabled: true, display: 1 }] + }, + 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: false, + 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: 'table', + label: 'another dataset', + description: 'This is another dataset', + display: 1, + data_path: '/path', + survey_name: 'mySurvey', + id_dataset_family: 1, + public: true, + full_data_path: '/data/path', + config: { + images: ['image1'], + survey: { + survey_enabled: true, + survey_label: 'More about this survey' + }, + 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: [{ id: 1, enabled: true, display: 1 }] + }, + 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.urlDisplayEnabled()).toBeFalsy(); + component.datasetSelected = 'anotherDataset'; + expect(component.urlDisplayEnabled()).toBeTruthy(); + }); + + it('#urlDisplayOpened() should return if URL tab has to be opened or not', () => { + component.datasetList = [ + { + name: 'myDataset', + table_ref: 'table', + label: 'my dataset', + description: 'This is my dataset', + display: 1, + data_path: '/path', + survey_name: 'mySurvey', + id_dataset_family: 1, + public: true, + full_data_path: '/data/path', + config: { + images: ['image1'], + survey: { + survey_enabled: true, + survey_label: 'More about this survey' + }, + 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: [{ id: 1, enabled: true, display: 1 }] + }, + 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: false, + server_link_opened: false + }, + samp: { + samp_enabled: true, + samp_opened: true + }, + datatable: { + datatable_enabled: true, + datatable_opened: true, + datatable_selectable_rows: true + } + } + }, + { + name: 'anotherDataset', + table_ref: 'table', + label: 'another dataset', + description: 'This is another dataset', + display: 1, + data_path: '/path', + survey_name: 'mySurvey', + id_dataset_family: 1, + public: true, + full_data_path: '/data/path', + config: { + images: ['image1'], + survey: { + survey_enabled: true, + survey_label: 'More about this survey' + }, + 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: [{ id: 1, enabled: true, display: 1 }] + }, + 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.urlDisplayOpened()).toBeFalsy(); + component.datasetSelected = 'anotherDataset'; + expect(component.urlDisplayOpened()).toBeTruthy(); + }); + + it('#getUrl() should construct url', () => { + appConfigServiceStub.apiUrl = 'http://test.com'; + component.datasetSelected = 'dataset'; + component.outputList = [1, 2, 3]; + component.criteriaList = []; + let url = component.getUrl(); + expect(url).toBe('http://test.com/search/dataset?a=1;2;3'); + 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 + ]; + url = component.getUrl(); + expect(url).toBe('http://test.com/search/dataset?a=1;2;3&c=1::eq::fd_crit_1;2::eq::fd_crit_2'); + component.criteriaList = []; + component.coneSearch = { ra: 4, dec: 5, radius: 6 }; + url = component.getUrl(); + expect(url).toBe('http://test.com/search/dataset?a=1;2;3&cs=4:5:6'); + }); +}); diff --git a/client/src/app/instance/search/components/result/url-display.component.ts b/client/src/app/instance/search/components/result/url-display.component.ts index d5ef1c03..9cd35d7a 100644 --- a/client/src/app/instance/search/components/result/url-display.component.ts +++ b/client/src/app/instance/search/components/result/url-display.component.ts @@ -16,15 +16,15 @@ import { Dataset } from 'src/app/metamodel/models'; import { getHost as host } from 'src/app/shared/utils'; import { AppConfigService } from 'src/app/app-config.service'; +/** + * @class + * @classdesc Search result URL display component. + */ @Component({ selector: 'app-url-display', templateUrl: 'url-display.component.html', changeDetection: ChangeDetectionStrategy.OnPush }) -/** - * @class - * @classdesc Search result URL display component. - */ export class UrlDisplayComponent { @Input() datasetSelected: string; @Input() datasetList: Dataset[]; @@ -44,6 +44,11 @@ export class UrlDisplayComponent { return config.server_link.server_link_enabled; } + /** + * Checks if URL tab has to be opened. + * + * @return boolean + */ urlDisplayOpened(): boolean { const config = this.datasetList.find(d => d.name === this.datasetSelected).config; return config.server_link.server_link_opened; -- GitLab