| import { PersonTypesReducer, INITIAL_STATE, getData, getLoading, getLoaded, getFailed, reducer} from '@app/shared/store/reducers/admin/person-types.reducer'; |
| import * as personTypesActions from '@shared/store/actions/admin/person-types.action'; |
| import { PersonType } from '@shared/models'; |
| |
| describe('PersonTypes reducer', () => { |
| |
| it('should return the initial state', () => { |
| const action = { type: 'NOOP' } as any; |
| const result = reducer(undefined, action); |
| |
| expect(result).toBe(INITIAL_STATE); |
| }); |
| |
| it('should trigger loading state', () => { |
| const action = personTypesActions.loadPersonTypes(); |
| const result = PersonTypesReducer(INITIAL_STATE, action); |
| |
| expect(result).toEqual({ |
| ...INITIAL_STATE, |
| loading: true, |
| }); |
| }); |
| |
| it('should trigger loaded state', () => { |
| const items: personTypesActions.ILoadPersonTypesSuccess = {payload: [new PersonType()]}; |
| items.payload[0].type = 'testme'; |
| const action = personTypesActions.loadPersonTypesSuccess(items); |
| const result = PersonTypesReducer(INITIAL_STATE, action); |
| |
| expect(result.loaded).toBe(true); |
| }); |
| |
| it('should trigger failed state', () => { |
| const error: personTypesActions.ILoadPersonTypesFail = {payload: 'err_msg'}; |
| const action = personTypesActions.loadPersonTypesFail(error); |
| const result = PersonTypesReducer(INITIAL_STATE, action); |
| |
| expect(result).toEqual({ |
| ...INITIAL_STATE, |
| failed: true, |
| }); |
| }); |
| |
| it('getData return state.data', () => { |
| const state = { ...INITIAL_STATE }; |
| const result = getData(state); |
| expect(result).toBe(state.data); |
| }); |
| |
| it('getLoading return state.loading', () => { |
| const state = { ...INITIAL_STATE }; |
| const result = getLoading(state); |
| expect(result).toBe(state.loading); |
| }); |
| |
| it('getLoaded return state.loaded', () => { |
| const state = { ...INITIAL_STATE }; |
| const result = getLoaded(state); |
| expect(result).toBe(state.loaded); |
| }); |
| |
| it('getFailed return state.failed', () => { |
| const state = { ...INITIAL_STATE }; |
| const result = getFailed(state); |
| expect(result).toBe(state.failed); |
| }); |
| |
| }); |