81ed2bfe1f993bce01ed58f6ccd568be8109203d
[aai/sparky-fe.git] / test / vnfSearch / vnfSearchVisualizations / vnfSearchVisualizationsReducer.test.js
1 /*
2  * ============LICENSE_START=======================================================
3  * org.onap.aai
4  * ================================================================================
5  * Copyright © 2017-2018 AT&T Intellectual Property. All rights reserved.
6  * Copyright © 2017-2018 Amdocs
7  * ================================================================================
8  * Licensed under the Apache License, Version 2.0 (the "License");
9  * you may not use this file except in compliance with the License.
10  * You may obtain a copy of the License at
11  *
12  *       http://www.apache.org/licenses/LICENSE-2.0
13  *
14  * Unless required by applicable law or agreed to in writing, software
15  * distributed under the License is distributed on an "AS IS" BASIS,
16  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
17  * See the License for the specific language governing permissions and
18  * limitations under the License.
19  * ============LICENSE_END=========================================================
20  */
21 import React from 'react';
22 import { expect } from 'chai';
23 import reducer from 'app/vnfSearch/VnfSearchReducer.js';
24 import {
25   CHART_ORCH_STATUS,
26   CHART_PROV_STATUS, vnfSearchVisualizationsActionTypes} from 'app/vnfSearch/VnfSearchConstants.js';
27
28
29
30 describe('VNF: Audit Visualizations Reducers test suite', function() {
31   const initialState = {
32     processedProvStatusCountChartData: CHART_PROV_STATUS.clearingEmptyData,
33     processedOrchStatusCountChartData: CHART_ORCH_STATUS.clearingEmptyData
34   };
35   const initStateWithData = {
36     processedProvStatusCountChartData: [
37       {
38         values: [
39           {
40             x: 'complex',
41             y: 60
42           }
43         ]
44       }
45     ],
46     processedOrchStatusCountChartData: [
47       {
48         values: [
49           {
50             x: 'prov-status',
51             y: 60
52           }
53         ]
54       }
55     ]
56   };
57
58
59
60   it('VNF: COUNT_BY_ORCH_STATUS_RECEIVED event', function() {
61     const chartData = [
62       {
63         'values': [
64           { 'x': 'physical-location-id', 'y':  22},
65           { 'x': 'prov-status', 'y': 14},
66           { 'x': 'status-type-3', 'y': 24}
67         ]
68       }
69     ];
70
71     const action = {
72       type: vnfSearchVisualizationsActionTypes.COUNT_BY_ORCH_STATUS_RECEIVED,
73       data: {
74         orchStatusCountChartData: {
75           chartData: chartData,
76         }
77       }
78     };
79
80     const newState = reducer(initialState, action);
81     expect(newState.processedOrchStatusCountChartData[0].values.length).to.equal(3);
82     expect(newState.processedOrchStatusCountChartData[0].values[0]['x']).to.equal('physical-location-id');
83     expect(newState.processedOrchStatusCountChartData[0].values[1]['x']).to.equal('prov-status');
84     expect(newState.processedOrchStatusCountChartData[0].values[2]['x']).to.equal('status-type-3');
85     expect(newState.processedOrchStatusCountChartData[0].values[0]['y']).to.equal(22);
86     expect(newState.processedOrchStatusCountChartData[0].values[1]['y']).to.equal(14);
87     expect(newState.processedOrchStatusCountChartData[0].values[2]['y']).to.equal(24);
88   });
89
90   it('VNF: COUNT_BY_PROV_STATUS_RECEIVED event', function() {
91     const chartData = [
92       {
93         'values': [
94           { 'x': 'physical-location-id', 'y':  22},
95           { 'x': 'prov-status', 'y': 14},
96           { 'x': 'status-type-3', 'y': 24}
97         ]
98       }
99     ];
100
101     const action = {
102       type: vnfSearchVisualizationsActionTypes.COUNT_BY_PROV_STATUS_RECEIVED,
103       data: {
104         provStatusCountChartData: {
105           chartData: chartData,
106         }
107       }
108     };
109
110     const newState = reducer(initialState, action);
111     expect(newState.processedProvStatusCountChartData[0].values.length).to.equal(3);
112     expect(newState.processedProvStatusCountChartData[0].values[0]['x']).to.equal('physical-location-id');
113     expect(newState.processedProvStatusCountChartData[0].values[1]['x']).to.equal('prov-status');
114     expect(newState.processedProvStatusCountChartData[0].values[2]['x']).to.equal('status-type-3');
115     expect(newState.processedProvStatusCountChartData[0].values[0]['y']).to.equal(22);
116     expect(newState.processedProvStatusCountChartData[0].values[1]['y']).to.equal(14);
117     expect(newState.processedProvStatusCountChartData[0].values[2]['y']).to.equal(24);
118   });
119
120
121   it('VNF: Total VNF event', function() {
122
123
124     const action = {
125       type: vnfSearchVisualizationsActionTypes.TOTAL_VNF_COUNT_RECEIVED,
126       data: {count: 10}
127     };
128
129     const newState = reducer(initialState, action);
130     expect(newState.count).to.equal(10);
131
132   });
133
134
135   it('VNF: NETWORK_ERROR event', function() {
136     const action = {
137       type: vnfSearchVisualizationsActionTypes.VNF_SEARCH_NETWORK_ERROR
138     }
139     const newState = reducer(initStateWithData, action);
140     expect(newState.processedProvStatusCountChartData).to.deep.equal(CHART_PROV_STATUS.clearingEmptyData);
141     expect(newState.processedOrchStatusCountChartData).to.deep.equal(CHART_ORCH_STATUS.clearingEmptyData);
142   });
143
144 });