Skip to content

Commit 8e6e8ba

Browse files
Merge pull request #2996 from OneCommunityGlobal/aaryaneil-Unit-Test-userProjectsReducer
Aaryaneil - Unit Tests for userProjectsReducer component
2 parents 2d125f9 + 88e7c16 commit 8e6e8ba

1 file changed

Lines changed: 56 additions & 0 deletions

File tree

Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,56 @@
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

Comments
 (0)