Skip to content
Snippets Groups Projects
Commit 2bf2d975 authored by Tifenn Guillas's avatar Tifenn Guillas
Browse files

Tests on search result components => DONE

parent 1294bb0e
No related branches found
No related tags found
2 merge requests!29Develop,!18Resolve "Add tests for instance search module"
import { Component, Input } from '@angular/core';
import { ComponentFixture, TestBed } from '@angular/core/testing';
import { BrowserAnimationsModule } from '@angular/platform-browser/animations';
import { AccordionModule } from 'ngx-bootstrap/accordion';
import { DatatableTabComponent } from './datatable-tab.component';
import { Attribute, Dataset, Instance } from '../../../../metamodel/models';
import { SearchQueryParams } from '../../../store/models';
import { DatasetByNamePipe } from '../../../../shared/pipes/dataset-by-name.pipe';
describe('[Instance][Search][Component][Result] DatatableTabComponent', () => {
@Component({ selector: 'app-datatable', template: '' })
class DatatableStubComponent {
@Input() dataset: Dataset;
@Input() instance: Instance;
@Input() attributeList: Attribute[];
@Input() outputList: number[];
@Input() queryParams: SearchQueryParams;
@Input() dataLength: number;
@Input() data: any[];
@Input() dataIsLoading: boolean;
@Input() dataIsLoaded: boolean;
@Input() selectedData: any[] = [];
}
let component: DatatableTabComponent;
let fixture: ComponentFixture<DatatableTabComponent>;
beforeEach(() => {
TestBed.configureTestingModule({
declarations: [
DatatableTabComponent,
DatatableStubComponent,
DatasetByNamePipe
],
imports: [
AccordionModule.forRoot(),
BrowserAnimationsModule
]
});
fixture = TestBed.createComponent(DatatableTabComponent);
component = fixture.componentInstance;
});
it('should create the component', () => {
expect(component).toBeTruthy();
});
});
...@@ -12,15 +12,15 @@ import { ChangeDetectionStrategy, Component, EventEmitter, Input, Output } from ...@@ -12,15 +12,15 @@ import { ChangeDetectionStrategy, Component, EventEmitter, Input, Output } from
import { Instance, Attribute, Dataset } from 'src/app/metamodel/models'; import { Instance, Attribute, Dataset } from 'src/app/metamodel/models';
import { Pagination, SearchQueryParams } from 'src/app/instance/store/models'; import { Pagination, SearchQueryParams } from 'src/app/instance/store/models';
/**
* @class
* @classdesc Search result datatable tab component.
*/
@Component({ @Component({
selector: 'app-datatable-tab', selector: 'app-datatable-tab',
templateUrl: 'datatable-tab.component.html', templateUrl: 'datatable-tab.component.html',
changeDetection: ChangeDetectionStrategy.OnPush changeDetection: ChangeDetectionStrategy.OnPush
}) })
/**
* @class
* @classdesc Search result datatable tab component.
*/
export class DatatableTabComponent { export class DatatableTabComponent {
@Input() datasetSelected: string; @Input() datasetSelected: string;
@Input() instance: Instance; @Input() instance: Instance;
......
import { ComponentFixture, TestBed } from '@angular/core/testing';
import { BrowserAnimationsModule } from '@angular/platform-browser/animations';
import { HttpClientTestingModule } from '@angular/common/http/testing';
import { AccordionModule } from 'ngx-bootstrap/accordion';
import { DownloadComponent } from './download.component';
import { AppConfigService } from '../../../../app-config.service';
import { FieldCriterion } from '../../../store/models/criterion';
describe('[Instance][Search][Component][Result] DownloadComponent', () => {
let component: DownloadComponent;
let fixture: ComponentFixture<DownloadComponent>;
let appConfigServiceStub = new AppConfigService();
beforeEach(() => {
TestBed.configureTestingModule({
declarations: [DownloadComponent],
imports: [
HttpClientTestingModule,
AccordionModule.forRoot(),
BrowserAnimationsModule
],
providers: [{ provide: AppConfigService, useValue: appConfigServiceStub }]
});
fixture = TestBed.createComponent(DownloadComponent);
component = fixture.componentInstance;
});
it('should create the component', () => {
expect(component).toBeTruthy();
});
it('#isDownloadActivated() should return if download section 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: false,
download_opened: false,
download_csv: false,
download_ascii: false,
download_vo: false,
download_archive: false
},
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.isDownloadActivated()).toBeTruthy();
component.datasetSelected = 'anotherDataset';
expect(component.isDownloadActivated()).toBeFalsy();
});
it('#isDownloadOpened() should return if download 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: false,
download_opened: false,
download_csv: false,
download_ascii: false,
download_vo: false,
download_archive: false
},
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.isDownloadOpened()).toBeTruthy();
component.datasetSelected = 'anotherDataset';
expect(component.isDownloadOpened()).toBeFalsy();
});
it('#getConfigDownloadResultFormat() should return if download button for the given format has to be displayed', () => {
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: false,
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: false,
download_opened: false,
download_csv: false,
download_ascii: false,
download_vo: false,
download_archive: false
},
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.getConfigDownloadResultFormat('download_csv')).toBeTruthy();
expect(component.getConfigDownloadResultFormat('download_ascii')).toBeFalsy();
});
it('#getUrl(format) should construct url with format parameter', () => {
appConfigServiceStub.apiUrl = 'http://test.com';
component.datasetSelected = 'myDataset';
component.outputList = [1, 2, 3];
component.criteriaList = [];
expect(component.getUrl('csv')).toBe('http://test.com/search/myDataset?a=1;2;3&f=csv');
component.criteriaList = [
{'id':1,'type':'field','operator':'eq','value':'one'} as FieldCriterion,
{'id':2,'type':'field','operator':'eq','value':'two'} as FieldCriterion
];
component.coneSearch = { ra: 4, dec: 5, radius: 6 };
expect(component.getUrl('csv')).toBe('http://test.com/search/myDataset?a=1;2;3&c=1::eq::one;2::eq::two&cs=4:5:6&f=csv');
});
it('#getUrlArchive() should construct url to access to archive', () => {
appConfigServiceStub.apiUrl = 'http://test.com';
component.datasetSelected = 'myDataset';
component.outputList = [1, 2, 3];
component.criteriaList = [
{'id':1,'type':'field','operator':'eq','value':'one'} as FieldCriterion,
{'id':2,'type':'field','operator':'eq','value':'two'} as FieldCriterion
];
component.coneSearch = { ra: 4, dec: 5, radius: 6 };
expect(component.getUrlArchive()).toBe('http://test.com/archive/myDataset?a=1;2;3&c=1::eq::one;2::eq::two&cs=4:5:6');
});
it('#broadcastVotable() should raise broadcast event when clicked', () => {
appConfigServiceStub.apiUrl = 'http://test.com';
component.datasetSelected = 'myDataset';
component.outputList = [1, 2, 3];
component.criteriaList = [];
component.broadcast.subscribe((event: string) => expect(event).toEqual('toto'));
component.broadcastVotable();
});
});
...@@ -15,16 +15,14 @@ import { Dataset } from 'src/app/metamodel/models'; ...@@ -15,16 +15,14 @@ import { Dataset } from 'src/app/metamodel/models';
import { getHost as host } from 'src/app/shared/utils'; import { getHost as host } from 'src/app/shared/utils';
import { AppConfigService } from 'src/app/app-config.service'; import { AppConfigService } from 'src/app/app-config.service';
@Component({
selector: 'app-download',
templateUrl: 'download.component.html'
})
/** /**
* @class * @class
* @classdesc Search result download component. * @classdesc Search result download component.
*
* @implements OnInit
*/ */
@Component({
selector: 'app-download',
templateUrl: 'download.component.html'
})
export class DownloadComponent { export class DownloadComponent {
@Input() datasetSelected: string; @Input() datasetSelected: string;
@Input() datasetList: Dataset[]; @Input() datasetList: Dataset[];
...@@ -37,11 +35,21 @@ export class DownloadComponent { ...@@ -37,11 +35,21 @@ export class DownloadComponent {
constructor(private appConfig: AppConfigService, private http: HttpClient) { } constructor(private appConfig: AppConfigService, private http: HttpClient) { }
/**
* Checks if download tab has to be display.
*
* @return boolean
*/
isDownloadActivated(): boolean { isDownloadActivated(): boolean {
const dataset = this.datasetList.find(dataset => dataset.name === this.datasetSelected); const dataset = this.datasetList.find(dataset => dataset.name === this.datasetSelected);
return dataset.config.download.download_enabled; return dataset.config.download.download_enabled;
} }
/**
* Checks if download tab has to be open.
*
* @return boolean
*/
isDownloadOpened(): boolean { isDownloadOpened(): boolean {
const dataset = this.datasetList.find(dataset => dataset.name === this.datasetSelected); const dataset = this.datasetList.find(dataset => dataset.name === this.datasetSelected);
return dataset.config.download.download_opened; return dataset.config.download.download_opened;
...@@ -78,6 +86,11 @@ export class DownloadComponent { ...@@ -78,6 +86,11 @@ export class DownloadComponent {
return query; return query;
} }
/**
* Returns URL to download archive.
*
* @return boolean
*/
getUrlArchive(): string { getUrlArchive(): string {
let query: string = host(this.appConfig.apiUrl) + '/archive/' + this.datasetSelected + '?a=' + this.outputList.join(';'); let query: string = host(this.appConfig.apiUrl) + '/archive/' + this.datasetSelected + '?a=' + this.outputList.join(';');
if (this.criteriaList.length > 0) { if (this.criteriaList.length > 0) {
...@@ -88,12 +101,20 @@ export class DownloadComponent { ...@@ -88,12 +101,20 @@ export class DownloadComponent {
} }
return query; return query;
} }
/**
* Emits event to action to broadcast data.
*
* @fires EventEmitter<string>
*/
broadcastVotable(): void { broadcastVotable(): void {
this.broadcast.emit(this.getUrl('votable')); this.broadcast.emit(this.getUrl('votable'));
} }
click(event, href, extension) { /**
* Allows to download file.
*/
click(event, href, extension): void {
event.preventDefault(); event.preventDefault();
this.http.get(href, {responseType: "blob"}).subscribe( this.http.get(href, {responseType: "blob"}).subscribe(
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment