Add new code new version
[sdc.git] / openecomp-ui / test / flows / flowsEditorModal.test.js
1 /*-
2  * ============LICENSE_START=======================================================
3  * SDC
4  * ================================================================================
5  * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved.
6  * ================================================================================
7  * Licensed under the Apache License, Version 2.0 (the "License");
8  * you may not use this file except in compliance with the License.
9  * You may obtain a copy of the License at
10  * 
11  *      http://www.apache.org/licenses/LICENSE-2.0
12  * 
13  * Unless required by applicable law or agreed to in writing, software
14  * distributed under the License is distributed on an "AS IS" BASIS,
15  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16  * See the License for the specific language governing permissions and
17  * limitations under the License.
18  * ============LICENSE_END=========================================================
19  */
20
21 import expect from 'expect';
22 import React from 'react';
23 import TestUtils from 'react-addons-test-utils';
24 import {mapStateToProps} from 'sdc-app/flows/FlowsEditorModal.js';
25 import FlowsEditorModalView from 'sdc-app/flows/FlowsEditorModalView.jsx';
26
27 describe('Flows Editor Modal Mapper and View Classes: ', function () {
28
29         it('mapStateToProps mapper exists', () => {
30                 expect(mapStateToProps).toExist();
31         });
32
33         it('mapStateToProps mapper - without currentFlow', () => {
34                 var flows = {
35                         serviceID: '123',
36                         diagramType: 'SOME_TYPE'
37                 };
38                 var results = mapStateToProps({flows});
39                 expect(results.currentFlow).toExist();
40                 expect(results.currentFlow.artifactName).toBe('');
41                 expect(results.currentFlow.description).toBe('');
42         });
43
44         it('mapStateToProps mapper - populated currentFlow', () => {
45                 let artifactName = 'test1', description = 'desc';
46                 var flows = {
47                         currentFlow: {artifactName, description},
48                         serviceID: '123',
49                         diagramType: 'SOME_TYPE'
50                 };
51                 var results = mapStateToProps({flows});
52                 expect(results.currentFlow).toExist();
53                 expect(results.currentFlow.artifactName).toBe(artifactName);
54                 expect(results.currentFlow.description).toBe(description);
55                 expect(results.currentFlow.serviceID).toBe(flows.serviceID);
56                 expect(results.currentFlow.artifactType).toBe(flows.diagramType);
57         });
58
59         it('basic modal view component run with empty artifact', () => {
60                 let renderer = TestUtils.createRenderer();
61                 renderer.render(
62                         <FlowsEditorModalView
63                                 onCancel={()=>{}}
64                                 onDataChanged={()=>{}}
65                                 currentFlow={{artifactName: '', description: ''}}/>);
66                 let renderedOutput = renderer.getRenderOutput();
67                 expect(renderedOutput).toExist();
68         });
69
70         it('modal view component run with data changed handler', done => {
71                 let handler = () => done();
72                 let document = TestUtils.renderIntoDocument(
73                         <FlowsEditorModalView
74                                 onCancel={()=>{}}
75                                 onDataChanged={handler}
76                                 currentFlow={{artifactName: '', description: ''}}/>);
77                 let result = TestUtils.scryRenderedDOMComponentsWithTag(document, 'input');
78                 expect(result).toExist();
79                 expect(result.length).toExist();
80                 TestUtils.Simulate.change(result[0]);
81         });
82
83         it('modal view component - on save click', done => {
84                 let handler = () => done();
85                 var flowsEditorModalView = new FlowsEditorModalView({currentFlow: {}, onSubmit: handler});
86                 flowsEditorModalView.onSaveClicked();
87         });
88
89 });