1 import configureStore from 'redux-mock-store';
2 import thunk from 'redux-thunk'
9 fetchSelectedNodeElement,
10 querySelectedNodeElement
12 from 'app/tierSupport/TierSupportActions';
13 import {tierSupportActionTypes} from 'app/tierSupport/TierSupportConstants';
14 import {MESSAGE_LEVEL_WARNING} from 'utils/GlobalConstants';
15 import {globalInlineMessageBarActionTypes} from 'app/globalInlineMessageBar/GlobalInlineMessageBarConstants';
19 } from 'app/networking/NetworkConstants';
20 import networkCall from 'app/networking/NetworkCalls';
22 const mockStore = configureStore([thunk]);
24 describe('TierSupportActionTests', () => {
28 store = mockStore({ tierSupportReducer: {} });
31 describe('onNodeDetailsChange', () => {
32 it('emits TS_GRAPH_NODE_SELECTED with payload', () => {
35 testDetails: 'Test Details',
37 const expectedActions = [{
38 type: tierSupportActionTypes.TS_GRAPH_NODE_SELECTED,
43 store.dispatch(onNodeDetailsChange(newDetails));
46 expect(store.getActions()).toEqual(expectedActions);
50 describe('splitPaneResize', () => {
51 it('emits SPLIT_PANE_RESIZE action with payload', () => {
56 const expectedActions = [{
57 type: tierSupportActionTypes.SPLIT_PANE_RESIZE,
62 store.dispatch(splitPaneResize(initialLoad));
65 expect(store.getActions()).toEqual(expectedActions);
69 describe('onNodeMenuChange', () => {
70 it('emits TS_GRAPH_NODE_MENU_SELECTED action with payload', () => {
72 const selectedMenu = {
75 const expectedActions = [{
76 type: tierSupportActionTypes.TS_GRAPH_NODE_MENU_SELECTED,
81 store.dispatch(onNodeMenuChange(selectedMenu));
84 expect(store.getActions()).toEqual(expectedActions);
88 describe('clearVIData', () => {
89 it('emits TIER_SUPPORT_CLEAR_DATA action', () => {
91 const expectedActions = [{
92 type: tierSupportActionTypes.TIER_SUPPORT_CLEAR_DATA
96 store.dispatch(clearVIData());
99 expect(store.getActions()).toEqual(expectedActions);
103 describe('fetchSelectedNodeElement', () => {
104 it('emits actions with proper error message when 204 code returned', async () => {
106 const promise = () => getPromiseWithStatusCode(204);
107 const expectedActions = [
109 type: tierSupportActionTypes.TIER_SUPPORT_DISABLE_BUSY_FEEDBACK,
112 type: tierSupportActionTypes.TS_NODE_SEARCH_NO_RESULTS,
113 data: {errorMsg: NO_RESULTS_FOUND}
118 await store.dispatch(fetchSelectedNodeElement(promise));
121 expect(store.getActions()).toEqual(expectedActions);
124 it('emits actions with proper error message when 3XX code returned', async () => {
126 const promise = () => getPromiseWithStatusCode(301);
127 const expectedActions = [
129 type: tierSupportActionTypes.TIER_SUPPORT_DISABLE_BUSY_FEEDBACK,
132 type: tierSupportActionTypes.TS_NODE_SEARCH_NO_RESULTS,
133 data: {errorMsg: NO_RESULTS_FOUND}
138 await store.dispatch(fetchSelectedNodeElement(promise));
141 expect(store.getActions()).toEqual(expectedActions);
144 it('emits actions with proper error message when 5XX code returned', async () => {
146 const promise = () => getPromiseWithStatusCode(501);
147 const expectedActions = [
149 type: tierSupportActionTypes.TIER_SUPPORT_DISABLE_BUSY_FEEDBACK,
152 type: tierSupportActionTypes.TIER_SUPPORT_NETWORK_ERROR,
153 data: {value: ERROR_RETRIEVING_DATA, errorMsg: ERROR_RETRIEVING_DATA}
158 await store.dispatch(fetchSelectedNodeElement(promise));
161 expect(store.getActions()).toEqual(expectedActions);
164 it('emits actions with payload when 200 code returned and nodes not empty', async () => {
166 const {nodes, node1} = prepareTestNodes();
167 const promise = () => getNodesPromise(nodes);
168 const expectedActions = [
170 type: tierSupportActionTypes.TS_NODE_SEARCH_RESULTS,
171 data: {"nodes": nodes}
174 type: tierSupportActionTypes.TS_GRAPH_NODE_SELECTED,
178 type: tierSupportActionTypes.TIER_SUPPORT_DISABLE_BUSY_FEEDBACK
183 await store.dispatch(fetchSelectedNodeElement(promise));
186 expect(store.getActions()).toEqual(expectedActions);
189 it('emits actions with payload when 200 code returned and nodes empty', async () => {
191 const promise = () => getNodesPromise([]);
192 const expectedActions = [
194 type: tierSupportActionTypes.TS_NODE_SEARCH_NO_RESULTS,
195 data: {errorMsg: NO_RESULTS_FOUND}
198 type: tierSupportActionTypes.TIER_SUPPORT_DISABLE_BUSY_FEEDBACK
203 await store.dispatch(fetchSelectedNodeElement(promise));
206 expect(store.getActions()).toEqual(expectedActions);
210 describe('querySelectedNodeElement', () => {
211 const searchHash = "testHash";
213 it('emits actions when fetchRequest defined ', async () => {
215 const promise = () => getNodesPromise([]);
216 const expectedAction = [
218 type: tierSupportActionTypes.TIER_SUPPORT_ACTIVATE_BUSY_FEEDBACK,
221 type: tierSupportActionTypes.TS_NODE_SEARCH_NO_RESULTS,
222 data: {errorMsg: NO_RESULTS_FOUND}
225 type: tierSupportActionTypes.TIER_SUPPORT_DISABLE_BUSY_FEEDBACK
230 await store.dispatch(querySelectedNodeElement(searchHash, promise));
233 expect(store.getActions()).toEqual(expectedAction);
236 it('builds request and emits actions when fetchRequest undefined ', async () => {
238 const stringifySpy = jest.spyOn(JSON, 'stringify');
239 const promise = getNodesPromise([]);
240 networkCall.fetchRequestObj = jest.fn(() => promise);
241 const expectedStringifyInput = {
244 const expectedFetchRequestBody = "{\"hashId\":\"testHash\"}";
245 const expectedAction = [
247 type: tierSupportActionTypes.TIER_SUPPORT_ACTIVATE_BUSY_FEEDBACK,
250 type: tierSupportActionTypes.TS_NODE_SEARCH_NO_RESULTS,
251 data: {errorMsg: NO_RESULTS_FOUND}
254 type: tierSupportActionTypes.TIER_SUPPORT_DISABLE_BUSY_FEEDBACK
259 await store.dispatch(querySelectedNodeElement(searchHash, undefined));
262 expect(stringifySpy).toHaveBeenCalledWith(expectedStringifyInput);
263 expect(networkCall.fetchRequestObj).toHaveBeenCalledWith(
267 expectedFetchRequestBody
269 expect(store.getActions()).toEqual(expectedAction);
273 describe('setNotificationText', () => {
274 const msgSeverity = MESSAGE_LEVEL_WARNING;
276 it('emits SET_GLOBAL_MESSAGE action with payload when msgText is not blank ', () => {
278 const msgText = 'some test text';
279 const expectedActions = [{
280 type: globalInlineMessageBarActionTypes.SET_GLOBAL_MESSAGE,
283 msgSeverity: msgSeverity
288 store.dispatch(setNotificationText(msgText, msgSeverity));
291 expect(store.getActions()).toEqual(expectedActions);
294 it('emits CLEAR_GLOBAL_MESSAGE when msgText is blank ', () => {
297 const expectedActions = [{
298 type: globalInlineMessageBarActionTypes.CLEAR_GLOBAL_MESSAGE
302 store.dispatch(setNotificationText(msgText, msgSeverity));
305 expect(store.getActions()).toEqual(expectedActions);
309 function getPromiseWithStatusCode(statusCode) {
310 return new Promise(function(resolve) {
311 resolve({status: statusCode});
315 function getNodesPromise(nodes) {
316 return new Promise(function (resolve) {
328 function prepareTestNodes() {
329 const node1 = prepareSelectedClassTestNode();
330 const node2 = prepareOtherClassTestNode();
332 nodes: [node1, node2],
338 function prepareOtherClassTestNode() {
340 id: '3899453d98c5b670952765974876e55ef954e0f8a930b1c',
341 itemType: 'generic-vnf',
343 className: 'someOtherClassName',
345 nodeValidated: false,
346 nodeLocation: 'bottom'
353 function prepareSelectedClassTestNode() {
355 id: '7352312c7bfa814c3071a803d98c5b670952765974876e55ef954e0f8a930b1c',
358 className: 'selectedSearchedNodeClass',
360 nodeValidated: false,
361 nodeLocation: 'bottom'