Skip to content

Commit 2898fb4

Browse files
Merge pull request #3005 from OneCommunityGlobal/aaryaneil-Unit-Test-popupEditorReducer
Aaryaneil - Unit tests for popupEditorReducer
2 parents 79ecb91 + 1296359 commit 2898fb4

1 file changed

Lines changed: 58 additions & 0 deletions

File tree

Lines changed: 58 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,58 @@
1+
import { popupEditorReducer } from "../popupEditorReducer";
2+
import * as types from "../../constants/popupEditorConstants";
3+
4+
describe("popupEditorReducer", () => {
5+
const initialState = {
6+
fetching: false,
7+
fetched: false,
8+
popupItems: [],
9+
currPopup: {},
10+
error: '',
11+
};
12+
13+
it("should return the initial state when no action is provided", () => {
14+
expect(popupEditorReducer(undefined, {})).toEqual(initialState);
15+
});
16+
17+
it("should handle RECEIVE_POPUP", () => {
18+
const action = {
19+
type: types.RECEIVE_POPUP,
20+
popupItems: [{ id: 1, title: "Popup 1" }],
21+
};
22+
23+
const expectedState = {
24+
...initialState,
25+
popupItems: action.popupItems,
26+
fetched: true,
27+
fetching: false,
28+
error: 'none',
29+
};
30+
31+
expect(popupEditorReducer(initialState, action)).toEqual(expectedState);
32+
});
33+
34+
it("should handle CURRENT_POPUP", () => {
35+
const action = {
36+
type: types.CURRENT_POPUP,
37+
currPopup: { id: 1, title: "Popup 1" },
38+
};
39+
40+
const expectedState = {
41+
...initialState,
42+
currPopup: action.currPopup,
43+
fetched: true,
44+
fetching: false,
45+
error: 'none',
46+
};
47+
48+
expect(popupEditorReducer(initialState, action)).toEqual(expectedState);
49+
});
50+
51+
it("should return the current state for an unknown action type", () => {
52+
const unknownAction = {
53+
type: "UNKNOWN_ACTION",
54+
};
55+
56+
expect(popupEditorReducer(initialState, unknownAction)).toEqual(initialState);
57+
});
58+
});

0 commit comments

Comments
 (0)