-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathSplitButtonSpec.js
166 lines (138 loc) · 4.78 KB
/
SplitButtonSpec.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
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
import React from 'react';
import ReactDOM from 'react-dom';
import ReactTestUtils from 'react-dom/test-utils';
import SplitButton from '../src/SplitButton';
import MenuItem from '../src/MenuItem';
import Button from '../src/Button';
describe('<SplitButton>', () => {
const simple = (
<SplitButton title="Title" id="test-id">
<MenuItem>Item 1</MenuItem>
<MenuItem>Item 2</MenuItem>
<MenuItem>Item 3</MenuItem>
<MenuItem>Item 4</MenuItem>
</SplitButton>
);
it('should open the menu when dropdown button is clicked', () => {
const instance = ReactTestUtils.renderIntoDocument(simple);
const toggleNode = ReactTestUtils.findRenderedDOMComponentWithClass(
instance,
'dropdown-toggle'
);
const splitButtonNode = ReactDOM.findDOMNode(instance);
splitButtonNode.className.should.not.match(/open/);
ReactTestUtils.Simulate.click(toggleNode);
splitButtonNode.className.should.match(/open/);
});
it('should not open the menu when other button is clicked', () => {
const instance = ReactTestUtils.renderIntoDocument(simple);
const buttonNode = ReactDOM.findDOMNode(
ReactTestUtils.scryRenderedComponentsWithType(instance, Button)[0]
);
const splitButtonNode = ReactDOM.findDOMNode(instance);
splitButtonNode.className.should.not.match(/open/);
ReactTestUtils.Simulate.click(buttonNode);
splitButtonNode.className.should.not.match(/open/);
});
it('should invoke onClick when SplitButton.Button is clicked (prop)', done => {
const instance = ReactTestUtils.renderIntoDocument(
<SplitButton title="Title" id="test-id" onClick={() => done()}>
<MenuItem>Item 1</MenuItem>
</SplitButton>
);
const buttonNode = ReactDOM.findDOMNode(
ReactTestUtils.scryRenderedComponentsWithType(instance, Button)[0]
);
ReactTestUtils.Simulate.click(buttonNode);
});
it('should not invoke onClick when SplitButton.Toggle is clicked (prop)', done => {
let onClickSpy = sinon.spy();
const instance = ReactTestUtils.renderIntoDocument(
<SplitButton title="Title" id="test-id" onClick={onClickSpy}>
<MenuItem>Item 1</MenuItem>
</SplitButton>
);
const toggleNode = ReactTestUtils.findRenderedDOMComponentWithClass(
instance,
'dropdown-toggle'
);
ReactTestUtils.Simulate.click(toggleNode);
setTimeout(() => {
onClickSpy.should.not.have.been.called;
done();
}, 10);
});
it('Should pass disabled to both buttons', () => {
const instance = ReactTestUtils.renderIntoDocument(
<SplitButton title="Title" id="test-id" disabled>
<MenuItem>Item 1</MenuItem>
</SplitButton>
);
const toggleNode = ReactTestUtils.findRenderedDOMComponentWithClass(
instance,
'dropdown-toggle'
);
const buttonNode = ReactDOM.findDOMNode(
ReactTestUtils.scryRenderedComponentsWithType(instance, Button)[0]
);
expect(toggleNode.disabled).to.be.true;
expect(buttonNode.disabled).to.be.true;
});
it('Should set target attribute on anchor', () => {
const instance = ReactTestUtils.renderIntoDocument(
<SplitButton
title="Title"
id="test-id"
href="/some/unique-thing/"
target="_blank"
>
<MenuItem eventKey="1">MenuItem 1 content</MenuItem>
</SplitButton>
);
let anchors = ReactTestUtils.scryRenderedDOMComponentsWithTag(
instance,
'a'
);
let linkElement = anchors[0];
assert.equal(linkElement.target, '_blank');
});
it('should set aria-label on toggle from title', () => {
const instance = ReactTestUtils.renderIntoDocument(simple);
const toggleNode = ReactTestUtils.findRenderedDOMComponentWithClass(
instance,
'dropdown-toggle'
);
expect(toggleNode.getAttribute('aria-label')).to.equal('Title');
});
it('should set aria-label on toggle from toggleLabel', () => {
const instance = ReactTestUtils.renderIntoDocument(
<SplitButton title="Title" id="test-id" toggleLabel="Label">
<MenuItem>Item 1</MenuItem>
</SplitButton>
);
const toggleNode = ReactTestUtils.findRenderedDOMComponentWithClass(
instance,
'dropdown-toggle'
);
expect(toggleNode.getAttribute('aria-label')).to.equal('Label');
});
it('should derive bsClass from parent', () => {
const instance = ReactTestUtils.renderIntoDocument(
<SplitButton title="title" id="test-id" bsClass="my-dropdown">
<MenuItem eventKey="1">MenuItem 1 content</MenuItem>
</SplitButton>
);
assert.ok(
ReactTestUtils.findRenderedDOMComponentWithClass(
instance,
'my-dropdown-toggle'
)
);
assert.ok(
ReactTestUtils.findRenderedDOMComponentWithClass(
instance,
'my-dropdown-menu'
)
);
});
});