svishnev | 1eb66b7 | 2018-01-11 14:39:45 +0200 | [diff] [blame] | 1 | /* |
| 2 | * Copyright © 2016-2017 European Support Limited |
AviZi | 280f801 | 2017-06-09 02:39:56 +0300 | [diff] [blame] | 3 | * |
Michael Lando | efa037d | 2017-02-19 12:57:33 +0200 | [diff] [blame] | 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 |
svishnev | 1eb66b7 | 2018-01-11 14:39:45 +0200 | [diff] [blame] | 7 | * |
| 8 | * http://www.apache.org/licenses/LICENSE-2.0 |
| 9 | * |
Michael Lando | efa037d | 2017-02-19 12:57:33 +0200 | [diff] [blame] | 10 | * Unless required by applicable law or agreed to in writing, software |
| 11 | * distributed under the License is distributed on an "AS IS" BASIS, |
svishnev | 1eb66b7 | 2018-01-11 14:39:45 +0200 | [diff] [blame] | 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. |
Michael Lando | efa037d | 2017-02-19 12:57:33 +0200 | [diff] [blame] | 15 | */ |
| 16 | |
Michael Lando | efa037d | 2017-02-19 12:57:33 +0200 | [diff] [blame] | 17 | import React from 'react'; |
svishnev | aa2eece | 2018-01-18 17:52:06 +0200 | [diff] [blame] | 18 | import TestUtils from 'react-addons-test-utils'; |
Michael Lando | efa037d | 2017-02-19 12:57:33 +0200 | [diff] [blame] | 19 | import {mapStateToProps} from 'sdc-app/flows/FlowsEditorModal.js'; |
| 20 | import FlowsEditorModalView from 'sdc-app/flows/FlowsEditorModalView.jsx'; |
svishnev | aa2eece | 2018-01-18 17:52:06 +0200 | [diff] [blame] | 21 | |
AviZi | 280f801 | 2017-06-09 02:39:56 +0300 | [diff] [blame] | 22 | import {FlowBasicFactory} from 'test-utils/factories/flows/FlowsFactories.js'; |
| 23 | |
Michael Lando | efa037d | 2017-02-19 12:57:33 +0200 | [diff] [blame] | 24 | describe('Flows Editor Modal Mapper and View Classes: ', function () { |
| 25 | |
| 26 | it('mapStateToProps mapper exists', () => { |
AviZi | 280f801 | 2017-06-09 02:39:56 +0300 | [diff] [blame] | 27 | expect(mapStateToProps).toBeTruthy(); |
Michael Lando | efa037d | 2017-02-19 12:57:33 +0200 | [diff] [blame] | 28 | }); |
| 29 | |
| 30 | it('mapStateToProps mapper - without currentFlow', () => { |
| 31 | var flows = { |
| 32 | serviceID: '123', |
| 33 | diagramType: 'SOME_TYPE' |
| 34 | }; |
| 35 | var results = mapStateToProps({flows}); |
AviZi | 280f801 | 2017-06-09 02:39:56 +0300 | [diff] [blame] | 36 | expect(results.currentFlow).toBeTruthy(); |
Michael Lando | efa037d | 2017-02-19 12:57:33 +0200 | [diff] [blame] | 37 | expect(results.currentFlow.artifactName).toBe(''); |
| 38 | expect(results.currentFlow.description).toBe(''); |
| 39 | }); |
| 40 | |
| 41 | it('mapStateToProps mapper - populated currentFlow', () => { |
AviZi | 280f801 | 2017-06-09 02:39:56 +0300 | [diff] [blame] | 42 | const currentFlow = FlowBasicFactory.build({artifactType: 'WORKFLOW'}); |
Michael Lando | efa037d | 2017-02-19 12:57:33 +0200 | [diff] [blame] | 43 | var flows = { |
AviZi | 280f801 | 2017-06-09 02:39:56 +0300 | [diff] [blame] | 44 | data: currentFlow, |
Michael Lando | efa037d | 2017-02-19 12:57:33 +0200 | [diff] [blame] | 45 | serviceID: '123', |
AviZi | 280f801 | 2017-06-09 02:39:56 +0300 | [diff] [blame] | 46 | diagramType: 'WORKFLOW' |
Michael Lando | efa037d | 2017-02-19 12:57:33 +0200 | [diff] [blame] | 47 | }; |
| 48 | var results = mapStateToProps({flows}); |
AviZi | 280f801 | 2017-06-09 02:39:56 +0300 | [diff] [blame] | 49 | expect(results.currentFlow).toBeTruthy(); |
| 50 | expect(results.currentFlow.artifactName).toBe(currentFlow.artifactName); |
| 51 | expect(results.currentFlow.description).toBe(currentFlow.description); |
Michael Lando | efa037d | 2017-02-19 12:57:33 +0200 | [diff] [blame] | 52 | 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', () => { |
svishnev | aa2eece | 2018-01-18 17:52:06 +0200 | [diff] [blame] | 57 | var renderer = TestUtils.createRenderer(); |
Michael Lando | efa037d | 2017-02-19 12:57:33 +0200 | [diff] [blame] | 58 | renderer.render( |
| 59 | <FlowsEditorModalView |
| 60 | onCancel={()=>{}} |
| 61 | onDataChanged={()=>{}} |
AviZi | 280f801 | 2017-06-09 02:39:56 +0300 | [diff] [blame] | 62 | currentFlow={FlowBasicFactory.build({artifactName: '', description: ''})}/>); |
Michael Lando | efa037d | 2017-02-19 12:57:33 +0200 | [diff] [blame] | 63 | let renderedOutput = renderer.getRenderOutput(); |
AviZi | 280f801 | 2017-06-09 02:39:56 +0300 | [diff] [blame] | 64 | expect(renderedOutput).toBeTruthy(); |
Michael Lando | efa037d | 2017-02-19 12:57:33 +0200 | [diff] [blame] | 65 | }); |
| 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} |
AviZi | 280f801 | 2017-06-09 02:39:56 +0300 | [diff] [blame] | 73 | currentFlow={FlowBasicFactory.build({artifactName: '', description: ''})} |
| 74 | genericFieldInfo={{artifactName : {isValid: true, errorText: ''}, description: {isValid: true, errorText: ''}}} />); |
Michael Lando | efa037d | 2017-02-19 12:57:33 +0200 | [diff] [blame] | 75 | let result = TestUtils.scryRenderedDOMComponentsWithTag(document, 'input'); |
AviZi | 280f801 | 2017-06-09 02:39:56 +0300 | [diff] [blame] | 76 | expect(result).toBeTruthy(); |
| 77 | expect(result.length).toBeTruthy(); |
Michael Lando | efa037d | 2017-02-19 12:57:33 +0200 | [diff] [blame] | 78 | 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 | }); |