AviZi | 280f801 | 2017-06-09 02:39:56 +0300 | [diff] [blame^] | 1 | /*! |
Michael Lando | efa037d | 2017-02-19 12:57:33 +0200 | [diff] [blame] | 2 | * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved. |
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 |
AviZi | 280f801 | 2017-06-09 02:39:56 +0300 | [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, |
AviZi | 280f801 | 2017-06-09 02:39:56 +0300 | [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'; |
AviZi | 280f801 | 2017-06-09 02:39:56 +0300 | [diff] [blame^] | 19 | |
Michael Lando | efa037d | 2017-02-19 12:57:33 +0200 | [diff] [blame] | 20 | import TestUtils from 'react-addons-test-utils'; |
AviZi | 280f801 | 2017-06-09 02:39:56 +0300 | [diff] [blame^] | 21 | import {mount} from 'enzyme'; |
Michael Lando | efa037d | 2017-02-19 12:57:33 +0200 | [diff] [blame] | 22 | import VersionController from 'nfvo-components/panel/versionController/VersionController.jsx'; |
AviZi | 280f801 | 2017-06-09 02:39:56 +0300 | [diff] [blame^] | 23 | import {actionsEnum, statusEnum} from 'nfvo-components/panel/versionController/VersionControllerConstants.js'; |
| 24 | import {scryRenderedDOMComponentsWithTestId} from 'test-utils/Util.js'; |
| 25 | import {VSPComponentsVersionControllerFactory} from 'test-utils/factories/softwareProduct/SoftwareProductComponentsNetworkFactories.js'; |
Michael Lando | efa037d | 2017-02-19 12:57:33 +0200 | [diff] [blame] | 26 | |
| 27 | describe('versionController UI Component', () => { |
AviZi | 280f801 | 2017-06-09 02:39:56 +0300 | [diff] [blame^] | 28 | 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 Lando | efa037d | 2017-02-19 12:57:33 +0200 | [diff] [blame] | 34 | |
| 35 | it('function does exist', () => { |
| 36 | var renderer = TestUtils.createRenderer(); |
AviZi | 280f801 | 2017-06-09 02:39:56 +0300 | [diff] [blame^] | 37 | renderer.render(<VersionController isCheckedOut={false} status={statusEnum.CHECK_OUT_STATUS} {...props} />); |
Michael Lando | efa037d | 2017-02-19 12:57:33 +0200 | [diff] [blame] | 38 | var renderedOutput = renderer.getRenderOutput(); |
AviZi | 280f801 | 2017-06-09 02:39:56 +0300 | [diff] [blame^] | 39 | expect(renderedOutput).toBeTruthy(); |
Michael Lando | efa037d | 2017-02-19 12:57:33 +0200 | [diff] [blame] | 40 | }); |
| 41 | |
| 42 | it('validating checkin function', () => { |
AviZi | 280f801 | 2017-06-09 02:39:56 +0300 | [diff] [blame^] | 43 | let versionController = TestUtils.renderIntoDocument(<VersionController isCheckedOut={true} status={statusEnum.CHECK_OUT_STATUS} {...props} />); |
Michael Lando | efa037d | 2017-02-19 12:57:33 +0200 | [diff] [blame] | 44 | let cb = action => expect(action).toBe(actionsEnum.CHECK_IN); |
| 45 | versionController.checkin(cb); |
AviZi | 280f801 | 2017-06-09 02:39:56 +0300 | [diff] [blame^] | 46 | }); |
| 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 Lando | efa037d | 2017-02-19 12:57:33 +0200 | [diff] [blame] | 150 | |
| 151 | }); |
| 152 | |
| 153 | }); |