Merge "Add tests to Inventory module"
[aai/sparky-fe.git] / test / vnfSearch / VnfSearchReducer.test.js
1 import VnfSearchReducer from 'app/vnfSearch/VnfSearchReducer.js';
2 import {
3   vnfActionTypes,
4   CHART_ORCH_STATUS,
5   CHART_PROV_STATUS,
6   CHART_NF_ROLE,
7   CHART_NF_TYPE,
8   TOTAL_VNF_COUNT
9 } from 'app/vnfSearch/VnfSearchConstants.js';
10 import {ERROR_RETRIEVING_DATA} from 'app/networking/NetworkConstants.js';
11 import {
12   filterBarActionTypes,
13   MESSAGE_LEVEL_DANGER
14 } from 'utils/GlobalConstants';
15 import {
16   globalAutoCompleteSearchBarActionTypes
17 } from 'app/globalAutoCompleteSearchBar/GlobalAutoCompleteSearchBarConstants.js';
18
19 describe('VnfSearchReducer - Reducer Action Type Tests', () => {
20   it('Action Type: VNF_NETWORK_ERROR', () => {
21     const action = {
22       type: vnfActionTypes.VNF_NETWORK_ERROR
23     };
24     let state = {
25       processedProvStatusCountChartData: {
26         values: [
27           {x: 'col 1', y: 3},
28           {x: 'col 2', y: 7},
29           {x: 'col 3', y: 2}
30         ]
31       },
32       processedOrchStatusCountChartData: {
33         values: [
34           {x: 'col 1', y: 3},
35           {x: 'col 2', y: 7},
36           {x: 'col 3', y: 2}
37         ]
38       },
39       processedNfTypeCountChartData: {
40         values: [
41           {x: 'col 1', y: 3},
42           {x: 'col 2', y: 7},
43           {x: 'col 3', y: 2}
44         ]
45       },
46       processedNfRoleCountChartData: {
47         values: [
48           {x: 'col 1', y: 3},
49           {x: 'col 2', y: 7},
50           {x: 'col 3', y: 2}
51         ]
52       },
53       count: 20,
54       feedbackMsgText: '',
55       feedbackMsgSeverity: ''
56     };
57     state = VnfSearchReducer(state, action);
58     expect(state).toEqual({
59       processedProvStatusCountChartData: CHART_PROV_STATUS.emptyData,
60       processedOrchStatusCountChartData: CHART_ORCH_STATUS.emptyData,
61       processedNfTypeCountChartData: CHART_NF_TYPE.emptyData,
62       processedNfRoleCountChartData: CHART_NF_ROLE.emptyData,
63       count: TOTAL_VNF_COUNT.emptyValue,
64       feedbackMsgText: ERROR_RETRIEVING_DATA,
65       feedbackMsgSeverity: MESSAGE_LEVEL_DANGER
66     });
67   });
68
69   it('Action Type: SEARCH_WARNING_EVENT', () => {
70     const action = {
71       type: globalAutoCompleteSearchBarActionTypes.SEARCH_WARNING_EVENT
72     };
73     let state = {
74       processedProvStatusCountChartData: {
75         values: [
76           {x: 'col 1', y: 3},
77           {x: 'col 2', y: 7},
78           {x: 'col 3', y: 2}
79         ]
80       },
81       processedOrchStatusCountChartData: {
82         values: [
83           {x: 'col 1', y: 3},
84           {x: 'col 2', y: 7},
85           {x: 'col 3', y: 2}
86         ]
87       },
88       processedNfTypeCountChartData: {
89         values: [
90           {x: 'col 1', y: 3},
91           {x: 'col 2', y: 7},
92           {x: 'col 3', y: 2}
93         ]
94       },
95       processedNfRoleCountChartData: {
96         values: [
97           {x: 'col 1', y: 3},
98           {x: 'col 2', y: 7},
99           {x: 'col 3', y: 2}
100         ]
101       },
102       count: 20,
103     };
104     state = VnfSearchReducer(state, action);
105     expect(state).toEqual({
106       processedProvStatusCountChartData: CHART_PROV_STATUS.emptyData,
107       processedOrchStatusCountChartData: CHART_ORCH_STATUS.emptyData,
108       processedNfTypeCountChartData: CHART_NF_TYPE.emptyData,
109       processedNfRoleCountChartData: CHART_NF_ROLE.emptyData,
110       count: TOTAL_VNF_COUNT.emptyValue,
111     });
112   });
113
114   it('Action Type: NEW_SELECTIONS', () => {
115     const action = {
116       type: filterBarActionTypes.NEW_SELECTIONS,
117       data: {
118         selectedValuesMap: [
119           { filter1: ['someValue'] }
120         ],
121         unifiedValues: [
122           { filter1: ['someValue', 'someOtherValue']}
123         ]
124       }
125     };
126     let state = {
127       vnfFilterValues: {},
128       unifiedFilterValues: {}
129     };
130     state = VnfSearchReducer(state, action);
131     expect(state).toEqual({
132       vnfFilterValues: action.data.selectedValuesMap,
133       unifiedFilterValues: action.data.unifiedValues
134     });
135   });
136
137   it('Action Type: SET_UNIFIED_VALUES', () => {
138     const action = {
139       type: filterBarActionTypes.SET_UNIFIED_VALUES,
140       data: {
141         unifiedValues: [
142           { filter1: ['someValue', 'someOtherValue']}
143         ]
144       }
145     };
146     let state = {
147       unifiedFilterValues: {}
148     };
149     state = VnfSearchReducer(state, action);
150     expect(state).toEqual({
151       unifiedFilterValues: action.data
152     });
153   });
154
155   it('Action Type: VNF_SEARCH_RESULTS_RECEIVED', () => {
156     const action = {
157       type: vnfActionTypes.VNF_SEARCH_RESULTS_RECEIVED,
158       data: {
159         provStatusData: {
160           values: [
161             {x: 'col 1', y: 3},
162             {x: 'col 2', y: 7},
163             {x: 'col 3', y: 2}
164           ]
165         },
166         orchStatusData: {
167           values: [
168             {x: 'col 1', y: 3},
169             {x: 'col 2', y: 7},
170             {x: 'col 3', y: 2}
171           ]
172         },
173         nfTypeData: {
174           values: [
175             {x: 'col 1', y: 3},
176             {x: 'col 2', y: 7},
177             {x: 'col 3', y: 2}
178           ]
179         },
180         nfRoleData: {
181           values: [
182             {x: 'col 1', y: 3},
183             {x: 'col 2', y: 7},
184             {x: 'col 3', y: 2}
185           ]
186         },
187         count: 25,
188       }
189     };
190     let state = {
191       processedProvStatusCountChartData: {},
192       processedOrchStatusCountChartData: {},
193       processedNfTypeCountChartData: {},
194       processedNfRoleCountChartData: {},
195       count: 0,
196       feedbackMsgText: 'some error msg',
197       feedbackMsgSeverity: 'someSeverityLevel'
198     };
199     state = VnfSearchReducer(state, action);
200     expect(state).toEqual({
201       processedProvStatusCountChartData: action.data.provStatusData,
202       processedOrchStatusCountChartData: action.data.orchStatusData,
203       processedNfTypeCountChartData: action.data.nfTypeData,
204       processedNfRoleCountChartData: action.data.nfRoleData,
205       count: action.data.count,
206       feedbackMsgText: '',
207       feedbackMsgSeverity: ''
208     });
209   });
210
211   it('Action Type: VNF_FILTER_PANEL_TOGGLED', () => {
212     const action = {
213       type: vnfActionTypes.VNF_FILTER_PANEL_TOGGLED,
214       data: {
215         vnfVisualizationPanelClass: 'hide',
216       }
217     };
218     let state = {
219       vnfVisualizationPanelClass: 'show'
220     };
221     state = VnfSearchReducer(state, action);
222     expect(state).toEqual({
223       vnfVisualizationPanelClass: 'hide'
224     });
225   });
226
227   it('Action Type: VNF_SEARCH_FILTERS_RECEIVED', () => {
228     const action = {
229       type: vnfActionTypes.VNF_SEARCH_FILTERS_RECEIVED,
230       data: [
231         { filter1: 'value 1' },
232         { filter2: 'value 2' }
233       ]
234     };
235     let state = {
236       vnfFilters: []
237     };
238     state = VnfSearchReducer(state, action);
239     expect(state).toEqual({
240       vnfFilters: action.data
241     });
242   });
243
244   it('Action Type: SET_NON_CONVERTED_VALUES', () => {
245     const action = {
246       type: filterBarActionTypes.SET_NON_CONVERTED_VALUES,
247       data: [
248         { value1: 'abc' },
249         { value2: 'xyz' }
250       ]
251     };
252     let state = {
253       nonConvertedFilters: []
254     };
255     state = VnfSearchReducer(state, action);
256     expect(state).toEqual({
257       nonConvertedFilters: action.data
258     });
259   });
260
261   it('Action Type: SET_CONVERTED_VALUES', () => {
262     const action = {
263       type: filterBarActionTypes.SET_CONVERTED_VALUES,
264       data: {
265         convertedValues: {
266           value1: 'abc',
267           value2: 'xyz'
268         },
269         nonConvertedValues: {
270           value1: 123,
271           value2: 456
272         }
273       }
274     };
275     let state = {
276       nonConvertedFilters: {
277         filter1: 'one',
278         filter2: 'two'
279       },
280       unifiedFilterValues: {},
281       vnfFilterValues: {}
282     };
283     state = VnfSearchReducer(state, action);
284     expect(state).toEqual({
285       nonConvertedFilters: {},
286       unifiedFilterValues: action.data.convertedValues,
287       vnfFilterValues: action.data.nonConvertedValues
288     });
289   });
290
291   it('Action Type: VNF_ACTIVATE_BUSY_FEEDBACK', () => {
292     const action = {
293       type: vnfActionTypes.VNF_ACTIVATE_BUSY_FEEDBACK
294     };
295     let state = {
296       enableBusyFeedback: false
297     };
298     state = VnfSearchReducer(state, action);
299     expect(state).toEqual({
300       enableBusyFeedback: true
301     });
302   });
303
304   it('Action Type: VNF_DISABLE_BUSY_FEEDBACK', () => {
305     const action = {
306       type: vnfActionTypes.VNF_DISABLE_BUSY_FEEDBACK
307     };
308     let state = {
309       enableBusyFeedback: true
310     };
311     state = VnfSearchReducer(state, action);
312     expect(state).toEqual({
313       enableBusyFeedback: false
314     });
315   });
316
317   it('Action Type: CLEAR_FILTERS', () => {
318     const action = {
319       type: filterBarActionTypes.CLEAR_FILTERS
320     };
321     let state = {
322       vnfFilters: {
323         filter1: 'filterName1'
324       },
325       vnfFilterValues: {
326         filter1: 'value 1'
327       },
328       nonConvertedFilters: {
329         nonConvertedFilter1: 'some fitler props'
330       },
331       unifiedFilterValues: {
332         unifiedFilter1: 'some unified props'
333       }
334     };
335     state = VnfSearchReducer(state, action);
336     expect(state).toEqual({
337       vnfFilters: {},
338       vnfFilterValues: {},
339       nonConvertedFilters: {},
340       unifiedFilterValues: {}
341     });
342   });
343
344   it('Invalid Action Type', () => {
345     const action = {
346       type: 'Nonexistent Action Type',
347     };
348     let state = {
349       vnfFilters: {
350         filter1: 'filterName1'
351       },
352       vnfFilterValues: {
353         filter1: 'value 1'
354       },
355       nonConvertedFilters: {
356         nonConvertedFilter1: 'some fitler props'
357       },
358       unifiedFilterValues: {
359         unifiedFilter1: 'some unified props'
360       },
361       enableBusyFeedback: true,
362       provStatusData: {
363         values: [
364           {x: 'col 1', y: 3},
365           {x: 'col 2', y: 7},
366           {x: 'col 3', y: 2}
367         ]
368       },
369       orchStatusData: {
370         values: [
371           {x: 'col 1', y: 3},
372           {x: 'col 2', y: 7},
373           {x: 'col 3', y: 2}
374         ]
375       },
376       nfTypeData: {
377         values: [
378           {x: 'col 1', y: 3},
379           {x: 'col 2', y: 7},
380           {x: 'col 3', y: 2}
381         ]
382       },
383       nfRoleData: {
384         values: [
385           {x: 'col 1', y: 3},
386           {x: 'col 2', y: 7},
387           {x: 'col 3', y: 2}
388         ]
389       },
390       count: 25
391     };
392     state = VnfSearchReducer(state, action);
393     expect(state).toEqual({
394       vnfFilters: {
395         filter1: 'filterName1'
396       },
397       vnfFilterValues: {
398         filter1: 'value 1'
399       },
400       nonConvertedFilters: {
401         nonConvertedFilter1: 'some fitler props'
402       },
403       unifiedFilterValues: {
404         unifiedFilter1: 'some unified props'
405       },
406       enableBusyFeedback: true,
407       provStatusData: {
408         values: [
409           {x: 'col 1', y: 3},
410           {x: 'col 2', y: 7},
411           {x: 'col 3', y: 2}
412         ]
413       },
414       orchStatusData: {
415         values: [
416           {x: 'col 1', y: 3},
417           {x: 'col 2', y: 7},
418           {x: 'col 3', y: 2}
419         ]
420       },
421       nfTypeData: {
422         values: [
423           {x: 'col 1', y: 3},
424           {x: 'col 2', y: 7},
425           {x: 'col 3', y: 2}
426         ]
427       },
428       nfRoleData: {
429         values: [
430           {x: 'col 1', y: 3},
431           {x: 'col 2', y: 7},
432           {x: 'col 3', y: 2}
433         ]
434       },
435       count: 25
436     });
437   });
438 })