Add tests to Inventory module
[aai/sparky-fe.git] / test / app / inventory / InventoryReducer.test.js
1 import fetchMock from 'fetch-mock';
2 import expect from 'expect';
3 import {InventoryActionTypes} from "app/inventory/InventoryConstants";
4 import reducer from 'app/inventory/InventoryReducer';
5
6
7
8 function verifyStateProducedByReducer(action, currentState, expectedState) {
9     // when
10     const actual = reducer(currentState, action);
11
12     // then
13     expect(actual).toEqual(expectedState);
14 }
15
16 describe('InventoryReducer', () => {
17
18     afterEach(() => {
19         fetchMock.restore()
20     });
21
22     it('verify store state after TOPOGRAPHIC_QUERY_SUCCESS action', async () => {
23
24         // given
25         const action = {
26             type: InventoryActionTypes.TOPOGRAPHIC_QUERY_SUCCESS,
27             data: {
28                 "plotPoints": {
29                     "keyA": "valueA",
30                     "keyB": "valueB"
31                 }
32             }
33         };
34
35         const expectedState = {
36             state: "dummy",
37             mapPlotPoints: {
38                 "keyA": "valueA",
39                 "keyB": "valueB"
40             }
41         };
42
43
44         const currentState = {state: "dummy"};
45
46         verifyStateProducedByReducer(action, currentState, expectedState);
47
48     });
49
50     it('verify store state after COUNT_BY_ENTITY_SUCCESS action', async () => {
51
52         // given
53         const action = {
54             type: InventoryActionTypes.COUNT_BY_ENTITY_SUCCESS,
55             data: {
56                 "countByType": {
57                     "keyA": "valueA",
58                     "keyB": "valueB"
59                 }
60             }
61         };
62
63         const expectedState = {
64             state: "dummy",
65             countByType: {
66                 "keyA": "valueA",
67                 "keyB": "valueB"
68             }
69         };
70
71         const currentState = {state: "dummy"};
72
73         verifyStateProducedByReducer(action, currentState, expectedState);
74     });
75
76
77     it('verify store state after COUNT_BY_DATE_SUCCESS action', async () => {
78
79         // given
80         const action = {
81             type: InventoryActionTypes.COUNT_BY_DATE_SUCCESS,
82             data: {
83                 "countByDate": {
84                     "keyA": "valueA",
85                     "keyB": "valueB"
86                 }
87             }
88         };
89
90         const expectedState = {
91             state: "dummy",
92             countByDate: {
93                 "keyA": "valueA",
94                 "keyB": "valueB"
95             }
96         };
97
98         const currentState = {state: "dummy"};
99
100         verifyStateProducedByReducer(action, currentState, expectedState);
101     });
102
103     it('verify store state after TOPOGRAPHIC_QUERY_FAILED action', async () => {
104
105         // given
106         const action = {
107             type: InventoryActionTypes.TOPOGRAPHIC_QUERY_FAILED,
108             data: {
109                 severity: "ERROR",
110                 message: "Some error occurred"
111             }
112         };
113
114         const expectedState = {
115             state: "dummy",
116             feedbackMsgSeverity: "ERROR",
117             feedbackMsgText: "Some error occurred"
118
119         };
120
121         const currentState = {state: "dummy"};
122
123         verifyStateProducedByReducer(action, currentState, expectedState);
124     });
125
126     it('verify store state after COUNT_BY_ENTITY_FAILED action', async () => {
127
128         // given
129         const action = {
130             type: InventoryActionTypes.COUNT_BY_ENTITY_FAILED,
131             data: {
132                 severity: "ERROR",
133                 message: "Some error occurred"
134             }
135         };
136
137         const expectedState = {
138             state: "dummy",
139             feedbackMsgSeverity: "ERROR",
140             feedbackMsgText: "Some error occurred"
141
142         };
143
144         const currentState = {state: "dummy"};
145
146         verifyStateProducedByReducer(action, currentState, expectedState);
147     });
148
149     it('verify store state after COUNT_BY_DATE_FAILED action', async () => {
150
151         // given
152         const action = {
153             type: InventoryActionTypes.COUNT_BY_DATE_FAILED,
154             data: {
155                 severity: "ERROR",
156                 message: "Some error occurred"
157             }
158         };
159
160         const expectedState = {
161             state: "dummy",
162             feedbackMsgSeverity: "ERROR",
163             feedbackMsgText: "Some error occurred"
164
165         };
166
167         const currentState = {state: "dummy"};
168
169         verifyStateProducedByReducer(action, currentState, expectedState);
170     });
171
172     it('verify store state after unknown action', async () => {
173
174         // given
175         const action = {
176             type: 'unknown',
177         };
178
179         const expectedState = {state: "dummy"};
180
181         const currentState = {state: "dummy"};
182
183         verifyStateProducedByReducer(action, currentState, expectedState);
184     });
185
186 });