forked from react-bootstrap/react-bootstrap
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathBreadcrumbItemSpec.js
138 lines (112 loc) · 4.48 KB
/
BreadcrumbItemSpec.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
import React from 'react';
import ReactTestUtils from 'react/lib/ReactTestUtils';
import ReactDOM from 'react-dom';
import BreadcrumbItem from '../src/BreadcrumbItem';
describe('BreadcrumbItem', () => {
it('Should render `a` as inner element when is not active', () => {
const instance = ReactTestUtils.renderIntoDocument(
<BreadcrumbItem href='#'>
Crumb
</BreadcrumbItem>
);
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(
<BreadcrumbItem active>
Active Crumb
</BreadcrumbItem>
);
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(
<BreadcrumbItem href="#" active>
Active Crumb
</BreadcrumbItem>
);
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(
<BreadcrumbItem className="custom-one custom-two">
Active Crumb
</BreadcrumbItem>
);
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(
<BreadcrumbItem href='#' onClick={handleClick}>
Crumb
</BreadcrumbItem>
);
const anchorNode = ReactTestUtils.findRenderedDOMComponentWithTag(instance, 'a');
ReactTestUtils.Simulate.click(anchorNode);
});
it('Should apply id onto `li` wrapper element via `id` property', () => {
const instance = ReactTestUtils.renderIntoDocument(
<BreadcrumbItem href='#' id='test-li-id'>
Crumb
</BreadcrumbItem>
);
assert.equal(ReactDOM.findDOMNode(instance).id, 'test-li-id');
});
it('Should apply id onto `a` inner alement via `linkId` property', () => {
const instance = ReactTestUtils.renderIntoDocument(
<BreadcrumbItem href='#' linkId='test-link-id'>
Crumb
</BreadcrumbItem>
);
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(
<BreadcrumbItem href='http://getbootstrap.com/components/#breadcrumbs'>
Crumb
</BreadcrumbItem>
);
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(
<BreadcrumbItem title='test-title' href='http://getbootstrap.com/components/#breadcrumbs'>
Crumb
</BreadcrumbItem>
);
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(
<BreadcrumbItem title='test-title' href='/hi'>
Crumb
</BreadcrumbItem>
);
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(
<BreadcrumbItem target='_blank' href='http://getbootstrap.com/components/#breadcrumbs'>
Crumb
</BreadcrumbItem>
);
const linkNode = ReactTestUtils.findRenderedDOMComponentWithTag(instance, 'a');
assert.equal(linkNode.target, '_blank');
});
});