blob: 5b68319a9f9517fb74b322d23bf1b70344d00062 [file] [log] [blame]
svishneva3e9c9e2018-01-15 15:55:53 +02001/*!
svishnev1eb66b72018-01-11 14:39:45 +02002 * Copyright © 2016-2017 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
svishneva3e9c9e2018-01-15 15:55:53 +02007 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
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,
svishneva3e9c9e2018-01-15 15:55:53 +020012 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express
13 * or implied. See the License for the specific language governing
14 * permissions and limitations under the License.
Michael Landoefa037d2017-02-19 12:57:33 +020015 */
16
AviZi280f8012017-06-09 02:39:56 +030017
Michael Landoefa037d2017-02-19 12:57:33 +020018import React from 'react';
svishnevaa2eece2018-01-18 17:52:06 +020019
20import TestUtils from 'react-addons-test-utils';
Michael Landoefa037d2017-02-19 12:57:33 +020021import VersionController from 'nfvo-components/panel/versionController/VersionController.jsx';
talig8e9c0652017-12-20 14:30:43 +020022import {actionsEnum} from 'nfvo-components/panel/versionController/VersionControllerConstants.js';
AviZi280f8012017-06-09 02:39:56 +030023import {scryRenderedDOMComponentsWithTestId} from 'test-utils/Util.js';
24import {VSPComponentsVersionControllerFactory} from 'test-utils/factories/softwareProduct/SoftwareProductComponentsNetworkFactories.js';
talig8e9c0652017-12-20 14:30:43 +020025import { Provider } from 'react-redux';
26import {storeCreator} from 'sdc-app/AppStore.js';
Michael Landoefa037d2017-02-19 12:57:33 +020027
28describe('versionController UI Component', () => {
AviZi280f8012017-06-09 02:39:56 +030029 let onSave, onClose, onVersionSwitching = onSave = onClose = () => {return Promise.resolve();};
30 const versionData = VSPComponentsVersionControllerFactory.build();
31 const isFormDataValid = true;
32 const viewableVersions = versionData.viewableVersions;
33 const version = versionData.version;
talig8e9c0652017-12-20 14:30:43 +020034 const itemPermission = {isCertified: false, isCollaborator: true, isDirty: false};
35 const props = {onSave, onClose, isFormDataValid, viewableVersions, version, onVersionSwitching, itemPermission};
36 const store = storeCreator();
Michael Landoefa037d2017-02-19 12:57:33 +020037
38 it('function does exist', () => {
svishnevaa2eece2018-01-18 17:52:06 +020039 var renderer = TestUtils.createRenderer();
talig8e9c0652017-12-20 14:30:43 +020040
41 renderer.render(<Provider store={store}><VersionController {...props} /></Provider>);
Michael Landoefa037d2017-02-19 12:57:33 +020042 var renderedOutput = renderer.getRenderOutput();
AviZi280f8012017-06-09 02:39:56 +030043 expect(renderedOutput).toBeTruthy();
Michael Landoefa037d2017-02-19 12:57:33 +020044 });
45
AviZi280f8012017-06-09 02:39:56 +030046 it('validating submit function', () => {
talig8e9c0652017-12-20 14:30:43 +020047 let provider = TestUtils.renderIntoDocument(<Provider store={store}>
48 <VersionController {...props} /></Provider>);
49 let versionController = TestUtils.findRenderedComponentWithType(
50 provider,
51 VersionController
52 );
AviZi280f8012017-06-09 02:39:56 +030053 let cb = action => expect(action).toBe(actionsEnum.SUBMIT);
54 versionController.submit(cb);
55 });
56
57 it('validating revert function', () => {
talig8e9c0652017-12-20 14:30:43 +020058 let provider = TestUtils.renderIntoDocument(<Provider store={store}><VersionController {...props} /></Provider>);
59 let versionController = TestUtils.findRenderedComponentWithType(
60 provider,
61 VersionController
62 );
63 let cb = action => expect(action).toBe(actionsEnum.REVERT);
64 versionController.revert(cb);
AviZi280f8012017-06-09 02:39:56 +030065 });
66
67 it('does not show the save button when no onSave available', () => {
68 let noSaveProps = {...props, onSave: null };
talig8e9c0652017-12-20 14:30:43 +020069 let versionController = TestUtils.renderIntoDocument(<Provider store={store}><VersionController {...noSaveProps} /></Provider>);
AviZi280f8012017-06-09 02:39:56 +030070 let elem = scryRenderedDOMComponentsWithTestId(versionController,'vc-save-btn');
71 expect(elem).toBeTruthy();
72 expect(elem.length).toBe(0);
73 });
74
75 it('does not show the submit button when no callVCAction available', () => {
76 let callVCActionProps = {...props, callVCAction: null};
talig8e9c0652017-12-20 14:30:43 +020077 let versionController = TestUtils.renderIntoDocument(<Provider store={store}><VersionController {...callVCActionProps} /></Provider>);
AviZi280f8012017-06-09 02:39:56 +030078 let elem = scryRenderedDOMComponentsWithTestId(versionController,'vc-submit-btn');
79 expect(elem).toBeTruthy();
80 expect(elem.length).toBe(0);
81 });
82
83 it('does not show the revert button when no callVCAction available', () => {
84 let callVCActionProps = {...props, callVCAction: null};
talig8e9c0652017-12-20 14:30:43 +020085 let versionController = TestUtils.renderIntoDocument(<Provider store={store}><VersionController {...callVCActionProps} /></Provider>);
AviZi280f8012017-06-09 02:39:56 +030086 let elem = scryRenderedDOMComponentsWithTestId(versionController,'vc-revert-btn');
87 expect(elem).toBeTruthy();
88 expect(elem.length).toBe(0);
89 });
90
91 it('Shows the save button when onSave available', () => {
talig8e9c0652017-12-20 14:30:43 +020092 let versionController = TestUtils.renderIntoDocument(<Provider store={store}><VersionController {...props} /></Provider>);
AviZi280f8012017-06-09 02:39:56 +030093 let elem = scryRenderedDOMComponentsWithTestId(versionController,'vc-save-btn');
94 expect(elem).toBeTruthy();
95 expect(elem.length).toBe(1);
96 });
97
talig8e9c0652017-12-20 14:30:43 +020098 it('Shows the submit button when callVCAction available and user is owner', () => {
99 const permissions = {owner: {userId: '111'}},
100 userInfo = {userId: '111'};
101 let callVCActionProps = { ...props, callVCAction: function(){}, permissions, userInfo};
102 let versionController = TestUtils.renderIntoDocument(<Provider store={store}><VersionController {...callVCActionProps} /></Provider>);
AviZi280f8012017-06-09 02:39:56 +0300103 let elem = scryRenderedDOMComponentsWithTestId(versionController,'vc-submit-btn');
104 expect(elem).toBeTruthy();
105 expect(elem.length).toBe(1);
106 });
107
svishneva3e9c9e2018-01-15 15:55:53 +0200108 it('Shows the submit button when callVCAction available and user is contributor', () => {
109 const permissions = {owner: {userId: '111'}, contributors: ['232']},
110 userInfo = {userId: '232'};
talig8e9c0652017-12-20 14:30:43 +0200111 let callVCActionProps = { ...props, callVCAction: function(){}, permissions, userInfo};
112 let versionController = TestUtils.renderIntoDocument(<Provider store={store}><VersionController {...callVCActionProps} /></Provider>);
113 let elem = scryRenderedDOMComponentsWithTestId(versionController,'vc-submit-btn');
114 expect(elem).toBeTruthy();
svishneva3e9c9e2018-01-15 15:55:53 +0200115 expect(elem.length).toBe(1);
116 });
117
118 it('Doesn\'t show the submit button when user is not owner or contributor', () => {
119 const permissions = {owner: {userId: '111'}, contributors: ['232']},
120 userInfo = {userId: '222'};
121 const propsViewer = {...props,
122 itemPermission: {isCertified: false, isCollaborator: false, isDirty: false}};
123 let callVCActionProps = { ...propsViewer, callVCAction: function(){}, permissions, userInfo};
124 let versionController = TestUtils.renderIntoDocument(<Provider store={store}><VersionController {...callVCActionProps} /></Provider>);
125 let elem = scryRenderedDOMComponentsWithTestId(versionController,'vc-submit-btn');
126 expect(elem).toBeTruthy();
talig8e9c0652017-12-20 14:30:43 +0200127 expect(elem.length).toBe(0);
128 });
129
AviZi280f8012017-06-09 02:39:56 +0300130 it('Shows the revert button when callVCAction available', () => {
131 let callVCActionProps = { ...props, callVCAction: function(){} };
talig8e9c0652017-12-20 14:30:43 +0200132 let versionController = TestUtils.renderIntoDocument(<Provider store={store}><VersionController {...callVCActionProps} /></Provider>);
AviZi280f8012017-06-09 02:39:56 +0300133 let elem = scryRenderedDOMComponentsWithTestId(versionController,'vc-revert-btn');
134 expect(elem).toBeTruthy();
135 expect(elem.length).toBe(1);
136 });
137
Michael Landoefa037d2017-02-19 12:57:33 +0200138});