From 8e9c0653dd6c6862123c9609ae34e1206d86456e Mon Sep 17 00:00:00 2001 From: talig Date: Wed, 20 Dec 2017 14:30:43 +0200 Subject: Add collaboration feature Issue-ID: SDC-767 Change-Id: I14fb4c1f54086ed03a56a7ff7fab9ecd40381795 Signed-off-by: talig --- .../nfvo-components/editor/TabulatedEditor.test.js | 9 +- .../test/nfvo-components/modal/globalModal.test.js | 8 +- .../VersionController/versionController.test.js | 108 +++++++---------- .../versionControllerUtils.test.js | 128 --------------------- .../test/nfvo-components/tree/tree.test.js | 31 +++++ 5 files changed, 82 insertions(+), 202 deletions(-) delete mode 100644 openecomp-ui/test/nfvo-components/panel/VersionController/versionControllerUtils.test.js create mode 100644 openecomp-ui/test/nfvo-components/tree/tree.test.js (limited to 'openecomp-ui/test/nfvo-components') diff --git a/openecomp-ui/test/nfvo-components/editor/TabulatedEditor.test.js b/openecomp-ui/test/nfvo-components/editor/TabulatedEditor.test.js index e61261e09a..5f9f06b714 100644 --- a/openecomp-ui/test/nfvo-components/editor/TabulatedEditor.test.js +++ b/openecomp-ui/test/nfvo-components/editor/TabulatedEditor.test.js @@ -18,13 +18,15 @@ import React from 'react'; import TestUtils from 'react-addons-test-utils'; import TabulatedEditor from 'nfvo-components/editor/TabulatedEditor.jsx'; +import { Provider } from 'react-redux'; +import {storeCreator} from 'sdc-app/AppStore.js'; describe('Tabulated Editor test: ', function () { - + const store = storeCreator(); it('basic view test', () => { let renderer = TestUtils.createRenderer(); renderer.render( - + ); let renderedOutput = renderer.getRenderOutput(); expect(renderedOutput).toBeTruthy(); @@ -41,11 +43,12 @@ describe('Tabulated Editor test: ', function () { isCheckedOut: false, version: {id: '0.1', label: '0.1'}, viewableVersions: [{id: '0.1', label: '0.1'}], + itemPermission: {isCertified: false, isCollaborator: true, isDirty: false}, onSubmit: ()=>{}, onRevert: ()=>{} } }; - const view = TestUtils.renderIntoDocument(); + const view = TestUtils.renderIntoDocument(); expect(view).toBeTruthy(); }); diff --git a/openecomp-ui/test/nfvo-components/modal/globalModal.test.js b/openecomp-ui/test/nfvo-components/modal/globalModal.test.js index efe43b6c37..f27b1359f8 100644 --- a/openecomp-ui/test/nfvo-components/modal/globalModal.test.js +++ b/openecomp-ui/test/nfvo-components/modal/globalModal.test.js @@ -81,10 +81,10 @@ describe('Global Modal tests: ', function () { it('checking component default render', ()=> { - expect(window.document).toBeTruthy(); - let globalModalView = TestUtils.renderIntoDocument( - {}} /> - ); + expect(window.document).toBeTruthy(); + let renderer = TestUtils.createRenderer(); + renderer.render({}} />); + let globalModalView = renderer.getRenderOutput(); expect(globalModalView).toBeTruthy(); }); diff --git a/openecomp-ui/test/nfvo-components/panel/VersionController/versionController.test.js b/openecomp-ui/test/nfvo-components/panel/VersionController/versionController.test.js index e14e9b76f5..f2db01f3f1 100644 --- a/openecomp-ui/test/nfvo-components/panel/VersionController/versionController.test.js +++ b/openecomp-ui/test/nfvo-components/panel/VersionController/versionController.test.js @@ -16,13 +16,14 @@ import React from 'react'; -import ReactDOMServer from 'react-dom/server'; + import TestUtils from 'react-addons-test-utils'; -import {mount} from 'enzyme'; import VersionController from 'nfvo-components/panel/versionController/VersionController.jsx'; -import {actionsEnum, statusEnum} from 'nfvo-components/panel/versionController/VersionControllerConstants.js'; +import {actionsEnum} from 'nfvo-components/panel/versionController/VersionControllerConstants.js'; import {scryRenderedDOMComponentsWithTestId} from 'test-utils/Util.js'; import {VSPComponentsVersionControllerFactory} from 'test-utils/factories/softwareProduct/SoftwareProductComponentsNetworkFactories.js'; +import { Provider } from 'react-redux'; +import {storeCreator} from 'sdc-app/AppStore.js'; describe('versionController UI Component', () => { let onSave, onClose, onVersionSwitching = onSave = onClose = () => {return Promise.resolve();}; @@ -30,42 +31,42 @@ describe('versionController UI Component', () => { const isFormDataValid = true; const viewableVersions = versionData.viewableVersions; const version = versionData.version; - const props = {onSave, onClose, isFormDataValid, viewableVersions, version, onVersionSwitching}; + const itemPermission = {isCertified: false, isCollaborator: true, isDirty: false}; + const props = {onSave, onClose, isFormDataValid, viewableVersions, version, onVersionSwitching, itemPermission}; + const store = storeCreator(); it('function does exist', () => { var renderer = TestUtils.createRenderer(); - renderer.render(); + + renderer.render(); var renderedOutput = renderer.getRenderOutput(); expect(renderedOutput).toBeTruthy(); }); - it('validating checkin function', () => { - let versionController = TestUtils.renderIntoDocument(); - let cb = action => expect(action).toBe(actionsEnum.CHECK_IN); - versionController.checkin(cb); - }); - - it('validating checkout function', () => { - let versionController = TestUtils.renderIntoDocument(); - let cb = action => expect(action).toBe(actionsEnum.CHECK_OUT); - versionController.checkout(cb); - }); - it('validating submit function', () => { - let versionController = TestUtils.renderIntoDocument(); + let provider = TestUtils.renderIntoDocument( + ); + let versionController = TestUtils.findRenderedComponentWithType( + provider, + VersionController + ); let cb = action => expect(action).toBe(actionsEnum.SUBMIT); versionController.submit(cb); }); it('validating revert function', () => { - let versionController = TestUtils.renderIntoDocument(); - let cb = action => expect(action).toBe(actionsEnum.UNDO_CHECK_OUT); - versionController.revertCheckout(cb); + let provider = TestUtils.renderIntoDocument(); + let versionController = TestUtils.findRenderedComponentWithType( + provider, + VersionController + ); + let cb = action => expect(action).toBe(actionsEnum.REVERT); + versionController.revert(cb); }); it('does not show the save button when no onSave available', () => { let noSaveProps = {...props, onSave: null }; - let versionController = TestUtils.renderIntoDocument(); + let versionController = TestUtils.renderIntoDocument(); let elem = scryRenderedDOMComponentsWithTestId(versionController,'vc-save-btn'); expect(elem).toBeTruthy(); expect(elem.length).toBe(0); @@ -73,7 +74,7 @@ describe('versionController UI Component', () => { it('does not show the submit button when no callVCAction available', () => { let callVCActionProps = {...props, callVCAction: null}; - let versionController = TestUtils.renderIntoDocument(); + let versionController = TestUtils.renderIntoDocument(); let elem = scryRenderedDOMComponentsWithTestId(versionController,'vc-submit-btn'); expect(elem).toBeTruthy(); expect(elem.length).toBe(0); @@ -81,72 +82,45 @@ describe('versionController UI Component', () => { it('does not show the revert button when no callVCAction available', () => { let callVCActionProps = {...props, callVCAction: null}; - let versionController = TestUtils.renderIntoDocument(); + let versionController = TestUtils.renderIntoDocument(); let elem = scryRenderedDOMComponentsWithTestId(versionController,'vc-revert-btn'); expect(elem).toBeTruthy(); expect(elem.length).toBe(0); }); it('Shows the save button when onSave available', () => { - let versionController = TestUtils.renderIntoDocument(); + let versionController = TestUtils.renderIntoDocument(); let elem = scryRenderedDOMComponentsWithTestId(versionController,'vc-save-btn'); expect(elem).toBeTruthy(); expect(elem.length).toBe(1); }); - it('Shows the submit button when callVCAction available', () => { - let callVCActionProps = { ...props, callVCAction: function(){} }; - let versionController = TestUtils.renderIntoDocument(); + it('Shows the submit button when callVCAction available and user is owner', () => { + const permissions = {owner: {userId: '111'}}, + userInfo = {userId: '111'}; + let callVCActionProps = { ...props, callVCAction: function(){}, permissions, userInfo}; + let versionController = TestUtils.renderIntoDocument(); let elem = scryRenderedDOMComponentsWithTestId(versionController,'vc-submit-btn'); expect(elem).toBeTruthy(); expect(elem.length).toBe(1); }); - it('Shows the revert button when callVCAction available', () => { - let callVCActionProps = { ...props, callVCAction: function(){} }; - let versionController = TestUtils.renderIntoDocument(); - let elem = scryRenderedDOMComponentsWithTestId(versionController,'vc-revert-btn'); - expect(elem).toBeTruthy(); - expect(elem.length).toBe(1); - }); - - it('Shows the checkin button', () => { - let callVCActionProps = { ...props, callVCAction: function(){} }; - let versionController = TestUtils.renderIntoDocument(); - let elem = scryRenderedDOMComponentsWithTestId(versionController,'vc-checkout-btn'); + it('Doesn\'t show the submit button when user is not owner', () => { + const permissions = {owner: {userId: '111'}}, + userInfo = {userId: '222'}; + let callVCActionProps = { ...props, callVCAction: function(){}, permissions, userInfo}; + let versionController = TestUtils.renderIntoDocument(); + let elem = scryRenderedDOMComponentsWithTestId(versionController,'vc-submit-btn'); expect(elem).toBeTruthy(); - expect(elem.length).toBe(1); + expect(elem.length).toBe(0); }); - it('Shows the checkout button', () => { + it('Shows the revert button when callVCAction available', () => { let callVCActionProps = { ...props, callVCAction: function(){} }; - let versionController = TestUtils.renderIntoDocument(); - let elem = scryRenderedDOMComponentsWithTestId(versionController,'vc-checkout-btn'); - expect(elem).toBeTruthy(); - expect(elem.length).toBe(1); - - }); - - it('Doesn\'t show the checkin button for prev version', () => { - let callVCActionProps = { ...props, version: '1.0', callVCAction: function(){} }; - let versionController = mount(); - let elem = versionController.find('[data-test-id="vc-checkout-btn"]'); - - expect(elem).toBeTruthy(); - expect(elem.length).toEqual(1); - expect(elem.find('.svg-icon').length).toEqual(1); - expect(elem.find('.svg-icon').hasClass('disabled')).toBe(true); - }); - - it('Doesn\'t show the checkout button', () => { - let callVCActionProps = { ...props, version: '1.0', callVCAction: function(){} }; - let versionController = mount(); - let elem = versionController.find('[data-test-id="vc-checkout-btn"]'); + let versionController = TestUtils.renderIntoDocument(); + let elem = scryRenderedDOMComponentsWithTestId(versionController,'vc-revert-btn'); expect(elem).toBeTruthy(); expect(elem.length).toBe(1); - expect(elem.find('.svg-icon').length).toEqual(1); - expect(elem.find('.svg-icon').hasClass('disabled')).toBe(true); - }); }); diff --git a/openecomp-ui/test/nfvo-components/panel/VersionController/versionControllerUtils.test.js b/openecomp-ui/test/nfvo-components/panel/VersionController/versionControllerUtils.test.js deleted file mode 100644 index d654e16ddf..0000000000 --- a/openecomp-ui/test/nfvo-components/panel/VersionController/versionControllerUtils.test.js +++ /dev/null @@ -1,128 +0,0 @@ -/*! - * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express - * or implied. See the License for the specific language governing - * permissions and limitations under the License. - */ - - -import Configuration from 'sdc-app/config/Configuration.js'; -import VersionControllerUtils from 'nfvo-components/panel/versionController/VersionControllerUtils.js'; -import {statusEnum} from 'nfvo-components/panel/versionController/VersionControllerConstants.js'; -import VersionControllerUtilsFactory from 'test-utils/factories/softwareProduct/VersionControllerUtilsFactory.js'; - -const status = 'testStatus'; -const {lockingUser: currentUser, viewableVersions: defaultVersions} = VersionControllerUtilsFactory.build(); - -describe('versionController UI Component', () => { - - it('function does exist', () => { - expect(VersionControllerUtils).toBeTruthy(); - }); - - it('validating getCheckOutStatusKindByUserID - without "UserID"', () => { - var result = VersionControllerUtils.getCheckOutStatusKindByUserID(status); - expect(result.status).toBe(status); - expect(result.isCheckedOut).toBe(false); - }); - - it('validating getCheckOutStatusKindByUserID - without "UserID" with locking user', () => { - var result = VersionControllerUtils.getCheckOutStatusKindByUserID(status, 'locking user'); - expect(result.status).toBe(statusEnum.LOCK_STATUS); - expect(result.isCheckedOut).toBe(false); - }); - - it('validating getCheckOutStatusKindByUserID - with "UserID" with configuration set', () => { - const Uid = 'ecomp'; - - Configuration.set('UserID', Uid); - var result = VersionControllerUtils.getCheckOutStatusKindByUserID(status, Uid); - Configuration.set('UserID', undefined); - expect(result.status).toBe(status); - expect(result.isCheckedOut).toBe(true); - }); - - - - it('validating isCheckedOutByCurrentUser - when resource is not checked out', () => { - const resource = VersionControllerUtilsFactory.build({status: statusEnum.SUBMIT_STATUS}); - - Configuration.set('UserID', currentUser); - const result = VersionControllerUtils.isCheckedOutByCurrentUser(resource); - Configuration.set('UserID', undefined); - - expect(result).toBe(false); - }); - - it('validating isCheckedOutByCurrentUser - when resource is checked out', () => { - const resource = VersionControllerUtilsFactory.build(); - - Configuration.set('UserID', currentUser); - const result = VersionControllerUtils.isCheckedOutByCurrentUser(resource); - Configuration.set('UserID', undefined); - - expect(result).toBe(true); - }); - - it('validating isCheckedOutByCurrentUser - when resource is checked out by another user', () => { - const resource = VersionControllerUtilsFactory.build({lockingUser: 'another'}); - - Configuration.set('UserID', currentUser); - const result = VersionControllerUtils.isCheckedOutByCurrentUser(resource); - Configuration.set('UserID', undefined); - - expect(result).toBe(false); - }); - - - - it('validating isReadOnly - when resource is not checked out', () => { - const resource = VersionControllerUtilsFactory.build({status: statusEnum.SUBMIT_STATUS}); - - Configuration.set('UserID', currentUser); - const result = VersionControllerUtils.isReadOnly(resource); - Configuration.set('UserID', undefined); - - expect(result).toBe(true); - }); - - it('validating isReadOnly - when resource is checked out', () => { - const resource = VersionControllerUtilsFactory.build(); - - Configuration.set('UserID', currentUser); - const result = VersionControllerUtils.isReadOnly(resource); - Configuration.set('UserID', undefined); - - expect(result).toBe(false); - }); - - it('validating isReadOnly - when version of resource is not latest', () => { - - const resource = VersionControllerUtilsFactory.build({version: defaultVersions[defaultVersions.length - 2]}); - - Configuration.set('UserID', currentUser); - const result = VersionControllerUtils.isReadOnly(resource); - Configuration.set('UserID', undefined); - - expect(result).toBe(true); - }); - - it('validating isReadOnly - when resource is checked out by another user', () => { - const resource = VersionControllerUtilsFactory.build({lockingUser: 'another'}); - - Configuration.set('UserID', currentUser); - const result = VersionControllerUtils.isReadOnly(resource); - Configuration.set('UserID', undefined); - - expect(result).toBe(true); - }); -}); diff --git a/openecomp-ui/test/nfvo-components/tree/tree.test.js b/openecomp-ui/test/nfvo-components/tree/tree.test.js new file mode 100644 index 0000000000..95d0ae7f87 --- /dev/null +++ b/openecomp-ui/test/nfvo-components/tree/tree.test.js @@ -0,0 +1,31 @@ +/*! + * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express + * or implied. See the License for the specific language governing + * permissions and limitations under the License. + */ +import Tree from 'nfvo-components/tree/Tree.jsx'; + +describe('Tree Module Tests', function () { + + it('Tree view should exist', () => { + expect(Tree).toBeTruthy(); + }); + + it('should render Tree and call onNodeClick', done => { + const tree = [{id: '123', name: '', parent: ''}]; + let treeView = new Tree({nodes: tree, onNodeClick: () => done()}); + expect(treeView).toBeTruthy(); + treeView.onNodeClick(tree[0]); + }); + +}); -- cgit 1.2.3-korg