diff options
author | Michael Lando <ml636r@att.com> | 2018-05-21 20:19:48 +0000 |
---|---|---|
committer | Gerrit Code Review <gerrit@onap.org> | 2018-05-21 20:19:48 +0000 |
commit | 05b37297177e8a342668c15e5d6f738b51f7aedd (patch) | |
tree | e236c96df52a13f935292db8aa73e84d0c41ad8a /test/react/Checkbox.spec.js | |
parent | 884dfb789593d2a3cc319047ab1f0215778aec9f (diff) | |
parent | 1994c98063c27a41797dec01f2ca9fcbe33ceab0 (diff) |
Merge "init commit onap ui"2.0.0-ONAPbeijing2.0.0-ONAP
Diffstat (limited to 'test/react/Checkbox.spec.js')
-rw-r--r-- | test/react/Checkbox.spec.js | 60 |
1 files changed, 60 insertions, 0 deletions
diff --git a/test/react/Checkbox.spec.js b/test/react/Checkbox.spec.js new file mode 100644 index 0000000..88ba660 --- /dev/null +++ b/test/react/Checkbox.spec.js @@ -0,0 +1,60 @@ +import React from 'react'; +import Checkbox from '../../src/react/Checkbox.js'; + +import renderer from 'react-test-renderer'; +import {mount} from 'enzyme'; + +class CheckboxForm extends React.Component { + constructor(props) { + super(props); + this.state = {checked: false}; + + this.handleChange = this.handleChange.bind(this); + } + + handleChange(val) { + this.setState({checked: val}); + } + + getChecked() { + return this.checkbox.getChecked(); + } + + render() { + return ( + <form > + <Checkbox ref={(checkbox)=>{this.checkbox = checkbox;}} checked={this.state.checked} onChange={this.handleChange} label='This is the checkbox label' /> + </form> + ); + } +} + +describe('Checkbox', () => { + test('Checkbox - unchecked', () => { + const checkbox = renderer.create(<Checkbox label='This is the checkbox label'/>).toJSON(); + expect(checkbox).toMatchSnapshot(); + }); + + test('Checkbox - disabled', () => { + const checkbox = renderer.create(<Checkbox disabled={true} label='This is the checkbox label' />).toJSON(); + expect(checkbox).toMatchSnapshot(); + }); + + test('Checkbox - checked state changes', () => { + const checkbox = mount(<CheckboxForm />); + expect(checkbox.instance().getChecked()).toEqual(false); + expect(checkbox.instance().getChecked()).toEqual(checkbox.find('input').props().checked); + checkbox.find('input').simulate('change', { target : { checked: true }}); + expect(checkbox.instance().getChecked()).toEqual(checkbox.find('input').props().checked); + expect(checkbox.instance().getChecked()).toEqual(true); + checkbox.find('input').simulate('change', { target : { checked: false }}); + expect(checkbox.instance().getChecked()).toEqual(false); + expect(checkbox.instance().getChecked()).toEqual(checkbox.find('input').props().checked); + }); + + test('Checkbox - returns its value', () => { + const checkbox = mount(<Checkbox label='This is the checkbox label' value='myVal' />); + expect(checkbox.instance().getValue()).toEqual('myVal'); + }); + +}); |