Commit 6510eeab authored by Tifenn Guillas's avatar Tifenn Guillas
Browse files

Tests => DONE

parent dc0c6ea6
import { async, ComponentFixture, TestBed } from '@angular/core/testing';
import { Component, Input } from '@angular/core';
import { DefaultObjectComponent } from './default-object.component';
import { Attribute, Category, Family } from '../../metamodel/model';
describe('[Detail] Component: DefaultObjectComponent', () => {
@Component({ selector: 'app-object-data', template: '' })
class ObjectDataStubComponent {
@Input() datasetName: string;
@Input() outputFamilyList: Family[];
@Input() categoryList: Category[];
@Input() attributeList: Attribute[];
@Input() object: any;
}
let component: DefaultObjectComponent;
let fixture: ComponentFixture<DefaultObjectComponent>;
beforeEach(async(() => {
TestBed.configureTestingModule({
declarations: [
DefaultObjectComponent,
ObjectDataStubComponent
]
});
fixture = TestBed.createComponent(DefaultObjectComponent);
component = fixture.componentInstance;
}));
it('should create the component', () => {
expect(component).toBeTruthy();
});
});
import { async, ComponentFixture, TestBed } from '@angular/core/testing';
import { AccordionModule } from 'ngx-bootstrap/accordion';
import { ObjectDataComponent } from './object-data.component';
import { ATTRIBUTE_LIST, CATEGORY_LIST } from '../../../settings/test-data';
describe('[Detail] Component: ObjectDataComponent', () => {
let component: ObjectDataComponent;
let fixture: ComponentFixture<ObjectDataComponent>;
beforeEach(async(() => {
TestBed.configureTestingModule({
declarations: [ObjectDataComponent],
imports: [AccordionModule.forRoot()]
});
fixture = TestBed.createComponent(ObjectDataComponent);
component = fixture.componentInstance;
}));
it('should create the component', () => {
expect(component).toBeTruthy();
});
it('#getCategoryByFamilySortedByDisplay() should return sorted categories for the given family', () => {
component.categoryList = CATEGORY_LIST;
expect(component.getCategoryByFamilySortedByDisplay(1).length).toEqual(2);
});
it('#getAttributesVisibleByCategory() should return visible attributes for the given category', () => {
component.attributeList = ATTRIBUTE_LIST;
expect(component.getAttributesVisibleByCategory(1).length).toEqual(1);
expect(component.getAttributesVisibleByCategory(1)[0].id).toEqual(1);
});
it('#getAttributesVisible() should return visible attributes', () => {
component.attributeList = ATTRIBUTE_LIST;
expect(component.getAttributesVisible().length).toEqual(2);
});
it('#getAttributeBySearchFlag() should return attribute for the given search_flag', () => {
component.attributeList = ATTRIBUTE_LIST;
expect(component.getAttributeBySearchFlag('ID').name).toEqual('name_one');
});
});
import { Component, Input, ChangeDetectionStrategy } from '@angular/core';
import { Attribute, Category, Family } from '../../metamodel/model';
import { getHost } from '../../shared/utils';
@Component({
selector: 'app-object-data',
......
// import { ComponentFixture, TestBed } from '@angular/core/testing';
//
// import { AccordionModule } from 'ngx-bootstrap/accordion';
//
// import { ObjectDisplayComponent } from './spectra-object.component';
// import { Attribute } from '../../../metamodel/model';
// import { ATTRIBUTE_LIST, CATEGORY_LIST, OBJECT_DETAIL } from '../../../../settings/test-data';
//
// describe('[Detail] Component: ObjectDisplayComponent', () => {
// let component: ObjectDisplayComponent;
// let fixture: ComponentFixture<ObjectDisplayComponent>;
//
// beforeEach(() => {
// TestBed.configureTestingModule({
// declarations: [ObjectDisplayComponent],
// imports: [AccordionModule.forRoot()]
// });
// fixture = TestBed.createComponent(ObjectDisplayComponent);
// 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();
// // To prevent `Spec has no expectation' bug
// expect(true).toBeTruthy();
// });
//
// it('#getSpectra() should return url to download spectra', () => {
// component.datasetName = 'dname';
// component.attributeList = ATTRIBUTE_LIST;
// component.object = OBJECT_DETAIL;
// expect(component.getSpectra()).toEqual('http://localhost:8080/download-file/dname/spec1d');
// });
//
// it('#getCategoryByFamilySortedByDisplay() should return sorted categories for the given family', () => {
// component.categoryList = CATEGORY_LIST;
// expect(component.getCategoryByFamilySortedByDisplay(1).length).toEqual(2);
// });
//
// it('#getAttributesVisibleByCategory() should return visible attributes for the given category', () => {
// component.attributeList = ATTRIBUTE_LIST;
// expect(component.getAttributesVisibleByCategory(1).length).toEqual(1);
// expect(component.getAttributesVisibleByCategory(1)[0].id).toEqual(1);
// });
//
// it('#getAttributesVisible() should return visible attributes', () => {
// component.attributeList = ATTRIBUTE_LIST;
// expect(component.getAttributesVisible().length).toEqual(2);
// });
//
// it('#getAttributeBySearchFlag() should return attribute for the given search_flag', () => {
// component.attributeList = ATTRIBUTE_LIST;
// expect(component.getAttributeBySearchFlag('ID').name).toEqual('name_one');
// });
//
// it('#getAttributeSpectraGraph() should return attribute for the spectra_graph renderer_detail', () => {
// component.attributeList = ATTRIBUTE_LIST;
// expect(component.getAttributeSpectraGraph().name).toEqual('name_two');
// });
//
// it('#getZ() should return Z value', () => {
// component.attributeList = ATTRIBUTE_LIST;
// component.object = OBJECT_DETAIL;
// expect(component.getZ()).toEqual(0);
// const attributeZ: Attribute = {
// id: 3,
// name: 'name_three',
// table_name: 'table_2',
// label: 'label_three',
// form_label: 'form_label_three',
// description: 'description_three',
// output_display: 1,
// criteria_display: 1,
// search_flag: 'Z',
// search_type: 'field',
// operator: '=',
// type: '',
// min: null,
// max: null,
// placeholder_min: '',
// placeholder_max: '',
// renderer: '',
// renderer_config: null,
// display_detail: 1,
// selected: true,
// order_by: true,
// order_display: 1,
// detail: true,
// renderer_detail: '',
// options: null,
// vo_utype: '',
// vo_ucd: '',
// vo_unit: '',
// vo_description: '',
// vo_datatype: '',
// vo_size: 1,
// id_criteria_family: 2,
// id_output_category: 2
// };
// component.attributeList = [...ATTRIBUTE_LIST, attributeZ];
// expect(component.getZ()).toEqual(4);
// });
// });
import { ComponentFixture, TestBed } from '@angular/core/testing';
import { Component, Input } from '@angular/core';
import { SpectraObjectComponent } from './spectra-object.component';
import { Attribute, Category, Family } from '../../../metamodel/model';
import { ATTRIBUTE_LIST, OBJECT_DETAIL } from '../../../../settings/test-data';
describe('[Detail][Spectra] Component: SpectraObjectComponent', () => {
@Component({ selector: 'app-object-data', template: '' })
class ObjectDataStubComponent {
@Input() datasetName: string;
@Input() outputFamilyList: Family[];
@Input() categoryList: Category[];
@Input() attributeList: Attribute[];
@Input() object: any;
}
let component: SpectraObjectComponent;
let fixture: ComponentFixture<SpectraObjectComponent>;
beforeEach(() => {
TestBed.configureTestingModule({
declarations: [
SpectraObjectComponent,
ObjectDataStubComponent
]
});
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();
// To prevent `Spec has no expectation' bug
expect(true).toBeTruthy();
});
it('#getSpectra() should return url to download spectra', () => {
component.datasetName = 'dname';
component.attributeList = ATTRIBUTE_LIST;
component.object = OBJECT_DETAIL;
expect(component.getSpectra()).toEqual('http://localhost:8080/download-file/dname/spec1d');
});
it('#getAttributeSpectraGraph() should return attribute for the spectra_graph renderer_detail', () => {
component.attributeList = ATTRIBUTE_LIST;
expect(component.getAttributeSpectraGraph().name).toEqual('name_two');
});
it('#getZ() should return Z value', () => {
component.attributeList = ATTRIBUTE_LIST;
component.object = OBJECT_DETAIL;
expect(component.getZ()).toEqual(0);
const attributeZ: Attribute = {
id: 3,
name: 'name_three',
table_name: 'table_2',
label: 'label_three',
form_label: 'form_label_three',
description: 'description_three',
output_display: 1,
criteria_display: 1,
search_flag: 'Z',
search_type: 'field',
operator: '=',
type: '',
min: null,
max: null,
placeholder_min: '',
placeholder_max: '',
renderer: '',
renderer_config: null,
display_detail: 1,
selected: true,
order_by: true,
order_display: 1,
detail: true,
renderer_detail: '',
options: null,
vo_utype: '',
vo_ucd: '',
vo_unit: '',
vo_description: '',
vo_datatype: '',
vo_size: 1,
id_criteria_family: 2,
id_output_category: 2
};
component.attributeList = [...ATTRIBUTE_LIST, attributeZ];
expect(component.getZ()).toEqual(4);
});
});
......@@ -10,7 +10,7 @@
<span class="fas fa-circle-notch fa-spin fa-3x"></span>
<span class="sr-only">Loading...</span>
</div>
<div *ngIf="objectIsLoaded | async" [ngSwitch]="objectType(attributeList | async)">
<div *ngIf="objectIsLoaded | async" [ngSwitch]="getObjectType(attributeList | async)">
<app-spectra-object *ngSwitchCase="'spectra'"
[datasetName]="datasetName | async"
[outputFamilyList]="outputFamilyList | async"
......
......@@ -9,6 +9,7 @@ import { DetailComponent } from './detail.component';
import * as fromDetail from '../store/detail.reducer';
import * as detailActions from '../store/detail.action';
import { Attribute, Family, Category } from '../../metamodel/model';
import { ATTRIBUTE_LIST } from '../../../settings/test-data';
describe('[Detail] Container: DetailComponent', () => {
@Component({ selector: 'app-object-display', template: '' })
......@@ -63,6 +64,12 @@ describe('[Detail] Container: DetailComponent', () => {
});
});
it ('#getObjectType() should return object type', () => {
expect(component.getObjectType(ATTRIBUTE_LIST)).toEqual('spectra');
const defaultAttributeList = ATTRIBUTE_LIST.filter(a => a.search_flag !== 'SPECTRUM_1D');
expect(component.getObjectType(defaultAttributeList)).toEqual('default');
});
it ('#goBackToResult() should go to the previous location', inject([LOCATION_TOKEN], (location: Location) => {
spyOn(location, 'back');
component.goBackToResult();
......
......@@ -55,7 +55,7 @@ export class DetailComponent implements OnInit, OnDestroy {
});
}
objectType(attributeList: Attribute[]): string {
getObjectType(attributeList: Attribute[]): string {
const spectrumAttribute: Attribute = attributeList
.filter(a => a.detail)
.find(attribute => attribute.search_flag === 'SPECTRUM_1D');
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment