From 5d26964e85d6f4fd0680869be80d8d546e5b2681 Mon Sep 17 00:00:00 2001
From: dangapay <divin.angapay@lam.fr>
Date: Thu, 27 Oct 2022 11:19:40 +0200
Subject: [PATCH] add test for admin/instance/dataset/containers

---
 .../dataset/dataset-form.component.spec.ts    | 28 ++++++++++
 .../image/image-form.component.spec.ts        | 14 ++++-
 .../configure-dataset.component.spec.ts       |  5 --
 .../containers/new-dataset.component.spec.ts  | 56 ++++++++++++++++---
 4 files changed, 89 insertions(+), 14 deletions(-)

diff --git a/client/src/app/admin/instance/dataset/components/dataset/dataset-form.component.spec.ts b/client/src/app/admin/instance/dataset/components/dataset/dataset-form.component.spec.ts
index 590a3c26..e01fed32 100644
--- a/client/src/app/admin/instance/dataset/components/dataset/dataset-form.component.spec.ts
+++ b/client/src/app/admin/instance/dataset/components/dataset/dataset-form.component.spec.ts
@@ -88,6 +88,34 @@ describe('[admin][instance][dataset][components][dataset] DatasetFormComponent',
         expect(spy).toHaveBeenCalledTimes(1);
         expect(component.form.controls.datatable_selectable_rows.value).toEqual(false);
 
+    });
+    it('should call ngOnChanges and enable on table_ref ', () => {
+        let spy = jest.spyOn(component, 'ngOnChanges');
+        let spyOnTable_ref = jest.spyOn(component.form.controls.table_ref, 'enable');
+        let tableListIsLoaded: boolean = true;
+        component.ngOnChanges(
+            {
+                tableListIsLoaded: new SimpleChange(undefined, tableListIsLoaded, false),
+            }
+        )
+        fixture.detectChanges();
+        expect(spy).toHaveBeenCalledTimes(1);
+        expect(spyOnTable_ref).toHaveBeenCalledTimes(1);
+    })
+
+    it('should call ngOnChanges and desable on table_ref ', () => {
+        let spy = jest.spyOn(component, 'ngOnChanges');
+        let spyOnTable_ref = jest.spyOn(component.form.controls.table_ref, 'disable');
+        let tableListIsLoaded: boolean = false;
+        component.ngOnChanges(
+            {
+                tableListIsLoaded: new SimpleChange(undefined, tableListIsLoaded, false),
+            }
+        )
+        fixture.detectChanges();
+        expect(spy).toHaveBeenCalledTimes(1);
+        expect(spyOnTable_ref).toHaveBeenCalledTimes(1);
     })
 
+
 });
diff --git a/client/src/app/admin/instance/dataset/components/image/image-form.component.spec.ts b/client/src/app/admin/instance/dataset/components/image/image-form.component.spec.ts
index 9f2df998..3011d996 100644
--- a/client/src/app/admin/instance/dataset/components/image/image-form.component.spec.ts
+++ b/client/src/app/admin/instance/dataset/components/image/image-form.component.spec.ts
@@ -7,10 +7,11 @@
  * file that was distributed with this source code.
  */
 
+import { SimpleChange } from '@angular/core';
 import { ComponentFixture, TestBed } from '@angular/core/testing';
 import { ReactiveFormsModule } from '@angular/forms';
 import { BrowserAnimationsModule } from '@angular/platform-browser/animations';
-import { FileInfo } from 'src/app/admin/store/models';
+import { FileInfo, FitsImageLimits } from 'src/app/admin/store/models';
 import { Dataset, Instance } from 'src/app/metamodel/models';
 import { ImageFormComponent } from './image-form.component';
 
@@ -82,6 +83,17 @@ describe('[admin][instance][dataset][components][image] ImageFormComponent', ()
         component.submit();
         expect(spy).toHaveBeenCalledTimes(1);
         expect(spy).toHaveBeenCalledWith({ ...component.form.getRawValue() });
+    });
+    it('should call ngOnChanges', () => {
+        let spy = jest.spyOn(component, 'ngOnChanges');
+        let fitsImageLimits: FitsImageLimits = { dec_max: 10, dec_min: 5, ra_max: 2, ra_min: 1 };
+        component.ngOnChanges(
+            {
+                fitsImageLimits: new SimpleChange(undefined, fitsImageLimits, false),
+            }
+        )
+        fixture.detectChanges();
+        expect(spy).toHaveBeenCalledTimes(1);
     })
 
 });
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
index c8b34fd6..13fdfc47 100644
--- 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
@@ -35,7 +35,6 @@ describe('[admin][instance][dataset][containers] ConfigureDatasetComponent', ()
     beforeEach(() => {
         TestBed.configureTestingModule({
             declarations: [
-
                 ConfigureDatasetComponent,
             ],
             providers: [
@@ -45,9 +44,7 @@ describe('[admin][instance][dataset][containers] ConfigureDatasetComponent', ()
                         queryParamMap: of({ tab_selected: 1 }),
                     },
                 },
-
                 provideMockStore({}),
-
             ],
 
             imports: [
@@ -55,12 +52,10 @@ describe('[admin][instance][dataset][containers] ConfigureDatasetComponent', ()
                 ReactiveFormsModule,
             ]
         });
-
         fixture = TestBed.createComponent(ConfigureDatasetComponent);
         component = fixture.componentInstance;
         store = TestBed.inject(MockStore);
         fixture.detectChanges();
-
     });
 
     it('should create the component', () => {
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
index bbf4eca7..cbf4db5f 100644
--- 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
@@ -14,8 +14,11 @@ 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 { Dataset, Instance } from 'src/app/metamodel/models';
 import { RouterTestingModule } from '@angular/router/testing';
+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';
 const params = {
     get: jest.fn()
 }
@@ -59,13 +62,50 @@ describe('[admin][instance][dataset][containers] NewDatasetComponent', () => {
     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));
-  })
+    it('store should dispatch tableActions.loadTableList', () => {
+        let idDatabase: number = 1;
+        let spy = jest.spyOn(store, 'dispatch');
+        component.loadTableList(idDatabase);
+        expect(spy).toHaveBeenCalledTimes(1);
+        expect(spy).toHaveBeenCalledWith(tableActions.loadTableList({ idDatabase }));
+
+    });
+    it('store should dispatch adminFileExplorerActions.loadFiles', () => {
+        let path: string = 'test';
+        let spy = jest.spyOn(store, 'dispatch');
+        component.loadRootDirectory(path);
+        expect(spy).toHaveBeenCalledTimes(1);
+        expect(spy).toHaveBeenCalledWith(adminFileExplorerActions.loadFiles({ path }));
+
+    });
+    it('store should dispatch datasetActions.addDataset', () => {
+        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'
+        };
+        let spy = jest.spyOn(store, 'dispatch');
+        component.addNewDataset(dataset);
+        expect(spy).toHaveBeenCalledTimes(1);
+        expect(spy).toHaveBeenCalledWith(datasetActions.addDataset({ dataset }));
+
+    });
+
 
 });
 
-- 
GitLab