blob: 8f2b7e7e88a20cba41d000a6f2ea1c7ba9f2707a [file] [log] [blame]
AviZi280f8012017-06-09 02:39:56 +03001/*!
Michael Landoefa037d2017-02-19 12:57:33 +02002 * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved.
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
AviZi280f8012017-06-09 02:39:56 +03007 *
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,
AviZi280f8012017-06-09 02:39:56 +030012 * 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';
AviZi280f8012017-06-09 02:39:56 +030019
Michael Landoefa037d2017-02-19 12:57:33 +020020import TestUtils from 'react-addons-test-utils';
AviZi280f8012017-06-09 02:39:56 +030021import {mount} from 'enzyme';
Michael Landoefa037d2017-02-19 12:57:33 +020022import VersionController from 'nfvo-components/panel/versionController/VersionController.jsx';
AviZi280f8012017-06-09 02:39:56 +030023import {actionsEnum, statusEnum} from 'nfvo-components/panel/versionController/VersionControllerConstants.js';
24import {scryRenderedDOMComponentsWithTestId} from 'test-utils/Util.js';
25import {VSPComponentsVersionControllerFactory} from 'test-utils/factories/softwareProduct/SoftwareProductComponentsNetworkFactories.js';
Michael Landoefa037d2017-02-19 12:57:33 +020026
27describe('versionController UI Component', () => {
AviZi280f8012017-06-09 02:39:56 +030028 let onSave, onClose, onVersionSwitching = onSave = onClose = () => {return Promise.resolve();};
29 const versionData = VSPComponentsVersionControllerFactory.build();
30 const isFormDataValid = true;
31 const viewableVersions = versionData.viewableVersions;
32 const version = versionData.version;
33 const props = {onSave, onClose, isFormDataValid, viewableVersions, version, onVersionSwitching};
Michael Landoefa037d2017-02-19 12:57:33 +020034
35 it('function does exist', () => {
36 var renderer = TestUtils.createRenderer();
AviZi280f8012017-06-09 02:39:56 +030037 renderer.render(<VersionController isCheckedOut={false} status={statusEnum.CHECK_OUT_STATUS} {...props} />);
Michael Landoefa037d2017-02-19 12:57:33 +020038 var renderedOutput = renderer.getRenderOutput();
AviZi280f8012017-06-09 02:39:56 +030039 expect(renderedOutput).toBeTruthy();
Michael Landoefa037d2017-02-19 12:57:33 +020040 });
41
42 it('validating checkin function', () => {
AviZi280f8012017-06-09 02:39:56 +030043 let versionController = TestUtils.renderIntoDocument(<VersionController isCheckedOut={true} status={statusEnum.CHECK_OUT_STATUS} {...props} />);
Michael Landoefa037d2017-02-19 12:57:33 +020044 let cb = action => expect(action).toBe(actionsEnum.CHECK_IN);
45 versionController.checkin(cb);
AviZi280f8012017-06-09 02:39:56 +030046 });
47
48 it('validating checkout function', () => {
49 let versionController = TestUtils.renderIntoDocument(<VersionController isCheckedOut={false} status={statusEnum.CHECK_IN_STATUS} {...props} />);
50 let cb = action => expect(action).toBe(actionsEnum.CHECK_OUT);
51 versionController.checkout(cb);
52 });
53
54 it('validating submit function', () => {
55 let versionController = TestUtils.renderIntoDocument(<VersionController isCheckedOut={false} status={statusEnum.CHECK_IN_STATUS} {...props} />);
56 let cb = action => expect(action).toBe(actionsEnum.SUBMIT);
57 versionController.submit(cb);
58 });
59
60 it('validating revert function', () => {
61 let versionController = TestUtils.renderIntoDocument(<VersionController isCheckedOut={true} status={statusEnum.CHECK_OUT_STATUS} {...props} />);
62 let cb = action => expect(action).toBe(actionsEnum.UNDO_CHECK_OUT);
63 versionController.revertCheckout(cb);
64 });
65
66 it('does not show the save button when no onSave available', () => {
67 let noSaveProps = {...props, onSave: null };
68 let versionController = TestUtils.renderIntoDocument(<VersionController isCheckedOut={true} status={statusEnum.CHECK_OUT_STATUS} {...noSaveProps} />);
69 let elem = scryRenderedDOMComponentsWithTestId(versionController,'vc-save-btn');
70 expect(elem).toBeTruthy();
71 expect(elem.length).toBe(0);
72 });
73
74 it('does not show the submit button when no callVCAction available', () => {
75 let callVCActionProps = {...props, callVCAction: null};
76 let versionController = TestUtils.renderIntoDocument(<VersionController isCheckedOut={false} status={statusEnum.CHECK_IN_STATUS} {...callVCActionProps} />);
77 let elem = scryRenderedDOMComponentsWithTestId(versionController,'vc-submit-btn');
78 expect(elem).toBeTruthy();
79 expect(elem.length).toBe(0);
80 });
81
82 it('does not show the revert button when no callVCAction available', () => {
83 let callVCActionProps = {...props, callVCAction: null};
84 let versionController = TestUtils.renderIntoDocument(<VersionController isCheckedOut={true} status={statusEnum.CHECK_OUT_STATUS} {...callVCActionProps} />);
85 let elem = scryRenderedDOMComponentsWithTestId(versionController,'vc-revert-btn');
86 expect(elem).toBeTruthy();
87 expect(elem.length).toBe(0);
88 });
89
90 it('Shows the save button when onSave available', () => {
91 let versionController = TestUtils.renderIntoDocument(<VersionController isCheckedOut={true} status={statusEnum.CHECK_OUT_STATUS} {...props} />);
92 let elem = scryRenderedDOMComponentsWithTestId(versionController,'vc-save-btn');
93 expect(elem).toBeTruthy();
94 expect(elem.length).toBe(1);
95 });
96
97 it('Shows the submit button when callVCAction available', () => {
98 let callVCActionProps = { ...props, callVCAction: function(){} };
99 let versionController = TestUtils.renderIntoDocument(<VersionController isCheckedOut={false} status={statusEnum.CHECK_IN_STATUS} {...callVCActionProps} />);
100 let elem = scryRenderedDOMComponentsWithTestId(versionController,'vc-submit-btn');
101 expect(elem).toBeTruthy();
102 expect(elem.length).toBe(1);
103 });
104
105 it('Shows the revert button when callVCAction available', () => {
106 let callVCActionProps = { ...props, callVCAction: function(){} };
107 let versionController = TestUtils.renderIntoDocument(<VersionController isCheckedOut={true} status={statusEnum.CHECK_OUT_STATUS} {...callVCActionProps} />);
108 let elem = scryRenderedDOMComponentsWithTestId(versionController,'vc-revert-btn');
109 expect(elem).toBeTruthy();
110 expect(elem.length).toBe(1);
111 });
112
113 it('Shows the checkin button', () => {
114 let callVCActionProps = { ...props, callVCAction: function(){} };
115 let versionController = TestUtils.renderIntoDocument(<VersionController isCheckedOut={true} status={statusEnum.CHECK_OUT_STATUS} {...callVCActionProps} />);
116 let elem = scryRenderedDOMComponentsWithTestId(versionController,'vc-checkout-btn');
117 expect(elem).toBeTruthy();
118 expect(elem.length).toBe(1);
119 });
120
121 it('Shows the checkout button', () => {
122 let callVCActionProps = { ...props, callVCAction: function(){} };
123 let versionController = TestUtils.renderIntoDocument(<VersionController isCheckedOut={false} status={statusEnum.CHECK_IN_STATUS} {...callVCActionProps} />);
124 let elem = scryRenderedDOMComponentsWithTestId(versionController,'vc-checkout-btn');
125 expect(elem).toBeTruthy();
126 expect(elem.length).toBe(1);
127
128 });
129
130 it('Doesn\'t show the checkin button for prev version', () => {
131 let callVCActionProps = { ...props, version: '1.0', callVCAction: function(){} };
132 let versionController = mount(<VersionController isCheckedOut={true} status={statusEnum.CHECK_OUT_STATUS} {...callVCActionProps} />);
133 let elem = versionController.find('[data-test-id="vc-checkout-btn"]');
134 let svgIcon = versionController.find('.version-controller-lock-closed');
135
136 expect(elem).toBeTruthy();
137 expect(elem.length).toEqual(1);
138 expect(svgIcon.hasClass('disabled')).toBe(true);
139 });
140
141 it('Doesn\'t show the checkout button', () => {
142 let callVCActionProps = { ...props, version: '1.0', callVCAction: function(){} };
143 let versionController = mount(<VersionController isCheckedOut={false} status={statusEnum.CHECK_IN_STATUS} {...callVCActionProps} />);
144 let elem = versionController.find('[data-test-id="vc-checkout-btn"]');
145 let svgIcon = versionController.find('.version-controller-lock-closed');
146
147 expect(elem).toBeTruthy();
148 expect(elem.length).toBe(1);
149 expect(svgIcon.hasClass('disabled')).toBe(true);
Michael Landoefa037d2017-02-19 12:57:33 +0200150
151 });
152
153});