-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathPanelSpec.js
222 lines (186 loc) · 5.59 KB
/
PanelSpec.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
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
import React from 'react';
import { mount } from 'enzyme';
import Panel from '../src/Panel';
describe('<Panel>', () => {
it('Should have class and body', () => {
const inst = mount(
<Panel>
<Panel.Body>Panel content</Panel.Body>
</Panel>
);
inst.assertSingle('div.panel.panel-default');
inst.assertSingle('div.panel-body');
});
it('Should have bootstrap style class', () => {
mount(
<Panel bsStyle="primary">
<Panel.Body>Panel content</Panel.Body>
</Panel>
).assertSingle('div.panel-primary');
});
it('Should honor additional classes passed in; adding not overriding', () => {
mount(<Panel className="foo" />).assertSingle('div.foo');
});
it('Should have unwrapped header', () => {
mount(
<Panel>
<Panel.Heading>Heading</Panel.Heading>
</Panel>
)
.assertSingle('div.panel-heading')
.text()
.should.equal('Heading');
});
it('Should have custom component header', () => {
mount(
<Panel>
<Panel.Heading componentClass="h3">Heading</Panel.Heading>
</Panel>
)
.assertSingle('h3.panel-heading')
.text()
.should.equal('Heading');
});
describe('<PanelTitle>', () => {
it('Should render a title', () => {
mount(<Panel.Title>foo</Panel.Title>)
.assertSingle('div.panel-title')
.text()
.should.equal('foo');
});
it('Should render a custom component', () => {
mount(<Panel.Title componentClass="h3">foo</Panel.Title>).assertSingle(
'h3.panel-title'
);
});
it('Should render with a toggle', () => {
mount(<Panel.Title toggle>foo</Panel.Title>).assertSingle(
'.panel-title > PanelToggle'
);
});
});
describe('<PanelToggle>', () => {
it('Should render a Toggle a SafeAnchor', () => {
mount(<Panel.Toggle>foo</Panel.Toggle>)
.assertSingle('SafeAnchor')
.assertSingle('a[role="button"][href="#"]');
});
it('Should render a custom component', () => {
mount(<Panel.Toggle componentClass="h3">foo</Panel.Toggle>).assertSingle(
'h3'
);
});
it('Should simulate onToggle', done => {
mount(
<Panel onToggle={() => done()}>
<Panel.Toggle>foo</Panel.Toggle>
</Panel>
)
.assertSingle('PanelToggle')
.simulate('click');
});
});
it('Should have a footer', () => {
mount(
<Panel>
<Panel.Footer>foo</Panel.Footer>
</Panel>
).assertSingle('div.panel-footer');
});
it('Should have collapse classes', () => {
mount(
<Panel defaultExpanded>
<Panel.Body collapsible>Panel content</Panel.Body>
</Panel>
).assertSingle('div.panel-collapse.collapse.in');
});
it('Should pass through dom properties', () => {
mount(<Panel id="testid">Panel content</Panel>).assertSingle('div#testid');
});
it('Should set ids on toggle and collapse', () => {
const inst = mount(
<Panel id="testid">
<Panel.Heading>
<Panel.Title toggle>foo</Panel.Title>
</Panel.Heading>
<Panel.Body collapsible>Panel content</Panel.Body>
</Panel>
);
inst.assertSingle('#testid--body.panel-collapse');
inst.assertSingle('#testid--heading.panel-heading');
});
it('Should be open', () => {
const inst = mount(
<Panel defaultExpanded>
<Panel.Heading>
<Panel.Title toggle>foo</Panel.Title>
</Panel.Heading>
<Panel.Body collapsible>Panel content</Panel.Body>
</Panel>
);
inst.assertSingle('.in.panel-collapse');
inst.assertNone('a.collapsed');
});
it('Should be closed', () => {
const inst = mount(
<Panel defaultExpanded={false}>
<Panel.Heading>
<Panel.Title toggle>foo</Panel.Title>
</Panel.Heading>
<Panel.Body collapsible>Panel content</Panel.Body>
</Panel>
);
inst.assertNone('.in.panel-collapse');
inst.assertSingle('a.collapsed');
});
it('Should toggle when uncontrolled', () => {
const wrapper = mount(
<Panel defaultExpanded={false}>
<Panel.Heading>
<Panel.Title toggle>foo</Panel.Title>
</Panel.Heading>
<Panel.Body collapsible>Panel content</Panel.Body>
</Panel>
);
wrapper.find('a').simulate('click');
expect(wrapper.find(Panel.ControlledComponent).props().expanded).to.equal(
true
);
});
describe('Web Accessibility', () => {
it('Should be aria-expanded=true', () => {
mount(
<Panel defaultExpanded>
<Panel.Heading>
<Panel.Title toggle>foo</Panel.Title>
</Panel.Heading>
<Panel.Body collapsible>Panel content</Panel.Body>
</Panel>
).assertSingle('.panel-title a[aria-expanded=true]');
});
it('Should be aria-expanded=false', () => {
mount(
<Panel defaultExpanded={false}>
<Panel.Heading>
<Panel.Title toggle>foo</Panel.Title>
</Panel.Heading>
<Panel.Body collapsible>Panel content</Panel.Body>
</Panel>
)
.assertSingle('.panel-title a')
.assertSingle('[aria-expanded=false]');
});
it('Should add aria-controls with id', () => {
const inst = mount(
<Panel id="testid">
<Panel.Heading>
<Panel.Title toggle>foo</Panel.Title>
</Panel.Heading>
<Panel.Body collapsible>Panel content</Panel.Body>
</Panel>
);
inst.assertSingle('a[aria-controls="testid--body"]');
inst.assertSingle('.panel-collapse[aria-labelledby="testid--heading"]');
});
});
});