forked from react-bootstrap/react-bootstrap
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathBreadcrumbItemSpec.js
More file actions
128 lines (104 loc) · 4.17 KB
/
BreadcrumbItemSpec.js
File metadata and controls
128 lines (104 loc) · 4.17 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
import React from 'react';
import ReactTestUtils from 'react-addons-test-utils';
import ReactDOM from 'react-dom';
import Breadcrumb from '../src/Breadcrumb';
describe('<Breadcrumb.Item>', () => {
it('Should render `a` as inner element when is not active', () => {
const instance = ReactTestUtils.renderIntoDocument(
<Breadcrumb.Item href="#">
Crumb
</Breadcrumb.Item>
);
assert.ok(ReactTestUtils.findRenderedDOMComponentWithTag(instance, 'a'));
assert.notInclude(ReactDOM.findDOMNode(instance).className, 'active');
});
it('Should render `span.active` with `active` attribute set.', () => {
const instance = ReactTestUtils.renderIntoDocument(
<Breadcrumb.Item active>
Active Crumb
</Breadcrumb.Item>
);
assert.include(ReactDOM.findDOMNode(instance).className, 'active');
assert.ok(ReactTestUtils.findRenderedDOMComponentWithTag(instance, 'span'));
});
it('Should render `span.active` when active and has href', () => {
const instance = ReactTestUtils.renderIntoDocument(
<Breadcrumb.Item href="#" active>
Active Crumb
</Breadcrumb.Item>
);
assert.include(ReactDOM.findDOMNode(instance).className, 'active');
const spanNode = ReactTestUtils.findRenderedDOMComponentWithTag(instance, 'span');
assert.ok(spanNode);
assert.notOk(spanNode.hasAttribute('href'));
assert.lengthOf(ReactTestUtils.scryRenderedDOMComponentsWithTag(instance, 'a'), 0);
});
it('Should add custom classes onto `li` wrapper element', () => {
const instance = ReactTestUtils.renderIntoDocument(
<Breadcrumb.Item className="custom-one custom-two">
Active Crumb
</Breadcrumb.Item>
);
const classes = ReactDOM.findDOMNode(instance).className;
assert.include(classes, 'custom-one');
assert.include(classes, 'custom-two');
});
it('Should spread additional props onto inner element', (done) => {
const handleClick = () => {
done();
};
const instance = ReactTestUtils.renderIntoDocument(
<Breadcrumb.Item href="#" onClick={handleClick}>
Crumb
</Breadcrumb.Item>
);
const anchorNode = ReactTestUtils.findRenderedDOMComponentWithTag(instance, 'a');
ReactTestUtils.Simulate.click(anchorNode);
});
it('Should apply id onto the anchor', () => {
const instance = ReactTestUtils.renderIntoDocument(
<Breadcrumb.Item href="#" id="test-link-id">
Crumb
</Breadcrumb.Item>
);
const linkNode = ReactTestUtils.findRenderedDOMComponentWithTag(instance, 'a');
assert.equal(linkNode.id, 'test-link-id');
});
it('Should apply `href` property onto `a` inner element', () => {
const instance = ReactTestUtils.renderIntoDocument(
<Breadcrumb.Item href="http://getbootstrap.com/components/#breadcrumbs">
Crumb
</Breadcrumb.Item>
);
const linkNode = ReactTestUtils.findRenderedDOMComponentWithTag(instance, 'a');
assert.equal(linkNode.href, 'http://getbootstrap.com/components/#breadcrumbs');
});
it('Should apply `title` property onto `a` inner element', () => {
const instance = ReactTestUtils.renderIntoDocument(
<Breadcrumb.Item title="test-title" href="http://getbootstrap.com/components/#breadcrumbs">
Crumb
</Breadcrumb.Item>
);
const linkNode = ReactTestUtils.findRenderedDOMComponentWithTag(instance, 'a');
assert.equal(linkNode.title, 'test-title');
});
it('Should not apply properties for inner `anchor` onto `li` wrapper element', () => {
const instance = ReactTestUtils.renderIntoDocument(
<Breadcrumb.Item title="test-title" href="/hi">
Crumb
</Breadcrumb.Item>
);
const liNode = ReactDOM.findDOMNode(instance);
assert.notOk(liNode.hasAttribute('href'));
assert.notOk(liNode.hasAttribute('title'));
});
it('Should set `target` attribute on `anchor`', () => {
const instance = ReactTestUtils.renderIntoDocument(
<Breadcrumb.Item target="_blank" href="http://getbootstrap.com/components/#breadcrumbs">
Crumb
</Breadcrumb.Item>
);
const linkNode = ReactTestUtils.findRenderedDOMComponentWithTag(instance, 'a');
assert.equal(linkNode.target, '_blank');
});
});