|
| 1 | +import React from 'react'; |
| 2 | +import ReactTestUtils from 'react/lib/ReactTestUtils'; |
| 3 | +import FormGroup from '../src/FormGroup'; |
| 4 | + |
| 5 | +describe('FormGroup', function() { |
| 6 | + beforeEach(function() { |
| 7 | + sinon.spy(console, 'warn'); |
| 8 | + }); |
| 9 | + |
| 10 | + afterEach(function() { |
| 11 | + if (typeof console.warn.restore === 'function') { |
| 12 | + console.warn.called.should.be.false; |
| 13 | + console.warn.restore(); |
| 14 | + } |
| 15 | + }); |
| 16 | + |
| 17 | + it('renders children', function() { |
| 18 | + let instance = ReactTestUtils.renderIntoDocument( |
| 19 | + <FormGroup> |
| 20 | + <span className='child1' /> |
| 21 | + <span className='child2' /> |
| 22 | + </FormGroup> |
| 23 | + ); |
| 24 | + |
| 25 | + assert.ok(ReactTestUtils.findRenderedDOMComponentWithClass(instance, 'child1')); |
| 26 | + assert.ok(ReactTestUtils.findRenderedDOMComponentWithClass(instance, 'child2')); |
| 27 | + }); |
| 28 | + |
| 29 | + it('renders with form-group class', function() { |
| 30 | + let instance = ReactTestUtils.renderIntoDocument( |
| 31 | + <FormGroup> |
| 32 | + <span /> |
| 33 | + </FormGroup> |
| 34 | + ); |
| 35 | + |
| 36 | + assert.ok(ReactTestUtils.findRenderedDOMComponentWithClass(instance, 'form-group')); |
| 37 | + }); |
| 38 | + |
| 39 | + it('renders no form-group class when standalone', function() { |
| 40 | + let instance = ReactTestUtils.renderIntoDocument( |
| 41 | + <FormGroup standalone> |
| 42 | + <span /> |
| 43 | + </FormGroup> |
| 44 | + ); |
| 45 | + |
| 46 | + assert.equal(ReactTestUtils.scryRenderedDOMComponentsWithClass(instance, 'form-group').length, 0); |
| 47 | + }); |
| 48 | + |
| 49 | + [{ |
| 50 | + className: 'has-feedback', |
| 51 | + props: { hasFeedback: true } |
| 52 | + }, { |
| 53 | + className: 'has-success', |
| 54 | + props: { bsStyle: 'success' } |
| 55 | + }, { |
| 56 | + className: 'has-warning', |
| 57 | + props: { bsStyle: 'warning' } |
| 58 | + }, { |
| 59 | + className: 'has-error', |
| 60 | + props: { bsStyle: 'error' } |
| 61 | + }, { |
| 62 | + className: 'custom-group', |
| 63 | + props: { groupClassName: 'custom-group' } |
| 64 | + } |
| 65 | + ].forEach(function(testCase) { |
| 66 | + it(`does not render ${testCase.className} class`, function() { |
| 67 | + let instance = ReactTestUtils.renderIntoDocument( |
| 68 | + <FormGroup> |
| 69 | + <span /> |
| 70 | + </FormGroup> |
| 71 | + ); |
| 72 | + |
| 73 | + assert.equal(ReactTestUtils.scryRenderedDOMComponentsWithClass(instance, testCase.className).length, 0); |
| 74 | + }); |
| 75 | + |
| 76 | + it(`renders with ${testCase.className} class`, function() { |
| 77 | + let instance = ReactTestUtils.renderIntoDocument( |
| 78 | + <FormGroup {...testCase.props}> |
| 79 | + <span /> |
| 80 | + </FormGroup> |
| 81 | + ); |
| 82 | + |
| 83 | + assert.ok(ReactTestUtils.findRenderedDOMComponentWithClass(instance, testCase.className)); |
| 84 | + }); |
| 85 | + }); |
| 86 | +}); |
0 commit comments