forked from react-bootstrap/react-bootstrap
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathPanelGroupSpec.js
More file actions
138 lines (108 loc) · 4.4 KB
/
PanelGroupSpec.js
File metadata and controls
138 lines (108 loc) · 4.4 KB
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
import React from 'react';
import ReactTestUtils from 'react-addons-test-utils';
import Panel from '../src/Panel';
import PanelGroup from '../src/PanelGroup';
import { getOne } from './helpers';
describe('<PanelGroup>', () => {
it('Should pass bsStyle to Panels', () => {
let instance = ReactTestUtils.renderIntoDocument(
<PanelGroup bsStyle="default">
<Panel>Panel 1</Panel>
</PanelGroup>
);
let panel = ReactTestUtils.findRenderedComponentWithType(instance, Panel);
assert.equal(panel.props.bsStyle, 'default');
});
it('Should not override bsStyle on Panel', () => {
let instance = ReactTestUtils.renderIntoDocument(
<PanelGroup bsStyle="default">
<Panel bsStyle="primary">Panel 1</Panel>
</PanelGroup>
);
let panel = ReactTestUtils.findRenderedComponentWithType(instance, Panel);
assert.equal(panel.props.bsStyle, 'primary');
});
it('Should not collapse panel by bubbling onSelect callback', () => {
let instance = ReactTestUtils.renderIntoDocument(
<PanelGroup accordion>
<Panel>
<input type="text" className="changeme" />
</Panel>
</PanelGroup>
);
let panel = ReactTestUtils.findRenderedComponentWithType(instance, Panel);
assert.notOk(panel.state.collapsing);
ReactTestUtils.Simulate.select(
ReactTestUtils.findRenderedDOMComponentWithClass(panel, 'changeme')
);
assert.notOk(panel.state.collapsing);
});
it('Should obey onSelect handler', () => {
function handleSelect(eventKey, e) {
if (e.target.className.indexOf('ignoreme') > -1) {
e.selected = false;
}
}
let header = (
<div>
<span className="clickme">Click me</span>
<span className="ignoreme">Ignore me</span>
</div>
);
let instance = ReactTestUtils.renderIntoDocument(
<PanelGroup accordion onSelect={handleSelect}>
<Panel eventKey="1" header={header}>
<div>Panel body</div>
</Panel>
</PanelGroup>
);
let panel = ReactTestUtils.findRenderedComponentWithType(instance, Panel);
assert.notOk(panel.state.expanded);
ReactTestUtils.Simulate.click(
ReactTestUtils.findRenderedDOMComponentWithClass(panel, 'ignoreme')
);
assert.notOk(panel.state.expanded);
ReactTestUtils.Simulate.click(
ReactTestUtils.findRenderedDOMComponentWithClass(panel, 'clickme')
);
assert.ok(panel.state.expanded);
});
describe('Web Accessibility', () => {
let instance, panelBodies, panelGroup, links;
beforeEach(() => {
instance = ReactTestUtils.renderIntoDocument(
<PanelGroup defaultActiveKey="1" accordion>
<Panel header="Collapsible Group Item #1" eventKey="1" id="Panel1ID">Panel 1</Panel>
<Panel header="Collapsible Group Item #2" eventKey="2" id="Panel2ID">Panel 2</Panel>
</PanelGroup>
);
let accordion = ReactTestUtils.findRenderedComponentWithType(instance, PanelGroup);
panelGroup = ReactTestUtils.findRenderedDOMComponentWithClass(accordion, 'panel-group');
panelBodies = panelGroup.getElementsByClassName('panel-collapse');
links = Array.from(panelGroup.getElementsByClassName('panel-heading'))
.map(header => getOne(header.getElementsByTagName('a')));
});
it('Should have a role of tablist', () => {
assert.equal(panelGroup.getAttribute('role'), 'tablist');
});
it('Should provide each header tab with role of tab', () => {
assert.equal(links[0].getAttribute('role'), 'tab');
assert.equal(links[1].getAttribute('role'), 'tab');
});
it('Should provide the panelBodies with role of tabpanel', () => {
assert.equal(panelBodies[0].getAttribute('role'), 'tabpanel');
});
it('Should provide each panel with an aria-labelledby referencing the corresponding header', () => {
assert.equal(panelBodies[0].id, links[0].getAttribute('aria-controls'));
assert.equal(panelBodies[1].id, links[1].getAttribute('aria-controls'));
});
it('Should maintain each tab aria-selected state', () => {
assert.equal(links[0].getAttribute('aria-selected'), 'true');
assert.equal(links[1].getAttribute('aria-selected'), 'false');
});
it('Should maintain each tab aria-hidden state', () => {
assert.equal(panelBodies[0].getAttribute('aria-hidden'), 'false');
assert.equal(panelBodies[1].getAttribute('aria-hidden'), 'true');
});
});
});