From f5bd0acd352650d26d7f4c7a7c46bde6321413af Mon Sep 17 00:00:00 2001
From: Tifenn Guillas <tifenn.guillas@lam.fr>
Date: Mon, 28 Sep 2020 16:36:47 +0200
Subject: [PATCH] WIP: Tests on search multiple datasets components

---
 .../datasets/dataset-list.component.spec.ts   | 187 +++++++++---------
 .../datasets/dataset-list.component.ts        |   2 +-
 ...tml => datasets-by-project.component.html} |   0
 ...nt.ts => datasets-by-project.component.ts} |   4 +-
 .../datasets-by-projet.component.spec.ts      |  10 +-
 src/app/search-multiple/components/index.ts   |   4 +-
 6 files changed, 101 insertions(+), 106 deletions(-)
 rename src/app/search-multiple/components/datasets/{datasets-by-projet.component.html => datasets-by-project.component.html} (100%)
 rename src/app/search-multiple/components/datasets/{datasets-by-projet.component.ts => datasets-by-project.component.ts} (95%)

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 4ca1fd3f..ce893263 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 869acfe8..2291178b 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 4e6a03c2..3e99c294 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 0c33542e..9fee7758 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 e9759b2e..c60a594a 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
-- 
GitLab