2 * Copyright © 2016-2017 European Support Limited
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
8 * http://www.apache.org/licenses/LICENSE-2.0
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.
17 import React from 'react';
18 import TestUtils from 'react-dom/test-utils';
19 import {mapStateToProps} from 'sdc-app/flows/FlowsEditorModal.js';
20 import FlowsEditorModalView from 'sdc-app/flows/FlowsEditorModalView.jsx';
21 import ShallowRenderer from 'react-test-renderer/shallow';
22 import {FlowBasicFactory} from 'test-utils/factories/flows/FlowsFactories.js';
24 describe('Flows Editor Modal Mapper and View Classes: ', function () {
26 it('mapStateToProps mapper exists', () => {
27 expect(mapStateToProps).toBeTruthy();
30 it('mapStateToProps mapper - without currentFlow', () => {
33 diagramType: 'SOME_TYPE'
35 var results = mapStateToProps({flows});
36 expect(results.currentFlow).toBeTruthy();
37 expect(results.currentFlow.artifactName).toBe('');
38 expect(results.currentFlow.description).toBe('');
41 it('mapStateToProps mapper - populated currentFlow', () => {
42 const currentFlow = FlowBasicFactory.build({artifactType: 'WORKFLOW'});
46 diagramType: 'WORKFLOW'
48 var results = mapStateToProps({flows});
49 expect(results.currentFlow).toBeTruthy();
50 expect(results.currentFlow.artifactName).toBe(currentFlow.artifactName);
51 expect(results.currentFlow.description).toBe(currentFlow.description);
52 expect(results.currentFlow.serviceID).toBe(flows.serviceID);
53 expect(results.currentFlow.artifactType).toBe(flows.diagramType);
56 it('basic modal view component run with empty artifact', () => {
57 const renderer = new ShallowRenderer();
61 onDataChanged={()=>{}}
62 currentFlow={FlowBasicFactory.build({artifactName: '', description: ''})}/>);
63 let renderedOutput = renderer.getRenderOutput();
64 expect(renderedOutput).toBeTruthy();
67 it('modal view component run with data changed handler', done => {
68 let handler = () => done();
69 let document = TestUtils.renderIntoDocument(
72 onDataChanged={handler}
73 currentFlow={FlowBasicFactory.build({artifactName: '', description: ''})}
74 genericFieldInfo={{artifactName : {isValid: true, errorText: ''}, description: {isValid: true, errorText: ''}}} />);
75 let result = TestUtils.scryRenderedDOMComponentsWithTag(document, 'input');
76 expect(result).toBeTruthy();
77 expect(result.length).toBeTruthy();
78 TestUtils.Simulate.change(result[0]);
81 it('modal view component - on save click', done => {
82 let handler = () => done();
83 var flowsEditorModalView = new FlowsEditorModalView({currentFlow: {}, onSubmit: handler});
84 flowsEditorModalView.onSaveClicked();