Add tests to Inventory module
[aai/sparky-fe.git] / test / configurableViews / ConfigurableViewActions.test.js
1 import configureStore from 'redux-mock-store';
2 import thunk from 'redux-thunk'
3 import fetchMock from 'fetch-mock';
4 import {
5   configurableViewsActionTypes
6 } from 'app/configurableViews/ConfigurableViewConstants.js';
7 import {
8   newCustomComponentsEvent,
9   setCustomRoutes,
10   getConfigurableViewConfigs
11 } from 'app/configurableViews/ConfigurableViewActions.js'
12
13
14 describe('ConfigurableViewActionTests', () => {
15   const sampleConfig = {
16     "id": "aggregateReport",
17     "title": "Aggregate Report",
18     "iconURL": "resources/images/sampleAggReportIcon.svg",
19     "iconHoverURL": "resources/images/sampleAggReportIconHover.svg",
20     "viewType": "ConfigurableCardView",
21     "layout": {
22       "draggable": true,
23       "resizable": true,
24       "rowHeight": 100,
25       "cardMargin": [
26         20,
27         20
28       ],
29       "cardPadding": [
30         20,
31         20
32       ],
33       "breakpoints": [
34         {
35           "id": "lg",
36           "col": 12,
37           "width": 1400
38         },
39         {
40           "id": "md",
41           "col": 8,
42           "width": 1200
43         },
44         {
45           "id": "sm",
46           "col": 6,
47           "width": 1024
48         }
49       ]
50     },
51     "components": [
52       {
53         "id": "visualization1",
54         "title": "Total VNFs",
55         "queryData": {
56           "eventId": "visualization1",
57           "api": "/get-component-data",
58           "method": "POST",
59           "headers": {
60             "accept": "application/json"
61           },
62           "componentDataDescriptor": {
63             "index": "aggregate_generic-vnf_index",
64             "queryType": "aggregation",
65             "query": {
66               "filter": {},
67               "queries": [],
68               "aggregations": [
69                 {
70                   "name": "prov-status",
71                   "aggregation": {
72                     "group-by": {
73                       "field": "prov-status",
74                       "size": 0
75                     }
76                   }
77                 },
78                 {
79                   "name": "orchestration-status",
80                   "aggregation": {
81                     "group-by": {
82                       "field": "orchestration-status",
83                       "size": 0
84                     }
85                   }
86                 },
87                 {
88                   "name": "nf-type",
89                   "aggregation": {
90                     "group-by": {
91                       "field": "nf-type",
92                       "size": 0
93                     }
94                   }
95                 },
96                 {
97                   "name": "nf-role",
98                   "aggregation": {
99                     "group-by": {
100                       "field": "nf-role",
101                       "size": 0
102                     }
103                   }
104                 }
105               ]
106             },
107             "responseTransformation": {
108               "type": "count",
109               "spec": {
110                 "countType": "total",
111                 "countResponseLabel": "display"
112               }
113             }
114           }
115         },
116         "containerData": {
117           "containerType": "NetworkQueryCard",
118           "visualizationType": "text",
119           "visualizationProp": {
120             "display": "",
121             "style": {
122               "textAlign": "center",
123               "fontSize": "50px",
124               "fontWeight": "bold",
125               "paddingTop": "50px"
126             }
127           },
128           "breakpoints": {
129             "lg": {
130               "w": 2,
131               "h": 2,
132               "x": 0,
133               "y": 0
134             },
135             "md": {
136               "w": 2,
137               "h": 2,
138               "x": 0,
139               "y": 0
140             },
141             "sm": {
142               "w": 6,
143               "h": 2,
144               "x": 0,
145               "y": 0
146             }
147           }
148         }
149       }
150     ]
151   };
152
153   it('newCustomComponentsEvent', () => {
154     const components = [
155       {
156         compId: 'someId',
157         compName: 'Some Name'
158       }
159     ];
160     const middlewares = [thunk];
161     const mockStore = configureStore(middlewares);
162     const store = mockStore({});
163     store.dispatch(newCustomComponentsEvent(components));
164     const actions = store.getActions();
165     expect(actions).toEqual([{
166       type: configurableViewsActionTypes.CUSTOM_COMPONENTS_RECEIVED,
167       data: components
168     }]);
169   });
170
171   it('setCustomRoutes', () => {
172     const routes = [
173       {
174         routeName: 'Some Custom Route',
175         path: 'some/route/path'
176       }
177     ];
178     const middlewares = [thunk];
179     const mockStore = configureStore(middlewares);
180     const store = mockStore({});
181     store.dispatch(setCustomRoutes(routes));
182     const actions = store.getActions();
183     expect(actions).toEqual([{
184       type: configurableViewsActionTypes.CUSTOM_ROUTES,
185       data: routes
186     }]);
187   });
188
189   it('getConfigurableViewConfigs', () => {
190     const middlewares = [thunk];
191     const mockStore = configureStore(middlewares);
192     const store = mockStore({});
193     const expectedActions = [
194       {
195         type: configurableViewsActionTypes.CONFIGURABLE_VIEWS_CONFIG_RECEIVED,
196         data: sampleConfig
197       }
198     ];
199     fetchMock.mock('*', sampleConfig);
200
201     return store.dispatch(getConfigurableViewConfigs())
202       .then( () => {
203         const actions = store.getActions();
204         expect(actions).toEqual(expectedActions);
205         fetchMock.restore();
206       });
207   });
208 })