Skip to content
Snippets Groups Projects
Commit 934fe3ad authored by Tifenn Guillas's avatar Tifenn Guillas
Browse files

Tests on coneSearch reducer => DONE

parent f65d747c
No related branches found
No related tags found
2 merge requests!29Develop,!8Resolve "Add tests for instance store module"
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);
// });
});
......@@ -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;
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment