Merge "Add tests to Inventory module"
[aai/sparky-fe.git] / test / app / tierSupport / TierSupportReducer.test.js
1 import TierSupportReducer from 'app/tierSupport/TierSupportReducer.js';
2 import ForceDirectedGraph from 'generic-components/graph/ForceDirectedGraph.jsx';
3 import {
4   tierSupportActionTypes,
5   TSUI_GRAPH_MENU_NODE_DETAILS
6 } from 'app/tierSupport/TierSupportConstants.js';
7 import {
8   MESSAGE_LEVEL_WARNING,
9   MESSAGE_LEVEL_DANGER
10 } from 'utils/GlobalConstants.js';
11 import {
12   globalAutoCompleteSearchBarActionTypes
13 } from 'app/globalAutoCompleteSearchBar/GlobalAutoCompleteSearchBarConstants.js';
14
15 describe('TierSupportReducerTests', () => {
16   it('Action Type: TS_NODE_SEARCH_RESULTS', () => {
17     ForceDirectedGraph.graphCounter = 0; // ensuring counter is at zero after previous tests
18     const action = {
19       type: tierSupportActionTypes.TS_NODE_SEARCH_RESULTS,
20       data: {
21         nodes: [
22           {
23             nodeMeta: {
24               searchTarget: true
25             },
26             itemProperties: 'someProperty'
27           }
28         ],
29         links: ['link', 'information'],
30         graphMeta: { graph: 'meta' }
31       }
32     };
33     let graphData = ForceDirectedGraph.generateNewProps(action.data.nodes, action.data.links,
34       action.data.graphMeta);
35     ForceDirectedGraph.graphCounter = 0; // ensuring counter is at zero after previous statement
36     let state = {};
37     state = TierSupportReducer(state, action);
38     expect(state.tierSupportReducer).toEqual({
39       forceDirectedGraphRawData: graphData,
40       feedbackMsgText: '',
41       feedbackMsgSeverity: ''
42     });
43   });
44
45   it('Action Type: TS_GRAPH_NODE_MENU_SELECTED', () => {
46     const action = {
47       type: tierSupportActionTypes.TS_GRAPH_NODE_MENU_SELECTED,
48       data: {
49         attr1: 'someValue',
50         attr2: 'someOterValue'
51       }
52     };
53     let state = {};
54     state = TierSupportReducer(state, action);
55     expect(state.tierSupportReducer).toEqual({
56       graphNodeSelectedMenu: action.data
57     });
58   });
59
60   it('Action Type: TS_NODE_SEARCH_NO_RESULTS', () => {
61     ForceDirectedGraph.graphCounter = 0; // ensuring counter is at zero after previous tests
62     let emptyNodesAndLinksNoResults = {
63       graphCounter: 1,
64       graphMeta: {},
65       linkDataArray: [],
66       nodeDataArray: []
67     };
68     const action = {
69       type: tierSupportActionTypes.TS_NODE_SEARCH_NO_RESULTS,
70       data: {
71         errorMsg: 'some error message'
72       }
73     };
74     let state = {};
75     state = TierSupportReducer(state, action);
76     expect(state.tierSupportReducer).toEqual({
77       forceDirectedGraphRawData: emptyNodesAndLinksNoResults,
78       graphNodeSelectedMenu: TSUI_GRAPH_MENU_NODE_DETAILS,
79       feedbackMsgText: action.data.errorMsg,
80       feedbackMsgSeverity: MESSAGE_LEVEL_WARNING
81     });
82   });
83
84   it('Action Type: TIER_SUPPORT_NETWORK_ERROR', () => {
85     ForceDirectedGraph.graphCounter = 0; // ensuring counter is at zero after previous tests
86     let emptyNodesAndLinksNoResults = {
87       graphCounter: 1,
88       graphMeta: {},
89       linkDataArray: [],
90       nodeDataArray: []
91     };
92     const action = {
93       type: tierSupportActionTypes.TIER_SUPPORT_NETWORK_ERROR,
94       data: {
95         errorMsg: 'some error message'
96       }
97     };
98     let state = {};
99     state = TierSupportReducer(state, action);
100     expect(state.tierSupportReducer).toEqual({
101       forceDirectedGraphRawData: emptyNodesAndLinksNoResults,
102       graphNodeSelectedMenu: TSUI_GRAPH_MENU_NODE_DETAILS,
103       feedbackMsgText: action.data.errorMsg,
104       feedbackMsgSeverity: MESSAGE_LEVEL_DANGER
105     });
106   });
107
108   it('Action Type: TIER_SUPPORT_CLEAR_DATA', () => {
109     ForceDirectedGraph.graphCounter = 0; // ensuring counter is at zero after previous tests
110     let emptyNodesAndLinksNoResults = {
111       graphCounter: 1,
112       graphMeta: {},
113       linkDataArray: [],
114       nodeDataArray: []
115     };
116     const action = {
117       type: tierSupportActionTypes.TIER_SUPPORT_CLEAR_DATA
118     };
119     let state = {};
120     state = TierSupportReducer(state, action);
121     expect(state.tierSupportReducer).toEqual({
122       forceDirectedGraphRawData: emptyNodesAndLinksNoResults,
123       graphNodeSelectedMenu: TSUI_GRAPH_MENU_NODE_DETAILS,
124       feedbackMsgText: '',
125       feedbackMsgSeverity: ''
126     });
127   });
128
129   it('Action Type: TS_GRAPH_NODE_SELECTED', () => {
130     const action = {
131       type: tierSupportActionTypes.TS_GRAPH_NODE_SELECTED,
132       data: 'some action data'
133     };
134     let state = {};
135     state = TierSupportReducer(state, action);
136     expect(state.tierSupportReducer).toEqual({
137       nodeData: action.data
138     });
139   });
140
141   it('Action Type: TIER_SUPPORT_ACTIVATE_BUSY_FEEDBACK', () => {
142     const action = {
143       type: tierSupportActionTypes.TIER_SUPPORT_ACTIVATE_BUSY_FEEDBACK,
144     };
145     let state = {};
146     state = TierSupportReducer(state, action);
147     expect(state.tierSupportReducer).toEqual({
148       enableBusyFeedback: true
149     });
150   });
151
152   it('Action Type: TIER_SUPPORT_DISABLE_BUSY_FEEDBACK', () => {
153     const action = {
154       type: tierSupportActionTypes.TIER_SUPPORT_DISABLE_BUSY_FEEDBACK,
155     };
156     let state = {};
157     state = TierSupportReducer(state, action);
158     expect(state.tierSupportReducer).toEqual({
159       enableBusyFeedback: false
160     });
161   });
162
163   it('Action Type: SEARCH_WARNING_EVENT', () => {
164     ForceDirectedGraph.graphCounter = 0; // ensuring counter is at zero after previous tests
165     let emptyNodesAndLinksNoResults = {
166       graphCounter: 1,
167       graphMeta: {},
168       linkDataArray: [],
169       nodeDataArray: []
170     };
171     const action = {
172       type: globalAutoCompleteSearchBarActionTypes.SEARCH_WARNING_EVENT,
173       data: {
174         errorMsg: 'some warning msg'
175       }
176     };
177     let state = {};
178     state = TierSupportReducer(state, action);
179     expect(state.tierSupportReducer).toEqual({
180       forceDirectedGraphRawData: emptyNodesAndLinksNoResults,
181       graphNodeSelectedMenu: TSUI_GRAPH_MENU_NODE_DETAILS
182     });
183   });
184
185   it('Action Type: TS_OVERLAY_NETWORK_CALLBACK_RESPONSE_RECEIVED', () => {
186     const action = {
187       type: tierSupportActionTypes.TS_OVERLAY_NETWORK_CALLBACK_RESPONSE_RECEIVED,
188       data: {
189         curData: {
190           attr1: 'value1',
191           attr2: 'value2'
192         },
193         paramName: 'attr2',
194         overlayData: 'someValue2'
195       }
196     };
197     let state = {};
198     state = TierSupportReducer(state, action);
199     expect(state.tierSupportReducer).toEqual({
200       nodeData: {
201         attr1: 'value1',
202         attr2: 'someValue2'
203       }
204     });
205   });
206 })