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

Tests on search output components => DONE

parent 56e37e3d
No related branches found
No related tags found
2 merge requests!147Develop,!137Resolve "[Module Multiple] : ajouter le nouveau module"
import { async, ComponentFixture, TestBed } from '@angular/core/testing';
import { Component, ViewChild } from '@angular/core';
import { async, ComponentFixture, TestBed } from '@angular/core/testing';
import { OutputByCategoryComponent } from './output-by-category.component';
import { Attribute } from '../../../metamodel/model';
......@@ -10,11 +10,11 @@ describe('[Search][Output] Component: OutputByCategoryComponent', () => {
selector: `app-host`,
template: `
<app-output-by-category
[categoryLabel]="categoryLabel"
[attributeList]="attributeList"
[outputList]="outputList"
[isAllSelected]="isAllSelected"
[isAllUnselected]="isAllUnselected">
[categoryLabel]='categoryLabel'
[attributeList]='attributeList'
[outputList]='outputList'
[isAllSelected]='isAllSelected'
[isAllUnselected]='isAllUnselected'>
</app-output-by-category>`
})
class TestHostComponent {
......
// import { async, ComponentFixture, TestBed } from '@angular/core/testing';
// import { Component, Input, Output, EventEmitter, ViewChild } from '@angular/core';
//
// import { OutputByFamilyComponent } from './output-by-family.component';
// import { Attribute, Family, Category } from '../../../metamodel/model';
// import { ATTRIBUTE_LIST, OUTPUT_FAMILY, CATEGORY_LIST } from '../../../../settings/test-data';
//
// describe('[Search][Output] Component: OutputByFamilyComponent', () => {
// @Component({
// selector: `app-host`,
// template: `
// <app-output-by-family
// [outputFamily]="outputFamily"
// [datasetAttributeList]="datasetAttributeList"
// [categoryList]="categoryList"
// [outputList]="outputList">
// </app-output-by-family>`
// })
// class TestHostComponent {
// @ViewChild(OutputByFamilyComponent, { static: false })
// public testedComponent: OutputByFamilyComponent;
// public outputFamily: Family = OUTPUT_FAMILY;
// public datasetAttributeList: Attribute[] = ATTRIBUTE_LIST;
// public categoryList: Category[] = CATEGORY_LIST;
// public outputList: number[] = [1];
// }
//
// @Component({ selector: 'app-output-by-category', template: '' })
// class OutputByCategoryStubComponent {
// @Input() categoryLabel: string;
// @Input() attributeList: Attribute[];
// @Input() outputList: number[];
// @Input() isAllSelected: boolean;
// @Input() isAllUnselected: boolean;
// @Output() change: EventEmitter<number[]> = new EventEmitter();
// }
//
// let testHostComponent: TestHostComponent;
// let testHostFixture: ComponentFixture<TestHostComponent>;
// let testedComponent: OutputByFamilyComponent;
//
// beforeEach(async(() => {
// TestBed.configureTestingModule({
// declarations: [
// OutputByFamilyComponent,
// TestHostComponent,
// OutputByCategoryStubComponent
// ]
// });
// testHostFixture = TestBed.createComponent(TestHostComponent);
// testHostComponent = testHostFixture.componentInstance;
// testHostFixture.detectChanges();
// testedComponent = testHostComponent.testedComponent;
// }));
//
// it('should create the component', () => {
// expect(testedComponent).toBeTruthy();
// });
//
// it('#getCategoryByFamilySortedByDisplay(idFamily) should sort by display categories belonging to idFamily', () => {
// const sortedCategoryList: Category[] = testedComponent.getCategoryByFamilySortedByDisplay(1);
// expect(sortedCategoryList.length).toBe(2);
// expect(sortedCategoryList[0].id).toBe(2);
// expect(sortedCategoryList[1].id).toBe(1);
// });
//
// it('#getAttributeByCategory(idCategory) should return attributes belonging to idCategory', () => {
// expect(testedComponent.getAttributeByCategory(1).length).toBe(1);
// expect(testedComponent.getAttributeByCategory(1)[0].id).toBe(1);
// });
//
// it('#getIsAllSelected(idCategory) should return true if all outputs of idCategory are selected', () => {
// expect(testedComponent.getIsAllSelected(1)).toBeTruthy();
// });
//
// it('#getIsAllSelected(idCategory) should return false if not all outputs of idCategory are selected', () => {
// testedComponent.outputList = [];
// expect(testedComponent.getIsAllSelected(1)).toBeFalsy();
// });
//
// it('#getIsAllUnselected(idCategory) should return true if all outputs of idCategory are not selected', () => {
// testedComponent.outputList = [];
// expect(testedComponent.getIsAllUnselected(1)).toBeTruthy();
// });
//
// it('#getIsAllUnselected(idCategory) should return false if not all outputs of idCategory are not selected', () => {
// expect(testedComponent.getIsAllUnselected(1)).toBeFalsy();
// });
//
// it('#emitChange(outputList) should raise change event', () => {
// const expectedOutputList = [1];
// testedComponent.change.subscribe((event: number[]) => expect(event).toEqual(expectedOutputList));
// testedComponent.emitChange([1]);
// });
// });
//
import { Component, Input, Output, EventEmitter, ViewChild } from '@angular/core';
import { async, ComponentFixture, TestBed } from '@angular/core/testing';
import { OutputByFamilyComponent } from './output-by-family.component';
import { Attribute, Family, Category } from '../../../metamodel/model';
import { ATTRIBUTE_LIST, OUTPUT_FAMILY, CATEGORY_LIST } from '../../../../settings/test-data';
describe('[Search][Output] Component: OutputByFamilyComponent', () => {
@Component({
selector: `app-host`,
template: `
<app-output-by-family
[outputFamily]='outputFamily'
[attributeList]='attributeList'
[categoryList]='categoryList'
[outputList]='outputList'>
</app-output-by-family>`
})
class TestHostComponent {
@ViewChild(OutputByFamilyComponent, { static: false })
public testedComponent: OutputByFamilyComponent;
public outputFamily: Family = OUTPUT_FAMILY;
public attributeList: Attribute[] = ATTRIBUTE_LIST;
public categoryList: Category[] = CATEGORY_LIST;
public outputList: number[] = [1];
}
@Component({ selector: 'app-output-by-category', template: '' })
class OutputByCategoryStubComponent {
@Input() categoryLabel: string;
@Input() attributeList: Attribute[];
@Input() outputList: number[];
@Input() isAllSelected: boolean;
@Input() isAllUnselected: boolean;
@Output() change: EventEmitter<number[]> = new EventEmitter();
}
let testHostComponent: TestHostComponent;
let testHostFixture: ComponentFixture<TestHostComponent>;
let testedComponent: OutputByFamilyComponent;
beforeEach(async(() => {
TestBed.configureTestingModule({
declarations: [
OutputByFamilyComponent,
TestHostComponent,
OutputByCategoryStubComponent
]
});
testHostFixture = TestBed.createComponent(TestHostComponent);
testHostComponent = testHostFixture.componentInstance;
testHostFixture.detectChanges();
testedComponent = testHostComponent.testedComponent;
}));
it('should create the component', () => {
expect(testedComponent).toBeTruthy();
});
it('#getCategoryByFamilySortedByDisplay(idFamily) should sort by display categories belonging to idFamily', () => {
const sortedCategoryList: Category[] = testedComponent.getCategoryByFamilySortedByDisplay(1);
expect(sortedCategoryList.length).toBe(2);
expect(sortedCategoryList[0].id).toBe(2);
expect(sortedCategoryList[1].id).toBe(1);
});
it('#getAttributeByCategory(idCategory) should return attributes belonging to idCategory', () => {
expect(testedComponent.getAttributeByCategory(1).length).toBe(1);
expect(testedComponent.getAttributeByCategory(1)[0].id).toBe(1);
});
it('#getIsAllSelected(idCategory) should return true if all outputs of idCategory are selected', () => {
expect(testedComponent.getIsAllSelected(1)).toBeTruthy();
});
it('#getIsAllSelected(idCategory) should return false if not all outputs of idCategory are selected', () => {
testedComponent.outputList = [];
expect(testedComponent.getIsAllSelected(1)).toBeFalsy();
});
it('#getIsAllUnselected(idCategory) should return true if all outputs of idCategory are not selected', () => {
testedComponent.outputList = [];
expect(testedComponent.getIsAllUnselected(1)).toBeTruthy();
});
it('#getIsAllUnselected(idCategory) should return false if not all outputs of idCategory are not selected', () => {
expect(testedComponent.getIsAllUnselected(1)).toBeFalsy();
});
it('#emitChange(outputList) should raise change event', () => {
const expectedOutputList = [1];
testedComponent.change.subscribe((event: number[]) => expect(event).toEqual(expectedOutputList));
testedComponent.emitChange([1]);
});
});
......@@ -17,12 +17,12 @@
<accordion-group #ag *ngFor="let family of outputFamilyList"
[panelClass]="'custom-accordion-output'" class="my-2" [isOpen]="true">
<button class="btn btn-link btn-block clearfix" accordion-heading>
<div class="pull-left float-left">
<span class="pull-left float-left">
{{ family.label }}
&nbsp;
<span *ngIf="ag.isOpen"><span class="fas fa-chevron-up"></span></span>
<span *ngIf="!ag.isOpen"><span class="fas fa-chevron-down"></span></span>
</div>
</span>
</button>
<app-output-by-family
[outputFamily]="family"
......
// import { async, ComponentFixture, TestBed } from '@angular/core/testing';
// import { Component, Input, Output, EventEmitter, ViewChild } from '@angular/core';
// import { BrowserAnimationsModule } from '@angular/platform-browser/animations';
//
// import { ToastrModule } from 'ngx-toastr';
// import { ToastrService } from 'ngx-toastr';
// import { AccordionModule } from 'ngx-bootstrap/accordion';
// import { OutputTabsComponent } from './output-tabs.component';
// import { Attribute, Family, Category } from '../../../metamodel/model';
// import { ATTRIBUTE_LIST, OUTPUT_FAMILY_LIST , CATEGORY_LIST } from '../../../../settings/test-data';
//
// describe('[Search][Output] Component: OutputTabsComponent', () => {
// @Component({
// selector: `app-host`,
// template: `
// <app-output-tabs
// [outputFamilyList]="outputFamilyList"
// [categoryList]="categoryList"
// [datasetAttributeList]="datasetAttributeList"
// [outputList]="outputList">
// </app-output-tabs>`
// })
// class TestHostComponent {
// @ViewChild(OutputTabsComponent, { static: false })
// public testedComponent: OutputTabsComponent;
// public outputFamilyList: Family[] = OUTPUT_FAMILY_LIST;
// public datasetAttributeList: Attribute[] = ATTRIBUTE_LIST;
// public categoryList: Category[] = CATEGORY_LIST;
// public outputList: number[] = [1];
// }
//
// @Component({ selector: 'app-output-by-family', template: '' })
// class OutputByFamilyStubComponent {
// @Input() outputFamily: Family;
// @Input() categoryList: Category[];
// @Input() datasetAttributeList: Attribute[];
// @Input() outputList: number[];
// @Output() change: EventEmitter<number[]> = new EventEmitter();
// }
//
// let testHostComponent: TestHostComponent;
// let testHostFixture: ComponentFixture<TestHostComponent>;
// let testedComponent: OutputTabsComponent;
//
// beforeEach(async(() => {
// TestBed.configureTestingModule({
// declarations: [
// OutputTabsComponent,
// TestHostComponent,
// OutputByFamilyStubComponent
// ],
// imports: [AccordionModule.forRoot(), BrowserAnimationsModule, ToastrModule.forRoot()],
// providers: [ToastrService]
// });
// testHostFixture = TestBed.createComponent(TestHostComponent);
// testHostComponent = testHostFixture.componentInstance;
// testHostFixture.detectChanges();
// testedComponent = testHostComponent.testedComponent;
// }));
//
// it('should create the component', () => {
// expect(testedComponent).toBeTruthy();
// });
//
// it('should raise outputListEmpty event as false', () => {
// // Used to prevent "no expectations" error
// expect(testedComponent).toBeTruthy();
//
// testedComponent.outputListEmpty.subscribe((event: boolean) => expect(event).toBeFalsy());
// });
//
// it('should raise outputListEmpty event as false', () => {
// testHostComponent.outputList = [];
// testedComponent.outputListEmpty.subscribe((event: boolean) => expect(event).toBeTruthy());
// testHostFixture.detectChanges();
// });
// });
//
import { Component, Input, Output, EventEmitter, ViewChild } from '@angular/core';
import { async, ComponentFixture, TestBed } from '@angular/core/testing';
import { BrowserAnimationsModule } from '@angular/platform-browser/animations';
import { ToastrModule, ToastrService } from 'ngx-toastr';
import { AccordionModule } from 'ngx-bootstrap/accordion';
import { OutputTabsComponent } from './output-tabs.component';
import { Attribute, Family, Category } from '../../../metamodel/model';
import { ATTRIBUTE_LIST, OUTPUT_FAMILY_LIST , CATEGORY_LIST } from '../../../../settings/test-data';
describe('[Search][Output] Component: OutputTabsComponent', () => {
@Component({
selector: `app-host`,
template: `
<app-output-tabs
[outputFamilyList]='outputFamilyList'
[categoryList]='categoryList'
[attributeList]='attributeList'
[outputList]='outputList'
[outputListEmpty]='outputListEmpty'>
</app-output-tabs>`
})
class TestHostComponent {
@ViewChild(OutputTabsComponent, { static: false })
public testedComponent: OutputTabsComponent;
public outputFamilyList: Family[] = OUTPUT_FAMILY_LIST;
public attributeList: Attribute[] = ATTRIBUTE_LIST;
public categoryList: Category[] = CATEGORY_LIST;
public outputList: number[] = [1];
public outputListEmpty: boolean = true;
}
@Component({ selector: 'app-output-by-family', template: '' })
class OutputByFamilyStubComponent {
@Input() outputFamily: Family;
@Input() categoryList: Category[];
@Input() attributeList: Attribute[];
@Input() outputList: number[];
@Output() change: EventEmitter<number[]> = new EventEmitter();
}
let testHostComponent: TestHostComponent;
let testHostFixture: ComponentFixture<TestHostComponent>;
let testedComponent: OutputTabsComponent;
beforeEach(async(() => {
TestBed.configureTestingModule({
declarations: [
OutputTabsComponent,
TestHostComponent,
OutputByFamilyStubComponent
],
imports: [AccordionModule.forRoot(), BrowserAnimationsModule, ToastrModule.forRoot()],
providers: [ToastrService]
});
testHostFixture = TestBed.createComponent(TestHostComponent);
testHostComponent = testHostFixture.componentInstance;
testHostFixture.detectChanges();
testedComponent = testHostComponent.testedComponent;
}));
it('should create the component', () => {
expect(testedComponent).toBeTruthy();
});
});
import { Component, Input, Output, EventEmitter, ChangeDetectionStrategy } from '@angular/core';
import { ToastrService } from 'ngx-toastr';
import { Family, Category, Attribute } from '../../../metamodel/model';
@Component({
......@@ -21,5 +22,4 @@ export class OutputTabsComponent {
@Output() change: EventEmitter<number[]> = new EventEmitter();
constructor(private toastr: ToastrService) { }
}
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