react-version-downgrade
[sdc.git] / openecomp-ui / test / flows / FlowsListEditor.test.js
1 /*
2  * Copyright © 2016-2017 European Support Limited
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 or implied.
13  * See the License for the specific language governing permissions and
14  * 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/flows/FlowsListEditor.js';
20 import FlowsListEditorView from 'sdc-app/flows/FlowsListEditorView.jsx';
21
22 import {FlowUpdateRequestFactory, FlowBasicFactory} from 'test-utils/factories/flows/FlowsFactories.js';
23
24 describe('Flows List Editor Mapper and View Classes: ', function () {
25
26         it('mapStateToProps mapper exists', () => {
27                 expect(mapStateToProps).toBeTruthy();
28         });
29
30         it('mapStateToProps mapper - without flowList', () => {
31                 let flows = {
32                         isDisplayModal: true,
33                         isModalInEditMode: false,
34                         shouldShowWorkflowsEditor: undefined
35                 };
36                 let results = mapStateToProps({flows});
37                 expect(results.flowList).toBeTruthy();
38                 expect(results.flowList.length).toEqual(0);
39                 expect(results.shouldShowWorkflowsEditor).toBe(true);
40         });
41
42         it('mapStateToProps mapper - populated flowList', () => {
43                 let flows = {
44                         flowList: FlowBasicFactory.buildList(1),
45                         isDisplayModal: true,
46                         isModalInEditMode: false,
47                         shouldShowWorkflowsEditor: false
48                 };
49                 let results = mapStateToProps({flows});
50                 expect(results.flowList).toBeTruthy();
51                 expect(results.flowList.length).toEqual(1);
52                 expect(results.shouldShowWorkflowsEditor).toBe(false);
53         });
54
55         it('mapStateToProps mapper - populated flowList and currentFlow is in readonly', () => {
56                 let currentFlow = FlowBasicFactory.build();
57                 currentFlow.readonly = true;
58                 let flows = {
59                         flowList: [currentFlow],
60                         data: currentFlow,
61                         isDisplayModal: true,
62                         isModalInEditMode: false,
63                         shouldShowWorkflowsEditor: false
64                 };
65                 let results = mapStateToProps({flows});
66                 expect(results.currentFlow).toBeTruthy();
67                 expect(results.isCheckedOut).toEqual(false);
68         });
69
70         it('mapStateToProps mapper - populated flowList and currentFlow is in not readonly', () => {
71                 let currentFlow = FlowBasicFactory.build();
72                 currentFlow.readonly = false;
73                 let flows = {
74                         flowList: [currentFlow],
75                         data: currentFlow,
76                         isDisplayModal: true,
77                         isModalInEditMode: false,
78                         shouldShowWorkflowsEditor: false
79                 };
80                 let results = mapStateToProps({flows});
81                 expect(results.currentFlow).toBeTruthy();
82                 expect(results.isCheckedOut).toEqual(true);
83         });
84
85         it('mapStateToProps mapper - populated flowList and service is in readonly', () => {
86                 let currentFlow = FlowBasicFactory.build();
87                 let flows = {
88                         flowList: [currentFlow],
89                         data: currentFlow,
90                         isDisplayModal: true,
91                         isModalInEditMode: false,
92                         shouldShowWorkflowsEditor: false,
93                         readonly: true
94                 };
95                 let results = mapStateToProps({flows});
96                 expect(results.currentFlow).toBeTruthy();
97                 expect(results.isCheckedOut).toEqual(false);
98         });
99
100         it('mapStateToProps mapper - populated flowList and service is in not readonly', () => {
101                 let currentFlow = FlowBasicFactory.build();
102                 let flows = {
103                         flowList: [currentFlow],
104                         data: currentFlow,
105                         isDisplayModal: true,
106                         isModalInEditMode: false,
107                         shouldShowWorkflowsEditor: false,
108                         readonly: false
109                 };
110                 let results = mapStateToProps({flows});
111                 expect(results.currentFlow).toBeTruthy();
112                 expect(results.isCheckedOut).toEqual(true);
113         });
114
115         it('basic view component run with empty flowList and should show the list', () => {
116                 var renderer = TestUtils.createRenderer();
117                 let currentFlow = FlowBasicFactory.build();
118                 renderer.render(<FlowsListEditorView shouldShowWorkflowsEditor={true} flowList={[currentFlow]}/>);
119                 let renderedOutput = renderer.getRenderOutput();
120                 expect(renderedOutput).toBeTruthy();
121         });
122
123         it('basic view component run with empty flowList and should show the diagram', () => {
124                 const flow = FlowUpdateRequestFactory.build();
125                 var renderer = TestUtils.createRenderer();
126                 renderer.render(<FlowsListEditorView currentFlow={flow} shouldShowWorkflowsEditor={false} flowList={[flow]}/>);
127                 let renderedOutput = renderer.getRenderOutput();
128                 expect(renderedOutput).toBeTruthy();
129         });
130
131         it('basic view component run with empty flowList and should show popup modal', () => {
132                 var renderer = TestUtils.createRenderer();
133                 let currentFlow = FlowBasicFactory.build();
134                 renderer.render(<FlowsListEditorView isDisplayModal={true} shouldShowWorkflowsEditor={true} flowList={[currentFlow]}/>);
135                 let renderedOutput = renderer.getRenderOutput();
136                 expect(renderedOutput).toBeTruthy();
137         });
138
139
140 });