diff --git a/client/src/app/admin/instance/dataset/containers/configure-dataset.component.spec.ts b/client/src/app/admin/instance/dataset/containers/configure-dataset.component.spec.ts new file mode 100644 index 0000000000000000000000000000000000000000..c8b34fd60eacdea1160a6121171de753113027dd --- /dev/null +++ b/client/src/app/admin/instance/dataset/containers/configure-dataset.component.spec.ts @@ -0,0 +1,253 @@ +/** + * This file is part of Anis Client. + * + * @copyright Laboratoire d'Astrophysique de Marseille / CNRS + * + * For the full copyright and license information, please view the LICENSE + * file that was distributed with this source code. + */ +import { ComponentFixture, TestBed } from '@angular/core/testing'; +import { ReactiveFormsModule } from '@angular/forms'; +import { BrowserAnimationsModule } from '@angular/platform-browser/animations'; +import { MockStore, provideMockStore } from '@ngrx/store/testing'; +import { ConfigureDatasetComponent } from './configure-dataset.component'; +import { ActivatedRoute } from '@angular/router'; +import * as fitsImageActions from 'src/app/admin/store/actions/fits-image.actions'; +import * as coneSearchConfigActions from 'src/app/metamodel/actions/cone-search-config.actions'; +import * as detailConfigActions from 'src/app/metamodel/actions/detail-config.actions'; +import * as columnActions from 'src/app/admin/store/actions/column.actions'; +import * as attributeDistinctActions from 'src/app/admin/store/actions/attribute-distinct.actions'; +import * as criteriaFamilyActions from 'src/app/metamodel/actions/criteria-family.actions'; +import * as outputFamilyActions from 'src/app/metamodel/actions/output-family.actions'; +import * as outputCategoryActions from 'src/app/metamodel/actions/output-category.actions'; +import * as attributeActions from 'src/app/metamodel/actions/attribute.actions'; +import * as adminFileExplorerActions from 'src/app/admin/store/actions/admin-file-explorer.actions'; +import * as imageActions from 'src/app/metamodel/actions/image.actions'; +import * as fileActions from 'src/app/metamodel/actions/file.actions'; +import { of } from 'rxjs'; +import { Attribute, ConeSearchConfig, CriteriaFamily, DetailConfig, File, Image, OutputCategory, OutputFamily } from 'src/app/metamodel/models'; + +describe('[admin][instance][dataset][containers] ConfigureDatasetComponent', () => { + let component: ConfigureDatasetComponent; + let fixture: ComponentFixture<ConfigureDatasetComponent>; + let store: MockStore; + let attribute: Attribute; + beforeEach(() => { + TestBed.configureTestingModule({ + declarations: [ + + ConfigureDatasetComponent, + ], + providers: [ + { + provide: ActivatedRoute, + useValue: { + queryParamMap: of({ tab_selected: 1 }), + }, + }, + + provideMockStore({}), + + ], + + imports: [ + BrowserAnimationsModule, + ReactiveFormsModule, + ] + }); + + fixture = TestBed.createComponent(ConfigureDatasetComponent); + component = fixture.componentInstance; + store = TestBed.inject(MockStore); + fixture.detectChanges(); + + }); + + it('should create the component', () => { + expect(component).toBeTruthy(); + }); + it('store should dispatch loadColumnList action', () => { + let spy = jest.spyOn(store, 'dispatch'); + component.loadColumnList() + expect(spy).toHaveBeenCalledTimes(1); + expect(spy).toHaveBeenCalledWith(columnActions.loadColumnList()); + }); + it('store should dispatch loadAttributeDistinctList action', () => { + let spy = jest.spyOn(store, 'dispatch'); + component.loadAttributeDistinctList(attribute); + expect(spy).toHaveBeenCalledTimes(1); + expect(spy).toHaveBeenCalledWith(attributeDistinctActions.loadAttributeDistinctList({ attribute })); + }) + it('getVoEnabled() should return true', () => { + + let result = component.getVoEnabled(); + expect(result).toEqual(true); + }); + it('store should dispatch addCriteriaFamily action', () => { + let spy = jest.spyOn(store, 'dispatch'); + let criteriaFamily: CriteriaFamily = { display: 10, id: 1, label: 'test', opened: false }; + component.addCriteriaFamily(criteriaFamily); + expect(spy).toHaveBeenCalledTimes(1); + expect(spy).toHaveBeenCalledWith(criteriaFamilyActions.addCriteriaFamily({ criteriaFamily })); + }); + it('store should dispatch editCriteriaFamily action', () => { + let spy = jest.spyOn(store, 'dispatch'); + let criteriaFamily: CriteriaFamily = { display: 10, id: 1, label: 'test', opened: false }; + component.editCriteriaFamily(criteriaFamily); + expect(spy).toHaveBeenCalledTimes(1); + expect(spy).toHaveBeenCalledWith(criteriaFamilyActions.editCriteriaFamily({ criteriaFamily })); + }); + it('store should dispatch deleteCriteriaFamily action', () => { + let spy = jest.spyOn(store, 'dispatch'); + let criteriaFamily: CriteriaFamily = { display: 10, id: 1, label: 'test', opened: false }; + component.deleteCriteriaFamily(criteriaFamily); + expect(spy).toHaveBeenCalledTimes(1); + expect(spy).toHaveBeenCalledWith(criteriaFamilyActions.deleteCriteriaFamily({ criteriaFamily })); + }); + it('store should dispatch addOutputFamily action', () => { + let spy = jest.spyOn(store, 'dispatch'); + let outputFamily: OutputFamily = { display: 10, id: 1, label: 'test', opened: false }; + component.addOutputFamily(outputFamily); + expect(spy).toHaveBeenCalledTimes(1); + expect(spy).toHaveBeenCalledWith(outputFamilyActions.addOutputFamily({ outputFamily })); + }); + it('store should dispatch editOutputFamily action', () => { + let spy = jest.spyOn(store, 'dispatch'); + let outputFamily: OutputFamily = { display: 10, id: 1, label: 'test', opened: false }; + component.editOutputFamily(outputFamily); + expect(spy).toHaveBeenCalledTimes(1); + expect(spy).toHaveBeenCalledWith(outputFamilyActions.editOutputFamily({ outputFamily })); + }); + it('store should dispatch deleteOutputFamily action', () => { + let spy = jest.spyOn(store, 'dispatch'); + let outputFamily: OutputFamily = { display: 10, id: 1, label: 'test', opened: false }; + component.deleteOutputFamily(outputFamily); + expect(spy).toHaveBeenCalledTimes(1); + expect(spy).toHaveBeenCalledWith(outputFamilyActions.deleteOutputFamily({ outputFamily })); + }); + it('store should dispatch addOutputCategory action', () => { + let spy = jest.spyOn(store, 'dispatch'); + let outputCategory: OutputCategory = { display: 10, id: 1, label: 'test', id_output_family: 1 }; + component.addOutputCategory(outputCategory); + expect(spy).toHaveBeenCalledTimes(1); + expect(spy).toHaveBeenCalledWith(outputCategoryActions.addOutputCategory({ outputCategory })); + }); + it('store should dispatch editOutputCategory action', () => { + let spy = jest.spyOn(store, 'dispatch'); + let outputCategory: OutputCategory = { display: 10, id: 1, label: 'test', id_output_family: 1 }; + component.editOutputCategory(outputCategory); + expect(spy).toHaveBeenCalledTimes(1); + expect(spy).toHaveBeenCalledWith(outputCategoryActions.editOutputCategory({ outputCategory })); + }); + it('store should dispatch deleteOutputCategory action', () => { + let spy = jest.spyOn(store, 'dispatch'); + let outputCategory: OutputCategory = { display: 10, id: 1, label: 'test', id_output_family: 1 }; + component.deleteOutputCategory(outputCategory); + expect(spy).toHaveBeenCalledTimes(1); + expect(spy).toHaveBeenCalledWith(outputCategoryActions.deleteOutputCategory({ outputCategory })); + }); + it('store should dispatch addAttribute action', () => { + let spy = jest.spyOn(store, 'dispatch'); + component.addAttribute(attribute); + expect(spy).toHaveBeenCalledTimes(1); + expect(spy).toHaveBeenCalledWith(attributeActions.addAttribute({ attribute })); + }); + it('store should dispatch editAttribute action', () => { + let spy = jest.spyOn(store, 'dispatch'); + component.editAttribute(attribute); + expect(spy).toHaveBeenCalledTimes(1); + expect(spy).toHaveBeenCalledWith(attributeActions.editAttribute({ attribute })); + }); + it('store should dispatch deleteAttribute action', () => { + let spy = jest.spyOn(store, 'dispatch'); + component.deleteAttribute(attribute); + expect(spy).toHaveBeenCalledTimes(1); + expect(spy).toHaveBeenCalledWith(attributeActions.deleteAttribute({ attribute })); + }); + it('store should dispatch adminFileExplorerActions.loadFiles action', () => { + let spy = jest.spyOn(store, 'dispatch'); + let path: string = 'test'; + component.loadRootDirectory(path); + expect(spy).toHaveBeenCalledTimes(1); + expect(spy).toHaveBeenCalledWith(adminFileExplorerActions.loadFiles({ path })); + }); + it('store should dispatch fitsImageActions.retrieveFitsImageLimits action', () => { + let spy = jest.spyOn(store, 'dispatch'); + let filePath: string = 'test'; + component.retrieveFitsImageLimits(filePath); + expect(spy).toHaveBeenCalledTimes(1); + expect(spy).toHaveBeenCalledWith(fitsImageActions.retrieveFitsImageLimits({ filePath })); + }); + it('store should dispatch imageActions.addImage action', () => { + let spy = jest.spyOn(store, 'dispatch'); + let image: Image = { dec_max: 1, dec_min: 0, file_path: 'test', file_size: 10, id: 1, label: 'test', pmax: 10, pmin: 1, ra_max: 10, ra_min: 10, stretch: 'test' }; + component.addImage(image); + expect(spy).toHaveBeenCalledTimes(1); + expect(spy).toHaveBeenCalledWith(imageActions.addImage({ image })); + }); + it('store should dispatch imageActions.editImage action', () => { + let spy = jest.spyOn(store, 'dispatch'); + let image: Image = { dec_max: 1, dec_min: 0, file_path: 'test', file_size: 10, id: 1, label: 'test', pmax: 10, pmin: 1, ra_max: 10, ra_min: 10, stretch: 'test' }; + component.editImage(image); + expect(spy).toHaveBeenCalledTimes(1); + expect(spy).toHaveBeenCalledWith(imageActions.editImage({ image })); + }); + it('store should dispatch imageActions.deleteImage action', () => { + let spy = jest.spyOn(store, 'dispatch'); + let image: Image = { dec_max: 1, dec_min: 0, file_path: 'test', file_size: 10, id: 1, label: 'test', pmax: 10, pmin: 1, ra_max: 10, ra_min: 10, stretch: 'test' }; + component.deleteImage(image); + expect(spy).toHaveBeenCalledTimes(1); + expect(spy).toHaveBeenCalledWith(imageActions.deleteImage({ image })); + }); + it('store should dispatch fileActions.addFile action', () => { + let spy = jest.spyOn(store, 'dispatch'); + let file: File = { file_path: 'test', file_size: 10, id: 1, label: 'test', type: 'test' } + component.addFile(file); + expect(spy).toHaveBeenCalledTimes(1); + expect(spy).toHaveBeenCalledWith(fileActions.addFile({ file })); + }); + it('store should dispatch fileActions.editFile action', () => { + let spy = jest.spyOn(store, 'dispatch'); + let file: File = { file_path: 'test', file_size: 10, id: 1, label: 'test', type: 'test' } + component.editFile(file); + expect(spy).toHaveBeenCalledTimes(1); + expect(spy).toHaveBeenCalledWith(fileActions.editFile({ file })); + }); + it('store should dispatch fileActions.deleteFile action', () => { + let spy = jest.spyOn(store, 'dispatch'); + let file: File = { file_path: 'test', file_size: 10, id: 1, label: 'test', type: 'test' } + component.deleteFile(file); + expect(spy).toHaveBeenCalledTimes(1); + expect(spy).toHaveBeenCalledWith(fileActions.deleteFile({ file })); + }); + it('store should dispatch coneSearchConfigActions.addConeSearchConfig action', () => { + let spy = jest.spyOn(store, 'dispatch'); + let coneSearchConfig: ConeSearchConfig = { column_dec: 10, column_ra: 10, enabled: false, id: 1, opened: false, plot_enabled: false }; + component.addConeSearchConfig(coneSearchConfig); + expect(spy).toHaveBeenCalledTimes(1); + expect(spy).toHaveBeenCalledWith(coneSearchConfigActions.addConeSearchConfig({ coneSearchConfig })); + }); + it('store should dispatch coneSearchConfigActions.editConeSearchConfig action', () => { + let spy = jest.spyOn(store, 'dispatch'); + let coneSearchConfig: ConeSearchConfig = { column_dec: 10, column_ra: 10, enabled: false, id: 1, opened: false, plot_enabled: false }; + component.editConeSearchConfig(coneSearchConfig); + expect(spy).toHaveBeenCalledTimes(1); + expect(spy).toHaveBeenCalledWith(coneSearchConfigActions.editConeSearchConfig({ coneSearchConfig })); + }); + it('store should dispatch detailConfigActions.addDetailConfig action', () => { + let spy = jest.spyOn(store, 'dispatch'); + let detailConfig: DetailConfig = { content: 'test', id: 1, style_sheet: 'test' }; + component.addDetailConfig(detailConfig); + expect(spy).toHaveBeenCalledTimes(1); + expect(spy).toHaveBeenCalledWith(detailConfigActions.addDetailConfig({ detailConfig })); + }); + it('store should dispatch detailConfigActions.editDetailConfig action', () => { + let spy = jest.spyOn(store, 'dispatch'); + let detailConfig: DetailConfig = { content: 'test', id: 1, style_sheet: 'test' }; + component.editDetailConfig(detailConfig); + expect(spy).toHaveBeenCalledTimes(1); + expect(spy).toHaveBeenCalledWith(detailConfigActions.editDetailConfig({ detailConfig })); + }); + +}); + diff --git a/client/src/app/admin/instance/dataset/containers/dataset-list.component.spec.ts b/client/src/app/admin/instance/dataset/containers/dataset-list.component.spec.ts new file mode 100644 index 0000000000000000000000000000000000000000..11587f5172ec8bb944bdc3bf160afe7083485b13 --- /dev/null +++ b/client/src/app/admin/instance/dataset/containers/dataset-list.component.spec.ts @@ -0,0 +1,100 @@ +/** + * This file is part of Anis Client. + * + * @copyright Laboratoire d'Astrophysique de Marseille / CNRS + * + * For the full copyright and license information, please view the LICENSE + * file that was distributed with this source code. + */ +import { ComponentFixture, TestBed } from '@angular/core/testing'; +import { ReactiveFormsModule } from '@angular/forms'; +import { BrowserAnimationsModule } from '@angular/platform-browser/animations'; +import { MockSelector, MockStore, provideMockStore } from '@ngrx/store/testing'; +import { DatasetListComponent } from './dataset-list.component'; +import * as instanceSelector from 'src/app/metamodel/selectors/instance.selector'; +import { Dataset, DatasetFamily, Instance } from 'src/app/metamodel/models'; +import * as datasetFamilyActions from 'src/app/metamodel/actions/dataset-family.actions'; +import * as datasetActions from 'src/app/metamodel/actions/dataset.actions'; +describe('[admin][instance][dataset][containers] DatasetListComponent', () => { + let component: DatasetListComponent; + let fixture: ComponentFixture<DatasetListComponent>; + let store: MockStore; + let mockinstanceSelectorInstanceByRouteName; + beforeEach(() => { + TestBed.configureTestingModule({ + declarations: [ + + DatasetListComponent, + ], + providers: [ + provideMockStore({}), + ], + + imports: [ + BrowserAnimationsModule, + ReactiveFormsModule, + ] + }); + + fixture = TestBed.createComponent(DatasetListComponent); + component = fixture.componentInstance; + store = TestBed.inject(MockStore); + let instance: Instance; + mockinstanceSelectorInstanceByRouteName = store.overrideSelector(instanceSelector.selectInstanceByRouteName, { ...instance, label: 'test' }) + fixture.detectChanges(); + + }); + + it('should create the component', () => { + expect(component).toBeTruthy(); + }); + it('store should dispatch datasetFamilyActions.addDatasetFamily action', () => { + let spy = jest.spyOn(store, 'dispatch'); + let datasetFamily: DatasetFamily = { display: 10, id: 1, label: 'test', opened: false }; + component.addDatasetFamily(datasetFamily); + expect(spy).toHaveBeenCalledTimes(1); + expect(spy).toHaveBeenCalledWith(datasetFamilyActions.addDatasetFamily({ datasetFamily })); + }); + it('store should dispatch datasetFamilyActions.editDatasetFamily action', () => { + let spy = jest.spyOn(store, 'dispatch'); + let datasetFamily: DatasetFamily = { display: 10, id: 1, label: 'test', opened: false }; + component.editDatasetFamily(datasetFamily); + expect(spy).toHaveBeenCalledTimes(1); + expect(spy).toHaveBeenCalledWith(datasetFamilyActions.editDatasetFamily({ datasetFamily })); + }); + it('store should dispatch datasetFamilyActions.deleteDatasetFamily action', () => { + let spy = jest.spyOn(store, 'dispatch'); + let datasetFamily: DatasetFamily = { display: 10, id: 1, label: 'test', opened: false }; + component.deleteDatasetFamily(datasetFamily); + expect(spy).toHaveBeenCalledTimes(1); + expect(spy).toHaveBeenCalledWith(datasetFamilyActions.deleteDatasetFamily({ datasetFamily })); + }); + it('store should dispatch datasetActions.deleteDataset action', () => { + let spy = jest.spyOn(store, 'dispatch'); + let dataset: Dataset = { + display: 10, + label: 'test', + cone_search_config_id: 1, + data_path: 'test', + datatable_enabled: false, + datatable_selectable_rows: false, + description: 'test', + download_ascii: false, + download_csv: false, + download_json: true, + download_vo: true, + full_data_path: 'test', + id_database: 10, + id_dataset_family: 1, + name: 'test', + public: false, + server_link_enabled: false, + table_ref: 'test' + }; + component.deleteDataset(dataset); + expect(spy).toHaveBeenCalledTimes(1); + expect(spy).toHaveBeenCalledWith(datasetActions.deleteDataset({ dataset })); + }); + +}); + diff --git a/client/src/app/admin/instance/dataset/containers/edit-dataset.component.spec.ts b/client/src/app/admin/instance/dataset/containers/edit-dataset.component.spec.ts new file mode 100644 index 0000000000000000000000000000000000000000..1fc40f877ae9581913adab82ef61915caf1489c8 --- /dev/null +++ b/client/src/app/admin/instance/dataset/containers/edit-dataset.component.spec.ts @@ -0,0 +1,96 @@ +/** + * This file is part of Anis Client. + * + * @copyright Laboratoire d'Astrophysique de Marseille / CNRS + * + * For the full copyright and license information, please view the LICENSE + * file that was distributed with this source code. + */ +import { ComponentFixture, TestBed } from '@angular/core/testing'; +import { ReactiveFormsModule } from '@angular/forms'; +import { BrowserAnimationsModule } from '@angular/platform-browser/animations'; +import { MockSelector, MockStore, provideMockStore } from '@ngrx/store/testing';; +import { EditDatasetComponent } from './edit-dataset.component'; +import * as instanceSelector from 'src/app/metamodel/selectors/instance.selector'; +import { Dataset, Instance } from 'src/app/metamodel/models'; +import * as tableActions from 'src/app/admin/store/actions/table.actions'; +import * as adminFileExplorerActions from 'src/app/admin/store/actions/admin-file-explorer.actions'; +import * as datasetActions from 'src/app/metamodel/actions/dataset.actions'; +describe('[admin][instance][dataset][containers] DatasetListComponent', () => { + let component: EditDatasetComponent; + let fixture: ComponentFixture<EditDatasetComponent>; + let store: MockStore; + let mockinstanceSelectorInstanceByRouteName; + beforeEach(() => { + TestBed.configureTestingModule({ + declarations: [ + EditDatasetComponent + ], + providers: [ + provideMockStore({}), + ], + + imports: [ + BrowserAnimationsModule, + ReactiveFormsModule, + ] + }); + + fixture = TestBed.createComponent(EditDatasetComponent); + component = fixture.componentInstance; + store = TestBed.inject(MockStore); + let instance: Instance; + mockinstanceSelectorInstanceByRouteName = store.overrideSelector(instanceSelector.selectInstanceByRouteName, { ...instance, name: 'test' }) + fixture.detectChanges(); + + }); + + it('should create the component', () => { + expect(component).toBeTruthy(); + }); + + it('store should dispatch tableActions.loadTableList', () => { + let spy = jest.spyOn(store, 'dispatch'); + let idDatabase: number = 1; + component.loadTableList(idDatabase); + expect(spy).toHaveBeenCalledTimes(1); + expect(spy).toHaveBeenCalledWith(tableActions.loadTableList({ idDatabase })); + }); + it('store should dispatch adminFileExplorerActions.loadFiles', () => { + let spy = jest.spyOn(store, 'dispatch'); + let path: string = 'test'; + component.loadRootDirectory(path); + expect(spy).toHaveBeenCalledTimes(1); + expect(spy).toHaveBeenCalledWith(adminFileExplorerActions.loadFiles({ path })); + }); + it('store should dispatch datasetActions.editDataset', () => { + let spy = jest.spyOn(store, 'dispatch'); + let dataset: Dataset = { + display: 10, + label: 'test', + cone_search_config_id: 1, + data_path: 'test', + datatable_enabled: false, + datatable_selectable_rows: false, + description: 'test', + download_ascii: false, + download_csv: false, + download_json: true, + download_vo: true, + full_data_path: 'test', + id_database: 10, + id_dataset_family: 1, + name: 'test', + public: false, + server_link_enabled: false, + table_ref: 'test' + }; + component.editDataset(dataset); + expect(spy).toHaveBeenCalledTimes(1); + expect(spy).toHaveBeenCalledWith(datasetActions.editDataset({ dataset })); + }); + + + +}); + diff --git a/client/src/app/admin/instance/dataset/containers/new-dataset.component.spec.ts b/client/src/app/admin/instance/dataset/containers/new-dataset.component.spec.ts new file mode 100644 index 0000000000000000000000000000000000000000..bbf4eca775c2d2ecc9959022ccdadfb85299b6f7 --- /dev/null +++ b/client/src/app/admin/instance/dataset/containers/new-dataset.component.spec.ts @@ -0,0 +1,71 @@ +/** + * This file is part of Anis Client. + * + * @copyright Laboratoire d'Astrophysique de Marseille / CNRS + * + * For the full copyright and license information, please view the LICENSE + * file that was distributed with this source code. + */ +import { ComponentFixture, TestBed } from '@angular/core/testing'; +import { ReactiveFormsModule } from '@angular/forms'; +import { BrowserAnimationsModule } from '@angular/platform-browser/animations'; +import { MockStore, provideMockStore } from '@ngrx/store/testing'; +import { ActivatedRoute, Router } from '@angular/router'; +import { of } from 'rxjs'; +import { NewDatasetComponent } from './new-dataset.component'; +import * as instanceSelector from 'src/app/metamodel/selectors/instance.selector'; +import { Instance } from 'src/app/metamodel/models'; +import { RouterTestingModule } from '@angular/router/testing'; +const params = { + get: jest.fn() +} +describe('[admin][instance][dataset][containers] NewDatasetComponent', () => { + let component: NewDatasetComponent; + let fixture: ComponentFixture<NewDatasetComponent>; + let store: MockStore; + let mockInstanceSelectorSelectInstanceByRouteName; + beforeEach(() => { + TestBed.configureTestingModule({ + declarations: [ + NewDatasetComponent, + ], + providers: [ + { + provide: ActivatedRoute, + useValue: { + queryParamMap: of(params) + } + }, + provideMockStore({}) + ], + + imports: [ + BrowserAnimationsModule, + ReactiveFormsModule, + RouterTestingModule.withRoutes([]) + ] + }); + + fixture = TestBed.createComponent(NewDatasetComponent); + component = fixture.componentInstance; + store = TestBed.inject(MockStore); + let instance: Instance; + mockInstanceSelectorSelectInstanceByRouteName = store.overrideSelector(instanceSelector.selectInstanceByRouteName, { ...instance, name: 'test' }); + fixture.detectChanges(); + TestBed.inject(ActivatedRoute); + + }); + + it('should create the component', () => { + expect(component).toBeTruthy() + }); + it('should set the partner property to PARTNER_X as in the GET parameter', () => { + const getParamSpy = jest.spyOn(params, 'get').mockReturnValueOnce('PARTNER_X') + + component.ngOnInit() + + expect(component.idDatasetFamily).toBe(of(1)); + }) + +}); +