Merge "Remove unused code"
[aai/sparky-fe.git] / test / app / tierSupport / TierSupportActions.test.js
1 import configureStore from 'redux-mock-store';
2 import thunk from 'redux-thunk'
3 import {
4   onNodeDetailsChange,
5   splitPaneResize,
6   onNodeMenuChange,
7   clearVIData,
8   setNotificationText
9 } from 'app/tierSupport/TierSupportActions.js';
10 import {
11   tierSupportActionTypes
12 } from 'app/tierSupport/TierSupportConstants.js';
13 import {
14   MESSAGE_LEVEL_WARNING
15 } from 'utils/GlobalConstants.js';
16 import {
17   globalInlineMessageBarActionTypes
18 } from 'app/globalInlineMessageBar/GlobalInlineMessageBarConstants.js';
19
20 describe('TierSupportActionTests', () => {
21   it('onNodeDetailsChange', () => {
22     const newDetails = {
23       id: '7352312c7bfa814c3071a803d98c5b670952765974876e55ef954e0f8a930b1c',
24       itemType: 'complex',
25       nodeMeta: {
26         nodeLabel1: 'Artic',
27         nodeValidated: false,
28         nodeLocation: 'bottom'
29       },
30       rootNode: false,
31       index: 2,
32     };
33     const middlewares = [thunk];
34     const mockStore = configureStore(middlewares);
35     const store = mockStore({ tierSupportReducer: {} });
36     store.dispatch(onNodeDetailsChange(newDetails));
37     const actions = store.getActions();
38     expect(actions).toEqual([{
39       type: tierSupportActionTypes.TS_GRAPH_NODE_SELECTED,
40       data: newDetails
41     }]);
42   });
43
44   it('splitPaneResize', () => {
45     const initialLoad = {
46       test: 'message'
47     };
48     const middlewares = [thunk];
49     const mockStore = configureStore(middlewares);
50     const store = mockStore({ tierSupportReducer: {} });
51     store.dispatch(splitPaneResize(initialLoad));
52     const actions = store.getActions();
53     expect(actions).toEqual([{
54       type: tierSupportActionTypes.SPLIT_PANE_RESIZE,
55       data: initialLoad
56     }]);
57   });
58
59   it('onNodeMenuChange', () => {
60     const selectedMenu = {
61       test: 'menuData'
62     };
63     const middlewares = [thunk];
64     const mockStore = configureStore(middlewares);
65     const store = mockStore({ tierSupportReducer: {} });
66     store.dispatch(onNodeMenuChange(selectedMenu));
67     const actions = store.getActions();
68     expect(actions).toEqual([{
69       type: tierSupportActionTypes.TS_GRAPH_NODE_MENU_SELECTED,
70       data: selectedMenu
71     }]);
72   });
73
74   it('clearVIData', () => {
75     const middlewares = [thunk];
76     const mockStore = configureStore(middlewares);
77     const store = mockStore({ tierSupportReducer: {} });
78     store.dispatch(clearVIData());
79     const actions = store.getActions();
80     expect(actions).toEqual([{
81       type: tierSupportActionTypes.TIER_SUPPORT_CLEAR_DATA
82     }]);
83   });
84   //
85   // it('fetchSelectedNodeElement - no results', () => {
86   //   const middlewares = [thunk];
87   //   const mockStore = configureStore(middlewares);
88   //   const store = mockStore({ tierSupportReducer: {} });
89   //   const nodes = [
90   //     {
91   //       id: '7352312c7bfa814c3071a803d98c5b670952765974876e55ef954e0f8a930b1c',
92   //       itemType: 'complex',
93   //       nodeMeta: {
94   //         className: 'selectedSearchedNodeClass',
95   //         nodeLabel1: 'Artic',
96   //         nodeValidated: false,
97   //         nodeLocation: 'bottom'
98   //       },
99   //       rootNode: false,
100   //       index: 2
101   //     },
102   //     {
103   //       id: '3899453d98c5b670952765974876e55ef954e0f8a930b1c',
104   //       itemType: 'generic-vnf',
105   //       nodeMeta: {
106   //         className: 'someOtherClassName',
107   //         nodeLabel1: 'Artic',
108   //         nodeValidated: false,
109   //         nodeLocation: 'bottom'
110   //       },
111   //       rootNode: false,
112   //       index: 1
113   //     }
114   //   ];
115   //   const expectedActions = [
116   //     {
117   //       type: tierSupportActionTypes.TS_NODE_SEARCH_RESULTS,
118   //       data: {
119   //         nodes: nodes
120   //       }
121   //     },
122   //     {
123   //       type: tierSupportActionTypes.TS_GRAPH_NODE_SELECTED,
124   //       data: nodes[0]
125   //     }
126   //   ];
127   //
128   //   console.log(nodes);
129   //
130   //   let fetchRequestCallback = () => {
131   //     const results = {
132   //       nodes: nodes
133   //     };
134   //     let init = { status: 200 };
135   //     let myBlob = new Blob();
136   //     let response = new Response();
137   //     return new Promise((resolve, reject) => {
138   //       resolve(response);
139   //     });
140   //   };
141   //   return store.dispatch(fetchSelectedNodeElement(fetchRequestCallback))
142   //     .then( () => {
143   //       const actions = store.getActions();
144   //       expect(actions).toEqual(expectedActions);
145   //     });
146   // });
147
148   it('setNotificationText', () => {
149     const middlewares = [thunk];
150     const mockStore = configureStore(middlewares);
151     const store = mockStore({ tierSupportReducer: {} });
152     const msgText = 'some test text';
153     const msgSeverity = MESSAGE_LEVEL_WARNING;
154     store.dispatch(setNotificationText(msgText, msgSeverity));
155     const actions = store.getActions();
156     expect(actions).toEqual([{
157       type: globalInlineMessageBarActionTypes.SET_GLOBAL_MESSAGE,
158       data: {
159         msgText: msgText,
160         msgSeverity: msgSeverity
161       }
162     }]);
163   });
164
165   it('Clear notification text with setNotificationText', () => {
166     const middlewares = [thunk];
167     const mockStore = configureStore(middlewares);
168     const store = mockStore({ tierSupportReducer: {} });
169     const msgText = '';
170     const msgSeverity = MESSAGE_LEVEL_WARNING;
171     store.dispatch(setNotificationText(msgText, msgSeverity));
172     const actions = store.getActions();
173     expect(actions).toEqual([{
174       type: globalInlineMessageBarActionTypes.CLEAR_GLOBAL_MESSAGE
175     }]);
176   });
177 })