aboutsummaryrefslogtreecommitdiffstats
path: root/openecomp-ui/test/nfvo-components/input/validation/input.test.js
blob: 7743483603eaf327c85cd17b0ab6731363cdb738 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
/*!
 * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved.
 *
 * 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-addons-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';

describe('Input', function () {
	it('should render with type text', () => {
		let renderedOutput = TestUtils.renderIntoDocument(<Input type='text' data-test-id='mytest' />);
		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(<Input type='textarea' data-test-id='mytest' />);
		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(<Input type='radio' data-test-id='mytest' />);
		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(<Input type='select' data-test-id='mytest' />);
		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(<Input type='number' data-test-id='mytest' />);
		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(<Input type='checkbox' data-test-id='mytest' />);
		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', () => {
		let renderedOutput = TestUtils.renderIntoDocument(<Input type='text' data-test-id='mytest' isValid={false} errorText='this is an error'/>);
		const elem = TestUtils.findRenderedComponentWithType(renderedOutput,Overlay);
		expect(elem).toBeTruthy();
		expect(elem.props.show).toBe(true);
	});

	it('should not render error overlay when valid', () => {
		let renderedOutput = TestUtils.renderIntoDocument(<Input type='text' data-test-id='mytest' isValid={true} errorText='this is an error'/>);
		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 (<div>
	 <Input type='radio' data-test-id='mytest' name='g1' value='0'/><Input type='radio' data-test-id='mytest1' name='g1' value='1' />
	 </div>);
	 }
	 });
	 let renderedOutput = TestUtils.renderIntoDocument(<MockComp />);
	 const radio1 = scryRenderedDOMComponentsWithTestId(renderedOutput,'mytest');
	 expect(radio1).toBeTruthy();
	 expect(radio1.length).toBe(1);
	 expect(radio1[0].type).toBe('radio');
	 expect(radio1[0].value).toBe('0');
	 const radio2 = scryRenderedDOMComponentsWithTestId(renderedOutput,'mytest1');
	 expect(radio2).toBeTruthy();
	 expect(radio2.length).toBe(1);
	 expect(radio2[0].type).toBe('radio');
	 expect(radio2[0].value).toBe('1');
	 TestUtils.Simulate.click(
	 radio2[0]
	 );
	 TestUtils.Simulate.click(
	 radio1[0]
	 );
	 console.log('radio1: ' + radio1[0].checked);
	 console.log('radio2: ' + radio2[0].checked);
	 expect(radio2[0].checked).toBe(false);
	 expect(radio1[0].checked).toBe(true);


	 });*/

});