[SDC-29] Amdocs OnBoard 1707 initial commit.
[sdc.git] / openecomp-ui / test / nfvo-components / input / validation / input.test.js
1 /*!
2  * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved.
3  *
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
7  *
8  * http://www.apache.org/licenses/LICENSE-2.0
9  *
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
13  * or implied. See the License for the specific language governing
14  * permissions and limitations under the License.
15  */
16
17 import React from 'react';
18 import TestUtils from 'react-addons-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
23 describe('Input', function () {
24         it('should render with type text', () => {
25                 let renderedOutput = TestUtils.renderIntoDocument(<Input type='text' data-test-id='mytest' />);
26                 const elem = scryRenderedDOMComponentsWithTestId(renderedOutput,'mytest');
27                 expect(elem).toBeTruthy();
28                 expect(elem.length).toBe(1);
29                 expect(elem[0].type).toBe('text');
30         });
31
32         it('should render with type textarea', () => {
33                 let renderedOutput = TestUtils.renderIntoDocument(<Input type='textarea' data-test-id='mytest' />);
34                 const elem = scryRenderedDOMComponentsWithTestId(renderedOutput,'mytest');
35                 expect(elem).toBeTruthy();
36                 expect(elem.length).toBe(1);
37                 expect(elem[0].tagName.toLowerCase()).toBe('textarea');
38         });
39
40         it('should render with type radio', () => {
41                 let renderedOutput = TestUtils.renderIntoDocument(<Input type='radio' data-test-id='mytest' />);
42                 const elem = scryRenderedDOMComponentsWithTestId(renderedOutput,'mytest');
43                 expect(elem).toBeTruthy();
44                 expect(elem.length).toBe(1);
45                 expect(elem[0].type).toBe('radio');
46         });
47
48         it('should render with type select', () => {
49                 let renderedOutput = TestUtils.renderIntoDocument(<Input type='select' data-test-id='mytest' />);
50                 const elem = scryRenderedDOMComponentsWithTestId(renderedOutput,'mytest');
51                 expect(elem).toBeTruthy();
52                 expect(elem.length).toBe(1);
53                 expect(elem[0].tagName.toLowerCase()).toBe('select');
54         });
55
56         it('should render with type number', () => {
57                 let renderedOutput = TestUtils.renderIntoDocument(<Input type='number' data-test-id='mytest' />);
58                 const elem = scryRenderedDOMComponentsWithTestId(renderedOutput,'mytest');
59                 expect(elem).toBeTruthy();
60                 expect(elem.length).toBe(1);
61                 expect(elem[0].tagName.toLowerCase()).toBe('input');
62                 expect(elem[0].type).toBe('number');
63         });
64
65         it('should render with type checkbox', () => {
66                 let renderedOutput = TestUtils.renderIntoDocument(<Input type='checkbox' data-test-id='mytest' />);
67                 const elem = scryRenderedDOMComponentsWithTestId(renderedOutput,'mytest');
68                 expect(elem).toBeTruthy();
69                 expect(elem.length).toBe(1);
70                 expect(elem[0].tagName.toLowerCase()).toBe('input');
71                 expect(elem[0].type).toBe('checkbox');
72         });
73
74         it('should render error overlay when invalid', () => {
75                 let renderedOutput = TestUtils.renderIntoDocument(<Input type='text' data-test-id='mytest' isValid={false} errorText='this is an error'/>);
76                 const elem = TestUtils.findRenderedComponentWithType(renderedOutput,Overlay);
77                 expect(elem).toBeTruthy();
78                 expect(elem.props.show).toBe(true);
79         });
80
81         it('should not render error overlay when valid', () => {
82                 let renderedOutput = TestUtils.renderIntoDocument(<Input type='text' data-test-id='mytest' isValid={true} errorText='this is an error'/>);
83                 const elem = TestUtils.findRenderedComponentWithType(renderedOutput,Overlay);
84                 expect(elem).toBeTruthy();
85                 expect(elem.props.show).toBe(false);
86         });
87
88         /*it('should return the value of a select', () => {
89
90         });
91
92         it('should return the value of a checkbox', () => {
93
94         });
95
96         it('should return the value of a radio', () => {
97
98         });
99
100         it('should return the value of a text', () => {
101
102         });
103
104         it('should return the value of a textarea', () => {
105
106         });*/
107
108         /*it('should render and work as a group', () => {
109          let MockComp = React.createClass({
110          render: function() {
111          return (<div>
112          <Input type='radio' data-test-id='mytest' name='g1' value='0'/><Input type='radio' data-test-id='mytest1' name='g1' value='1' />
113          </div>);
114          }
115          });
116          let renderedOutput = TestUtils.renderIntoDocument(<MockComp />);
117          const radio1 = scryRenderedDOMComponentsWithTestId(renderedOutput,'mytest');
118          expect(radio1).toBeTruthy();
119          expect(radio1.length).toBe(1);
120          expect(radio1[0].type).toBe('radio');
121          expect(radio1[0].value).toBe('0');
122          const radio2 = scryRenderedDOMComponentsWithTestId(renderedOutput,'mytest1');
123          expect(radio2).toBeTruthy();
124          expect(radio2.length).toBe(1);
125          expect(radio2[0].type).toBe('radio');
126          expect(radio2[0].value).toBe('1');
127          TestUtils.Simulate.click(
128          radio2[0]
129          );
130          TestUtils.Simulate.click(
131          radio1[0]
132          );
133          console.log('radio1: ' + radio1[0].checked);
134          console.log('radio2: ' + radio2[0].checked);
135          expect(radio2[0].checked).toBe(false);
136          expect(radio1[0].checked).toBe(true);
137
138
139          });*/
140
141 });