group reducer and group registry tests

This commit is contained in:
Marie Verdonck
2020-03-19 17:35:38 +01:00
parent e10a37e414
commit 909158c30e
6 changed files with 189 additions and 8 deletions

View File

@@ -0,0 +1,54 @@
import { GroupMock } from '../../../shared/testing/group-mock';
import { GroupRegistryCancelGroupAction, GroupRegistryEditGroupAction } from './group-registry.actions';
import { groupRegistryReducer, GroupRegistryState } from './group-registry.reducers';
const initialState: GroupRegistryState = {
editGroup: null,
};
const editState: GroupRegistryState = {
editGroup: GroupMock,
};
class NullAction extends GroupRegistryEditGroupAction {
type = null;
constructor() {
super(undefined);
}
}
describe('groupRegistryReducer', () => {
it('should return the current state when no valid actions have been made', () => {
const state = initialState;
const action = new NullAction();
const newState = groupRegistryReducer(state, action);
expect(newState).toEqual(state);
});
it('should start with an initial state', () => {
const state = initialState;
const action = new NullAction();
const initState = groupRegistryReducer(undefined, action);
expect(initState).toEqual(state);
});
it('should update the current state to change the editGroup to a new group when GroupRegistryEditGroupAction is dispatched', () => {
const state = editState;
const action = new GroupRegistryEditGroupAction(GroupMock);
const newState = groupRegistryReducer(state, action);
expect(newState.editGroup).toEqual(GroupMock);
});
it('should update the current state to remove the editGroup from the state when GroupRegistryCancelGroupAction is dispatched', () => {
const state = editState;
const action = new GroupRegistryCancelGroupAction();
const newState = groupRegistryReducer(state, action);
expect(newState.editGroup).toEqual(null);
});
});