-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathDropdownToggleSpec.js
145 lines (122 loc) · 3.93 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
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
import React from 'react';
import ReactTestUtils from 'react-dom/test-utils';
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.textContent.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.textContent.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/);
});
it('does not forward bsClass', () => {
const instance = ReactTestUtils.renderIntoDocument(
<DropdownToggle
bsClass="my-custom-bsClass"
open={false}
title="bsClass"
/>
);
const button = ReactTestUtils.findRenderedDOMComponentWithTag(
instance,
'BUTTON'
);
button.className.should.match(/\bmy-custom-bsClass\b/);
button.className.should.match(/\bbtn\b/);
});
});