Skip to content

Commit fd509ae

Browse files
Merge pull request #2995 from OneCommunityGlobal/aaryaneil-Unit-Test-WBSReducer
Aaryaneil unit tests wbsReducer
2 parents 0c413cd + 9f975d1 commit fd509ae

1 file changed

Lines changed: 86 additions & 0 deletions

File tree

Lines changed: 86 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,86 @@
1+
import { wbsReducer } from "../wbsReducer";
2+
import * as types from "../../constants/WBS";
3+
4+
describe("wbsReducer", () => {
5+
const initialState = {
6+
fetching: false,
7+
fetched: false,
8+
WBSItems: [],
9+
error: '',
10+
};
11+
12+
it("should return the initial state when an unknown action is provided", () => {
13+
expect(wbsReducer(undefined, {})).toEqual(initialState);
14+
});
15+
16+
it("should handle FETCH_WBS_START", () => {
17+
const action = { type: types.FETCH_WBS_START };
18+
const expectedState = { ...initialState, fetching: true, error: 'none' };
19+
expect(wbsReducer(initialState, action)).toEqual(expectedState);
20+
});
21+
22+
it("should handle FETCH_WBS_ERROR", () => {
23+
const action = { type: types.FETCH_WBS_ERROR, err: "Error fetching WBS" };
24+
const expectedState = {
25+
...initialState,
26+
fetching: false,
27+
fetched: true,
28+
error: "Error fetching WBS",
29+
};
30+
expect(wbsReducer(initialState, action)).toEqual(expectedState);
31+
});
32+
33+
it("should handle RECEIVE_WBS", () => {
34+
const action = {
35+
type: types.RECEIVE_WBS,
36+
WBSItems: [{ id: 1, name: "WBS Item 1" }],
37+
};
38+
const expectedState = {
39+
...initialState,
40+
WBSItems: [{ id: 1, name: "WBS Item 1" }],
41+
fetching: false,
42+
fetched: true,
43+
error: 'none',
44+
};
45+
expect(wbsReducer(initialState, action)).toEqual(expectedState);
46+
});
47+
48+
it("should handle ADD_NEW_WBS", () => {
49+
const action = {
50+
type: types.ADD_NEW_WBS,
51+
wbs: { id: 2, name: "New WBS Item" },
52+
};
53+
const expectedState = {
54+
...initialState,
55+
WBSItems: [{ id: 2, name: "New WBS Item" }, ...initialState.WBSItems],
56+
};
57+
expect(wbsReducer(initialState, action)).toEqual(expectedState);
58+
});
59+
60+
it("should handle ADD_NEW_WBS_ERROR", () => {
61+
const action = { type: types.ADD_NEW_WBS_ERROR, err: "Error adding WBS" };
62+
const expectedState = {
63+
...initialState,
64+
fetching: false,
65+
fetched: true,
66+
error: "Error adding WBS",
67+
};
68+
expect(wbsReducer(initialState, action)).toEqual(expectedState);
69+
});
70+
71+
it("should handle DELETE_WBS", () => {
72+
const currentState = {
73+
...initialState,
74+
WBSItems: [
75+
{ _id: 1, name: "WBS Item 1" },
76+
{ _id: 2, name: "WBS Item 2" },
77+
],
78+
};
79+
const action = { type: types.DELETE_WBS, wbsId: 1 };
80+
const expectedState = {
81+
...initialState,
82+
WBSItems: [{ _id: 2, name: "WBS Item 2" }],
83+
};
84+
expect(wbsReducer(currentState, action)).toEqual(expectedState);
85+
});
86+
});

0 commit comments

Comments
 (0)