[SDC-29] Amdocs OnBoard 1707 initial commit.
[sdc.git] / openecomp-ui / test / softwareProduct / components / monitoring / SoftwareProductComponentsMonitoring.test.js
1 /*!
2  * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved.
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
13  * or implied. See the License for the specific language governing
14  * permissions and limitations under the License.
15  */
16
17 import React from 'react';
18 import TestUtils from 'react-addons-test-utils';
19 import {mapStateToProps} from 'sdc-app/onboarding/softwareProduct/components/monitoring/SoftwareProductComponentsMonitoring.js';
20 import SoftwareProductComponentsMonitoringView from 'sdc-app/onboarding/softwareProduct/components/monitoring/SoftwareProductComponentsMonitoringView.jsx';
21
22 import {VSPComponentsMonitoringViewFactory} from 'test-utils/factories/softwareProduct/SoftwareProductComponentsMonitoringFactories.js';
23 import VersionControllerUtilsFactory from 'test-utils/factories/softwareProduct/VersionControllerUtilsFactory.js';
24
25 const version = VersionControllerUtilsFactory.build();
26
27 describe('SoftwareProductComponentsMonitoring Module Tests', function () {
28
29         it('should mapper exist', () => {
30                 expect(mapStateToProps).toBeTruthy();
31         });
32
33         it('should return empty file names', () => {
34                 let softwareProduct = {softwareProductEditor: {data: {...version}}, softwareProductComponents: {monitoring: {}}};
35                 var results = mapStateToProps({softwareProduct});
36                 expect(results.trapFilename).toEqual(undefined);
37                 expect(results.pollFilename).toEqual(undefined);
38         });
39
40         it('should return trap file name', () => {
41                 const monitoring = VSPComponentsMonitoringViewFactory.build({}, {snmpTrapFlag: true});
42                 let softwareProduct = {softwareProductEditor: {data: {...version}}, softwareProductComponents: {monitoring}};
43                 var results = mapStateToProps({softwareProduct});
44                 expect(results.trapFilename).toEqual(monitoring.trapFilename);
45                 expect(results.pollFilename).toEqual(undefined);
46         });
47
48         it('should return poll file names', () => {
49                 const monitoring = VSPComponentsMonitoringViewFactory.build({}, {snmpPollFlag: true});
50                 let softwareProduct = {softwareProductEditor: {data: {...version}}, softwareProductComponents: {monitoring}};
51                 var results = mapStateToProps({softwareProduct});
52                 expect(results.trapFilename).toEqual(undefined);
53                 expect(results.pollFilename).toEqual(monitoring.pollFilename);
54
55                 let renderer = TestUtils.createRenderer();
56                 renderer.render(<SoftwareProductComponentsMonitoringView {...results} />);
57                 let renderedOutput = renderer.getRenderOutput();
58                 expect(renderedOutput).toBeTruthy();
59         });
60
61         it('should return both file names', () => {
62                 const monitoring =  VSPComponentsMonitoringViewFactory.build({}, {snmpTrapFlag: true, snmpPollFlag: true});
63                 let softwareProduct = {softwareProductEditor: {data: {...version}}, softwareProductComponents: {monitoring}};
64                 var results = mapStateToProps({softwareProduct});
65                 expect(results.trapFilename).toEqual(monitoring.trapFilename);
66                 expect(results.pollFilename).toEqual(monitoring.pollFilename);
67
68                 let renderer = TestUtils.createRenderer();
69                 renderer.render(<SoftwareProductComponentsMonitoringView {...results} />);
70                 let renderedOutput = renderer.getRenderOutput();
71                 expect(renderedOutput).toBeTruthy();
72         });
73
74         it('should change state to dragging', done => {
75                 var view = TestUtils.renderIntoDocument(<SoftwareProductComponentsMonitoringView />);
76                 expect(view.state.dragging).toBe(false);
77                 view.handleOnDragEnter(false);
78                 setTimeout(()=> {
79                         expect(view.state.dragging).toBe(true);
80                         done();
81                 }, 100);
82         });
83
84         it('should not change state to dragging', done => {
85                 var view = TestUtils.renderIntoDocument(<SoftwareProductComponentsMonitoringView />);
86                 expect(view.state.dragging).toBe(false);
87                 view.handleOnDragEnter(true);
88                 setTimeout(()=> {
89                         expect(view.state.dragging).toBe(false);
90                         done();
91                 }, 0);
92         });
93
94 });