Add tests to Inventory module
[aai/sparky-fe.git] / test / vnfSearch / VnfSearchActions.test.js
1 import configureStore from 'redux-mock-store';
2 import thunk from 'redux-thunk'
3 import fetchMock from 'fetch-mock';
4
5 import {
6   processVnfFilterPanelCollapse,
7   clearVnfSearchData,
8   setNotificationText,
9   processVnfVisualizationsOnFilterChange
10 } from 'app/vnfSearch/VnfSearchActions.js';
11 import {
12   vnfActionTypes,
13   CHART_PROV_STATUS,
14   CHART_ORCH_STATUS,
15   CHART_NF_TYPE,
16   CHART_NF_ROLE,
17   TOTAL_VNF_COUNT,
18   VNF_FILTER_EMPTY_RESULT
19 } from 'app/vnfSearch/VnfSearchConstants.js';
20 import { globalInlineMessageBarActionTypes } from 'app/globalInlineMessageBar/GlobalInlineMessageBarConstants.js';
21 import { ERROR_RETRIEVING_DATA } from 'app/networking/NetworkConstants.js';
22
23 describe('VnfSearchAction - Action Tests', () => {
24   it('Action: processVnfFilterPanelCollapse - open', () => {
25     const result = processVnfFilterPanelCollapse(true);
26     expect(result).toEqual({
27       type: vnfActionTypes.VNF_FILTER_PANEL_TOGGLED,
28       data: {
29         vnfVisualizationPanelClass: 'collapsible-panel-main-panel vertical-filter-panel-is-open'
30       }
31     });
32   });
33
34   it('Action: processVnfFilterPanelCollapse - close', () => {
35     const result = processVnfFilterPanelCollapse(false);
36     expect(result).toEqual({
37       type: vnfActionTypes.VNF_FILTER_PANEL_TOGGLED,
38       data: {
39         vnfVisualizationPanelClass: 'collapsible-panel-main-panel'
40       }
41     });
42   });
43
44   it('Action: clearVnfSearchData', () => {
45     const result = clearVnfSearchData();
46     expect(result).toEqual({
47       type: vnfActionTypes.VNF_SEARCH_RESULTS_RECEIVED,
48       data: {
49         count: '',
50         provStatusData: CHART_PROV_STATUS.emptyData,
51         orchStatusData: CHART_ORCH_STATUS.emptyData,
52         nfTypeData: CHART_NF_TYPE.emptyData,
53         nfRoleData: CHART_NF_ROLE.emptyData
54       }
55     });
56   });
57
58   it('Action: setNotificationText - with message', () => {
59     const middlewares = [thunk];
60     const mockStore = configureStore(middlewares);
61     const store = mockStore({ vnfSearch: {} });
62     store.dispatch(setNotificationText('test error message', 'WARNING'));
63     const actions = store.getActions();
64     expect(actions).toEqual([{
65       type: globalInlineMessageBarActionTypes.SET_GLOBAL_MESSAGE,
66       data: {
67         msgText: 'test error message',
68         msgSeverity: 'WARNING'
69       }
70     }]);
71   });
72
73   it('Action: processVnfVisualizationsOnFilterChange - data for filter values', () => {
74     const middlewares = [thunk];
75     const mockStore = configureStore(middlewares);
76     const store = mockStore({ vnfSearch: {} });
77     const filterValueMap = {
78       1: 'Running',
79       2: 'Junk',
80       7: 'Blah',
81       8: 'Doh'
82     };
83     const expectedActions = [
84       { type: vnfActionTypes.VNF_ACTIVATE_BUSY_FEEDBACK },
85       { type: globalInlineMessageBarActionTypes.CLEAR_GLOBAL_MESSAGE },
86       {
87         type: vnfActionTypes.VNF_SEARCH_RESULTS_RECEIVED,
88         data: {
89           count: 10,
90           provStatusData: {
91             values: [
92               { x: 'junk', y: 10 }
93             ]
94           },
95           orchStatusData: {
96             values: [
97               { x: 'running', y: 10 }
98             ]
99           },
100           nfTypeData: {
101             values: [
102               { x: 'doh', y: 10 }
103             ]
104           },
105           nfRoleData: {
106             values: [
107               { x: 'blah', y: 10 }
108             ]
109           }
110         }
111       },
112       { type: vnfActionTypes.VNF_DISABLE_BUSY_FEEDBACK }
113     ];
114     fetchMock.mock('*', {
115       "total": 10,
116       "aggregations":{
117         "nf-role":[{"doc_count":10,"key":"blah"}],
118         "nf-type":[{"doc_count":10,"key":"doh"}],
119         "prov-status":[{"doc_count":10,"key":"junk"}],
120         "orchestration-status":[{"doc_count":10,"key":"running"}]
121       }
122     });
123
124     return store.dispatch(processVnfVisualizationsOnFilterChange(filterValueMap))
125       .then( () => {
126         const actions = store.getActions();
127         expect(actions).toEqual(expectedActions);
128         fetchMock.restore();
129       });
130   });
131
132   it('Action: processVnfVisualizationsOnFilterChange - no data for filter values', () => {
133     const middlewares = [thunk];
134     const mockStore = configureStore(middlewares);
135     const store = mockStore({ vnfSearch: {} });
136     const filterValueMap = {
137       1: 'Running',
138       2: 'Junk',
139       7: '',
140       8: 'Doh'
141     };
142     const expectedActions = [
143       { type: vnfActionTypes.VNF_ACTIVATE_BUSY_FEEDBACK },
144       { type: globalInlineMessageBarActionTypes.SET_GLOBAL_MESSAGE,
145         data: { msgSeverity: "warning", msgText: VNF_FILTER_EMPTY_RESULT }
146       },
147       {
148         type: vnfActionTypes.VNF_SEARCH_RESULTS_RECEIVED,
149         data: {
150           count: TOTAL_VNF_COUNT.emptyData,
151           provStatusData: CHART_PROV_STATUS.emptyData,
152           orchStatusData: CHART_ORCH_STATUS.emptyData,
153           nfTypeData: CHART_NF_TYPE.emptyData,
154           nfRoleData: CHART_NF_ROLE.emptyData
155         }
156       },
157       { type: vnfActionTypes.VNF_DISABLE_BUSY_FEEDBACK }
158     ];
159     fetchMock.mock('*', {
160       "total": 0,
161       "aggregations":{
162         "nf-role":[],
163         "nf-type":[],
164         "prov-status":[],
165         "orchestration-status":[]
166       }
167     });
168
169     return store.dispatch(processVnfVisualizationsOnFilterChange(filterValueMap))
170       .then( () => {
171         const actions = store.getActions();
172         expect(actions).toEqual(expectedActions);
173         fetchMock.restore();
174       });
175   });
176
177   it('Action: processVnfVisualizationsOnFilterChange - network error', () => {
178     const middlewares = [thunk];
179     const mockStore = configureStore(middlewares);
180     const store = mockStore({ vnfSearch: {} });
181     const filterValueMap = {
182       1: 'Running',
183       2: 'Junk',
184       7: 'Blah',
185       8: 'Doh'
186     };
187     const expectedActions = [
188       { type: vnfActionTypes.VNF_ACTIVATE_BUSY_FEEDBACK },
189       { type: vnfActionTypes.VNF_DISABLE_BUSY_FEEDBACK },
190       {
191         type: vnfActionTypes.VNF_NETWORK_ERROR,
192         data: { errorMsg: ERROR_RETRIEVING_DATA }
193       }
194     ];
195     fetchMock.mock('*', 503);
196
197     return store.dispatch(processVnfVisualizationsOnFilterChange(filterValueMap))
198       .then( () => {
199         const actions = store.getActions();
200         expect(actions).toEqual(expectedActions);
201         fetchMock.restore();
202       });
203   });
204
205   it('Action: setNotificationText - no message', () => {
206     const middlewares = [thunk];
207     const mockStore = configureStore(middlewares);
208     const store = mockStore({ vnfSearch: {} });
209     store.dispatch(setNotificationText('', ''));
210     const actions = store.getActions();
211     expect(actions).toEqual([{
212       type: globalInlineMessageBarActionTypes.CLEAR_GLOBAL_MESSAGE
213     }]);
214   });
215 })

© 2017 ONAP. Copyright © The Linux Foundation ®. All Rights Reserved.
The Linux Foundation has registered trademarks and uses trademarks.
For a list of trademarks of The Linux Foundation, please see our Trademark Usage page.
Linux is a registered trademark of Linus Torvalds.
Privacy Policy and Terms of Use