blob: 64304ab9dedc38b43c657d61d6f591ebb35ddd50 [file] [log] [blame]
svishnev1eb66b72018-01-11 14:39:45 +02001/*
2 * 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
svishnev1eb66b72018-01-11 14:39:45 +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,
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
AviZi280f8012017-06-09 02:39:56 +030017
Michael Landoefa037d2017-02-19 12:57:33 +020018import React from 'react';
svishnev1eb66b72018-01-11 14:39:45 +020019import ShallowRenderer from 'react-test-renderer/shallow';
20import TestUtils from 'react-dom/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', () => {
svishnev1eb66b72018-01-11 14:39:45 +020039 const renderer = new ShallowRenderer();
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
talig8e9c0652017-12-20 14:30:43 +0200108 it('Doesn\'t show the submit button when user is not owner', () => {
109 const permissions = {owner: {userId: '111'}},
110 userInfo = {userId: '222'};
111 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();
115 expect(elem.length).toBe(0);
116 });
117
AviZi280f8012017-06-09 02:39:56 +0300118 it('Shows the revert button when callVCAction available', () => {
119 let callVCActionProps = { ...props, callVCAction: function(){} };
talig8e9c0652017-12-20 14:30:43 +0200120 let versionController = TestUtils.renderIntoDocument(<Provider store={store}><VersionController {...callVCActionProps} /></Provider>);
AviZi280f8012017-06-09 02:39:56 +0300121 let elem = scryRenderedDOMComponentsWithTestId(versionController,'vc-revert-btn');
122 expect(elem).toBeTruthy();
123 expect(elem.length).toBe(1);
124 });
125
Michael Landoefa037d2017-02-19 12:57:33 +0200126});