/* * Copyright © 2016-2018 European Support Limited * * 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 React from 'react'; import TestUtils from 'react-dom/test-utils'; import {scryRenderedDOMComponentsWithTestId} from 'test-utils/Util.js'; import Input from 'nfvo-components/input/validation/Input.jsx'; import Overlay from 'react-bootstrap/lib/Overlay.js'; import {shallow} from 'enzyme'; describe('Input', function () { it('should render with type text', () => { let renderedOutput = TestUtils.renderIntoDocument(); const elem = scryRenderedDOMComponentsWithTestId(renderedOutput,'mytest'); expect(elem).toBeTruthy(); expect(elem.length).toBe(1); expect(elem[0].type).toBe('text'); }); it('should render with type textarea', () => { let renderedOutput = TestUtils.renderIntoDocument(); const elem = scryRenderedDOMComponentsWithTestId(renderedOutput,'mytest'); expect(elem).toBeTruthy(); expect(elem.length).toBe(1); expect(elem[0].tagName.toLowerCase()).toBe('textarea'); }); it('should render with type radio', () => { let renderedOutput = TestUtils.renderIntoDocument(); const elem = scryRenderedDOMComponentsWithTestId(renderedOutput,'mytest'); expect(elem).toBeTruthy(); expect(elem.length).toBe(1); expect(elem[0].type).toBe('radio'); }); it('should render with type select', () => { let renderedOutput = TestUtils.renderIntoDocument(); const elem = scryRenderedDOMComponentsWithTestId(renderedOutput,'mytest'); expect(elem).toBeTruthy(); expect(elem.length).toBe(1); expect(elem[0].tagName.toLowerCase()).toBe('select'); }); it('should render with type number', () => { let renderedOutput = TestUtils.renderIntoDocument(); const elem = scryRenderedDOMComponentsWithTestId(renderedOutput,'mytest'); expect(elem).toBeTruthy(); expect(elem.length).toBe(1); expect(elem[0].tagName.toLowerCase()).toBe('input'); expect(elem[0].type).toBe('number'); }); it('should render with type checkbox', () => { let renderedOutput = TestUtils.renderIntoDocument(); const elem = scryRenderedDOMComponentsWithTestId(renderedOutput,'mytest'); expect(elem).toBeTruthy(); expect(elem.length).toBe(1); expect(elem[0].tagName.toLowerCase()).toBe('input'); expect(elem[0].type).toBe('checkbox'); }); it('should render error overlay when invalid', () => { const elem = shallow(); expect(elem).toBeTruthy(); const overlay = elem.find(Overlay); expect(overlay).toBeTruthy(); expect(overlay.props().show).toBe(true); }); it('should not render error overlay when valid', () => { let renderedOutput = TestUtils.renderIntoDocument(); const elem = TestUtils.findRenderedComponentWithType(renderedOutput,Overlay); expect(elem).toBeTruthy(); expect(elem.props.show).toBe(false); }); /*it('should return the value of a select', () => { }); it('should return the value of a checkbox', () => { }); it('should return the value of a radio', () => { }); it('should return the value of a text', () => { }); it('should return the value of a textarea', () => { });*/ /*it('should render and work as a group', () => { let MockComp = React.createClass({ render: function() { return (