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 ShallowRenderer from 'react-test-renderer/shallow';
19 import {mapStateToProps} from 'sdc-app/flows/FlowsListEditor.js';
20 import FlowsListEditorView from 'sdc-app/flows/FlowsListEditorView.jsx';
22 import {FlowUpdateRequestFactory, FlowBasicFactory} from 'test-utils/factories/flows/FlowsFactories.js';
24 describe('Flows List Editor Mapper and View Classes: ', function () {
26 it('mapStateToProps mapper exists', () => {
27 expect(mapStateToProps).toBeTruthy();
30 it('mapStateToProps mapper - without flowList', () => {
33 isModalInEditMode: false,
34 shouldShowWorkflowsEditor: undefined
36 let results = mapStateToProps({flows});
37 expect(results.flowList).toBeTruthy();
38 expect(results.flowList.length).toEqual(0);
39 expect(results.shouldShowWorkflowsEditor).toBe(true);
42 it('mapStateToProps mapper - populated flowList', () => {
44 flowList: FlowBasicFactory.buildList(1),
46 isModalInEditMode: false,
47 shouldShowWorkflowsEditor: false
49 let results = mapStateToProps({flows});
50 expect(results.flowList).toBeTruthy();
51 expect(results.flowList.length).toEqual(1);
52 expect(results.shouldShowWorkflowsEditor).toBe(false);
55 it('mapStateToProps mapper - populated flowList and currentFlow is in readonly', () => {
56 let currentFlow = FlowBasicFactory.build();
57 currentFlow.readonly = true;
59 flowList: [currentFlow],
62 isModalInEditMode: false,
63 shouldShowWorkflowsEditor: false
65 let results = mapStateToProps({flows});
66 expect(results.currentFlow).toBeTruthy();
67 expect(results.isCheckedOut).toEqual(false);
70 it('mapStateToProps mapper - populated flowList and currentFlow is in not readonly', () => {
71 let currentFlow = FlowBasicFactory.build();
72 currentFlow.readonly = false;
74 flowList: [currentFlow],
77 isModalInEditMode: false,
78 shouldShowWorkflowsEditor: false
80 let results = mapStateToProps({flows});
81 expect(results.currentFlow).toBeTruthy();
82 expect(results.isCheckedOut).toEqual(true);
85 it('mapStateToProps mapper - populated flowList and service is in readonly', () => {
86 let currentFlow = FlowBasicFactory.build();
88 flowList: [currentFlow],
91 isModalInEditMode: false,
92 shouldShowWorkflowsEditor: false,
95 let results = mapStateToProps({flows});
96 expect(results.currentFlow).toBeTruthy();
97 expect(results.isCheckedOut).toEqual(false);
100 it('mapStateToProps mapper - populated flowList and service is in not readonly', () => {
101 let currentFlow = FlowBasicFactory.build();
103 flowList: [currentFlow],
105 isDisplayModal: true,
106 isModalInEditMode: false,
107 shouldShowWorkflowsEditor: false,
110 let results = mapStateToProps({flows});
111 expect(results.currentFlow).toBeTruthy();
112 expect(results.isCheckedOut).toEqual(true);
115 it('basic view component run with empty flowList and should show the list', () => {
116 const renderer = new ShallowRenderer();
117 let currentFlow = FlowBasicFactory.build();
118 renderer.render(<FlowsListEditorView shouldShowWorkflowsEditor={true} flowList={[currentFlow]}/>);
119 let renderedOutput = renderer.getRenderOutput();
120 expect(renderedOutput).toBeTruthy();
123 it('basic view component run with empty flowList and should show the diagram', () => {
124 const flow = FlowUpdateRequestFactory.build();
125 const renderer = new ShallowRenderer();
126 renderer.render(<FlowsListEditorView currentFlow={flow} shouldShowWorkflowsEditor={false} flowList={[flow]}/>);
127 let renderedOutput = renderer.getRenderOutput();
128 expect(renderedOutput).toBeTruthy();
131 it('basic view component run with empty flowList and should show popup modal', () => {
132 const renderer = new ShallowRenderer();
133 let currentFlow = FlowBasicFactory.build();
134 renderer.render(<FlowsListEditorView isDisplayModal={true} shouldShowWorkflowsEditor={true} flowList={[currentFlow]}/>);
135 let renderedOutput = renderer.getRenderOutput();
136 expect(renderedOutput).toBeTruthy();