Skip to content

Commit 43755f9

Browse files
Merge pull request #3004 from OneCommunityGlobal/aaryaneil-Unit-Test-userProfileByIdReducer
Aaryaneil - Unit Tests for userProfileByIdReducer
2 parents 504bb8f + 8a786da commit 43755f9

1 file changed

Lines changed: 100 additions & 0 deletions

File tree

Lines changed: 100 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,100 @@
1+
import {
2+
userProfileByIdReducer,
3+
userTaskByIdReducer,
4+
updateObject
5+
} from '../userProfileByIdReducer';
6+
import {
7+
GET_USER_PROFILE,
8+
EDIT_USER_PROFILE,
9+
GET_USER_TASKS
10+
} from '../../constants/userProfile';
11+
12+
describe('userProfileByIdReducer', () => {
13+
const initialState = {
14+
firstName: '',
15+
lastName: '',
16+
jobTitle: '',
17+
isActive: '',
18+
};
19+
20+
it('should return the initial state', () => {
21+
const result = userProfileByIdReducer(undefined, {});
22+
expect(result).toEqual(initialState);
23+
});
24+
25+
it('should handle GET_USER_PROFILE', () => {
26+
const action = {
27+
type: GET_USER_PROFILE,
28+
payload: {
29+
firstName: 'John',
30+
lastName: 'Doe',
31+
jobTitle: 'Developer',
32+
isActive: true,
33+
},
34+
};
35+
const result = userProfileByIdReducer(initialState, action);
36+
expect(result).toEqual(action.payload);
37+
});
38+
39+
it('should handle EDIT_USER_PROFILE', () => {
40+
const initialState = {
41+
firstName: 'John',
42+
lastName: 'Doe',
43+
jobTitle: 'Developer',
44+
isActive: true,
45+
};
46+
const action = {
47+
type: EDIT_USER_PROFILE,
48+
payload: {
49+
jobTitle: 'Senior Developer',
50+
},
51+
};
52+
const expectedState = {
53+
...initialState,
54+
jobTitle: 'Senior Developer',
55+
};
56+
const result = userProfileByIdReducer(initialState, action);
57+
expect(result).toEqual(expectedState);
58+
});
59+
60+
it('should handle CLEAR_USER_PROFILE', () => {
61+
const action = { type: 'CLEAR_USER_PROFILE' };
62+
const result = userProfileByIdReducer(initialState, action);
63+
expect(result).toBeNull();
64+
});
65+
});
66+
67+
describe('userTaskByIdReducer', () => {
68+
it('should return the initial state', () => {
69+
const result = userTaskByIdReducer(undefined, {});
70+
expect(result).toEqual([]);
71+
});
72+
73+
it('should handle GET_USER_TASKS', () => {
74+
const action = {
75+
type: GET_USER_TASKS,
76+
payload: [
77+
{ id: 1, task: 'Task 1' },
78+
{ id: 2, task: 'Task 2' },
79+
],
80+
};
81+
const result = userTaskByIdReducer([], action);
82+
expect(result).toEqual(action.payload);
83+
});
84+
});
85+
86+
describe('updateObject utility function', () => {
87+
it('should update an object with new properties', () => {
88+
const oldObject = { a: 1, b: 2 };
89+
const updatedProperties = { b: 3, c: 4 };
90+
const result = updateObject(oldObject, updatedProperties);
91+
expect(result).toEqual({ a: 1, b: 3, c: 4 });
92+
});
93+
94+
it('should not mutate the original object', () => {
95+
const oldObject = { a: 1, b: 2 };
96+
const updatedProperties = { b: 3, c: 4 };
97+
updateObject(oldObject, updatedProperties);
98+
expect(oldObject).toEqual({ a: 1, b: 2 });
99+
});
100+
});

0 commit comments

Comments
 (0)