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

WIP:Tests on selectors

parent 03d8a91d
No related branches found
No related tags found
2 merge requests!72Develop,!27Resolve "Add tests for metamodel module"
import { Action } from '@ngrx/store';
import * as fromSurvey from './survey.reducer';
import * as surveyActions from '../actions/survey.actions';
import { SURVEY, SURVEY_LIST } from '../../../test-data';
describe('[Metamodel][Reducers] Survey reducer', () => {
it('unknown action should return the default state', () => {
const { initialState } = fromSurvey;
const action = { type: 'Unknown' };
const state = fromSurvey.surveyReducer(initialState, action);
expect(state).toBe(initialState);
});
it('addConeSearch action should add conesearch', () => {
const { initialState } = fromSurvey;
const action = surveyActions.loadSurveyListSuccess({ surveys: SURVEY_LIST });
const state = fromSurvey.surveyReducer(initialState, action);
console.log(state);
// 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();
// });
});
import * as selectOptionSelector from './select-option.selector';
import * as fromSelectOption from '../reducers/select-option.reducer';
import { SELECT_OPTION } from '../../../test-data';
describe('[Metamodel][Selector] Select option selector', () => {
it('should get selectOption state', () => {
const state = { metamodel: { selectOption: { ...fromSelectOption.initialState }}};
expect(selectOptionSelector.selectSelectOptionState(state)).toEqual(state.metamodel.selectOption);
});
it('should get selectOption IDs', () => {
const state = { metamodel: { selectOption: { ...fromSelectOption.initialState }}};
expect(selectOptionSelector.selectSelectOptionIds(state).length).toEqual(0);
});
it('should get selectOption entities', () => {
const state = { metamodel: { selectOption: { ...fromSelectOption.initialState }}};
expect(selectOptionSelector.selectSelectOptionEntities(state)).toEqual({ });
});
it('should get all selectOption', () => {
const state = { metamodel: { selectOption: { ...fromSelectOption.initialState }}};
expect(selectOptionSelector.selectAllSelectOptions(state).length).toEqual(0);
});
it('should get selectOption count', () => {
const state = { metamodel: { selectOption: { ...fromSelectOption.initialState }}};
expect(selectOptionSelector.selectSelectOptionTotal(state)).toEqual(0);
});
it('should get selectOptionListIsLoading', () => {
const state = { metamodel: { selectOption: { ...fromSelectOption.initialState }}};
expect(selectOptionSelector.selectSelectOptionListIsLoading(state)).toBe(false);
});
it('should get selectOptionListIsLoaded', () => {
const state = { metamodel: { selectOption: { ...fromSelectOption.initialState }}};
expect(selectOptionSelector.selectSelectOptionListIsLoaded(state)).toBe(false);
});
it('should get select option by select name', () => {
const state = {
router: { state: { params: { select: 'name_one' }}},
metamodel: {
selectOption: {
...fromSelectOption.initialState,
ids: [1],
entities: { 1: SELECT_OPTION }
}
}
};
expect(selectOptionSelector.getOptionBySelectName(state)).toEqual([SELECT_OPTION]);
});
});
import * as surveySelector from './survey.selector';
import * as fromSurvey from '../reducers/survey.reducer';
import { SURVEY } from '../../../test-data';
describe('[Metamodel][Selector] Survey selector', () => {
it('should get survey state', () => {
const state = { metamodel: { survey: { ...fromSurvey.initialState }}};
expect(surveySelector.selectSurveyState(state)).toEqual(state.metamodel.survey);
});
it('should get survey IDs', () => {
const state = { metamodel: { survey: { ...fromSurvey.initialState }}};
expect(surveySelector.selectSurveyIds(state).length).toEqual(0);
});
it('should get survey entities', () => {
const state = { metamodel: { survey: { ...fromSurvey.initialState }}};
expect(surveySelector.selectSurveyEntities(state)).toEqual({ });
});
it('should get all surveys', () => {
const state = { metamodel: { survey: { ...fromSurvey.initialState }}};
expect(surveySelector.selectAllSurveys(state).length).toEqual(0);
});
it('should get survey count', () => {
const state = { metamodel: { survey: { ...fromSurvey.initialState }}};
expect(surveySelector.selectSurveyTotal(state)).toEqual(0);
});
it('should get surveyListIsLoading', () => {
const state = { metamodel: { survey: { ...fromSurvey.initialState }}};
expect(surveySelector.selectSurveyListIsLoading(state)).toBe(false);
});
it('should get surveyListIsLoaded', () => {
const state = { metamodel: { survey: { ...fromSurvey.initialState }}};
expect(surveySelector.selectSurveyListIsLoaded(state)).toBe(false);
});
it('should get survey by route', () => {
const state = {
router: { state: { params: { name: 'survey-one' }}},
metamodel: {
survey: {
...fromSurvey.initialState,
ids: ['survey-one'],
entities: { 'survey-one': SURVEY }
}
}
};
expect(surveySelector.selectSurveyByRouteName(state)).toEqual(SURVEY);
});
});
import * as tableSelector from './table.selector';
import * as fromTable from '../reducers/table.reducer';
describe('[Metamodel][Selector] Table selector', () => {
it('should get table state', () => {
const state = { metamodel: { table: { ...fromTable.initialState }}};
expect(tableSelector.selectTableState(state)).toEqual(state.metamodel.table);
});
it('should get table IDs', () => {
const state = { metamodel: { table: { ...fromTable.initialState }}};
expect(tableSelector.selectTableIds(state).length).toEqual(0);
});
it('should get table entities', () => {
const state = { metamodel: { table: { ...fromTable.initialState }}};
expect(tableSelector.selectTableEntities(state)).toEqual({ });
});
it('should get all tables', () => {
const state = { metamodel: { table: { ...fromTable.initialState }}};
expect(tableSelector.selectAllTables(state).length).toEqual(0);
});
it('should get table count', () => {
const state = { metamodel: { table: { ...fromTable.initialState }}};
expect(tableSelector.selectTableTotal(state)).toEqual(0);
});
it('should get tableListIsLoading', () => {
const state = { metamodel: { table: { ...fromTable.initialState }}};
expect(tableSelector.selectTableListIsLoading(state)).toBe(false);
});
it('should get tableListIsLoaded', () => {
const state = { metamodel: { table: { ...fromTable.initialState }}};
expect(tableSelector.selectTableListIsLoaded(state)).toBe(false);
});
});
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