react-version-downgrade
[sdc.git] / openecomp-ui / test / softwareProduct / components / monitoring / SoftwareProductComponentsMonitoring.test.js
1 /*
2  * Copyright © 2016-2017 European Support Limited
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  * 
8  *      http://www.apache.org/licenses/LICENSE-2.0
9  * 
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */
16
17 import React from 'react';
18
19 import TestUtils from 'react-addons-test-utils';
20 import {mapStateToProps} from 'sdc-app/onboarding/softwareProduct/components/monitoring/SoftwareProductComponentsMonitoring.js';
21 import SoftwareProductComponentsMonitoringView from 'sdc-app/onboarding/softwareProduct/components/monitoring/SoftwareProductComponentsMonitoringView.jsx';
22
23 import {VSPComponentsMonitoringViewFactory, trap, poll, ves} from 'test-utils/factories/softwareProduct/SoftwareProductComponentsMonitoringFactories.js';
24 import VersionControllerUtilsFactory from 'test-utils/factories/softwareProduct/VersionControllerUtilsFactory.js';
25
26 const version = VersionControllerUtilsFactory.build();
27
28
29 describe('SoftwareProductComponentsMonitoring Module Tests', function () {
30
31         it('should mapper exist', () => {
32                 expect(mapStateToProps).toBeTruthy();
33         });
34
35         it('should return empty file names', () => {
36                 let softwareProduct = {softwareProductEditor: {data: {...version}}, softwareProductComponents: {monitoring: {}}};
37                 var results = mapStateToProps({softwareProduct});
38                 expect(results.filenames[trap]).toEqual(undefined);
39                 expect(results.filenames[poll]).toEqual(undefined);
40                 expect(results.filenames[ves]).toEqual(undefined);
41         });
42
43         it('should return trap file name', () => {
44                 const monitoring = VSPComponentsMonitoringViewFactory.build({}, {createTrap: true});
45                 let softwareProduct = {softwareProductEditor: {data: {...version}}, softwareProductComponents: {monitoring}};
46                 var results = mapStateToProps({softwareProduct});
47                 expect(results.filenames[trap]).toEqual(monitoring[trap]);
48                 expect(results.filenames[poll]).toEqual(undefined);
49                 expect(results.filenames[ves]).toEqual(undefined);
50         });
51
52         it('should return ves events file name', () => {
53                 const monitoring = VSPComponentsMonitoringViewFactory.build({}, {createVes: true});
54                 let softwareProduct = {softwareProductEditor: {data: {...version}}, softwareProductComponents: {monitoring}};
55                 var results = mapStateToProps({softwareProduct});
56                 expect(results.filenames[ves]).toEqual(monitoring[ves]);
57                 expect(results.filenames[poll]).toEqual(undefined);
58                 expect(results.filenames[trap]).toEqual(undefined);
59         });
60
61         it('should return poll file names', () => {
62                 const monitoring = VSPComponentsMonitoringViewFactory.build({}, {createPoll: true});
63                 let softwareProduct = {softwareProductEditor: {data: {...version}}, softwareProductComponents: {monitoring}};
64                 var results = mapStateToProps({softwareProduct});
65                 expect(results.filenames[poll]).toEqual(monitoring[poll]);
66                 expect(results.filenames[trap]).toEqual(undefined);
67                 expect(results.filenames[ves]).toEqual(undefined);
68
69                 var renderer = TestUtils.createRenderer();
70                 renderer.render(<SoftwareProductComponentsMonitoringView {...results} />);
71                 let renderedOutput = renderer.getRenderOutput();
72                 expect(renderedOutput).toBeTruthy();
73         });
74
75         it('should return all file names', () => {
76                 const monitoring =  VSPComponentsMonitoringViewFactory.build({}, {createTrap: true, createVes: true, createPoll: true});
77                 let softwareProduct = {softwareProductEditor: {data: {...version}}, softwareProductComponents: {monitoring}};
78                 var results = mapStateToProps({softwareProduct});
79                 expect(results.filenames[poll]).toEqual(monitoring[poll]);
80                 expect(results.filenames[trap]).toEqual(monitoring[trap]);
81                 expect(results.filenames[ves]).toEqual(monitoring[ves]);
82
83                 var renderer = TestUtils.createRenderer();
84                 renderer.render(<SoftwareProductComponentsMonitoringView {...results} />);
85                 let renderedOutput = renderer.getRenderOutput();
86                 expect(renderedOutput).toBeTruthy();
87         });
88
89         it('should change state to dragging', () => {
90                 var view = TestUtils.renderIntoDocument(<SoftwareProductComponentsMonitoringView />);
91                 expect(view.state.dragging).toBe(false);
92                 view.handleOnDragEnter(false);
93                 expect(view.state.dragging).toBe(true);
94         });
95
96         it('should not change state to dragging', () => {
97                 var view = TestUtils.renderIntoDocument(<SoftwareProductComponentsMonitoringView />);
98                 expect(view.state.dragging).toBe(false);
99                 view.handleOnDragEnter(true);
100                 expect(view.state.dragging).toBe(false);
101         });
102
103 });