diff --git a/src/app/search-multiple/components/datasets/dataset-list.component.spec.ts b/src/app/search-multiple/components/datasets/dataset-list.component.spec.ts index 4ca1fd3f5aea15926395bafce0f30b943104d9be..ce893263b45580c1793edd5d5e446453b20f2d9e 100644 --- a/src/app/search-multiple/components/datasets/dataset-list.component.spec.ts +++ b/src/app/search-multiple/components/datasets/dataset-list.component.spec.ts @@ -1,96 +1,91 @@ -// import { async, ComponentFixture, TestBed } from '@angular/core/testing'; -// import { Component, Input, Output, EventEmitter, ViewChild } from '@angular/core'; -// -// import { DatasetListComponent } 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(DatasetListComponent, { static: false }) -// public testedComponent: DatasetListComponent; -// 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: DatasetListComponent; -// -// beforeEach(async(() => { -// TestBed.configureTestingModule({ -// declarations: [ -// DatasetListComponent, -// 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 { async, ComponentFixture, TestBed } from '@angular/core/testing'; +import { Component, Input, ViewChild } from '@angular/core'; + +import { DatasetListComponent } from './dataset-list.component'; +import { Project, Dataset } from '../../../metamodel/model'; +import { PROJECT_LIST, DATASET_LIST } from '../../../../settings/test-data'; + +describe('[SearchMultiple][Datasets] Component: DatasetListComponent', () => { + @Component({ + selector: `app-host`, + template: ` + <app-dataset-list + [projectList]="projectList" + [datasetList]="datasetList" + [selectedDatasets]="selectedDatasets"> + </app-dataset-list>` + }) + class TestHostComponent { + @ViewChild(DatasetListComponent, { static: false }) + public testedComponent: DatasetListComponent; + public projectList: Project[] = PROJECT_LIST; + public datasetList: Dataset[] = DATASET_LIST; + public selectedDatasets: string[] = []; + } + + @Component({ selector: 'app-datasets-by-project', template: '' }) + class DatasetsByProjectStubComponent { + @Input() project: string; + @Input() datasetList: Dataset[]; + @Input() selectedDatasets: string[]; + @Input() isAllSelected: boolean; + @Input() isAllUnselected: boolean; + } + + let testHostComponent: TestHostComponent; + let testHostFixture: ComponentFixture<TestHostComponent>; + let testedComponent: DatasetListComponent; + + beforeEach(async(() => { + TestBed.configureTestingModule({ + declarations: [ + DatasetListComponent, + TestHostComponent, + DatasetsByProjectStubComponent + ] + }); + testHostFixture = TestBed.createComponent(TestHostComponent); + testHostComponent = testHostFixture.componentInstance; + testHostFixture.detectChanges(); + testedComponent = testHostComponent.testedComponent; + })); + + it('should create the component', () => { + expect(testedComponent).toBeTruthy(); + }); + + it('#getProjectSortedByName() should return sorted project list', () => { + const sortedProjectList: Project[] = testedComponent.getProjectSortedByName(); + expect(sortedProjectList.length).toBe(2); + expect(sortedProjectList[0].name).toBe('project_1'); + expect(sortedProjectList[1].name).toBe('project_2'); + }); + + it('#getDatasetsByProject() should return dataset list for the given project', () => { + const datasetList: Dataset[] = testedComponent.getDatasetsByProject('project_1'); + expect(datasetList.length).toBe(2); + expect(datasetList[0].name).toBe('cat_1'); + expect(datasetList[1].name).toBe('cat_2'); + }); + + it('#getIsAllSelected() should return true if all datasets of the given project are selected', () => { + testHostComponent.selectedDatasets = ['cat_3']; + testHostFixture.detectChanges(); + expect(testedComponent.getIsAllSelected('project_2')).toBeTruthy(); + }); + + it('#getIsAllSelected() should return false if not all datasets of the given project are selected', () => { + expect(testedComponent.getIsAllSelected('project_1')).toBeFalsy(); + }); + + it('#getIsAllUnselected() should return true if all datasets of the given project are not selected', () => { + expect(testedComponent.getIsAllUnselected('project_1')).toBeTruthy(); + }); + + it('#getIsAllUnselected() should return false if not all datasets of the given project are not selected', () => { + testHostComponent.selectedDatasets = ['cat_1']; + testHostFixture.detectChanges(); + expect(testedComponent.getIsAllUnselected('project_1')).toBeFalsy(); + }); +}); + diff --git a/src/app/search-multiple/components/datasets/dataset-list.component.ts b/src/app/search-multiple/components/datasets/dataset-list.component.ts index 869acfe8f1d8917ee31135e43d1167d7db871ac0..2291178b693ae60063a35a3a4ffa7b2c2b85b991 100644 --- a/src/app/search-multiple/components/datasets/dataset-list.component.ts +++ b/src/app/search-multiple/components/datasets/dataset-list.component.ts @@ -1,6 +1,6 @@ import { Component, Input, Output, EventEmitter, ChangeDetectionStrategy } from '@angular/core'; -import { Dataset, Project } from "../../../metamodel/model"; +import { Dataset, Project } from '../../../metamodel/model'; @Component({ selector: 'app-dataset-list', diff --git a/src/app/search-multiple/components/datasets/datasets-by-projet.component.html b/src/app/search-multiple/components/datasets/datasets-by-project.component.html similarity index 100% rename from src/app/search-multiple/components/datasets/datasets-by-projet.component.html rename to src/app/search-multiple/components/datasets/datasets-by-project.component.html diff --git a/src/app/search-multiple/components/datasets/datasets-by-projet.component.ts b/src/app/search-multiple/components/datasets/datasets-by-project.component.ts similarity index 95% rename from src/app/search-multiple/components/datasets/datasets-by-projet.component.ts rename to src/app/search-multiple/components/datasets/datasets-by-project.component.ts index 4e6a03c28d0afad39374ab610294da159dbe68e6..3e99c294f2d590c92181380823ea154b7cdc0333 100644 --- a/src/app/search-multiple/components/datasets/datasets-by-projet.component.ts +++ b/src/app/search-multiple/components/datasets/datasets-by-project.component.ts @@ -5,10 +5,10 @@ import { sortByDisplay } from "../../../shared/utils"; @Component({ selector: 'app-datasets-by-project', - templateUrl: 'datasets-by-projet.component.html', + templateUrl: 'datasets-by-project.component.html', changeDetection: ChangeDetectionStrategy.OnPush }) -export class DatasetsByProjetComponent { +export class DatasetsByProjectComponent { @Input() project: Project; @Input() datasetList: Dataset[]; @Input() selectedDatasets: string[]; diff --git a/src/app/search-multiple/components/datasets/datasets-by-projet.component.spec.ts b/src/app/search-multiple/components/datasets/datasets-by-projet.component.spec.ts index 0c33542e25f93045d3b52fe705b58bf8047ea582..9fee775896b1230ea49fd88740298495ce13c7ed 100644 --- a/src/app/search-multiple/components/datasets/datasets-by-projet.component.spec.ts +++ b/src/app/search-multiple/components/datasets/datasets-by-projet.component.spec.ts @@ -1,7 +1,7 @@ // import { async, ComponentFixture, TestBed } from '@angular/core/testing'; // import { Component, ViewChild } from '@angular/core'; // -// import { DatasetsByProjetComponent } from './output-by-category.component'; +// import { DatasetsByProjectComponent } from './output-by-category.component'; // import { Attribute } from '../../../metamodel/model'; // import { ATTRIBUTE_LIST } from '../../../../settings/test-data'; // @@ -18,8 +18,8 @@ // </app-output-by-category>` // }) // class TestHostComponent { -// @ViewChild(DatasetsByProjetComponent, { static: false }) -// public testedComponent: DatasetsByProjetComponent; +// @ViewChild(DatasetsByProjectComponent, { static: false }) +// public testedComponent: DatasetsByProjectComponent; // public categoryLabel = 'Default output category'; // public attributeList: Attribute[] = ATTRIBUTE_LIST; // public outputList: number[] = [1]; @@ -29,12 +29,12 @@ // // let testHostComponent: TestHostComponent; // let testHostFixture: ComponentFixture<TestHostComponent>; -// let testedComponent: DatasetsByProjetComponent; +// let testedComponent: DatasetsByProjectComponent; // // beforeEach(async(() => { // TestBed.configureTestingModule({ // declarations: [ -// DatasetsByProjetComponent, +// DatasetsByProjectComponent, // TestHostComponent // ] // }); diff --git a/src/app/search-multiple/components/index.ts b/src/app/search-multiple/components/index.ts index e9759b2e82a6247e29246651c3eea281e8d71cef..c60a594a42e907d2794e0f9f28a63a8d86d4e4cb 100644 --- a/src/app/search-multiple/components/index.ts +++ b/src/app/search-multiple/components/index.ts @@ -1,7 +1,7 @@ import { ProgressBarMultipleComponent } from './progress-bar-multiple.component'; import { SummaryMultipleComponent } from './summary-multiple.component'; import { DatasetListComponent } from './datasets/dataset-list.component'; -import { DatasetsByProjetComponent } from './datasets/datasets-by-projet.component'; +import { DatasetsByProjectComponent } from './datasets/datasets-by-project.component'; import { OverviewComponent } from './result/overview.component'; import { DatasetsResultComponent } from './result/datasets-result.component'; @@ -9,7 +9,7 @@ export const dummiesComponents = [ ProgressBarMultipleComponent, SummaryMultipleComponent, DatasetListComponent, - DatasetsByProjetComponent, + DatasetsByProjectComponent, OverviewComponent, DatasetsResultComponent ]; \ No newline at end of file