forked from react-bootstrap/react-bootstrap
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathSplitButtonSpec.js
104 lines (80 loc) · 3.4 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
import React from 'react';
import ReactTestUtils from 'react/lib/ReactTestUtils';
import ReactDOM from 'react-dom';
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');
});
});