From 0519fc221ecd0c6338641064be27b4dc1d485d15 Mon Sep 17 00:00:00 2001 From: Tifenn Guillas <tifenn.guillas@gmail.com> Date: Wed, 27 Oct 2021 11:24:55 +0200 Subject: [PATCH] Tests for shared search detail components => DONE --- .../default/default-object.component.spec.ts | 34 ++++ .../default/default-object.component.ts | 8 +- .../detail/components/spectra/graph/rays.ts | 192 +++++++++--------- .../spectra/spectra-object.component.spec.ts | 90 ++++++++ .../spectra/spectra-object.component.ts | 14 +- client/src/test-data.ts | 8 +- 6 files changed, 238 insertions(+), 108 deletions(-) create mode 100644 client/src/app/instance/shared-search/detail/components/default/default-object.component.spec.ts create mode 100644 client/src/app/instance/shared-search/detail/components/spectra/spectra-object.component.spec.ts diff --git a/client/src/app/instance/shared-search/detail/components/default/default-object.component.spec.ts b/client/src/app/instance/shared-search/detail/components/default/default-object.component.spec.ts new file mode 100644 index 00000000..e665ccd8 --- /dev/null +++ b/client/src/app/instance/shared-search/detail/components/default/default-object.component.spec.ts @@ -0,0 +1,34 @@ +import { ComponentFixture, TestBed, waitForAsync } from '@angular/core/testing'; +import { Component, Input } from '@angular/core'; + +import { DefaultObjectComponent } from './default-object.component'; +import { Attribute, OutputCategory, OutputFamily } from '../../../../../metamodel/models'; + +describe('[Instance][SharedSearch][Detail][Component][Default] DefaultObjectComponent', () => { + @Component({ selector: 'app-object-data', template: '' }) + class ObjectDataStubComponent { + @Input() datasetSelected: string; + @Input() outputFamilyList: OutputFamily[]; + @Input() outputCategoryList: OutputCategory[]; + @Input() attributeList: Attribute[]; + @Input() object: any; + } + + let component: DefaultObjectComponent; + let fixture: ComponentFixture<DefaultObjectComponent>; + + beforeEach(waitForAsync(() => { + TestBed.configureTestingModule({ + declarations: [ + DefaultObjectComponent, + ObjectDataStubComponent + ] + }); + fixture = TestBed.createComponent(DefaultObjectComponent); + component = fixture.componentInstance; + })); + + it('should create the component', () => { + expect(component).toBeTruthy(); + }); +}); diff --git a/client/src/app/instance/shared-search/detail/components/default/default-object.component.ts b/client/src/app/instance/shared-search/detail/components/default/default-object.component.ts index 058a6eda..b690b814 100644 --- a/client/src/app/instance/shared-search/detail/components/default/default-object.component.ts +++ b/client/src/app/instance/shared-search/detail/components/default/default-object.component.ts @@ -11,15 +11,15 @@ import { Component, Input, ChangeDetectionStrategy } from '@angular/core'; import { Attribute, OutputFamily, OutputCategory } from 'src/app/metamodel/models'; +/** + * @class + * @classdesc Detail default object component. + */ @Component({ selector: 'app-default-object', templateUrl: 'default-object.component.html', changeDetection: ChangeDetectionStrategy.OnPush }) -/** - * @class - * @classdesc Detail default object component. - */ export class DefaultObjectComponent { @Input() datasetSelected: string; @Input() outputFamilyList: OutputFamily[]; diff --git a/client/src/app/instance/shared-search/detail/components/spectra/graph/rays.ts b/client/src/app/instance/shared-search/detail/components/spectra/graph/rays.ts index 8dbba2bc..440d7c54 100644 --- a/client/src/app/instance/shared-search/detail/components/spectra/graph/rays.ts +++ b/client/src/app/instance/shared-search/detail/components/spectra/graph/rays.ts @@ -7,102 +7,102 @@ * file that was distributed with this source code. */ - export const emissionLines = [ - {name: 'SII', wavelength: 10320}, - {name: 'HeI', wavelength: 7065.2}, - {name: 'SII', wavelength: 6732.68}, - {name: 'SII', wavelength: 6718.39}, - {name: 'NII', wavelength: 6585.27}, - {name: 'Hα', wavelength: 6564.61}, - {name: 'NII', wavelength: 6549.86}, - {name: 'HeI', wavelength: 5876.0}, - {name: 'OIII', wavelength: 5008.24}, - {name: 'OIII', wavelength: 4960.29}, - {name: 'Hβ', wavelength: 4862.70}, - {name: 'OIII', wavelength: 4364.44}, - {name: 'Hγ', wavelength: 4341.68}, - {name: 'Hδ', wavelength: 4102.89}, - {name: 'SII', wavelength: 4072.0}, - {name: 'Hksi', wavelength: 3890.15}, - {name: 'NeIII', wavelength: 3869.81}, - {name: 'H9', wavelength: 3836.47}, - {name: 'Hθ', wavelength: 3798.98}, - {name: 'H11', wavelength: 3771.70}, - {name: 'OII', wavelength: 3728.49}, - {name: 'NeV', wavelength: 3426.5}, - {name: 'NeV', wavelength: 3346.4}, - {name: 'HeII', wavelength: 3204.03}, - {name: 'FeII', wavelength: 2964.0}, - {name: 'MgII', wavelength: 2799.0}, - {name: 'NII', wavelength: 2142.0}, - {name: 'CIII', wavelength: 1908.73}, - {name: 'HeII', wavelength: 1640.42}, - {name: 'CIV', wavelength: 1549.0}, - {name: 'SiIV', wavelength: 1397.0}, - {name: 'CII', wavelength: 1334.53}, - {name: 'OI', wavelength: 1303.0}, - {name: 'NV', wavelength: 1240.0}, - {name: 'LyA', wavelength: 1215.67}, - {name: 'OVI', wavelength: 1033.0}, - {name: 'LyB', wavelength: 1025.72}, - {name: 'LyG', wavelength: 972.53} + export const emissionLines: { name: string, wavelength: number }[] = [ + { name: 'SII', wavelength: 10320 }, + { name: 'HeI', wavelength: 7065.2 }, + { name: 'SII', wavelength: 6732.68 }, + { name: 'SII', wavelength: 6718.39 }, + { name: 'NII', wavelength: 6585.27 }, + { name: 'Hα', wavelength: 6564.61 }, + { name: 'NII', wavelength: 6549.86 }, + { name: 'HeI', wavelength: 5876.0 }, + { name: 'OIII', wavelength: 5008.24 }, + { name: 'OIII', wavelength: 4960.29 }, + { name: 'Hβ', wavelength: 4862.70 }, + { name: 'OIII', wavelength: 4364.44 }, + { name: 'Hγ', wavelength: 4341.68 }, + { name: 'Hδ', wavelength: 4102.89 }, + { name: 'SII', wavelength: 4072.0 }, + { name: 'Hksi', wavelength: 3890.15 }, + { name: 'NeIII', wavelength: 3869.81 }, + { name: 'H9', wavelength: 3836.47 }, + { name: 'Hθ', wavelength: 3798.98 }, + { name: 'H11', wavelength: 3771.70 }, + { name: 'OII', wavelength: 3728.49 }, + { name: 'NeV', wavelength: 3426.5 }, + { name: 'NeV', wavelength: 3346.4 }, + { name: 'HeII', wavelength: 3204.03 }, + { name: 'FeII', wavelength: 2964.0 }, + { name: 'MgII', wavelength: 2799.0 }, + { name: 'NII', wavelength: 2142.0 }, + { name: 'CIII', wavelength: 1908.73 }, + { name: 'HeII', wavelength: 1640.42 }, + { name: 'CIV', wavelength: 1549.0 }, + { name: 'SiIV', wavelength: 1397.0 }, + { name: 'CII', wavelength: 1334.53 }, + { name: 'OI', wavelength: 1303.0 }, + { name: 'NV', wavelength: 1240.0 }, + { name: 'LyA', wavelength: 1215.67 }, + { name: 'OVI', wavelength: 1033.0 }, + { name: 'LyB', wavelength: 1025.72 }, + { name: 'LyG', wavelength: 972.53 } ]; -export const absorptionLines = [ - {name: 'TiO', wavelength: 8863.0}, - {name: 'TiO', wavelength: 8430.0}, - {name: 'NaI', wavelength: 8197.05}, - {name: 'NaI', wavelength: 8185.50}, - {name: 'TiO', wavelength: 7590.0}, - {name: 'HeI', wavelength: 7065.2}, - {name: 'Hα', wavelength: 6564.61}, - {name: 'TiO', wavelength: 6159.0}, - {name: 'NaD', wavelength: 5892.5}, - {name: 'TiO', wavelength: 5603.0}, - {name: 'Ca,Fe', wavelength: 5269.0}, - {name: 'MgI', wavelength: 5174.12}, - {name: 'Hβ', wavelength: 4862.70}, - {name: 'Hγ', wavelength: 4341.68}, - {name: 'Gband', wavelength: 4304.4}, - {name: 'CN', wavelength: 4216.0}, - {name: 'Hδ', wavelength: 4102.89}, - {name: 'CaII_H', wavelength: 3969.59}, - {name: 'CaII_K', wavelength: 3934.78}, - {name: 'Hksi', wavelength: 3890.15}, - {name: 'H9', wavelength: 3836.47}, - {name: 'Hθ', wavelength: 3798.98}, - {name: 'H11', wavelength: 3771.70}, - {name: 'FeI', wavelength: 3581.0}, - {name: 'HeII', wavelength: 3204.03}, - {name: 'FeII', wavelength: 2964.0}, - {name: 'MgII', wavelength: 2796.35}, - {name: 'MgII', wavelength: 2803.53}, - {name: 'FeII', wavelength: 2626.45}, - {name: 'FeII', wavelength: 2600.17}, - {name: 'FeII', wavelength: 2586.65}, - {name: 'FeII', wavelength: 2382.76}, - {name: 'FeII', wavelength: 2374.46}, - {name: 'FeII', wavelength: 2344.21}, - {name: 'FeII', wavelength: 2260.78}, - {name: 'AlIII', wavelength: 1854.72}, - {name: 'AlII', wavelength: 1670.78}, - {name: 'HeII', wavelength: 1640.42}, - {name: 'FeII', wavelength: 1608.45}, - {name: 'CIV', wavelength: 1548.20}, - {name: 'CIV', wavelength: 1550.77}, - {name: 'SiII', wavelength: 1533.43}, - {name: 'SiII', wavelength: 1526.71}, - {name: 'SiIV', wavelength: 1402.77}, - {name: 'SiIV', wavelength: 1393.75}, - {name: 'CII', wavelength: 1334.53}, - {name: 'OI', wavelength: 1302.17}, - {name: 'OI', wavelength: 1304.86}, - {name: 'SiII', wavelength: 1260.42}, - {name: 'NV', wavelength: 1238.82}, - {name: 'NV', wavelength: 1242.80}, - {name: 'LyA', wavelength: 1215.67}, - {name: 'OVI', wavelength: 1037.62}, - {name: 'OVI', wavelength: 1031.93}, - {name: 'LyB', wavelength: 1025.72}, - {name: 'LyG', wavelength: 972.53} +export const absorptionLines: { name: string, wavelength: number }[] = [ + { name: 'TiO', wavelength: 8863.0 }, + { name: 'TiO', wavelength: 8430.0 }, + { name: 'NaI', wavelength: 8197.05 }, + { name: 'NaI', wavelength: 8185.50 }, + { name: 'TiO', wavelength: 7590.0 }, + { name: 'HeI', wavelength: 7065.2 }, + { name: 'Hα', wavelength: 6564.61 }, + { name: 'TiO', wavelength: 6159.0 }, + { name: 'NaD', wavelength: 5892.5 }, + { name: 'TiO', wavelength: 5603.0 }, + { name: 'Ca,Fe', wavelength: 5269.0 }, + { name: 'MgI', wavelength: 5174.12 }, + { name: 'Hβ', wavelength: 4862.70 }, + { name: 'Hγ', wavelength: 4341.68 }, + { name: 'Gband', wavelength: 4304.4 }, + { name: 'CN', wavelength: 4216.0 }, + { name: 'Hδ', wavelength: 4102.89 }, + { name: 'CaII_H', wavelength: 3969.59 }, + { name: 'CaII_K', wavelength: 3934.78 }, + { name: 'Hksi', wavelength: 3890.15 }, + { name: 'H9', wavelength: 3836.47 }, + { name: 'Hθ', wavelength: 3798.98 }, + { name: 'H11', wavelength: 3771.70 }, + { name: 'FeI', wavelength: 3581.0 }, + { name: 'HeII', wavelength: 3204.03 }, + { name: 'FeII', wavelength: 2964.0 }, + { name: 'MgII', wavelength: 2796.35 }, + { name: 'MgII', wavelength: 2803.53 }, + { name: 'FeII', wavelength: 2626.45 }, + { name: 'FeII', wavelength: 2600.17 }, + { name: 'FeII', wavelength: 2586.65 }, + { name: 'FeII', wavelength: 2382.76 }, + { name: 'FeII', wavelength: 2374.46 }, + { name: 'FeII', wavelength: 2344.21 }, + { name: 'FeII', wavelength: 2260.78 }, + { name: 'AlIII', wavelength: 1854.72 }, + { name: 'AlII', wavelength: 1670.78 }, + { name: 'HeII', wavelength: 1640.42 }, + { name: 'FeII', wavelength: 1608.45 }, + { name: 'CIV', wavelength: 1548.20 }, + { name: 'CIV', wavelength: 1550.77 }, + { name: 'SiII', wavelength: 1533.43 }, + { name: 'SiII', wavelength: 1526.71 }, + { name: 'SiIV', wavelength: 1402.77 }, + { name: 'SiIV', wavelength: 1393.75 }, + { name: 'CII', wavelength: 1334.53 }, + { name: 'OI', wavelength: 1302.17 }, + { name: 'OI', wavelength: 1304.86 }, + { name: 'SiII', wavelength: 1260.42 }, + { name: 'NV', wavelength: 1238.82 }, + { name: 'NV', wavelength: 1242.80 }, + { name: 'LyA', wavelength: 1215.67 }, + { name: 'OVI', wavelength: 1037.62 }, + { name: 'OVI', wavelength: 1031.93 }, + { name: 'LyB', wavelength: 1025.72 }, + { name: 'LyG', wavelength: 972.53 } ]; diff --git a/client/src/app/instance/shared-search/detail/components/spectra/spectra-object.component.spec.ts b/client/src/app/instance/shared-search/detail/components/spectra/spectra-object.component.spec.ts new file mode 100644 index 00000000..293a5498 --- /dev/null +++ b/client/src/app/instance/shared-search/detail/components/spectra/spectra-object.component.spec.ts @@ -0,0 +1,90 @@ +import { ComponentFixture, TestBed } from '@angular/core/testing'; +import { Component, Input } from '@angular/core'; + +import { SpectraObjectComponent } from './spectra-object.component'; +import { Attribute, OutputCategory, OutputFamily } from '../../../../../metamodel/models'; +import { AppConfigService } from '../../../../../app-config.service'; +import { ATTRIBUTE_LIST, OBJECT_DETAIL } from '../../../../../../test-data'; + +describe('[Instance][SharedSearch][Detail][Component][Spectra] SpectraObjectComponent', () => { + @Component({ selector: 'app-spectra-graph', template: '' }) + class SpectraGraphStubComponent { + @Input() z: number; + @Input() spectraCSV: string; + } + + @Component({ selector: 'app-object-data', template: '' }) + class ObjectDataStubComponent { + @Input() datasetSelected: string; + @Input() outputFamilyList: OutputFamily[]; + @Input() outputCategoryList: OutputCategory[]; + @Input() attributeList: Attribute[]; + @Input() object: any; + } + + let component: SpectraObjectComponent; + let fixture: ComponentFixture<SpectraObjectComponent>; + let appConfigServiceStub = new AppConfigService(); + + beforeEach(() => { + TestBed.configureTestingModule({ + declarations: [ + SpectraObjectComponent, + SpectraGraphStubComponent, + ObjectDataStubComponent + ], + providers: [{ provide: AppConfigService, useValue: appConfigServiceStub }] + }); + fixture = TestBed.createComponent(SpectraObjectComponent); + component = fixture.componentInstance; + }); + + it('should create the component', () => { + expect(component).toBeTruthy(); + }); + + it('#ngOnInit() should emit getSpectraCSV event if an attribute have spectra_graph renderer_detail', () => { + component.attributeList = ATTRIBUTE_LIST; + component.object = OBJECT_DETAIL; + component.getSpectraCSV.subscribe((event: string) => expect(event).toEqual('spec1d')); + component.ngOnInit(); + }); + + it('#getSpectra() should return url to download spectra', () => { + component.datasetSelected = 'myDataset'; + component.attributeList = ATTRIBUTE_LIST; + component.object = OBJECT_DETAIL; + appConfigServiceStub.apiUrl = 'http://test.com'; + expect(component.getSpectra()).toEqual('http://test.com/download-file/myDataset/spec1d'); + }); + + it('#getAttributeSpectraGraph() should return attribute for the spectra_graph renderer_detail', () => { + component.attributeList = ATTRIBUTE_LIST; + expect(component.getAttributeSpectraGraph().name).toEqual('name_four'); + }); + + it('#getZ() should return Z value', () => { + component.attributeList = ATTRIBUTE_LIST; + component.object = OBJECT_DETAIL; + expect(component.getZ()).toEqual(0); + const attributeZ: Attribute = { + id:5, + name: 'name_five', + label: 'label_five', + form_label: 'form_label_five', + description: 'description_five', + output_display: 5, + criteria_display: 5, + search_flag: 'Z', + search_type: 'field', + operator: '=', + type: 'integer', + detail: true, + display_detail: 4, + options: [], + id_output_category: 1 + }; + component.attributeList = [...ATTRIBUTE_LIST, attributeZ]; + expect(component.getZ()).toEqual(5); + }); +}); diff --git a/client/src/app/instance/shared-search/detail/components/spectra/spectra-object.component.ts b/client/src/app/instance/shared-search/detail/components/spectra/spectra-object.component.ts index 9c7095f2..908822e2 100644 --- a/client/src/app/instance/shared-search/detail/components/spectra/spectra-object.component.ts +++ b/client/src/app/instance/shared-search/detail/components/spectra/spectra-object.component.ts @@ -13,18 +13,18 @@ import { Attribute, OutputCategory, OutputFamily } from 'src/app/metamodel/model import { getHost } from 'src/app/shared/utils'; import { AppConfigService } from 'src/app/app-config.service'; -@Component({ - selector: 'app-spectra-object', - templateUrl: 'spectra-object.component.html', - styleUrls: ['spectra-object.component.scss'], - changeDetection: ChangeDetectionStrategy.OnPush -}) /** * @class * @classdesc Detail spectra object component. * * @implements OnInit */ +@Component({ + selector: 'app-spectra-object', + templateUrl: 'spectra-object.component.html', + styleUrls: ['spectra-object.component.scss'], + changeDetection: ChangeDetectionStrategy.OnPush +}) export class SpectraObjectComponent implements OnInit { @Input() datasetSelected: string; @Input() outputFamilyList: OutputFamily[]; @@ -38,7 +38,7 @@ export class SpectraObjectComponent implements OnInit { constructor(private appConfig: AppConfigService) { } - ngOnInit() { + ngOnInit(): void { const attributeSpectraGraph = this.getAttributeSpectraGraph(); if (attributeSpectraGraph) { Promise.resolve(null).then(() => this.getSpectraCSV.emit(this.object[attributeSpectraGraph.label])); diff --git a/client/src/test-data.ts b/client/src/test-data.ts index c90cd0be..dd800418 100644 --- a/client/src/test-data.ts +++ b/client/src/test-data.ts @@ -79,7 +79,8 @@ export const ATTRIBUTE_LIST: Attribute[] = [ { label: 'One', value: 'one', display: 1 }, { label: 'Two', value: 'two', display: 2 } ], - id_output_category: 1 + id_output_category: 1, + renderer_detail: 'spectra_graph' } ]; @@ -103,3 +104,8 @@ export const CATEGORY_LIST: OutputCategory[] = [ id_output_family: 1 } ]; + +export const OBJECT_DETAIL: any = { + label_four: 'spec1d', + label_five: 5 +}; -- GitLab