svishnev | 1eb66b7 | 2018-01-11 14:39:45 +0200 | [diff] [blame] | 1 | /* |
| 2 | * Copyright © 2016-2017 European Support Limited |
AviZi | 280f801 | 2017-06-09 02:39:56 +0300 | [diff] [blame] | 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 |
svishnev | 1eb66b7 | 2018-01-11 14:39:45 +0200 | [diff] [blame] | 7 | * |
| 8 | * http://www.apache.org/licenses/LICENSE-2.0 |
| 9 | * |
AviZi | 280f801 | 2017-06-09 02:39:56 +0300 | [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, |
svishnev | 1eb66b7 | 2018-01-11 14:39:45 +0200 | [diff] [blame] | 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. |
AviZi | 280f801 | 2017-06-09 02:39:56 +0300 | [diff] [blame] | 15 | */ |
| 16 | |
| 17 | import React from 'react'; |
svishnev | aa2eece | 2018-01-18 17:52:06 +0200 | [diff] [blame] | 18 | import TestUtils from 'react-addons-test-utils'; |
AviZi | 280f801 | 2017-06-09 02:39:56 +0300 | [diff] [blame] | 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'; |
svishnev | 1eb66b7 | 2018-01-11 14:39:45 +0200 | [diff] [blame] | 22 | import {shallow} from 'enzyme'; |
AviZi | 280f801 | 2017-06-09 02:39:56 +0300 | [diff] [blame] | 23 | |
| 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'); |
| 31 | }); |
| 32 | |
| 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'); |
| 39 | }); |
| 40 | |
| 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'); |
| 47 | }); |
| 48 | |
| 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'); |
| 55 | }); |
| 56 | |
| 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'); |
| 64 | }); |
| 65 | |
| 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'); |
| 73 | }); |
| 74 | |
| 75 | it('should render error overlay when invalid', () => { |
svishnev | 1eb66b7 | 2018-01-11 14:39:45 +0200 | [diff] [blame] | 76 | const elem = shallow(<Input type='text' data-test-id='mytest' isValid={false} errorText='this is an error'/>); |
AviZi | 280f801 | 2017-06-09 02:39:56 +0300 | [diff] [blame] | 77 | expect(elem).toBeTruthy(); |
svishnev | 1eb66b7 | 2018-01-11 14:39:45 +0200 | [diff] [blame] | 78 | const overlay = elem.find(Overlay); |
| 79 | expect(overlay).toBeTruthy(); |
| 80 | expect(overlay.props().show).toBe(true); |
AviZi | 280f801 | 2017-06-09 02:39:56 +0300 | [diff] [blame] | 81 | }); |
| 82 | |
| 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); |
| 88 | }); |
| 89 | |
| 90 | /*it('should return the value of a select', () => { |
| 91 | |
| 92 | }); |
| 93 | |
| 94 | it('should return the value of a checkbox', () => { |
| 95 | |
| 96 | }); |
| 97 | |
| 98 | it('should return the value of a radio', () => { |
| 99 | |
| 100 | }); |
| 101 | |
| 102 | it('should return the value of a text', () => { |
| 103 | |
| 104 | }); |
| 105 | |
| 106 | it('should return the value of a textarea', () => { |
| 107 | |
| 108 | });*/ |
| 109 | |
| 110 | /*it('should render and work as a group', () => { |
| 111 | let MockComp = React.createClass({ |
| 112 | render: function() { |
| 113 | return (<div> |
| 114 | <Input type='radio' data-test-id='mytest' name='g1' value='0'/><Input type='radio' data-test-id='mytest1' name='g1' value='1' /> |
| 115 | </div>); |
| 116 | } |
| 117 | }); |
| 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( |
| 130 | radio2[0] |
| 131 | ); |
| 132 | TestUtils.Simulate.click( |
| 133 | radio1[0] |
| 134 | ); |
| 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); |
| 139 | |
| 140 | |
| 141 | });*/ |
| 142 | |
| 143 | }); |