Upversion for Casablanca
[aai/sparky-fe.git] / src / app / tierSupport / selectedNodeDetails / SelectedNodeDetailsReducer.test.js
1 import SelectedNodeDetailsReducer from './SelectedNodeDetailsReducer.js';
2 import {tierSupportActionTypes} from 'app/tierSupport/TierSupportConstants.js';
3 import {
4   globalAutoCompleteSearchBarActionTypes
5 } from 'app/globalAutoCompleteSearchBar/GlobalAutoCompleteSearchBarConstants.js';
6
7 describe('SelectedNodeDetails - Reducer Tests', () => {
8   it('Action Type: TS_NODE_SEARCH_RESULTS', () => {
9     const action = {
10       type: tierSupportActionTypes.TS_NODE_SEARCH_RESULTS,
11       data: {
12         nodes: [
13           {
14             'id': 'AAI/CLYMR/000509/SD_WAN',
15             'itemType': 'service-instance',
16             'itemNameKey': 'service-instance.AAI/SPRKY/000509/SD_WAN',
17             'itemNameValue': 'AAI/SPRKY/000509/SD_WAN',
18             'itemProperties': {
19               'service-instance-id': 'AAI/SPRKY/000509/SD_WAN',
20               'resource-version':'1508078039815'
21             },
22             'itemIntegrity' : {
23               'entityId' : 'AEEhny_vnf1_under_fw-si1',
24               'entityType' : 'vnf',
25               'entityLink' : 'cloud-infrastr084-1377-4f49-9c72-f0_location2',
26               'initialTimestamp' :'2017-11-13T16:58:01Z',
27               'latestValidationTimestamp':'2017-11-13T16:58:01Z',
28               'resourceVersion':'1510592264096',
29               'violations': []
30             },
31             'nodeMeta': {
32               'className': 'selectedSearchedNodeClass',
33               'nodeDebug': null,
34               'selfLinkResponseTimeInMs': 628,
35               'relationshipNode': false,
36               'searchTarget': true,
37               'enrichableNode': false,
38               'nodeValidated': true,
39               'nodeIssue': false,
40               'maxAltitude': 4,
41               'nodeType': 'serviceInstance',
42               'nodeLabel1':'service-instance',
43               'nodeLabel2':'AAI/SPRKY/000509/SD_WAN'
44             },
45             'rootNode' : false
46           }
47         ]
48       }
49     };
50     let state = {
51       nodeType: '',
52       uid: '',
53       nodeData: {}
54     };
55     state = SelectedNodeDetailsReducer(state, action);
56     expect(state).toEqual({
57       nodeType: action['data']['nodes'][0]['itemType'],
58       uid: action['data']['nodes'][0]['itemNameValue'],
59       nodeData: action['data']['nodes'][0]['itemProperties']
60     });
61   });
62
63   it('Action Type: TS_NODE_SEARCH_RESULTS - searchTarget === false', () => {
64     const action = {
65       type: tierSupportActionTypes.TS_NODE_SEARCH_RESULTS,
66       data: {
67         nodes: [
68           {
69             'id': 'AAI/CLYMR/000509/SD_WAN',
70             'itemType': 'service-instance',
71             'itemNameKey': 'service-instance.AAI/SPRKY/000509/SD_WAN',
72             'itemNameValue': 'AAI/SPRKY/000509/SD_WAN',
73             'itemProperties': {
74               'service-instance-id': 'AAI/SPRKY/000509/SD_WAN',
75               'resource-version':'1508078039815'
76             },
77             'itemIntegrity' : {
78               'entityId' : 'AEEhny_vnf1_under_fw-si1',
79               'entityType' : 'vnf',
80               'entityLink' : 'cloud-infrastr084-1377-4f49-9c72-f0_location2',
81               'initialTimestamp' :'2017-11-13T16:58:01Z',
82               'latestValidationTimestamp':'2017-11-13T16:58:01Z',
83               'resourceVersion':'1510592264096',
84               'violations': []
85             },
86             'nodeMeta': {
87               'className': 'selectedSearchedNodeClass',
88               'nodeDebug': null,
89               'selfLinkResponseTimeInMs': 628,
90               'relationshipNode': false,
91               'searchTarget': false,
92               'enrichableNode': false,
93               'nodeValidated': true,
94               'nodeIssue': false,
95               'maxAltitude': 4,
96               'nodeType': 'serviceInstance',
97               'nodeLabel1':'service-instance',
98               'nodeLabel2':'AAI/SPRKY/000509/SD_WAN'
99             },
100             'rootNode' : false
101           }
102         ]
103       }
104     };
105     let state = {
106       nodeType: 'Complex',
107       uid: 'ABC',
108       nodeData: {
109         'service-instance-id': 'blah/blah/blah',
110         'resource-version':'123456'
111       }
112     };
113     state = SelectedNodeDetailsReducer(state, action);
114     expect(state).toEqual({
115       nodeType: '',
116       uid: '',
117       nodeData: {}
118     });
119   });
120
121   it('Action Type: TS_GRAPH_NODE_SELECTED', () => {
122     const action = {
123       type: tierSupportActionTypes.TS_GRAPH_NODE_SELECTED,
124       data: {
125         itemProperties: {
126           'service-instance-id': 'AAI/SPRKY/000509/SD_WAN',
127           'resource-version':'1508078039815'
128         },
129         itemType: 'Complex',
130         itemNameValue: '123456'
131       }
132     };
133     let state = {
134       nodeType: '',
135       uid: '',
136       nodeData: {}
137     };
138     state = SelectedNodeDetailsReducer(state, action);
139     expect(state).toEqual({
140       nodeType: action['data']['itemType'],
141       uid: action['data']['itemNameValue'],
142       nodeData: action['data']['itemProperties']
143     });
144   });
145
146   it('Action Type: TIER_SUPPORT_NETWORK_ERROR', () => {
147     const action = {
148       type: tierSupportActionTypes.TIER_SUPPORT_NETWORK_ERROR,
149     };
150     let state = {
151       nodeType: 'Complex',
152       uid: '12345',
153       nodeData: {
154         'service-instance-id': 'AAI/SPRKY/000509/SD_WAN',
155         'resource-version':'1508078039815'
156       }
157     };
158     state = SelectedNodeDetailsReducer(state, action);
159     expect(state).toEqual({
160       nodeType: '',
161       uid: '',
162       nodeData: {}
163     });
164   });
165
166   it('Action Type: TIER_SUPPORT_CLEAR_DATA', () => {
167     const action = {
168       type: tierSupportActionTypes.TIER_SUPPORT_CLEAR_DATA,
169     };
170     let state = {
171       nodeType: 'Complex',
172       uid: '12345',
173       nodeData: {
174         'service-instance-id': 'AAI/SPRKY/000509/SD_WAN',
175         'resource-version':'1508078039815'
176       }
177     };
178     state = SelectedNodeDetailsReducer(state, action);
179     expect(state).toEqual({
180       nodeType: '',
181       uid: '',
182       nodeData: {}
183     });
184   });
185
186   it('Action Type: TS_NODE_SEARCH_NO_RESULTS', () => {
187     const action = {
188       type: tierSupportActionTypes.TS_NODE_SEARCH_NO_RESULTS,
189     };
190     let state = {
191       nodeType: 'Complex',
192       uid: '12345',
193       nodeData: {
194         'service-instance-id': 'AAI/SPRKY/000509/SD_WAN',
195         'resource-version':'1508078039815'
196       }
197     };
198     state = SelectedNodeDetailsReducer(state, action);
199     expect(state).toEqual({
200       nodeType: '',
201       uid: '',
202       nodeData: {}
203     });
204   });
205
206   it('Action Type: SEARCH_WARNING_EVENT', () => {
207     const action = {
208       type: globalAutoCompleteSearchBarActionTypes.SEARCH_WARNING_EVENT,
209     };
210     let state = {
211       nodeType: 'Complex',
212       uid: '12345',
213       nodeData: {
214         'service-instance-id': 'AAI/SPRKY/000509/SD_WAN',
215         'resource-version':'1508078039815'
216       }
217     };
218     state = SelectedNodeDetailsReducer(state, action);
219     expect(state).toEqual({
220       nodeType: '',
221       uid: '',
222       nodeData: {}
223     });
224   });
225
226   it('Invalid Action Type', () => {
227     const action = {
228       type: 'Nonexistent Action Type',
229     };
230     let state = {
231       nodeType: 'Complex',
232       uid: '12345',
233       nodeData: {
234         'service-instance-id': 'AAI/SPRKY/000509/SD_WAN',
235         'resource-version':'1508078039815'
236       }
237     };
238     state = SelectedNodeDetailsReducer(state, action);
239     expect(state).toEqual({
240       nodeType: 'Complex',
241       uid: '12345',
242       nodeData: {
243         'service-instance-id': 'AAI/SPRKY/000509/SD_WAN',
244         'resource-version':'1508078039815'
245       }
246     });
247   });
248 })