|
1 | 1 | import React from 'react'; |
2 | 2 | import ReactTestUtils from 'react/lib/ReactTestUtils'; |
3 | 3 | import BreadcrumbItem from '../src/BreadcrumbItem'; |
| 4 | +import { shouldWarn } from './helpers'; |
4 | 5 |
|
5 | | -describe('BreadcrumbItem', function () { |
6 | | - it('Should add active class', function () { |
7 | | - let instance = ReactTestUtils.renderIntoDocument( |
8 | | - <BreadcrumbItem active> |
9 | | - Active Crumb |
| 6 | +describe('BreadcrumbItem', () => { |
| 7 | + it('Should warn if `active` and `href` attributes set', () => { |
| 8 | + ReactTestUtils.renderIntoDocument( |
| 9 | + <BreadcrumbItem href='#' active> |
| 10 | + Crumb |
10 | 11 | </BreadcrumbItem> |
11 | 12 | ); |
12 | 13 |
|
13 | | - assert.ok(ReactTestUtils.findRenderedDOMComponentWithClass(instance, 'active')); |
| 14 | + shouldWarn('[react-bootstrap] `href` and `active` properties cannot be set at the same time'); |
14 | 15 | }); |
15 | 16 |
|
16 | | - it('Should not add active class', function () { |
17 | | - let instance = ReactTestUtils.renderIntoDocument( |
18 | | - <BreadcrumbItem> |
| 17 | + it('Should render `a` as inner element when is not active', () => { |
| 18 | + const instance = ReactTestUtils.renderIntoDocument( |
| 19 | + <BreadcrumbItem href='#'> |
19 | 20 | Crumb |
20 | 21 | </BreadcrumbItem> |
21 | 22 | ); |
22 | 23 |
|
23 | | - let liNode = React.findDOMNode(instance); |
24 | | - assert.notInclude(liNode.className, 'active'); |
| 24 | + assert.ok(ReactTestUtils.findRenderedDOMComponentWithTag(instance, 'a')); |
| 25 | + assert.notInclude(React.findDOMNode(instance).className, 'active'); |
25 | 26 | }); |
26 | 27 |
|
27 | | - it('Should add custom classes', function () { |
28 | | - let instance = ReactTestUtils.renderIntoDocument( |
29 | | - <BreadcrumbItem className="custom-one custom-two" active> |
| 28 | + it('Should add `active` class with `active` attribute set.', () => { |
| 29 | + const instance = ReactTestUtils.renderIntoDocument( |
| 30 | + <BreadcrumbItem active> |
30 | 31 | Active Crumb |
31 | 32 | </BreadcrumbItem> |
32 | 33 | ); |
33 | 34 |
|
34 | | - let liNode = React.findDOMNode(ReactTestUtils.findRenderedDOMComponentWithClass(instance, 'active')); |
| 35 | + assert.include(React.findDOMNode(instance).className, 'active'); |
| 36 | + }); |
35 | 37 |
|
36 | | - let classes = liNode.className; |
37 | | - assert.include(classes, 'active'); |
38 | | - assert.include(classes, 'custom-one'); |
39 | | - assert.include(classes, 'custom-two'); |
| 38 | + it('Should render `span` as inner element when is active', () => { |
| 39 | + const instance = ReactTestUtils.renderIntoDocument( |
| 40 | + <BreadcrumbItem active> |
| 41 | + Crumb |
| 42 | + </BreadcrumbItem> |
| 43 | + ); |
| 44 | + |
| 45 | + assert.ok(ReactTestUtils.findRenderedDOMComponentWithTag(instance, 'span')); |
40 | 46 | }); |
41 | 47 |
|
42 | | - it('Should spread props onto an active item', function() { |
43 | | - let instance = ReactTestUtils.renderIntoDocument( |
44 | | - <BreadcrumbItem herpa='derpa' active> |
| 48 | + it('Should add custom classes onto `li` wrapper element', () => { |
| 49 | + const instance = ReactTestUtils.renderIntoDocument( |
| 50 | + <BreadcrumbItem className="custom-one custom-two"> |
45 | 51 | Active Crumb |
46 | 52 | </BreadcrumbItem> |
47 | 53 | ); |
48 | 54 |
|
49 | | - let spanNode = ReactTestUtils.findRenderedDOMComponentWithTag(instance, 'span'); |
50 | | - |
51 | | - spanNode.props.herpa.should.equal('derpa'); |
| 55 | + const classes = React.findDOMNode(instance).className; |
| 56 | + assert.include(classes, 'custom-one'); |
| 57 | + assert.include(classes, 'custom-two'); |
52 | 58 | }); |
53 | 59 |
|
54 | | - it('Should spread props onto anchor', function(done) { |
| 60 | + it('Should spread additional props onto inner element', (done) => { |
55 | 61 | const handleClick = () => { |
56 | 62 | done(); |
57 | 63 | }; |
58 | 64 |
|
59 | | - let instance = ReactTestUtils.renderIntoDocument( |
60 | | - <BreadcrumbItem href='#' onClick={handleClick} herpa='derpa'> |
61 | | - Crumb 1 |
| 65 | + const instance = ReactTestUtils.renderIntoDocument( |
| 66 | + <BreadcrumbItem href='#' onClick={handleClick}> |
| 67 | + Crumb |
62 | 68 | </BreadcrumbItem> |
63 | 69 | ); |
64 | 70 |
|
65 | | - let anchorNode = ReactTestUtils.findRenderedDOMComponentWithTag(instance, 'a'); |
| 71 | + const anchorNode = ReactTestUtils.findRenderedDOMComponentWithTag(instance, 'a'); |
66 | 72 | ReactTestUtils.Simulate.click(anchorNode); |
67 | | - |
68 | | - anchorNode.props.herpa.should.equal('derpa'); |
69 | 73 | }); |
70 | 74 |
|
71 | | - it('Should add id for li element', function() { |
72 | | - let instance = ReactTestUtils.renderIntoDocument( |
| 75 | + it('Should apply id onto `li` wrapper element via `id` property', () => { |
| 76 | + const instance = ReactTestUtils.renderIntoDocument( |
73 | 77 | <BreadcrumbItem href='#' id='test-li-id'> |
74 | | - Crumb 1 |
| 78 | + Crumb |
75 | 79 | </BreadcrumbItem> |
76 | 80 | ); |
77 | 81 |
|
78 | | - let liNode = React.findDOMNode(ReactTestUtils.findRenderedDOMComponentWithTag(instance, 'li')); |
79 | | - assert.equal(liNode.id, 'test-li-id'); |
| 82 | + assert.equal(React.findDOMNode(instance).id, 'test-li-id'); |
80 | 83 | }); |
81 | 84 |
|
82 | | - it('Should add linkId', function() { |
83 | | - let instance = ReactTestUtils.renderIntoDocument( |
| 85 | + it('Should apply id onto `a` inner alement via `linkId` property', () => { |
| 86 | + const instance = ReactTestUtils.renderIntoDocument( |
84 | 87 | <BreadcrumbItem href='#' linkId='test-link-id'> |
85 | | - Crumb 1 |
| 88 | + Crumb |
86 | 89 | </BreadcrumbItem> |
87 | 90 | ); |
88 | 91 |
|
89 | | - let linkNode = React.findDOMNode(ReactTestUtils.findRenderedDOMComponentWithTag(instance, 'a')); |
| 92 | + const linkNode = React.findDOMNode(ReactTestUtils.findRenderedDOMComponentWithTag(instance, 'a')); |
90 | 93 | assert.equal(linkNode.id, 'test-link-id'); |
91 | 94 | }); |
92 | 95 |
|
93 | | - it('Should add href', function() { |
94 | | - let instance = ReactTestUtils.renderIntoDocument( |
| 96 | + it('Should apply `href` property onto `a` inner element', () => { |
| 97 | + const instance = ReactTestUtils.renderIntoDocument( |
95 | 98 | <BreadcrumbItem href='http://getbootstrap.com/components/#breadcrumbs'> |
96 | | - Crumb 1 |
| 99 | + Crumb |
97 | 100 | </BreadcrumbItem> |
98 | 101 | ); |
99 | 102 |
|
100 | | - let linkNode = React.findDOMNode(ReactTestUtils.findRenderedDOMComponentWithTag(instance, 'a')); |
| 103 | + const linkNode = React.findDOMNode(ReactTestUtils.findRenderedDOMComponentWithTag(instance, 'a')); |
101 | 104 | assert.equal(linkNode.href, 'http://getbootstrap.com/components/#breadcrumbs'); |
102 | 105 | }); |
103 | 106 |
|
104 | | - it('Should have a title', function() { |
105 | | - let instance = ReactTestUtils.renderIntoDocument( |
| 107 | + it('Should apply `title` property onto `a` inner element', () => { |
| 108 | + const instance = ReactTestUtils.renderIntoDocument( |
106 | 109 | <BreadcrumbItem title='test-title' href='http://getbootstrap.com/components/#breadcrumbs'> |
107 | | - Crumb 1 |
| 110 | + Crumb |
108 | 111 | </BreadcrumbItem> |
109 | 112 | ); |
110 | 113 |
|
111 | | - let linkNode = React.findDOMNode(ReactTestUtils.findRenderedDOMComponentWithTag(instance, 'a')); |
| 114 | + const linkNode = React.findDOMNode(ReactTestUtils.findRenderedDOMComponentWithTag(instance, 'a')); |
112 | 115 | assert.equal(linkNode.title, 'test-title'); |
113 | 116 | }); |
114 | 117 |
|
115 | | - it('Should not add anchor properties to li', function() { |
116 | | - let instance = ReactTestUtils.renderIntoDocument( |
| 118 | + it('Should not apply properties for inner `anchor` onto `li` wrapper element', () => { |
| 119 | + const instance = ReactTestUtils.renderIntoDocument( |
117 | 120 | <BreadcrumbItem title='test-title' href='/hi'> |
118 | | - Crumb 1 |
| 121 | + Crumb |
119 | 122 | </BreadcrumbItem> |
120 | 123 | ); |
121 | 124 |
|
122 | | - let liNode = React.findDOMNode(instance); |
| 125 | + const liNode = React.findDOMNode(instance); |
123 | 126 | assert.notOk(liNode.hasAttribute('href')); |
124 | 127 | assert.notOk(liNode.hasAttribute('title')); |
125 | 128 | }); |
126 | 129 |
|
127 | | - it('Should set target attribute on anchor', function () { |
128 | | - let instance = ReactTestUtils.renderIntoDocument( |
| 130 | + it('Should set `target` attribute on `anchor`', () => { |
| 131 | + const instance = ReactTestUtils.renderIntoDocument( |
129 | 132 | <BreadcrumbItem target='_blank' href='http://getbootstrap.com/components/#breadcrumbs'> |
130 | | - Crumb 1 |
| 133 | + Crumb |
131 | 134 | </BreadcrumbItem> |
132 | 135 | ); |
133 | 136 |
|
134 | | - let linkNode = React.findDOMNode(ReactTestUtils.findRenderedDOMComponentWithTag(instance, 'a')); |
| 137 | + const linkNode = React.findDOMNode(ReactTestUtils.findRenderedDOMComponentWithTag(instance, 'a')); |
135 | 138 | assert.equal(linkNode.target, '_blank'); |
136 | 139 | }); |
137 | 140 | }); |
0 commit comments