2 * Copyright © 2016-2017 European Support Limited
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
8 * http://www.apache.org/licenses/LICENSE-2.0
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
17 import React from 'react';
18 import TestUtils from 'react-dom/test-utils';
19 import {scryRenderedDOMComponentsWithTestId} from 'test-utils/Util.js';
20 import Input from 'nfvo-components/input/validation/Input.jsx';
21 import Overlay from 'react-bootstrap/lib/Overlay.js';
22 import {shallow} from 'enzyme';
24 describe('Input', function () {
25 it('should render with type text', () => {
26 let renderedOutput = TestUtils.renderIntoDocument(<Input type='text' data-test-id='mytest' />);
27 const elem = scryRenderedDOMComponentsWithTestId(renderedOutput,'mytest');
28 expect(elem).toBeTruthy();
29 expect(elem.length).toBe(1);
30 expect(elem[0].type).toBe('text');
33 it('should render with type textarea', () => {
34 let renderedOutput = TestUtils.renderIntoDocument(<Input type='textarea' data-test-id='mytest' />);
35 const elem = scryRenderedDOMComponentsWithTestId(renderedOutput,'mytest');
36 expect(elem).toBeTruthy();
37 expect(elem.length).toBe(1);
38 expect(elem[0].tagName.toLowerCase()).toBe('textarea');
41 it('should render with type radio', () => {
42 let renderedOutput = TestUtils.renderIntoDocument(<Input type='radio' data-test-id='mytest' />);
43 const elem = scryRenderedDOMComponentsWithTestId(renderedOutput,'mytest');
44 expect(elem).toBeTruthy();
45 expect(elem.length).toBe(1);
46 expect(elem[0].type).toBe('radio');
49 it('should render with type select', () => {
50 let renderedOutput = TestUtils.renderIntoDocument(<Input type='select' data-test-id='mytest' />);
51 const elem = scryRenderedDOMComponentsWithTestId(renderedOutput,'mytest');
52 expect(elem).toBeTruthy();
53 expect(elem.length).toBe(1);
54 expect(elem[0].tagName.toLowerCase()).toBe('select');
57 it('should render with type number', () => {
58 let renderedOutput = TestUtils.renderIntoDocument(<Input type='number' data-test-id='mytest' />);
59 const elem = scryRenderedDOMComponentsWithTestId(renderedOutput,'mytest');
60 expect(elem).toBeTruthy();
61 expect(elem.length).toBe(1);
62 expect(elem[0].tagName.toLowerCase()).toBe('input');
63 expect(elem[0].type).toBe('number');
66 it('should render with type checkbox', () => {
67 let renderedOutput = TestUtils.renderIntoDocument(<Input type='checkbox' data-test-id='mytest' />);
68 const elem = scryRenderedDOMComponentsWithTestId(renderedOutput,'mytest');
69 expect(elem).toBeTruthy();
70 expect(elem.length).toBe(1);
71 expect(elem[0].tagName.toLowerCase()).toBe('input');
72 expect(elem[0].type).toBe('checkbox');
75 it('should render error overlay when invalid', () => {
76 const elem = shallow(<Input type='text' data-test-id='mytest' isValid={false} errorText='this is an error'/>);
77 expect(elem).toBeTruthy();
78 const overlay = elem.find(Overlay);
79 expect(overlay).toBeTruthy();
80 expect(overlay.props().show).toBe(true);
83 it('should not render error overlay when valid', () => {
84 let renderedOutput = TestUtils.renderIntoDocument(<Input type='text' data-test-id='mytest' isValid={true} errorText='this is an error'/>);
85 const elem = TestUtils.findRenderedComponentWithType(renderedOutput,Overlay);
86 expect(elem).toBeTruthy();
87 expect(elem.props.show).toBe(false);
90 /*it('should return the value of a select', () => {
94 it('should return the value of a checkbox', () => {
98 it('should return the value of a radio', () => {
102 it('should return the value of a text', () => {
106 it('should return the value of a textarea', () => {
110 /*it('should render and work as a group', () => {
111 let MockComp = React.createClass({
114 <Input type='radio' data-test-id='mytest' name='g1' value='0'/><Input type='radio' data-test-id='mytest1' name='g1' value='1' />
118 let renderedOutput = TestUtils.renderIntoDocument(<MockComp />);
119 const radio1 = scryRenderedDOMComponentsWithTestId(renderedOutput,'mytest');
120 expect(radio1).toBeTruthy();
121 expect(radio1.length).toBe(1);
122 expect(radio1[0].type).toBe('radio');
123 expect(radio1[0].value).toBe('0');
124 const radio2 = scryRenderedDOMComponentsWithTestId(renderedOutput,'mytest1');
125 expect(radio2).toBeTruthy();
126 expect(radio2.length).toBe(1);
127 expect(radio2[0].type).toBe('radio');
128 expect(radio2[0].value).toBe('1');
129 TestUtils.Simulate.click(
132 TestUtils.Simulate.click(
135 console.log('radio1: ' + radio1[0].checked);
136 console.log('radio2: ' + radio2[0].checked);
137 expect(radio2[0].checked).toBe(false);
138 expect(radio1[0].checked).toBe(true);