From 934fe3ad01fcd82d627fa2953b4060c6a4c06052 Mon Sep 17 00:00:00 2001
From: Tifenn Guillas <tifenn.guillas@gmail.com>
Date: Fri, 10 Sep 2021 16:45:16 +0200
Subject: [PATCH] Tests on coneSearch reducer => DONE

---
 .../reducers/cone-search.reducer.spec.ts      | 118 ++++++++++++++++++
 .../store/reducers/cone-search.reducer.ts     |   5 +
 2 files changed, 123 insertions(+)
 create mode 100644 client/src/app/instance/store/reducers/cone-search.reducer.spec.ts

diff --git a/client/src/app/instance/store/reducers/cone-search.reducer.spec.ts b/client/src/app/instance/store/reducers/cone-search.reducer.spec.ts
new file mode 100644
index 00000000..2e09b014
--- /dev/null
+++ b/client/src/app/instance/store/reducers/cone-search.reducer.spec.ts
@@ -0,0 +1,118 @@
+import * as fromConeSearch from './cone-search.reducer';
+import * as coneSearchActions from '../actions/cone-search.actions';
+import { ConeSearch, Resolver } from '../models';
+import { Action } from '@ngrx/store';
+
+describe('ConeSearch reducer', () => {
+    it('unknown action should return the default state', () => {
+        const { initialState } = fromConeSearch;
+        const action = { type: 'Unknown' };
+        const state = fromConeSearch.coneSearchReducer(initialState, action);
+
+        expect(state).toBe(initialState);
+    });
+
+    it('addConeSearch action should add conesearch', () => {
+        const { initialState } = fromConeSearch;
+        const coneSearch: ConeSearch = { ra: 1, dec: 2, radius: 3 };
+        const action = coneSearchActions.addConeSearch({ coneSearch });
+        const state = fromConeSearch.coneSearchReducer(initialState, action);
+
+        expect(state.coneSearch).toEqual(coneSearch);
+        expect(state.resolver).toBeNull();
+        expect(state.resolverIsLoading).toBeFalsy();
+        expect(state.resolverIsLoaded).toBeFalsy();
+        expect(state).not.toBe(initialState);
+    });
+
+    it('deleteConeSearch action should delete conesearch', () => {
+        const initialState = {
+            ...fromConeSearch.initialState,
+            coneSearch: { ra: 1, dec: 2, radius: 3 }
+        };
+        const action = coneSearchActions.deleteConeSearch();
+        const state = fromConeSearch.coneSearchReducer(initialState, action);
+
+        expect(state.coneSearch).toBeNull();
+        expect(state.resolver).toBeNull();
+        expect(state.resolverIsLoading).toBeFalsy();
+        expect(state.resolverIsLoaded).toBeFalsy();
+        expect(state).not.toBe(initialState);
+    });
+
+    it('retrieveCoordinates action should set resolverIsLoading to true and resolverIsLoaded to false', () => {
+        const { initialState } = fromConeSearch;
+        const action = coneSearchActions.retrieveCoordinates({ name: 'myObject' });
+        const state = fromConeSearch.coneSearchReducer(initialState, action);
+
+        expect(state.coneSearch).toBeNull();
+        expect(state.resolver).toBeNull();
+        expect(state.resolverIsLoading).toBeTruthy();
+        expect(state.resolverIsLoaded).toBeFalsy();
+        expect(state).not.toBe(initialState);
+    });
+
+    it('retrieveCoordinatesSuccess action should set resolverIsLoading to false and resolverIsLoaded to true', () => {
+        const { initialState } = fromConeSearch;
+        const resolver: Resolver = { name: 'myObject', ra: 1, dec: 2 };
+        const action = coneSearchActions.retrieveCoordinatesSuccess({ resolver });
+        const state = fromConeSearch.coneSearchReducer(initialState, action);
+
+        expect(state.coneSearch).toBeNull();
+        expect(state.resolver).toBe(resolver);
+        expect(state.resolverIsLoading).toBeFalsy();
+        expect(state.resolverIsLoaded).toBeTruthy();
+        expect(state).not.toBe(initialState);
+    });
+
+    it('retrieveCoordinatesFail action should set resolverIsLoading to false', () => {
+        const initialState = {
+            ...fromConeSearch.initialState,
+            resolverIsLoading: true
+        };
+        const action = coneSearchActions.retrieveCoordinatesFail();
+        const state = fromConeSearch.coneSearchReducer(initialState, action);
+
+        expect(state.coneSearch).toBeNull();
+        expect(state.resolver).toBeNull();
+        expect(state.resolverIsLoading).toBeFalsy();
+        expect(state.resolverIsLoaded).toBeFalsy();
+        expect(state).not.toBe(initialState);
+    });
+
+    it('should get coneSearch', () => {
+        const action = {} as Action;
+        const state =  fromConeSearch.coneSearchReducer(undefined, action);
+
+        expect(fromConeSearch.selectConeSearch(state)).toBeNull();
+    });
+
+    it('should get resolver', () => {
+        const action = {} as Action;
+        const state = fromConeSearch.coneSearchReducer(undefined, action);
+
+        expect(fromConeSearch.selectResolver(state)).toBeNull();
+    });
+
+    it('should get resolverIsLoading', () => {
+        const action = {} as Action;
+        const state =  fromConeSearch.coneSearchReducer(undefined, action);
+
+        expect(fromConeSearch.selectResolverIsLoading(state)).toBeFalsy();
+    });
+
+    it('should get resolverIsLoaded', () => {
+        const action = {} as Action;
+        const state = fromConeSearch.coneSearchReducer(undefined, action);
+
+        expect(fromConeSearch.selectResolverIsLoaded(state)).toBeFalsy();
+    });
+
+    // it('should get coneSearch', () => {
+    //     const action = {} as coneSearchActions.Actions;
+    //     const state = fromConeSearch.reducer(undefined, action);
+    //     const expectedConeSearch: ConeSearch = { ra: null, dec: null, radius: null };
+    //
+    //     expect(fromConeSearch.getConeSearch(state)).toEqual(expectedConeSearch);
+    // });
+});
diff --git a/client/src/app/instance/store/reducers/cone-search.reducer.ts b/client/src/app/instance/store/reducers/cone-search.reducer.ts
index 6a4ee35c..63715d1a 100644
--- a/client/src/app/instance/store/reducers/cone-search.reducer.ts
+++ b/client/src/app/instance/store/reducers/cone-search.reducer.ts
@@ -12,6 +12,11 @@ import { createReducer, on } from '@ngrx/store';
 import * as coneSearchActions from '../actions/cone-search.actions';
 import { ConeSearch, Resolver } from '../models';
 
+/**
+ * Interface for cone search state.
+ *
+ * @interface State
+ */
 export interface State {
     coneSearch: ConeSearch;
     resolver: Resolver;
-- 
GitLab