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