|
| 1 | +import jsdom from 'mocha-jsdom'; |
| 2 | +import sinon from 'sinon'; |
| 3 | +import { mount, shallow } from 'enzyme'; |
| 4 | +import { expect } from 'chai'; |
| 5 | +import React from 'react'; |
| 6 | + |
| 7 | +import RadioButton from '../../source/react/library/radiobutton/RadioButton'; |
| 8 | + |
| 9 | +describe('<RadioButton />', () => { |
| 10 | + jsdom({ skipWindowCheck: true }); |
| 11 | + |
| 12 | + const requiredProps = { |
| 13 | + name: 'test-name', |
| 14 | + label: 'test-label', |
| 15 | + }; |
| 16 | + |
| 17 | + it('propagates the provided className to the top level element', () => { |
| 18 | + expect( |
| 19 | + shallow(<RadioButton {...requiredProps} className="test-class" />), |
| 20 | + ).to.have.className('test-class'); |
| 21 | + }); |
| 22 | + |
| 23 | + it('propagates provided inline style to the top level element', () => { |
| 24 | + expect( |
| 25 | + shallow(<RadioButton {...requiredProps} style={{ marginTop: 10 }} />), |
| 26 | + ).to.have.style('margin-top', '10px'); |
| 27 | + }); |
| 28 | + |
| 29 | + it('should have an accessible ref method to the inner input element', async () => { |
| 30 | + const radiobutton = await new Promise(resolve => { |
| 31 | + mount(<RadioButton {...requiredProps} inputRef={resolve} />); |
| 32 | + }); |
| 33 | + |
| 34 | + expect(radiobutton.nodeName).to.equal('INPUT'); |
| 35 | + }); |
| 36 | + |
| 37 | + it('should respond to change if onChange is provided', () => { |
| 38 | + const onChange = sinon.spy(); |
| 39 | + const wrapper = mount( |
| 40 | + <RadioButton {...requiredProps} onChange={onChange} />, |
| 41 | + ); |
| 42 | + |
| 43 | + wrapper.find('input').simulate('change'); |
| 44 | + |
| 45 | + expect(onChange.called).to.equal(true); |
| 46 | + }); |
| 47 | + |
| 48 | + it('should respond to focus if onFocus is provided', () => { |
| 49 | + const onFocus = sinon.spy(); |
| 50 | + const wrapper = mount(<RadioButton {...requiredProps} onFocus={onFocus} />); |
| 51 | + |
| 52 | + wrapper.find('input').simulate('focus'); |
| 53 | + |
| 54 | + expect(onFocus.called).to.equal(true); |
| 55 | + }); |
| 56 | + |
| 57 | + it('should have className corresponding to a present error if provided', () => { |
| 58 | + expect( |
| 59 | + shallow(<RadioButton {...requiredProps} error />).find('input'), |
| 60 | + ).to.have.className('rc-radiobutton-error'); |
| 61 | + }); |
| 62 | + |
| 63 | + it('should have an attribute corresponding to being disabled', () => { |
| 64 | + expect(shallow(<RadioButton {...requiredProps} disabled />).find('input')) |
| 65 | + .to.have.prop('disabled') |
| 66 | + .to.equal(true); |
| 67 | + }); |
| 68 | +}); |
0 commit comments