forked from react-bootstrap/react-bootstrap
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathDropdownToggleSpec.js
97 lines (76 loc) · 3.31 KB
/
DropdownToggleSpec.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
96
97
import React from 'react';
import ReactTestUtils from 'react/lib/ReactTestUtils';
import DropdownToggle from '../src/DropdownToggle';
import {getOne} from './helpers';
describe('DropdownToggle', () => {
const simpleToggle = <DropdownToggle open={false} title='herpa derpa' />;
it('renders toggle button', () => {
const instance = ReactTestUtils.renderIntoDocument(simpleToggle);
const buttonNode = ReactTestUtils.findRenderedDOMComponentWithTag(instance, 'BUTTON');
buttonNode.className.should.match(/\bbtn[ $]/);
buttonNode.className.should.match(/\bbtn-default\b/);
buttonNode.className.should.match(/\bdropdown-toggle\b/);
buttonNode.getAttribute('aria-expanded').should.equal('false');
});
it('renders title prop', () => {
const instance = ReactTestUtils.renderIntoDocument(simpleToggle);
const buttonNode = ReactTestUtils.findRenderedDOMComponentWithTag(instance, 'BUTTON');
buttonNode.innerText.should.match(/herpa derpa/);
});
it('renders title children', () => {
const instance = ReactTestUtils.renderIntoDocument(
<DropdownToggle title="toggle" open={false}>
<h3>herpa derpa</h3>
</DropdownToggle>
);
const button = ReactTestUtils.findRenderedDOMComponentWithTag(instance, 'BUTTON');
const h3Node = getOne(button.getElementsByTagName('h3'));
h3Node.innerText.should.match(/herpa derpa/);
});
it('renders dropdown toggle button caret', () => {
const instance = ReactTestUtils.renderIntoDocument(simpleToggle);
const caretNode = ReactTestUtils.findRenderedDOMComponentWithClass(instance, 'caret');
caretNode.tagName.should.equal('SPAN');
});
it('does not render toggle button caret', () => {
const instance = ReactTestUtils.renderIntoDocument(
<DropdownToggle open={false} title='no caret' noCaret />
);
const caretNode = ReactTestUtils.scryRenderedDOMComponentsWithClass(instance, 'caret');
caretNode.length.should.equal(0);
});
it('forwards onClick handler', (done) => {
const handleClick = (event) => {
event.should.be.ok;
done();
};
const instance = ReactTestUtils.renderIntoDocument(
<DropdownToggle open={false} title='click forwards' onClick={handleClick} />
);
const button = ReactTestUtils.findRenderedDOMComponentWithTag(instance, 'BUTTON');
ReactTestUtils.Simulate.click(button);
});
it('forwards id', () => {
const id = 'testid';
const instance = ReactTestUtils.renderIntoDocument(
<DropdownToggle id={id} open={false} title='id forwards' />
);
const button = ReactTestUtils.findRenderedDOMComponentWithTag(instance, 'BUTTON');
button.getAttribute('id').should.equal(id);
});
it('forwards bsStyle', () => {
const style = 'success';
const instance = ReactTestUtils.renderIntoDocument(
<DropdownToggle bsStyle={style} open={false} title='bsStyle forwards' />
);
const button = ReactTestUtils.findRenderedDOMComponentWithTag(instance, 'BUTTON');
button.className.should.match(/\bbtn-success\b/);
});
it('forwards bsSize', () => {
const instance = ReactTestUtils.renderIntoDocument(
<DropdownToggle bsSize='small' open={false} title='bsSize forwards' />
);
const button = ReactTestUtils.findRenderedDOMComponentWithTag(instance, 'BUTTON');
button.className.should.match(/\bbtn-sm\b/);
});
});