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