|
| 1 | +import React from 'react'; |
| 2 | +import ReactTestUtils from 'react/lib/ReactTestUtils'; |
| 3 | +import ResponsiveEmbed from '../src/ResponsiveEmbed'; |
| 4 | +import { shouldWarn } from './helpers'; |
| 5 | + |
| 6 | +describe('ResponsiveEmbed', () => { |
| 7 | + it('should contain `embed-responsive` class', () => { |
| 8 | + let instance = ReactTestUtils.renderIntoDocument( |
| 9 | + <ResponsiveEmbed a16by9> |
| 10 | + <div /> |
| 11 | + </ResponsiveEmbed> |
| 12 | + ); |
| 13 | + |
| 14 | + let instanceClassName = React.findDOMNode(instance).className; |
| 15 | + assert.ok(instanceClassName, 'embed-responsive'); |
| 16 | + }); |
| 17 | + |
| 18 | + it('should warn if neither `a16by9` nor `a4by3` attribute is set', () => { |
| 19 | + ReactTestUtils.renderIntoDocument( |
| 20 | + <ResponsiveEmbed> |
| 21 | + <div /> |
| 22 | + </ResponsiveEmbed> |
| 23 | + ); |
| 24 | + |
| 25 | + shouldWarn('`a16by9` or `a4by3` attribute must be set.'); |
| 26 | + }); |
| 27 | + |
| 28 | + it('should warn about both `a16by9` or `a4by3` attributes set', () => { |
| 29 | + ReactTestUtils.renderIntoDocument( |
| 30 | + <ResponsiveEmbed a16by9 a4by3> |
| 31 | + <div /> |
| 32 | + </ResponsiveEmbed> |
| 33 | + ); |
| 34 | + |
| 35 | + shouldWarn('Either `a16by9` or `a4by3` attribute can be set. Not both.'); |
| 36 | + }); |
| 37 | + |
| 38 | + it('should add `embed-responsive-item` class to child element', () => { |
| 39 | + const instance = ReactTestUtils.renderIntoDocument( |
| 40 | + <ResponsiveEmbed a16by9> |
| 41 | + <div /> |
| 42 | + </ResponsiveEmbed> |
| 43 | + ); |
| 44 | + |
| 45 | + let child = React.findDOMNode(instance).firstChild; |
| 46 | + assert.ok(child.className.match(/\bembed-responsive-item\b/)); |
| 47 | + }); |
| 48 | + |
| 49 | + it('should add custom classes to child element', () => { |
| 50 | + const instance = ReactTestUtils.renderIntoDocument( |
| 51 | + <ResponsiveEmbed a16by9 className='custom-class'> |
| 52 | + <div /> |
| 53 | + </ResponsiveEmbed> |
| 54 | + ); |
| 55 | + |
| 56 | + let child = React.findDOMNode(instance).firstChild; |
| 57 | + assert.ok(child.className.match(/\bcustom-class\b/)); |
| 58 | + }); |
| 59 | + |
| 60 | + it('should pass custom attributes to child element', () => { |
| 61 | + const instance = ReactTestUtils.renderIntoDocument( |
| 62 | + <ResponsiveEmbed a16by9 style={{color: 'white'}}> |
| 63 | + <div /> |
| 64 | + </ResponsiveEmbed> |
| 65 | + ); |
| 66 | + |
| 67 | + let child = React.findDOMNode(instance).firstChild; |
| 68 | + assert.equal(child.style.color, 'white'); |
| 69 | + }); |
| 70 | + |
| 71 | + it('should add `embed-responsive-16by9` class with `a16by9` attribute set', () => { |
| 72 | + const instance = ReactTestUtils.renderIntoDocument( |
| 73 | + <ResponsiveEmbed a16by9> |
| 74 | + <div /> |
| 75 | + </ResponsiveEmbed> |
| 76 | + ); |
| 77 | + |
| 78 | + let wrapper = React.findDOMNode(instance); |
| 79 | + assert.ok(wrapper.className.match(/\bembed-responsive-16by9\b/)); |
| 80 | + }); |
| 81 | + |
| 82 | + it('should add `embed-responsive-4by3` class with `a4by3` attribute set', () => { |
| 83 | + const instance = ReactTestUtils.renderIntoDocument( |
| 84 | + <ResponsiveEmbed a4by3> |
| 85 | + <div /> |
| 86 | + </ResponsiveEmbed> |
| 87 | + ); |
| 88 | + |
| 89 | + let wrapper = React.findDOMNode(instance); |
| 90 | + assert.ok(wrapper.className.match(/\bembed-responsive-4by3\b/)); |
| 91 | + }); |
| 92 | +}); |
0 commit comments