diff options
Diffstat (limited to 'openecomp-ui/test/nfvo-components')
5 files changed, 550 insertions, 0 deletions
diff --git a/openecomp-ui/test/nfvo-components/input/dualListBox/dualListbox.test.js b/openecomp-ui/test/nfvo-components/input/dualListBox/dualListbox.test.js new file mode 100644 index 0000000000..eaa06eedf4 --- /dev/null +++ b/openecomp-ui/test/nfvo-components/input/dualListBox/dualListbox.test.js @@ -0,0 +1,94 @@ +/*- + * ============LICENSE_START======================================================= + * SDC + * ================================================================================ + * 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. + * ============LICENSE_END========================================================= + */ + +import expect from 'expect'; +import React from 'react'; +import TestUtils from 'react-addons-test-utils'; +import DualListboxView from 'nfvo-components/input/dualListbox/DualListboxView.jsx'; + +const ITEMS = [{id: '1', name: 'aaa'}, {id: '2', name: 'bbb'}, {id: '3', name: 'ccc'}]; + +describe('dualListBox Module Tests', function () { + + + it('should render basically', () => { + var renderer = TestUtils.createRenderer(); + renderer.render(<DualListboxView onChange={()=>{}}/>); + var renderedOutput = renderer.getRenderOutput(); + expect(renderedOutput).toExist(); + }); + + it('should render with available list and 4 control buttons', () => { + var view = TestUtils.renderIntoDocument(<DualListboxView availableList={ITEMS} onChange={()=>{}}/>); + expect(view).toExist(); + var results = TestUtils.scryRenderedDOMComponentsWithClass(view, 'dual-list-option'); + expect(results.length).toBe(4); + }); + + it('should add item to selected list', done => { + const newItemValue = 'new item'; + let onChange = (value)=> { + expect(value).toEqual(newItemValue); + done(); + }; + var view = new DualListboxView({availableList:ITEMS, onChange, selectedValuesList:[]}); + expect(view).toExist(); + view.refs = { + availableValues: {getValue(){return newItemValue;}} + }; + view.addToSelectedList(); + }); + + it('should remove item from selected list', done => { + const selectedValuesList = ['a','b']; + let onChange = (value)=> { + expect(value).toEqual(selectedValuesList[1]); + done(); + }; + var view = new DualListboxView({availableList:ITEMS, onChange, selectedValuesList}); + expect(view).toExist(); + view.refs = { + selectedValues: {getValue(){return ['a'];}} + }; + view.removeFromSelectedList(); + }); + + it('should add all items to selected list', done => { + let onChange = (value)=> { + expect(value).toEqual(ITEMS.map(item => item.id)); + done(); + }; + var view = new DualListboxView({availableList:ITEMS, onChange, selectedValuesList:[]}); + expect(view).toExist(); + view.addAllToSelectedList(); + }); + + it('should remove all items from selected list', done => { + let onChange = (value)=> { + expect(value.length).toBe(0); + done(); + }; + var view = new DualListboxView({availableList:ITEMS, onChange, selectedValuesList:[]}); + expect(view).toExist(); + view.removeAllFromSelectedList(); + }); + + +}); diff --git a/openecomp-ui/test/nfvo-components/listEditor/listEditor.test.js b/openecomp-ui/test/nfvo-components/listEditor/listEditor.test.js new file mode 100644 index 0000000000..a3b098f611 --- /dev/null +++ b/openecomp-ui/test/nfvo-components/listEditor/listEditor.test.js @@ -0,0 +1,96 @@ +/*- + * ============LICENSE_START======================================================= + * SDC + * ================================================================================ + * 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. + * ============LICENSE_END========================================================= + */ + +import expect from 'expect'; +import React from 'react'; +import TestUtils from 'react-addons-test-utils'; +import ListEditorView from 'src/nfvo-components/listEditor/ListEditorView.jsx'; +import ListEditorItemView from 'src/nfvo-components/listEditor/ListEditorItemView.jsx'; + +describe('listEditor Module Tests', function () { + + + it('list editor view should exist', () => { + expect(ListEditorView).toExist(); + }); + + it('list editor item view should exist', () => { + expect(ListEditorItemView).toExist(); + }); + + it('should render list and list item and call onEdit', done => { + let itemView = TestUtils.renderIntoDocument( + <ListEditorView title='some title'> + <ListEditorItemView onEdit={done}> + <div></div> + </ListEditorItemView> + </ListEditorView> + ); + expect(itemView).toExist(); + let sliderIcon = TestUtils.findRenderedDOMComponentWithClass(itemView, 'fa-sliders'); + TestUtils.Simulate.click(sliderIcon); + }); + + it('should render list and list item and call onFilter', done => { + let itemView = TestUtils.renderIntoDocument( + <ListEditorView onFilter={()=>{done();}}> + <ListEditorItemView> + <div></div> + </ListEditorItemView> + </ListEditorView> + ); + expect(itemView).toExist(); + let filterInput = TestUtils.findRenderedDOMComponentWithTag(itemView, 'input'); + TestUtils.Simulate.change(filterInput); + }); + + it('should render READONLY list item and not call onEdit', done => { + let itemView = TestUtils.renderIntoDocument( + <ListEditorItemView onEdit={done} isReadOnlyMode={true}> + <div></div> + </ListEditorItemView> + ); + expect(itemView).toExist(); + let sliderIcon = TestUtils.findRenderedDOMComponentWithClass(itemView, 'fa-sliders'); + TestUtils.Simulate.click(sliderIcon); + }); + + it('should render list item and call onDelete', done => { + let itemView = TestUtils.renderIntoDocument( + <ListEditorItemView onDelete={done} isReadOnlyMode={false}> + <div></div> + </ListEditorItemView> + ); + expect(itemView).toExist(); + let sliderIcon = TestUtils.findRenderedDOMComponentWithClass(itemView, 'fa-trash-o'); + TestUtils.Simulate.click(sliderIcon); + }); + + it('should render READONLY list item and not call onDelete', () => { + let itemView = TestUtils.renderIntoDocument( + <ListEditorItemView onDelete={()=>{}} isReadOnlyMode={true}> + <div></div> + </ListEditorItemView> + ); + expect(itemView).toExist(); + let sliderIcon = TestUtils.scryRenderedDOMComponentsWithClass(itemView, 'fa-trash-o'); + expect(sliderIcon).toEqual(0); + }); +}); diff --git a/openecomp-ui/test/nfvo-components/notifications/notificationsModal.test.js b/openecomp-ui/test/nfvo-components/notifications/notificationsModal.test.js new file mode 100644 index 0000000000..f84d38246d --- /dev/null +++ b/openecomp-ui/test/nfvo-components/notifications/notificationsModal.test.js @@ -0,0 +1,144 @@ +/*- + * ============LICENSE_START======================================================= + * SDC + * ================================================================================ + * 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. + * ============LICENSE_END========================================================= + */ + +import expect from 'expect'; +import React from 'react'; +import TestUtils from 'react-addons-test-utils'; +import store from 'sdc-app/AppStore.js'; +import ConnectedNotificationModal, {NotificationModal} from 'nfvo-components/notifications/NotificationModal.jsx'; +import NotificationConstants from 'nfvo-components/notifications/NotificationConstants.js'; + +const title = 'test title'; +const msg = 'test msg'; + +describe('Notification Modal Mapper and View Class: ', function () { + + it('notification should show with type error', done => { + store.dispatch({type: NotificationConstants.NOTIFY_ERROR, data: {title, msg}}); + setTimeout(()=> { + expect(store.getState().notification).toExist(); + expect(store.getState().notification.type).toBe('error'); + done(); + }, 0); + }); + + it('notification should show with type default', done => { + store.dispatch({type: NotificationConstants.NOTIFY_INFO, data: {title, msg}}); + setTimeout(()=> { + expect(store.getState().notification).toExist(); + expect(store.getState().notification.type).toBe('default'); + done(); + }, 0); + }); + + it('notification should show with type warning', done => { + store.dispatch({type: NotificationConstants.NOTIFY_WARNING, data: {title, msg}}); + setTimeout(()=> { + expect(store.getState().notification).toExist(); + expect(store.getState().notification.type).toBe('warning'); + done(); + }, 0); + }); + + it('notification should show with type success', done => { + store.dispatch({type: NotificationConstants.NOTIFY_SUCCESS, data: {title, msg}}); + setTimeout(()=> { + expect(store.getState().notification).toExist(); + expect(store.getState().notification.type).toBe('success'); + done(); + }, 0); + }); + + it('notification should show with type success with connected component', done => { + store.dispatch({type: NotificationConstants.NOTIFY_SUCCESS, data: {title, msg}}); + setTimeout(()=> { + expect(store.getState().notification).toExist(); + expect(store.getState().notification.type).toBe('success'); + let renderer = TestUtils.createRenderer(); + renderer.render(<ConnectedNotificationModal store={store}/>); + let renderedOutput = renderer.getRenderOutput(); + expect(renderedOutput).toExist(); + done(); + }, 0); + }); + + it('notification should hide with connected component', done => { + setTimeout(()=> { + expect(store.getState().notification).toNotExist(); + let renderer = TestUtils.createRenderer(); + renderer.render(<ConnectedNotificationModal store={store}/>); + let renderedOutput = renderer.getRenderOutput(); + expect(renderedOutput).toExist(); + done(); + }, 0); + store.dispatch({type: NotificationConstants.NOTIFY_CLOSE}); + }); + + it('notification should hide', done => { + store.dispatch({type: NotificationConstants.NOTIFY_CLOSE}); + setTimeout(()=> { + expect(store.getState().notification).toNotExist(); + done(); + }, 0); + }); + + it('NotificationModal should not render', ()=> { + let renderer = TestUtils.createRenderer(); + renderer.render(<NotificationModal show={false} title={title} msg={msg} type='error'/>); + let renderedOutput = renderer.getRenderOutput(); + expect(renderedOutput).toExist(); + }); + + it('NotificationModal basic default render', ()=> { + expect(window.document).toExist(); + let document = TestUtils.renderIntoDocument( + <NotificationModal show={true} title={title} msg={msg} type='default' onCloseClick={()=>{}}/> + ); + var result = TestUtils.findAllInRenderedTree(document, element => element.props.className === 'notification-modal primary'); + expect(result.length).toBeGreaterThan(0); + }); + + it('NotificationModal basic error render', ()=> { + expect(window.document).toExist(); + let document = TestUtils.renderIntoDocument( + <NotificationModal show={true} title={title} msg={msg} type='error' onCloseClick={()=>{}}/> + ); + var result = TestUtils.findAllInRenderedTree(document, element => element.props.className === 'notification-modal danger'); + expect(result.length).toBeGreaterThan(0); + }); + + it('NotificationModal basic warning render', ()=> { + expect(window.document).toExist(); + let document = TestUtils.renderIntoDocument( + <NotificationModal show={true} title={title} msg={msg} type='warning' onCloseClick={()=>{}}/> + ); + var result = TestUtils.findAllInRenderedTree(document, element => element.props.className === 'notification-modal warning'); + expect(result.length).toBeGreaterThan(0); + }); + + it('NotificationModal basic success render', ()=> { + expect(window.document).toExist(); + let document = TestUtils.renderIntoDocument( + <NotificationModal show={true} title={title} msg={msg} type='success' onCloseClick={()=>{}}/> + ); + var result = TestUtils.findAllInRenderedTree(document, element => element.props.className === 'notification-modal success'); + expect(result.length).toBeGreaterThan(0); + }); +}); diff --git a/openecomp-ui/test/nfvo-components/panel/VersionController/versionController.test.js b/openecomp-ui/test/nfvo-components/panel/VersionController/versionController.test.js new file mode 100644 index 0000000000..9ab18137cf --- /dev/null +++ b/openecomp-ui/test/nfvo-components/panel/VersionController/versionController.test.js @@ -0,0 +1,44 @@ +/*- + * ============LICENSE_START======================================================= + * SDC + * ================================================================================ + * 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. + * ============LICENSE_END========================================================= + */ + +import expect from 'expect'; +import React from 'react'; +import TestUtils from 'react-addons-test-utils'; +import VersionController from 'nfvo-components/panel/versionController/VersionController.jsx'; +import {actionsEnum} from 'nfvo-components/panel/versionController/VersionControllerConstants.js'; + +describe('versionController UI Component', () => { + + it('function does exist', () => { + var renderer = TestUtils.createRenderer(); + renderer.render(<VersionController isCheckedOut={false} status={'OUT'} />); + var renderedOutput = renderer.getRenderOutput(); + expect(renderedOutput).toExist(); + }); + + it('validating checkin function', () => { + + let versionController = TestUtils.renderIntoDocument(<VersionController isCheckedOut={false} status={'OUT'} onSave={()=>{return Promise.resolve();}}/>); + let cb = action => expect(action).toBe(actionsEnum.CHECK_IN); + versionController.checkin(cb); + + }); + +}); diff --git a/openecomp-ui/test/nfvo-components/panel/VersionController/versionControllerUtils.test.js b/openecomp-ui/test/nfvo-components/panel/VersionController/versionControllerUtils.test.js new file mode 100644 index 0000000000..0e4a92118e --- /dev/null +++ b/openecomp-ui/test/nfvo-components/panel/VersionController/versionControllerUtils.test.js @@ -0,0 +1,172 @@ +/*- + * ============LICENSE_START======================================================= + * SDC + * ================================================================================ + * 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. + * ============LICENSE_END========================================================= + */ + +import expect from 'expect'; +import deepFreeze from 'deep-freeze'; +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'; + +const status = 'testStatus'; + +describe('versionController UI Component', () => { + + it('function does exist', () => { + expect(VersionControllerUtils).toExist(); + }); + + it('validating getCheckOutStatusKindByUserID - without "UserID"', () => { + var result = VersionControllerUtils.getCheckOutStatusKindByUserID(status); + expect(result.status).toBe(status); + expect(result.isCheckedOut).toBe(true); + }); + + 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 userId = 'att'; + + Configuration.set('ATTUserID', userId); + var result = VersionControllerUtils.getCheckOutStatusKindByUserID(status, userId); + Configuration.set('ATTUserID', undefined); + + expect(result.status).toBe(status); + expect(result.isCheckedOut).toBe(true); + }); + + + + it('validating isCheckedOutByCurrentUser - when resource is not checked out', () => { + const currentUser = 'current'; + const resource = deepFreeze({ + version: '0.6', + viewableVersions: ['0.1', '0.2', '0.3', '0.4', '0.5', '0.6'], + status: 'Final' + }); + + Configuration.set('ATTUserID', currentUser); + const result = VersionControllerUtils.isCheckedOutByCurrentUser(resource); + Configuration.set('ATTUserID', undefined); + + expect(result).toBe(false); + }); + + it('validating isCheckedOutByCurrentUser - when resource is checked out', () => { + const currentUser = 'current'; + const resource = deepFreeze({ + version: '0.6', + viewableVersions: ['0.1', '0.2', '0.3', '0.4', '0.5', '0.6'], + status: 'Locked', + lockingUser: 'current' + }); + + Configuration.set('ATTUserID', currentUser); + const result = VersionControllerUtils.isCheckedOutByCurrentUser(resource); + Configuration.set('ATTUserID', undefined); + + expect(result).toBe(true); + }); + + it('validating isCheckedOutByCurrentUser - when resource is checked out by another user', () => { + const currentUser = 'current'; + const resource = deepFreeze({ + version: '0.6', + viewableVersions: ['0.1', '0.2', '0.3', '0.4', '0.5', '0.6'], + status: 'Locked', + lockingUser: 'another' + }); + + Configuration.set('ATTUserID', currentUser); + const result = VersionControllerUtils.isCheckedOutByCurrentUser(resource); + Configuration.set('ATTUserID', undefined); + + expect(result).toBe(false); + }); + + + + it('validating isReadOnly - when resource is not checked out', () => { + const currentUser = 'current'; + const resource = deepFreeze({ + version: '0.6', + viewableVersions: ['0.1', '0.2', '0.3', '0.4', '0.5', '0.6'], + status: 'Final' + }); + + Configuration.set('ATTUserID', currentUser); + const result = VersionControllerUtils.isReadOnly(resource); + Configuration.set('ATTUserID', undefined); + + expect(result).toBe(true); + }); + + it('validating isReadOnly - when resource is checked out', () => { + const currentUser = 'current'; + const resource = deepFreeze({ + version: '0.6', + viewableVersions: ['0.1', '0.2', '0.3', '0.4', '0.5', '0.6'], + status: 'Locked', + lockingUser: 'current' + }); + + Configuration.set('ATTUserID', currentUser); + const result = VersionControllerUtils.isReadOnly(resource); + Configuration.set('ATTUserID', undefined); + + expect(result).toBe(false); + }); + + it('validating isReadOnly - when version of resource is not latest', () => { + const currentUser = 'current'; + const resource = deepFreeze({ + version: '0.2', + viewableVersions: ['0.1', '0.2', '0.3', '0.4', '0.5', '0.6'], + status: 'Locked', + lockingUser: 'current' + }); + + Configuration.set('ATTUserID', currentUser); + const result = VersionControllerUtils.isReadOnly(resource); + Configuration.set('ATTUserID', undefined); + + expect(result).toBe(true); + }); + + it('validating isReadOnly - when resource is checked out by another user', () => { + const currentUser = 'current'; + const resource = deepFreeze({ + version: '0.6', + viewableVersions: ['0.1', '0.2', '0.3', '0.4', '0.5', '0.6'], + status: 'Locked', + lockingUser: 'another' + }); + + Configuration.set('ATTUserID', currentUser); + const result = VersionControllerUtils.isReadOnly(resource); + Configuration.set('ATTUserID', undefined); + + expect(result).toBe(true); + }); +}); + |