summaryrefslogtreecommitdiffstats
path: root/test/app/tierSupport/TierSupportActions.test.js
blob: 62485eebdbaac548b27f964e672defe71f99116c (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
import configureStore from 'redux-mock-store';
import thunk from 'redux-thunk'
import {
  onNodeDetailsChange,
  splitPaneResize,
  onNodeMenuChange,
  clearVIData,
  setNotificationText
} from 'app/tierSupport/TierSupportActions.js';
import {
  tierSupportActionTypes
} from 'app/tierSupport/TierSupportConstants.js';
import {
  MESSAGE_LEVEL_WARNING
} from 'utils/GlobalConstants.js';
import {
  globalInlineMessageBarActionTypes
} from 'app/globalInlineMessageBar/GlobalInlineMessageBarConstants.js';

describe('TierSupportActionTests', () => {
  it('onNodeDetailsChange', () => {
    const newDetails = {
      id: '7352312c7bfa814c3071a803d98c5b670952765974876e55ef954e0f8a930b1c',
      itemType: 'complex',
      nodeMeta: {
        nodeLabel1: 'Artic',
        nodeValidated: false,
        nodeLocation: 'bottom'
      },
      rootNode: false,
      index: 2,
    };
    const middlewares = [thunk];
    const mockStore = configureStore(middlewares);
    const store = mockStore({ tierSupportReducer: {} });
    store.dispatch(onNodeDetailsChange(newDetails));
    const actions = store.getActions();
    expect(actions).toEqual([{
      type: tierSupportActionTypes.TS_GRAPH_NODE_SELECTED,
      data: newDetails
    }]);
  });

  it('splitPaneResize', () => {
    const initialLoad = {
      test: 'message'
    };
    const middlewares = [thunk];
    const mockStore = configureStore(middlewares);
    const store = mockStore({ tierSupportReducer: {} });
    store.dispatch(splitPaneResize(initialLoad));
    const actions = store.getActions();
    expect(actions).toEqual([{
      type: tierSupportActionTypes.SPLIT_PANE_RESIZE,
      data: initialLoad
    }]);
  });

  it('onNodeMenuChange', () => {
    const selectedMenu = {
      test: 'menuData'
    };
    const middlewares = [thunk];
    const mockStore = configureStore(middlewares);
    const store = mockStore({ tierSupportReducer: {} });
    store.dispatch(onNodeMenuChange(selectedMenu));
    const actions = store.getActions();
    expect(actions).toEqual([{
      type: tierSupportActionTypes.TS_GRAPH_NODE_MENU_SELECTED,
      data: selectedMenu
    }]);
  });

  it('clearVIData', () => {
    const middlewares = [thunk];
    const mockStore = configureStore(middlewares);
    const store = mockStore({ tierSupportReducer: {} });
    store.dispatch(clearVIData());
    const actions = store.getActions();
    expect(actions).toEqual([{
      type: tierSupportActionTypes.TIER_SUPPORT_CLEAR_DATA
    }]);
  });
  //
  // it('fetchSelectedNodeElement - no results', () => {
  //   const middlewares = [thunk];
  //   const mockStore = configureStore(middlewares);
  //   const store = mockStore({ tierSupportReducer: {} });
  //   const nodes = [
  //     {
  //       id: '7352312c7bfa814c3071a803d98c5b670952765974876e55ef954e0f8a930b1c',
  //       itemType: 'complex',
  //       nodeMeta: {
  //         className: 'selectedSearchedNodeClass',
  //         nodeLabel1: 'Artic',
  //         nodeValidated: false,
  //         nodeLocation: 'bottom'
  //       },
  //       rootNode: false,
  //       index: 2
  //     },
  //     {
  //       id: '3899453d98c5b670952765974876e55ef954e0f8a930b1c',
  //       itemType: 'generic-vnf',
  //       nodeMeta: {
  //         className: 'someOtherClassName',
  //         nodeLabel1: 'Artic',
  //         nodeValidated: false,
  //         nodeLocation: 'bottom'
  //       },
  //       rootNode: false,
  //       index: 1
  //     }
  //   ];
  //   const expectedActions = [
  //     {
  //       type: tierSupportActionTypes.TS_NODE_SEARCH_RESULTS,
  //       data: {
  //         nodes: nodes
  //       }
  //     },
  //     {
  //       type: tierSupportActionTypes.TS_GRAPH_NODE_SELECTED,
  //       data: nodes[0]
  //     }
  //   ];
  //
  //   console.log(nodes);
  //
  //   let fetchRequestCallback = () => {
  //     const results = {
  //       nodes: nodes
  //     };
  //     let init = { status: 200 };
  //     let myBlob = new Blob();
  //     let response = new Response();
  //     return new Promise((resolve, reject) => {
  //       resolve(response);
  //     });
  //   };
  //   return store.dispatch(fetchSelectedNodeElement(fetchRequestCallback))
  //     .then( () => {
  //       const actions = store.getActions();
  //       expect(actions).toEqual(expectedActions);
  //     });
  // });

  it('setNotificationText', () => {
    const middlewares = [thunk];
    const mockStore = configureStore(middlewares);
    const store = mockStore({ tierSupportReducer: {} });
    const msgText = 'some test text';
    const msgSeverity = MESSAGE_LEVEL_WARNING;
    store.dispatch(setNotificationText(msgText, msgSeverity));
    const actions = store.getActions();
    expect(actions).toEqual([{
      type: globalInlineMessageBarActionTypes.SET_GLOBAL_MESSAGE,
      data: {
        msgText: msgText,
        msgSeverity: msgSeverity
      }
    }]);
  });

  it('Clear notification text with setNotificationText', () => {
    const middlewares = [thunk];
    const mockStore = configureStore(middlewares);
    const store = mockStore({ tierSupportReducer: {} });
    const msgText = '';
    const msgSeverity = MESSAGE_LEVEL_WARNING;
    store.dispatch(setNotificationText(msgText, msgSeverity));
    const actions = store.getActions();
    expect(actions).toEqual([{
      type: globalInlineMessageBarActionTypes.CLEAR_GLOBAL_MESSAGE
    }]);
  });
})