svishnev | a3e9c9e | 2018-01-15 15:55:53 +0200 | [diff] [blame] | 1 | /*! |
svishnev | 1eb66b7 | 2018-01-11 14:39:45 +0200 | [diff] [blame] | 2 | * Copyright © 2016-2017 European Support Limited |
AviZi | 280f801 | 2017-06-09 02:39:56 +0300 | [diff] [blame] | 3 | * |
Michael Lando | efa037d | 2017-02-19 12:57:33 +0200 | [diff] [blame] | 4 | * 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 |
svishnev | a3e9c9e | 2018-01-15 15:55:53 +0200 | [diff] [blame] | 7 | * |
| 8 | * http://www.apache.org/licenses/LICENSE-2.0 |
| 9 | * |
Michael Lando | efa037d | 2017-02-19 12:57:33 +0200 | [diff] [blame] | 10 | * Unless required by applicable law or agreed to in writing, software |
| 11 | * distributed under the License is distributed on an "AS IS" BASIS, |
svishnev | a3e9c9e | 2018-01-15 15:55:53 +0200 | [diff] [blame] | 12 | * 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 Lando | efa037d | 2017-02-19 12:57:33 +0200 | [diff] [blame] | 15 | */ |
| 16 | |
AviZi | 280f801 | 2017-06-09 02:39:56 +0300 | [diff] [blame] | 17 | |
Michael Lando | efa037d | 2017-02-19 12:57:33 +0200 | [diff] [blame] | 18 | import React from 'react'; |
svishnev | aa2eece | 2018-01-18 17:52:06 +0200 | [diff] [blame] | 19 | |
| 20 | import TestUtils from 'react-addons-test-utils'; |
Michael Lando | efa037d | 2017-02-19 12:57:33 +0200 | [diff] [blame] | 21 | import VersionController from 'nfvo-components/panel/versionController/VersionController.jsx'; |
talig | 8e9c065 | 2017-12-20 14:30:43 +0200 | [diff] [blame] | 22 | import {actionsEnum} from 'nfvo-components/panel/versionController/VersionControllerConstants.js'; |
AviZi | 280f801 | 2017-06-09 02:39:56 +0300 | [diff] [blame] | 23 | import {scryRenderedDOMComponentsWithTestId} from 'test-utils/Util.js'; |
| 24 | import {VSPComponentsVersionControllerFactory} from 'test-utils/factories/softwareProduct/SoftwareProductComponentsNetworkFactories.js'; |
talig | 8e9c065 | 2017-12-20 14:30:43 +0200 | [diff] [blame] | 25 | import { Provider } from 'react-redux'; |
| 26 | import {storeCreator} from 'sdc-app/AppStore.js'; |
Michael Lando | efa037d | 2017-02-19 12:57:33 +0200 | [diff] [blame] | 27 | |
| 28 | describe('versionController UI Component', () => { |
AviZi | 280f801 | 2017-06-09 02:39:56 +0300 | [diff] [blame] | 29 | 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; |
talig | 8e9c065 | 2017-12-20 14:30:43 +0200 | [diff] [blame] | 34 | const itemPermission = {isCertified: false, isCollaborator: true, isDirty: false}; |
| 35 | const props = {onSave, onClose, isFormDataValid, viewableVersions, version, onVersionSwitching, itemPermission}; |
| 36 | const store = storeCreator(); |
Michael Lando | efa037d | 2017-02-19 12:57:33 +0200 | [diff] [blame] | 37 | |
| 38 | it('function does exist', () => { |
svishnev | aa2eece | 2018-01-18 17:52:06 +0200 | [diff] [blame] | 39 | var renderer = TestUtils.createRenderer(); |
talig | 8e9c065 | 2017-12-20 14:30:43 +0200 | [diff] [blame] | 40 | |
| 41 | renderer.render(<Provider store={store}><VersionController {...props} /></Provider>); |
Michael Lando | efa037d | 2017-02-19 12:57:33 +0200 | [diff] [blame] | 42 | var renderedOutput = renderer.getRenderOutput(); |
AviZi | 280f801 | 2017-06-09 02:39:56 +0300 | [diff] [blame] | 43 | expect(renderedOutput).toBeTruthy(); |
Michael Lando | efa037d | 2017-02-19 12:57:33 +0200 | [diff] [blame] | 44 | }); |
| 45 | |
AviZi | 280f801 | 2017-06-09 02:39:56 +0300 | [diff] [blame] | 46 | it('validating submit function', () => { |
talig | 8e9c065 | 2017-12-20 14:30:43 +0200 | [diff] [blame] | 47 | let provider = TestUtils.renderIntoDocument(<Provider store={store}> |
| 48 | <VersionController {...props} /></Provider>); |
| 49 | let versionController = TestUtils.findRenderedComponentWithType( |
| 50 | provider, |
| 51 | VersionController |
| 52 | ); |
AviZi | 280f801 | 2017-06-09 02:39:56 +0300 | [diff] [blame] | 53 | let cb = action => expect(action).toBe(actionsEnum.SUBMIT); |
| 54 | versionController.submit(cb); |
| 55 | }); |
| 56 | |
| 57 | it('validating revert function', () => { |
talig | 8e9c065 | 2017-12-20 14:30:43 +0200 | [diff] [blame] | 58 | 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); |
AviZi | 280f801 | 2017-06-09 02:39:56 +0300 | [diff] [blame] | 65 | }); |
| 66 | |
| 67 | it('does not show the save button when no onSave available', () => { |
| 68 | let noSaveProps = {...props, onSave: null }; |
talig | 8e9c065 | 2017-12-20 14:30:43 +0200 | [diff] [blame] | 69 | let versionController = TestUtils.renderIntoDocument(<Provider store={store}><VersionController {...noSaveProps} /></Provider>); |
AviZi | 280f801 | 2017-06-09 02:39:56 +0300 | [diff] [blame] | 70 | 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}; |
talig | 8e9c065 | 2017-12-20 14:30:43 +0200 | [diff] [blame] | 77 | let versionController = TestUtils.renderIntoDocument(<Provider store={store}><VersionController {...callVCActionProps} /></Provider>); |
AviZi | 280f801 | 2017-06-09 02:39:56 +0300 | [diff] [blame] | 78 | 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}; |
talig | 8e9c065 | 2017-12-20 14:30:43 +0200 | [diff] [blame] | 85 | let versionController = TestUtils.renderIntoDocument(<Provider store={store}><VersionController {...callVCActionProps} /></Provider>); |
AviZi | 280f801 | 2017-06-09 02:39:56 +0300 | [diff] [blame] | 86 | 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', () => { |
talig | 8e9c065 | 2017-12-20 14:30:43 +0200 | [diff] [blame] | 92 | let versionController = TestUtils.renderIntoDocument(<Provider store={store}><VersionController {...props} /></Provider>); |
AviZi | 280f801 | 2017-06-09 02:39:56 +0300 | [diff] [blame] | 93 | let elem = scryRenderedDOMComponentsWithTestId(versionController,'vc-save-btn'); |
| 94 | expect(elem).toBeTruthy(); |
| 95 | expect(elem.length).toBe(1); |
| 96 | }); |
| 97 | |
talig | 8e9c065 | 2017-12-20 14:30:43 +0200 | [diff] [blame] | 98 | 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>); |
AviZi | 280f801 | 2017-06-09 02:39:56 +0300 | [diff] [blame] | 103 | let elem = scryRenderedDOMComponentsWithTestId(versionController,'vc-submit-btn'); |
| 104 | expect(elem).toBeTruthy(); |
| 105 | expect(elem.length).toBe(1); |
| 106 | }); |
| 107 | |
svishnev | a3e9c9e | 2018-01-15 15:55:53 +0200 | [diff] [blame] | 108 | it('Shows the submit button when callVCAction available and user is contributor', () => { |
| 109 | const permissions = {owner: {userId: '111'}, contributors: ['232']}, |
| 110 | userInfo = {userId: '232'}; |
talig | 8e9c065 | 2017-12-20 14:30:43 +0200 | [diff] [blame] | 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(); |
svishnev | a3e9c9e | 2018-01-15 15:55:53 +0200 | [diff] [blame] | 115 | 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(); |
talig | 8e9c065 | 2017-12-20 14:30:43 +0200 | [diff] [blame] | 127 | expect(elem.length).toBe(0); |
| 128 | }); |
| 129 | |
AviZi | 280f801 | 2017-06-09 02:39:56 +0300 | [diff] [blame] | 130 | it('Shows the revert button when callVCAction available', () => { |
| 131 | let callVCActionProps = { ...props, callVCAction: function(){} }; |
talig | 8e9c065 | 2017-12-20 14:30:43 +0200 | [diff] [blame] | 132 | let versionController = TestUtils.renderIntoDocument(<Provider store={store}><VersionController {...callVCActionProps} /></Provider>); |
AviZi | 280f801 | 2017-06-09 02:39:56 +0300 | [diff] [blame] | 133 | let elem = scryRenderedDOMComponentsWithTestId(versionController,'vc-revert-btn'); |
| 134 | expect(elem).toBeTruthy(); |
| 135 | expect(elem.length).toBe(1); |
| 136 | }); |
| 137 | |
Michael Lando | efa037d | 2017-02-19 12:57:33 +0200 | [diff] [blame] | 138 | }); |