forked from react-bootstrap/react-bootstrap
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathNavSpec.js
146 lines (120 loc) · 4.88 KB
/
NavSpec.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
import React from 'react';
import ReactTestUtils from 'react/lib/ReactTestUtils';
import Button from '../src/Button';
import Nav from '../src/Nav';
import NavItem from '../src/NavItem';
import {shouldWarn} from './helpers';
describe('Nav', () => {
it('Should set the correct item active', () => {
let instance = ReactTestUtils.renderIntoDocument(
<Nav bsStyle="pills" activeKey={1}>
<NavItem eventKey={1}>Pill 1 content</NavItem>
<NavItem eventKey={2}>Pill 2 content</NavItem>
</Nav>
);
let items = ReactTestUtils.scryRenderedComponentsWithType(instance, NavItem);
assert.ok(items[0].props.active);
assert.notOk(items[1].props.active);
});
it('Should adds style class', () => {
let instance = ReactTestUtils.renderIntoDocument(
<Nav bsStyle="tabs" activeKey={1}>
<NavItem eventKey={1}>Tab 1 content</NavItem>
<NavItem eventKey={2}>Tab 2 content</NavItem>
</Nav>
);
assert.ok(ReactTestUtils.findRenderedDOMComponentWithClass(instance, 'nav'));
assert.ok(ReactTestUtils.findRenderedDOMComponentWithClass(instance, 'nav-tabs'));
});
it('Should adds stacked variation class', () => {
let instance = ReactTestUtils.renderIntoDocument(
<Nav bsStyle="tabs" stacked activeKey={1}>
<NavItem eventKey={1}>Tab 1 content</NavItem>
<NavItem eventKey={2}>Tab 2 content</NavItem>
</Nav>
);
assert.ok(ReactTestUtils.findRenderedDOMComponentWithClass(instance, 'nav-stacked'));
});
it('Should adds variation class', () => {
let instance = ReactTestUtils.renderIntoDocument(
<Nav bsStyle="tabs" justified activeKey={1}>
<NavItem eventKey={1}>Tab 1 content</NavItem>
<NavItem eventKey={2}>Tab 2 content</NavItem>
</Nav>
);
assert.ok(ReactTestUtils.findRenderedDOMComponentWithClass(instance, 'nav-justified'));
});
it('Should add pull-right class', () => {
let instance = ReactTestUtils.renderIntoDocument(
<Nav bsStyle="tabs" pullRight activeKey={1}>
<NavItem eventKey={1}>Tab 1 content</NavItem>
<NavItem eventKey={2}>Tab 2 content</NavItem>
</Nav>
);
assert.ok(ReactTestUtils.findRenderedDOMComponentWithClass(instance, 'pull-right'));
});
it('Should add navbar-right class', () => {
let instance = ReactTestUtils.renderIntoDocument(
<Nav bsStyle="tabs" navbar pullRight activeKey={1}>
<NavItem key={1}>Tab 1 content</NavItem>
<NavItem key={2}>Tab 2 content</NavItem>
</Nav>
);
assert.ok(ReactTestUtils.findRenderedDOMComponentWithClass(instance, 'navbar-right'));
});
it('Should call on select when item is selected', (done) => {
function handleSelect(key) {
assert.equal(key, '2');
done();
}
let instance = ReactTestUtils.renderIntoDocument(
<Nav bsStyle="tabs" activeKey={1} onSelect={handleSelect}>
<NavItem eventKey={1}>Tab 1 content</NavItem>
<NavItem eventKey={2}><span>Tab 2 content</span></NavItem>
</Nav>
);
let items = ReactTestUtils.scryRenderedDOMComponentsWithTag(instance, 'A');
ReactTestUtils.Simulate.click(items[1]);
});
it('Should set the correct item active by href', () => {
let instance = ReactTestUtils.renderIntoDocument(
<Nav bsStyle="pills" activeHref="#item2">
<NavItem eventKey={1} href="#item1">Pill 1 content</NavItem>
<NavItem eventKey={2} href="#item2">Pill 2 content</NavItem>
</Nav>
);
let items = ReactTestUtils.scryRenderedComponentsWithType(instance, NavItem);
assert.ok(items[1].props.active);
assert.notOk(items[0].props.active);
});
it('Should set navItem prop on passed in buttons', () => {
let instance = ReactTestUtils.renderIntoDocument(
<Nav bsStyle="pills" activeHref="#item2">
<Button eventKey={1}>Button 1 content</Button>
<NavItem eventKey={2} href="#item2">Pill 2 content</NavItem>
</Nav>
);
let items = ReactTestUtils.scryRenderedComponentsWithType(instance, NavItem);
assert.ok(items[0].props.navItem);
});
it('Should warn when attempting to use a justified navbar nav', () => {
ReactTestUtils.renderIntoDocument(
<Nav navbar justified />
);
shouldWarn('justified navbar `Nav`s are not supported');
});
describe('Web Accessibility', () => {
it('Should have tablist and tab roles', () => {
let instance = ReactTestUtils.renderIntoDocument(
<Nav bsStyle="tabs" activeKey={1}>
<NavItem key={1}>Tab 1 content</NavItem>
<NavItem key={2}>Tab 2 content</NavItem>
</Nav>
);
let ul = ReactTestUtils.scryRenderedDOMComponentsWithTag(instance, 'ul')[0];
let navItem = ReactTestUtils.scryRenderedDOMComponentsWithTag(instance, 'a')[0];
assert.equal(ul.getAttribute('role'), 'tablist');
assert.equal(navItem.getAttribute('role'), 'tab');
});
});
});