diff --git a/src/app/search/containers/criteria.component.spec.ts b/src/app/search/containers/criteria.component.spec.ts index f59ea654f53a76ca36a5d5aad1041d10815e6054..993aeec6d38723b69b802d0f52b576edad0028bc 100644 --- a/src/app/search/containers/criteria.component.spec.ts +++ b/src/app/search/containers/criteria.component.spec.ts @@ -1,18 +1,20 @@ import { ComponentFixture, TestBed, async } from '@angular/core/testing'; -import { provideMockStore, MockStore } from '@ngrx/store/testing'; import { Component, Input } from '@angular/core'; +import { provideMockStore, MockStore } from '@ngrx/store/testing'; +import { of } from 'rxjs'; + import { CriteriaComponent } from './criteria.component'; -import * as fromMetamodel from '../../metamodel/reducers'; import * as fromSearch from '../store/search.reducer'; -import * as fromConeSearch from '../../shared/cone-search/store/cone-search.reducer'; -import * as datasetActions from '../../metamodel/action/dataset.action'; import * as searchActions from '../store/search.action'; -import { Dataset, Attribute, Family, Category } from 'src/app/metamodel/model'; import { Criterion, FieldCriterion, SearchQueryParams } from '../store/model'; +import * as fromMetamodel from '../../metamodel/reducers'; +import * as datasetActions from '../../metamodel/action/dataset.action'; +import { Dataset, Attribute, Family, Category } from '../../metamodel/model'; +import * as fromConeSearch from '../../shared/cone-search/store/cone-search.reducer'; +import { ConeSearch } from '../../shared/cone-search/store/model'; import { ScrollTopService } from '../../shared/service/sroll-top.service'; import { RouterLinkDirectiveStub } from '../../../settings/test-data/router-link-directive-stub'; -import { ConeSearch } from "../../shared/cone-search/store/model"; describe('[Search] Container: CriteriaComponent', () => { @Component({ selector: 'app-cone-search-tab', template: '' }) @@ -84,6 +86,7 @@ describe('[Search] Container: CriteriaComponent', () => { }); it('should execute ngOnInit lifecycle', (done) => { + component.datasetName = of('toto'); const loadDatasetSearchMetaAction = new datasetActions.LoadDatasetSearchMetaAction(); const initSearchByUrl = new searchActions.InitSearchByUrl(); const changeStepAction = new searchActions.ChangeStepAction('criteria'); diff --git a/src/app/search/containers/criteria.component.ts b/src/app/search/containers/criteria.component.ts index a2f3647b5c258b08d4ebc51487108378d02ec2fc..73a3ccb1e77ed3a3e9de161dbdfc579772781077 100644 --- a/src/app/search/containers/criteria.component.ts +++ b/src/app/search/containers/criteria.component.ts @@ -1,18 +1,19 @@ import { Component, OnInit } from '@angular/core'; -import { Observable } from 'rxjs'; import { Store } from '@ngrx/store'; +import { Observable } from 'rxjs'; + +import * as fromSearch from '../store/search.reducer'; +import * as searchActions from '../store/search.action'; +import * as searchSelector from '../store/search.selector'; import { Criterion, SearchQueryParams } from '../store/model'; import { Dataset, Family, Attribute, Category } from '../../metamodel/model'; -import * as searchActions from '../store/search.action'; -import * as datasetActions from '../../metamodel/action/dataset.action'; -import * as fromSearch from '../store/search.reducer'; import * as fromMetamodel from '../../metamodel/reducers'; -import * as searchSelector from '../store/search.selector'; +import * as datasetActions from '../../metamodel/action/dataset.action'; import * as metamodelSelector from '../../metamodel/selectors'; import * as coneSearchSelector from '../../shared/cone-search/store/cone-search.selector'; -import { ScrollTopService } from '../../shared/service/sroll-top.service'; import { ConeSearch } from '../../shared/cone-search/store/model'; +import { ScrollTopService } from '../../shared/service/sroll-top.service'; interface StoreState { search: fromSearch.State; diff --git a/src/app/search/containers/dataset.component.spec.ts b/src/app/search/containers/dataset.component.spec.ts index 355365c4361cd76ffd9c7aa939c47a403dee5798..a44f1f4ec1529f8931322560e637e632169fbe49 100644 --- a/src/app/search/containers/dataset.component.spec.ts +++ b/src/app/search/containers/dataset.component.spec.ts @@ -1,23 +1,24 @@ import { ComponentFixture, TestBed, async } from '@angular/core/testing'; -import { provideMockStore, MockStore } from '@ngrx/store/testing'; import { Component, Input } from '@angular/core'; +import { provideMockStore, MockStore } from '@ngrx/store/testing'; + import { DatasetComponent } from './dataset.component'; -import * as fromMetamodel from '../../metamodel/reducers'; import * as fromSearch from '../store/search.reducer'; -import * as fromConeSearch from '../../shared/cone-search/store/cone-search.reducer'; -import * as datasetActions from '../../metamodel/action/dataset.action'; import * as searchActions from '../store/search.action'; -import { Dataset, Attribute, Project, Family, Category } from 'src/app/metamodel/model'; import { Criterion, SearchQueryParams } from '../store/model'; +import * as fromMetamodel from '../../metamodel/reducers'; +import * as datasetActions from '../../metamodel/action/dataset.action'; +import * as attActions from '../../metamodel/action/att.action'; +import * as criteriaActions from '../../metamodel/action/criteria.action'; +import * as outputActions from '../../metamodel/action/output.action'; +import { Dataset, Attribute, Project, Family, Category } from '../../metamodel/model'; +import * as fromConeSearch from '../../shared/cone-search/store/cone-search.reducer'; +import { ConeSearch } from '../../shared/cone-search/store/model'; import { ScrollTopService } from '../../shared/service/sroll-top.service'; import { RouterLinkDirectiveStub } from '../../../settings/test-data/router-link-directive-stub'; -import * as attributeActions from "../../metamodel/action/attribute.action"; -import * as criteriaActions from "../../metamodel/action/criteria.action"; -import * as outputActions from "../../metamodel/action/output.action"; -import { ConeSearch } from "../../shared/cone-search/store/model"; -fdescribe('[Search] Container: DatasetComponent', () => { +describe('[Search] Container: DatasetComponent', () => { @Component({ selector: 'app-dataset-tabs', template: '' }) class DatasetTabsStubComponent { @Input() projectList: Project[]; @@ -91,17 +92,17 @@ fdescribe('[Search] Container: DatasetComponent', () => { }); }); - it('#selectDataset() should dispatch LoadAttributeSearchMetaAction, LoadCriteriaSearchMetaAction, ' + + it('#selectDataset() should dispatch loadAttributeListAction, LoadCriteriaSearchMetaAction, ' + 'LoadOutputSearchMetaAction and NewSearchAction', (done) => { const newSearchAction = new searchActions.NewSearchAction('toto'); - const loadAttributeSearchMetaAction = new attributeActions.LoadAttributeSearchMetaAction('toto'); + const loadAttributeListAction = new attActions.LoadAttributeListAction('toto'); const loadCriteriaSearchMetaAction = new criteriaActions.LoadCriteriaSearchMetaAction('toto'); const loadOutputSearchMetaAction = new outputActions.LoadOutputSearchMetaAction('toto'); const spy = spyOn(store, 'dispatch'); component.selectDataset('toto'); Promise.resolve(null).then(function() { expect(spy).toHaveBeenCalledTimes(4); - expect(spy).toHaveBeenCalledWith(loadAttributeSearchMetaAction); + expect(spy).toHaveBeenCalledWith(loadAttributeListAction); expect(spy).toHaveBeenCalledWith(loadCriteriaSearchMetaAction); expect(spy).toHaveBeenCalledWith(loadOutputSearchMetaAction); expect(spy).toHaveBeenCalledWith(newSearchAction); diff --git a/src/app/search/containers/output.component.spec.ts b/src/app/search/containers/output.component.spec.ts index e935c120c027833ee648732899556d7d8298e7ab..7714e848ce01f1a93886152e67c8506a69339f52 100644 --- a/src/app/search/containers/output.component.spec.ts +++ b/src/app/search/containers/output.component.spec.ts @@ -1,113 +1,105 @@ -// import { ComponentFixture, TestBed, async } from '@angular/core/testing'; -// import { provideMockStore, MockStore } from '@ngrx/store/testing'; -// import { Component, Input } from '@angular/core'; -// -// import { OutputComponent } from './output.component'; -// import * as fromMetamodel from '../../metamodel/reducers'; -// import * as fromSearch from '../store/search.reducer'; -// import * as fromConeSearch from '../../shared/cone-search/store/cone-search.reducer'; -// import * as datasetActions from '../../metamodel/action/dataset.action'; -// import * as searchActions from '../store/search.action'; -// import { Dataset, Attribute, Family, Category } from 'src/app/metamodel/model'; -// import { Criterion, SearchQueryParams } from '../store/model'; -// import { ScrollTopService } from '../../shared/service/sroll-top.service'; -// import { RouterLinkDirectiveStub } from '../../../settings/test-data/router-link-directive-stub'; -// import { ConeSearch } from "../../shared/cone-search/store/model"; -// -// describe('[Search] Container: OutputComponent', () => { -// @Component({ selector: 'app-output-tabs', template: '' }) -// class OutputTabsStubComponent { -// @Input() outputFamilyList: Family[]; -// @Input() categoryList: Category[]; -// @Input() datasetAttributeList: Attribute[]; -// @Input() outputList: number[]; -// } -// -// @Component({ selector: 'app-summary', template: '' }) -// class SummaryStubComponent { -// @Input() currentStep: string; -// @Input() datasetName: string; -// @Input() datasetList: Dataset[]; -// @Input() isConeSearchAdded: boolean; -// @Input() coneSearch: ConeSearch; -// @Input() criteriaFamilyList: Family[]; -// @Input() criteriaList: Criterion[]; -// @Input() datasetAttributeList: Attribute[]; -// @Input() outputFamilyList: Family[]; -// @Input() categoryList: Category[]; -// @Input() outputList: number[]; -// @Input() outputListEmpty: boolean; -// @Input() queryParams: SearchQueryParams; -// } -// -// let scrollTopServiceStub: Partial<ScrollTopService> = { -// setScrollTop() {} -// }; -// -// let component: OutputComponent; -// let fixture: ComponentFixture<OutputComponent>; -// let store: MockStore; -// const initialState = { -// search: { ...fromSearch.initialState }, -// metamodel: { ...fromMetamodel }, -// coneSearch: { ...fromConeSearch } -// }; -// -// beforeEach(async(() => { -// TestBed.configureTestingModule({ -// declarations: [ -// OutputComponent, -// OutputTabsStubComponent, -// SummaryStubComponent, -// RouterLinkDirectiveStub -// ], -// providers: [ -// provideMockStore({ initialState }), -// { provide: ScrollTopService, useValue: scrollTopServiceStub } -// ] -// }); -// fixture = TestBed.createComponent(OutputComponent); -// component = fixture.componentInstance; -// store = TestBed.inject(MockStore); -// })); -// -// it('should create the component', () => { -// expect(component).toBeTruthy(); -// }); -// -// it('should execute ngOnInit lifecycle', (done) => { -// const loadDatasetSearchMetaAction = new datasetActions.LoadDatasetSearchMetaAction(); -// const changeStepAction = new searchActions.ChangeStepAction('output'); -// const outputChecked = new searchActions.OutputChecked(); -// const initSearchByUrl = new searchActions.InitSearchByUrl(); -// const spy = spyOn(store, 'dispatch'); -// component.ngOnInit(); -// Promise.resolve(null).then(function() { -// expect(spy).toHaveBeenCalledTimes(4); -// expect(spy).toHaveBeenCalledWith(loadDatasetSearchMetaAction); -// expect(spy).toHaveBeenCalledWith(changeStepAction); -// expect(spy).toHaveBeenCalledWith(outputChecked); -// expect(spy).toHaveBeenCalledWith(initSearchByUrl); -// done(); -// }); -// }); -// -// it('#updateOutputList() should dispatch UpdateOutputListAction', () => { -// const updateOutputListAction = new searchActions.UpdateOutputListAction([1, 2, 3]); -// const spy = spyOn(store, 'dispatch'); -// component.updateOutputList([1, 2, 3]); -// expect(spy).toHaveBeenCalledTimes(1); -// expect(spy).toHaveBeenCalledWith(updateOutputListAction); -// }); -// -// it('#emitOutputListEmpty() should dispatch AddSelectedDataAction', (done) => { -// const outputListEmptyAction = new searchActions.OutputListEmptyAction(true); -// const spy = spyOn(store, 'dispatch'); -// component.emitOutputListEmpty(true); -// Promise.resolve(null).then(function() { -// expect(spy).toHaveBeenCalledTimes(1); -// expect(spy).toHaveBeenCalledWith(outputListEmptyAction); -// done(); -// }); -// }); -// }); +import { ComponentFixture, TestBed, async } from '@angular/core/testing'; +import { Component, Input } from '@angular/core'; + +import { provideMockStore, MockStore } from '@ngrx/store/testing'; +import { of } from 'rxjs'; + +import { OutputComponent } from './output.component'; +import * as fromSearch from '../store/search.reducer'; +import * as searchActions from '../store/search.action'; +import { Criterion, SearchQueryParams } from '../store/model'; +import * as fromMetamodel from '../../metamodel/reducers'; +import * as datasetActions from '../../metamodel/action/dataset.action'; +import { Dataset, Attribute, Family, Category } from '../../metamodel/model'; +import * as fromConeSearch from '../../shared/cone-search/store/cone-search.reducer'; +import { ConeSearch } from '../../shared/cone-search/store/model'; +import { ScrollTopService } from '../../shared/service/sroll-top.service'; +import { RouterLinkDirectiveStub } from '../../../settings/test-data/router-link-directive-stub'; + +describe('[Search] Container: OutputComponent', () => { + @Component({ selector: 'app-output-tabs', template: '' }) + class OutputTabsStubComponent { + @Input() outputFamilyList: Family[]; + @Input() categoryList: Category[]; + @Input() datasetAttributeList: Attribute[]; + @Input() outputList: number[]; + } + + @Component({ selector: 'app-summary', template: '' }) + class SummaryStubComponent { + @Input() currentStep: string; + @Input() datasetName: string; + @Input() datasetList: Dataset[]; + @Input() isConeSearchAdded: boolean; + @Input() coneSearch: ConeSearch; + @Input() criteriaFamilyList: Family[]; + @Input() criteriaList: Criterion[]; + @Input() datasetAttributeList: Attribute[]; + @Input() outputFamilyList: Family[]; + @Input() categoryList: Category[]; + @Input() outputList: number[]; + @Input() outputListEmpty: boolean; + @Input() queryParams: SearchQueryParams; + } + + let scrollTopServiceStub: Partial<ScrollTopService> = { + setScrollTop() {} + }; + + let component: OutputComponent; + let fixture: ComponentFixture<OutputComponent>; + let store: MockStore; + const initialState = { + search: { ...fromSearch.initialState }, + metamodel: { ...fromMetamodel }, + coneSearch: { ...fromConeSearch } + }; + + beforeEach(async(() => { + TestBed.configureTestingModule({ + declarations: [ + OutputComponent, + OutputTabsStubComponent, + SummaryStubComponent, + RouterLinkDirectiveStub + ], + providers: [ + provideMockStore({ initialState }), + { provide: ScrollTopService, useValue: scrollTopServiceStub } + ] + }); + fixture = TestBed.createComponent(OutputComponent); + component = fixture.componentInstance; + store = TestBed.inject(MockStore); + })); + + it('should create the component', () => { + expect(component).toBeTruthy(); + }); + + it('should execute ngOnInit lifecycle', (done) => { + component.datasetName = of('toto'); + const loadDatasetSearchMetaAction = new datasetActions.LoadDatasetSearchMetaAction(); + const changeStepAction = new searchActions.ChangeStepAction('output'); + const outputChecked = new searchActions.OutputChecked(); + const initSearchByUrl = new searchActions.InitSearchByUrl(); + const spy = spyOn(store, 'dispatch'); + component.ngOnInit(); + Promise.resolve(null).then(function() { + expect(spy).toHaveBeenCalledTimes(4); + expect(spy).toHaveBeenCalledWith(loadDatasetSearchMetaAction); + expect(spy).toHaveBeenCalledWith(changeStepAction); + expect(spy).toHaveBeenCalledWith(outputChecked); + expect(spy).toHaveBeenCalledWith(initSearchByUrl); + done(); + }); + }); + + it('#updateOutputList() should dispatch UpdateOutputListAction', () => { + const updateOutputListAction = new searchActions.UpdateOutputListAction([1, 2, 3]); + const spy = spyOn(store, 'dispatch'); + component.updateOutputList([1, 2, 3]); + expect(spy).toHaveBeenCalledTimes(1); + expect(spy).toHaveBeenCalledWith(updateOutputListAction); + }); +}); diff --git a/src/app/search/containers/output.component.ts b/src/app/search/containers/output.component.ts index 0f8686d79b996ea4f8d552fee496bf71581f3c62..1240c59b34258aba8aa07dce756569c67641ba37 100644 --- a/src/app/search/containers/output.component.ts +++ b/src/app/search/containers/output.component.ts @@ -1,19 +1,19 @@ import { Component, OnInit } from '@angular/core'; -import { Observable } from 'rxjs'; import { Store } from '@ngrx/store'; +import { Observable } from 'rxjs'; -import { Criterion, SearchQueryParams } from '../store/model'; -import { Dataset, Family, Category, Attribute } from '../../metamodel/model'; -import * as searchActions from '../store/search.action'; -import * as datasetActions from '../../metamodel/action/dataset.action'; import * as fromSearch from '../store/search.reducer'; -import * as fromMetamodel from '../../metamodel/reducers'; +import * as searchActions from '../store/search.action'; import * as searchSelector from '../store/search.selector'; +import { Criterion, SearchQueryParams } from '../store/model'; +import * as fromMetamodel from '../../metamodel/reducers'; +import * as datasetActions from '../../metamodel/action/dataset.action'; import * as metamodelSelector from '../../metamodel/selectors'; +import { Dataset, Family, Category, Attribute } from '../../metamodel/model'; import * as coneSearchSelector from '../../shared/cone-search/store/cone-search.selector'; -import { ScrollTopService } from '../../shared/service/sroll-top.service'; import { ConeSearch } from '../../shared/cone-search/store/model'; +import { ScrollTopService } from '../../shared/service/sroll-top.service'; interface StoreState { search: fromSearch.State; diff --git a/src/app/search/containers/result.component.spec.ts b/src/app/search/containers/result.component.spec.ts index 93c44dcb7387462250405fc1e16e9cbf4e80e886..28f9e4e12feb70ca3b9a0a8aa0acf349f58f52e5 100644 --- a/src/app/search/containers/result.component.spec.ts +++ b/src/app/search/containers/result.component.spec.ts @@ -1,161 +1,170 @@ -// import { ComponentFixture, TestBed, async } from '@angular/core/testing'; -// import { provideMockStore, MockStore } from '@ngrx/store/testing'; -// import { Component, Input } from '@angular/core'; -// -// import { ResultComponent } from './result.component'; -// import * as fromMetamodel from '../../metamodel/reducers'; -// import * as fromSearch from '../store/search.reducer'; -// import * as fromConeSearch from '../../shared/cone-search/store/cone-search.reducer'; -// import * as datasetActions from '../../metamodel/action/dataset.action'; -// import * as searchActions from '../store/search.action'; -// import { Dataset, Attribute, Family, Category } from 'src/app/metamodel/model'; -// import { Criterion, SearchQueryParams } from '../store/model'; -// import { ScrollTopService } from '../../shared/service/sroll-top.service'; -// import { RouterLinkDirectiveStub } from '../../../settings/test-data/router-link-directive-stub'; -// import { ConeSearch } from "../../shared/cone-search/store/model"; -// -// describe('[Search] Container: ResultComponent', () => { -// @Component({ selector: 'app-result-download', template: '' }) -// class DownloadSectionStubComponent { -// @Input() datasetName: string; -// @Input() datasetList: Dataset[]; -// @Input() dataLength: number; -// @Input() isConeSearchAdded: boolean; -// @Input() coneSearch: ConeSearch; -// @Input() criteriaList: Criterion[]; -// @Input() outputList: number[]; -// } -// -// @Component({ selector: 'app-reminder', template: '' }) -// class ReminderStubComponent { -// @Input() datasetAttributeList: Attribute[]; -// @Input() isConeSearchAdded: boolean; -// @Input() coneSearch: ConeSearch; -// @Input() criteriaList: Criterion[]; -// @Input() criteriaFamilyList: Family[]; -// @Input() outputFamilyList: Family[]; -// @Input() categoryList: Category[]; -// @Input() outputList: number[]; -// } -// -// @Component({ selector: 'app-result-url-display', template: '' }) -// class UrlDisplaySectionStubComponent { -// @Input() datasetList: Dataset[]; -// @Input() datasetName: string; -// @Input() isConeSearchAdded: boolean; -// @Input() coneSearch: ConeSearch; -// @Input() criteriaList: Criterion[]; -// @Input() outputList: number[]; -// } -// -// @Component({ selector: 'app-result-datatable', template: '' }) -// class DatatableSectionStubComponent { -// @Input() datasetName: string; -// @Input() datasetList: Dataset[]; -// @Input() queryParams: SearchQueryParams; -// @Input() datasetAttributeList: Attribute[]; -// @Input() outputList: number[]; -// @Input() searchData: any[]; -// @Input() dataLength: number; -// @Input() selectedData: any[]; -// @Input() processWip: boolean; -// @Input() processDone: boolean; -// @Input() processId: string; -// } -// -// let scrollTopServiceStub: Partial<ScrollTopService> = { -// setScrollTop() {} -// }; -// -// let component: ResultComponent; -// let fixture: ComponentFixture<ResultComponent>; -// let store: MockStore; -// const initialState = { -// search: { ...fromSearch.initialState }, -// metamodel: { ...fromMetamodel }, -// coneSearch: { ...fromConeSearch } -// }; -// -// beforeEach(async(() => { -// TestBed.configureTestingModule({ -// declarations: [ -// ResultComponent, -// DownloadSectionStubComponent, -// ReminderStubComponent, -// UrlDisplaySectionStubComponent, -// DatatableSectionStubComponent, -// RouterLinkDirectiveStub -// ], -// providers: [ -// provideMockStore({ initialState }), -// { provide: ScrollTopService, useValue: scrollTopServiceStub } -// ] -// }); -// fixture = TestBed.createComponent(ResultComponent); -// component = fixture.componentInstance; -// store = TestBed.inject(MockStore); -// })); -// -// it('should create the component', () => { -// expect(component).toBeTruthy(); -// }); -// -// it('should execute ngOnInit lifecycle', (done) => { -// const loadDatasetSearchMetaAction = new datasetActions.LoadDatasetSearchMetaAction(); -// const changeStepAction = new searchActions.ChangeStepAction('result'); -// const resultChecked = new searchActions.ResultChecked(); -// const initSearchByUrl = new searchActions.InitSearchByUrl(); -// const spy = spyOn(store, 'dispatch'); -// component.ngOnInit(); -// Promise.resolve(null).then(function() { -// expect(spy).toHaveBeenCalledTimes(4); -// expect(spy).toHaveBeenCalledWith(loadDatasetSearchMetaAction); -// expect(spy).toHaveBeenCalledWith(changeStepAction); -// expect(spy).toHaveBeenCalledWith(resultChecked); -// expect(spy).toHaveBeenCalledWith(initSearchByUrl); -// done(); -// }); -// }); -// -// it('#getSearchData() should dispatch RetrieveDataAction and GetDataLengthAction', () => { -// const retrieveDataAction = new searchActions.RetrieveDataAction([1, 2, 3, 'four']); -// const getDataLengthAction = new searchActions.GetDataLengthAction(); -// const spy = spyOn(store, 'dispatch'); -// component.getSearchData([1, 2, 3, 'four']); -// expect(spy).toHaveBeenCalledTimes(2); -// expect(spy).toHaveBeenCalledWith(retrieveDataAction); -// expect(spy).toHaveBeenCalledWith(getDataLengthAction); -// }); -// -// it('#addSearchData() should dispatch AddSelectedDataAction', () => { -// const addSelectedDataAction = new searchActions.AddSelectedDataAction('toto'); -// const spy = spyOn(store, 'dispatch'); -// component.addSearchData('toto'); -// expect(spy).toHaveBeenCalledTimes(1); -// expect(spy).toHaveBeenCalledWith(addSelectedDataAction); -// }); -// -// it('#deleteSearchData() should dispatch DeleteSelectedDataAction', () => { -// const deleteSelectedDataAction = new searchActions.DeleteSelectedDataAction('toto'); -// const spy = spyOn(store, 'dispatch'); -// component.deleteSearchData('toto'); -// expect(spy).toHaveBeenCalledTimes(1); -// expect(spy).toHaveBeenCalledWith(deleteSelectedDataAction); -// }); -// -// it('#executeProcess() should dispatch ExecuteProcessAction', () => { -// const executeProcessAction = new searchActions.ExecuteProcessAction('toto'); -// const spy = spyOn(store, 'dispatch'); -// component.executeProcess('toto'); -// expect(spy).toHaveBeenCalledTimes(1); -// expect(spy).toHaveBeenCalledWith(executeProcessAction); -// }); -// -// it('#ngOnDestroy() should dispatch DestroyResultsAction', () => { -// const destroyResultsAction = new searchActions.DestroyResultsAction(); -// const spy = spyOn(store, 'dispatch'); -// component.ngOnDestroy(); -// expect(spy).toHaveBeenCalledTimes(1); -// expect(spy).toHaveBeenCalledWith(destroyResultsAction); -// }); -// }); +import { async, ComponentFixture, TestBed } from '@angular/core/testing'; +import { Component, Input } from '@angular/core'; + +import { MockStore, provideMockStore } from '@ngrx/store/testing'; + +import { ResultComponent } from './result.component'; +import * as fromSearch from '../store/search.reducer'; +import * as searchActions from '../store/search.action'; +import { Criterion, SearchQueryParams } from '../store/model'; +import * as fromMetamodel from '../../metamodel/reducers'; +import * as datasetActions from '../../metamodel/action/dataset.action'; +import { Attribute, Category, Dataset, Family } from '../../metamodel/model'; +import * as fromConeSearch from '../../shared/cone-search/store/cone-search.reducer'; +import { ConeSearch } from '../../shared/cone-search/store/model'; +import { Pagination, PaginationOrder } from '../../shared/datatable/model'; +import { ScrollTopService } from '../../shared/service/sroll-top.service'; +import { RouterLinkDirectiveStub } from '../../../settings/test-data/router-link-directive-stub'; + +describe('[Search] Container: ResultComponent', () => { + @Component({ selector: 'app-result-download', template: '' }) + class DownloadSectionStubComponent { + @Input() datasetName: string; + @Input() datasetList: Dataset[]; + @Input() dataLength: number; + @Input() isConeSearchAdded: boolean; + @Input() coneSearch: ConeSearch; + @Input() criteriaList: Criterion[]; + @Input() outputList: number[]; + } + + @Component({ selector: 'app-reminder', template: '' }) + class ReminderStubComponent { + @Input() datasetAttributeList: Attribute[]; + @Input() isConeSearchAdded: boolean; + @Input() coneSearch: ConeSearch; + @Input() criteriaList: Criterion[]; + @Input() criteriaFamilyList: Family[]; + @Input() outputFamilyList: Family[]; + @Input() categoryList: Category[]; + @Input() outputList: number[]; + } + + @Component({ selector: 'app-result-url-display', template: '' }) + class UrlDisplaySectionStubComponent { + @Input() datasetList: Dataset[]; + @Input() datasetName: string; + @Input() isConeSearchAdded: boolean; + @Input() coneSearch: ConeSearch; + @Input() criteriaList: Criterion[]; + @Input() outputList: number[]; + } + + @Component({ selector: 'app-result-datatable', template: '' }) + class DatatableSectionStubComponent { + @Input() datasetName: string; + @Input() datasetList: Dataset[]; + @Input() queryParams: SearchQueryParams; + @Input() datasetAttributeList: Attribute[]; + @Input() outputList: number[]; + @Input() searchData: any[]; + @Input() dataLength: number; + @Input() selectedData: any[]; + @Input() processWip: boolean; + @Input() processDone: boolean; + @Input() processId: string; + } + + let scrollTopServiceStub: Partial<ScrollTopService> = { + setScrollTop() {} + }; + + let component: ResultComponent; + let fixture: ComponentFixture<ResultComponent>; + let store: MockStore; + const initialState = { + search: { ...fromSearch.initialState }, + metamodel: { ...fromMetamodel }, + coneSearch: { ...fromConeSearch } + }; + + beforeEach(async(() => { + TestBed.configureTestingModule({ + declarations: [ + ResultComponent, + DownloadSectionStubComponent, + ReminderStubComponent, + UrlDisplaySectionStubComponent, + DatatableSectionStubComponent, + RouterLinkDirectiveStub + ], + providers: [ + provideMockStore({ initialState }), + { provide: ScrollTopService, useValue: scrollTopServiceStub } + ] + }); + fixture = TestBed.createComponent(ResultComponent); + component = fixture.componentInstance; + store = TestBed.inject(MockStore); + })); + + it('should create the component', () => { + expect(component).toBeTruthy(); + }); + + it('should execute ngOnInit lifecycle', (done) => { + const loadDatasetSearchMetaAction = new datasetActions.LoadDatasetSearchMetaAction(); + const changeStepAction = new searchActions.ChangeStepAction('result'); + const resultChecked = new searchActions.ResultChecked(); + const initSearchByUrl = new searchActions.InitSearchByUrl(); + const spy = spyOn(store, 'dispatch'); + component.ngOnInit(); + Promise.resolve(null).then(function() { + expect(spy).toHaveBeenCalledTimes(4); + expect(spy).toHaveBeenCalledWith(loadDatasetSearchMetaAction); + expect(spy).toHaveBeenCalledWith(changeStepAction); + expect(spy).toHaveBeenCalledWith(resultChecked); + expect(spy).toHaveBeenCalledWith(initSearchByUrl); + done(); + }); + }); + + it('#getDataLength() should dispatch GetDataLengthAction', () => { + const getDataLengthAction = new searchActions.GetDataLengthAction(); + const spy = spyOn(store, 'dispatch'); + component.getDataLength(); + expect(spy).toHaveBeenCalledTimes(1); + expect(spy).toHaveBeenCalledWith(getDataLengthAction); + }); + + it('#getSearchData() should dispatch RetrieveDataAction', () => { + const pagination: Pagination = { dname: 'toto', nbItems: 10, page: 1, sortedCol: 1, order: PaginationOrder.a }; + const retrieveDataAction = new searchActions.RetrieveDataAction(pagination); + const spy = spyOn(store, 'dispatch'); + component.getSearchData(pagination); + expect(spy).toHaveBeenCalledTimes(1); + expect(spy).toHaveBeenCalledWith(retrieveDataAction); + }); + + it('#addSearchData() should dispatch AddSelectedDataAction', () => { + const addSelectedDataAction = new searchActions.AddSelectedDataAction('toto'); + const spy = spyOn(store, 'dispatch'); + component.addSearchData('toto'); + expect(spy).toHaveBeenCalledTimes(1); + expect(spy).toHaveBeenCalledWith(addSelectedDataAction); + }); + + it('#deleteSearchData() should dispatch DeleteSelectedDataAction', () => { + const deleteSelectedDataAction = new searchActions.DeleteSelectedDataAction('toto'); + const spy = spyOn(store, 'dispatch'); + component.deleteSearchData('toto'); + expect(spy).toHaveBeenCalledTimes(1); + expect(spy).toHaveBeenCalledWith(deleteSelectedDataAction); + }); + + it('#executeProcess() should dispatch ExecuteProcessAction', () => { + const executeProcessAction = new searchActions.ExecuteProcessAction('toto'); + const spy = spyOn(store, 'dispatch'); + component.executeProcess('toto'); + expect(spy).toHaveBeenCalledTimes(1); + expect(spy).toHaveBeenCalledWith(executeProcessAction); + }); + + it('#ngOnDestroy() should dispatch DestroyResultsAction', () => { + const destroyResultsAction = new searchActions.DestroyResultsAction(); + const spy = spyOn(store, 'dispatch'); + component.ngOnDestroy(); + expect(spy).toHaveBeenCalledTimes(1); + expect(spy).toHaveBeenCalledWith(destroyResultsAction); + }); +}); diff --git a/src/app/search/containers/result.component.ts b/src/app/search/containers/result.component.ts index 1d41ceb79c796d44e56b2a565622219d8510bfd9..cd3d6259dee5470b3ded6587cbe0834c1d7f2064 100644 --- a/src/app/search/containers/result.component.ts +++ b/src/app/search/containers/result.component.ts @@ -1,20 +1,20 @@ import { Component, OnInit, OnDestroy } from '@angular/core'; -import { Observable } from 'rxjs'; import { Store } from '@ngrx/store'; +import { Observable } from 'rxjs'; -import { Criterion, SearchQueryParams } from '../store/model'; -import { Dataset, Attribute, Family, Category } from '../../metamodel/model'; -import { ConeSearch } from "../../shared/cone-search/store/model"; -import * as searchActions from '../store/search.action'; -import * as datasetActions from '../../metamodel/action/dataset.action'; import * as fromSearch from '../store/search.reducer'; -import * as fromMetamodel from '../../metamodel/reducers'; +import * as searchActions from '../store/search.action'; import * as searchSelector from '../store/search.selector'; +import { Criterion, SearchQueryParams } from '../store/model'; +import * as fromMetamodel from '../../metamodel/reducers'; +import * as datasetActions from '../../metamodel/action/dataset.action'; import * as metamodelSelector from '../../metamodel/selectors'; +import { Dataset, Attribute, Family, Category } from '../../metamodel/model'; import * as coneSearchSelector from '../../shared/cone-search/store/cone-search.selector'; +import { ConeSearch } from '../../shared/cone-search/store/model'; +import { Pagination } from '../../shared/datatable/model'; import { ScrollTopService } from '../../shared/service/sroll-top.service'; -import {Pagination} from "../../shared/datatable/model"; interface StoreState { search: fromSearch.State;