f772762b5a6294e215e49ba7d20eb3b8823cc7d6
[aai/sparky-fe.git] / test / vnfSearch / vnfSearchVisualizations / vnfSearchVisualizationsReducer.test.js
1 /*
2  * ============LICENSE_START=======================================================
3  * org.onap.aai
4  * ================================================================================
5  * Copyright © 2017 AT&T Intellectual Property. All rights reserved.
6  * Copyright © 2017 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  * ECOMP is a trademark and service mark of AT&T Intellectual Property.
22  */
23 import React from 'react';
24 import { expect } from 'chai';
25 import reducer from 'app/vnfSearch/VnfSearchReducer.js';
26 import {
27   CHART_ORCH_STATUS,
28   CHART_PROV_STATUS, vnfSearchVisualizationsActionTypes} from 'app/vnfSearch/VnfSearchConstants.js';
29
30
31
32 describe('VNF: Audit Visualizations Reducers test suite', function() {
33   const initialState = {
34     processedProvStatusCountChartData: CHART_PROV_STATUS.clearingEmptyData,
35     processedOrchStatusCountChartData: CHART_ORCH_STATUS.clearingEmptyData
36   };
37   const initStateWithData = {
38     processedProvStatusCountChartData: [
39       {
40         values: [
41           {
42             x: 'complex',
43             y: 60
44           }
45         ]
46       }
47     ],
48     processedOrchStatusCountChartData: [
49       {
50         values: [
51           {
52             x: 'prov-status',
53             y: 60
54           }
55         ]
56       }
57     ]
58   };
59
60
61
62   it('VNF: COUNT_BY_ORCH_STATUS_RECEIVED event', function() {
63     const chartData = [
64       {
65         'values': [
66           { 'x': 'physical-location-id', 'y':  22},
67           { 'x': 'prov-status', 'y': 14},
68           { 'x': 'status-type-3', 'y': 24}
69         ]
70       }
71     ];
72
73     const action = {
74       type: vnfSearchVisualizationsActionTypes.COUNT_BY_ORCH_STATUS_RECEIVED,
75       data: {
76         orchStatusCountChartData: {
77           chartData: chartData,
78         }
79       }
80     };
81
82     const newState = reducer(initialState, action);
83     expect(newState.processedOrchStatusCountChartData[0].values.length).to.equal(3);
84     expect(newState.processedOrchStatusCountChartData[0].values[0]['x']).to.equal('physical-location-id');
85     expect(newState.processedOrchStatusCountChartData[0].values[1]['x']).to.equal('prov-status');
86     expect(newState.processedOrchStatusCountChartData[0].values[2]['x']).to.equal('status-type-3');
87     expect(newState.processedOrchStatusCountChartData[0].values[0]['y']).to.equal(22);
88     expect(newState.processedOrchStatusCountChartData[0].values[1]['y']).to.equal(14);
89     expect(newState.processedOrchStatusCountChartData[0].values[2]['y']).to.equal(24);
90   });
91
92   it('VNF: COUNT_BY_PROV_STATUS_RECEIVED event', function() {
93     const chartData = [
94       {
95         'values': [
96           { 'x': 'physical-location-id', 'y':  22},
97           { 'x': 'prov-status', 'y': 14},
98           { 'x': 'status-type-3', 'y': 24}
99         ]
100       }
101     ];
102
103     const action = {
104       type: vnfSearchVisualizationsActionTypes.COUNT_BY_PROV_STATUS_RECEIVED,
105       data: {
106         provStatusCountChartData: {
107           chartData: chartData,
108         }
109       }
110     };
111
112     const newState = reducer(initialState, action);
113     expect(newState.processedProvStatusCountChartData[0].values.length).to.equal(3);
114     expect(newState.processedProvStatusCountChartData[0].values[0]['x']).to.equal('physical-location-id');
115     expect(newState.processedProvStatusCountChartData[0].values[1]['x']).to.equal('prov-status');
116     expect(newState.processedProvStatusCountChartData[0].values[2]['x']).to.equal('status-type-3');
117     expect(newState.processedProvStatusCountChartData[0].values[0]['y']).to.equal(22);
118     expect(newState.processedProvStatusCountChartData[0].values[1]['y']).to.equal(14);
119     expect(newState.processedProvStatusCountChartData[0].values[2]['y']).to.equal(24);
120   });
121
122
123   it('VNF: Total VNF event', function() {
124
125
126     const action = {
127       type: vnfSearchVisualizationsActionTypes.TOTAL_VNF_COUNT_RECEIVED,
128       data: {count: 10}
129     };
130
131     const newState = reducer(initialState, action);
132     expect(newState.count).to.equal(10);
133
134   });
135
136
137   it('VNF: NETWORK_ERROR event', function() {
138     const action = {
139       type: vnfSearchVisualizationsActionTypes.VNF_SEARCH_NETWORK_ERROR
140     }
141     const newState = reducer(initStateWithData, action);
142     expect(newState.processedProvStatusCountChartData).to.deep.equal(CHART_PROV_STATUS.clearingEmptyData);
143     expect(newState.processedOrchStatusCountChartData).to.deep.equal(CHART_ORCH_STATUS.clearingEmptyData);
144   });
145
146 });