blob: 188ba51ef825f0423ce945d2ee5036ce8570b9a5 [file] [log] [blame]
svishnev1eb66b72018-01-11 14:39:45 +02001/*
Einav Weiss Keidard2f57942018-02-14 14:00:07 +02002 * Copyright © 2016-2018 European Support Limited
AviZi280f8012017-06-09 02:39:56 +03003 *
Michael Landoefa037d2017-02-19 12:57:33 +02004 * 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
Einav Weiss Keidard2f57942018-02-14 14:00:07 +02007 *
svishnev1eb66b72018-01-11 14:39:45 +02008 * http://www.apache.org/licenses/LICENSE-2.0
Einav Weiss Keidard2f57942018-02-14 14:00:07 +02009 *
Michael Landoefa037d2017-02-19 12:57:33 +020010 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
svishnev1eb66b72018-01-11 14:39:45 +020012 * 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.
Michael Landoefa037d2017-02-19 12:57:33 +020015 */
16
Michael Landoefa037d2017-02-19 12:57:33 +020017import React from 'react';
Einav Weiss Keidard2f57942018-02-14 14:00:07 +020018import TestUtils from 'react-dom/test-utils';
Michael Landoefa037d2017-02-19 12:57:33 +020019import {mapStateToProps} from 'sdc-app/flows/FlowsEditorModal.js';
20import FlowsEditorModalView from 'sdc-app/flows/FlowsEditorModalView.jsx';
Einav Weiss Keidard2f57942018-02-14 14:00:07 +020021import ShallowRenderer from 'react-test-renderer/shallow';
AviZi280f8012017-06-09 02:39:56 +030022import {FlowBasicFactory} from 'test-utils/factories/flows/FlowsFactories.js';
23
Michael Landoefa037d2017-02-19 12:57:33 +020024describe('Flows Editor Modal Mapper and View Classes: ', function () {
25
26 it('mapStateToProps mapper exists', () => {
AviZi280f8012017-06-09 02:39:56 +030027 expect(mapStateToProps).toBeTruthy();
Michael Landoefa037d2017-02-19 12:57:33 +020028 });
29
30 it('mapStateToProps mapper - without currentFlow', () => {
31 var flows = {
32 serviceID: '123',
33 diagramType: 'SOME_TYPE'
34 };
35 var results = mapStateToProps({flows});
AviZi280f8012017-06-09 02:39:56 +030036 expect(results.currentFlow).toBeTruthy();
Michael Landoefa037d2017-02-19 12:57:33 +020037 expect(results.currentFlow.artifactName).toBe('');
38 expect(results.currentFlow.description).toBe('');
39 });
40
41 it('mapStateToProps mapper - populated currentFlow', () => {
AviZi280f8012017-06-09 02:39:56 +030042 const currentFlow = FlowBasicFactory.build({artifactType: 'WORKFLOW'});
Michael Landoefa037d2017-02-19 12:57:33 +020043 var flows = {
AviZi280f8012017-06-09 02:39:56 +030044 data: currentFlow,
Michael Landoefa037d2017-02-19 12:57:33 +020045 serviceID: '123',
AviZi280f8012017-06-09 02:39:56 +030046 diagramType: 'WORKFLOW'
Michael Landoefa037d2017-02-19 12:57:33 +020047 };
48 var results = mapStateToProps({flows});
AviZi280f8012017-06-09 02:39:56 +030049 expect(results.currentFlow).toBeTruthy();
50 expect(results.currentFlow.artifactName).toBe(currentFlow.artifactName);
51 expect(results.currentFlow.description).toBe(currentFlow.description);
Michael Landoefa037d2017-02-19 12:57:33 +020052 expect(results.currentFlow.serviceID).toBe(flows.serviceID);
53 expect(results.currentFlow.artifactType).toBe(flows.diagramType);
54 });
55
56 it('basic modal view component run with empty artifact', () => {
Einav Weiss Keidard2f57942018-02-14 14:00:07 +020057 const renderer = new ShallowRenderer();
Michael Landoefa037d2017-02-19 12:57:33 +020058 renderer.render(
59 <FlowsEditorModalView
60 onCancel={()=>{}}
61 onDataChanged={()=>{}}
AviZi280f8012017-06-09 02:39:56 +030062 currentFlow={FlowBasicFactory.build({artifactName: '', description: ''})}/>);
Michael Landoefa037d2017-02-19 12:57:33 +020063 let renderedOutput = renderer.getRenderOutput();
AviZi280f8012017-06-09 02:39:56 +030064 expect(renderedOutput).toBeTruthy();
Michael Landoefa037d2017-02-19 12:57:33 +020065 });
66
67 it('modal view component run with data changed handler', done => {
68 let handler = () => done();
69 let document = TestUtils.renderIntoDocument(
70 <FlowsEditorModalView
71 onCancel={()=>{}}
72 onDataChanged={handler}
AviZi280f8012017-06-09 02:39:56 +030073 currentFlow={FlowBasicFactory.build({artifactName: '', description: ''})}
74 genericFieldInfo={{artifactName : {isValid: true, errorText: ''}, description: {isValid: true, errorText: ''}}} />);
Michael Landoefa037d2017-02-19 12:57:33 +020075 let result = TestUtils.scryRenderedDOMComponentsWithTag(document, 'input');
AviZi280f8012017-06-09 02:39:56 +030076 expect(result).toBeTruthy();
77 expect(result.length).toBeTruthy();
Michael Landoefa037d2017-02-19 12:57:33 +020078 TestUtils.Simulate.change(result[0]);
79 });
80
81 it('modal view component - on save click', done => {
82 let handler = () => done();
83 var flowsEditorModalView = new FlowsEditorModalView({currentFlow: {}, onSubmit: handler});
84 flowsEditorModalView.onSaveClicked();
85 });
86
87});