|
| 1 | +import { userProjectsReducer } from '../userProjectsReducer'; |
| 2 | +import types from '../../constants/userProjects'; |
| 3 | + |
| 4 | +describe('userProjectsReducer', () => { |
| 5 | + const initialState = { |
| 6 | + projects: [], |
| 7 | + wbs: [], |
| 8 | + }; |
| 9 | + |
| 10 | + it('should return the initial state when no action is provided', () => { |
| 11 | + const result = userProjectsReducer(undefined, {}); |
| 12 | + expect(result).toEqual(initialState); |
| 13 | + }); |
| 14 | + |
| 15 | + it('should handle GET_USER_PROJECTS action type', () => { |
| 16 | + const mockProjects = [ |
| 17 | + { id: 1, name: 'Project 1' }, |
| 18 | + { id: 2, name: 'Project 2' }, |
| 19 | + ]; |
| 20 | + |
| 21 | + const action = { |
| 22 | + type: types.GET_USER_PROJECTS, |
| 23 | + payload: mockProjects, |
| 24 | + }; |
| 25 | + |
| 26 | + const expectedState = { |
| 27 | + ...initialState, |
| 28 | + projects: mockProjects, |
| 29 | + }; |
| 30 | + |
| 31 | + const result = userProjectsReducer(initialState, action); |
| 32 | + expect(result).toEqual(expectedState); |
| 33 | + }); |
| 34 | + |
| 35 | + it('should return the current state for unknown action types', () => { |
| 36 | + const action = { type: 'UNKNOWN_ACTION' }; |
| 37 | + const result = userProjectsReducer(initialState, action); |
| 38 | + expect(result).toEqual(initialState); |
| 39 | + }); |
| 40 | + |
| 41 | + it('should handle GET_USER_PROJECTS with empty payload', () => { |
| 42 | + const action = { |
| 43 | + type: types.GET_USER_PROJECTS, |
| 44 | + payload: [], |
| 45 | + }; |
| 46 | + |
| 47 | + const expectedState = { |
| 48 | + ...initialState, |
| 49 | + projects: [], |
| 50 | + }; |
| 51 | + |
| 52 | + const result = userProjectsReducer(initialState, action); |
| 53 | + expect(result).toEqual(expectedState); |
| 54 | + }); |
| 55 | + |
| 56 | +}); |
0 commit comments