forked from muicss/mui
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtest-tabs.js
More file actions
151 lines (118 loc) · 3.53 KB
/
test-tabs.js
File metadata and controls
151 lines (118 loc) · 3.53 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
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
/**
* MUI test react select library
* @module test/react-tests/test-select
*/
import assert from 'assert';
import createClass from'create-react-class';
import React from 'react';
import ReactDOMServer from 'react-dom/server';
import ReactUtils from 'react-dom/test-utils';
import Tab from '../../src/react/tab';
import Tabs from '../../src/react/tabs';
import { getShallowRendererOutput } from '../lib/react-helpers';
describe('react/tabs', function() {
it('renders wrapper properly', function() {
let result = getShallowRendererOutput(<Tabs><Tab /></Tabs>);
assert.equal(result.type, 'div');
assert.equal(result.props.className, '');
});
it('renders properly with additional classNames', function() {
let result = getShallowRendererOutput(
<Tabs className="additional">
<Tab />
</Tabs>
);
assert.equal(result.props.className, 'additional');
});
it('renders with one Tab as child', function() {
let result = ReactDOMServer.renderToStaticMarkup(
<Tabs>
<Tab>ABC</Tab>
</Tabs>
);
assert.equal((result.match(/ABC/g) || []).length, 1);
});
it('renders with two Tabs as children', function() {
let result = ReactDOMServer.renderToStaticMarkup(
<Tabs>
<Tab>ABC</Tab>
<Tab>ABC</Tab>
</Tabs>
);
assert.equal((result.match(/ABC/g) || []).length, 2);
});
it('renders properly with additional styles', function() {
let result = getShallowRendererOutput(
<Tabs style={{additonal: 'style'}}>
<Tab />
</Tabs>
);
assert.equal(result.props.style.additonal, 'style');
});
it('can be used as a controlled component', function() {
var TestApp = createClass({
getInitialState: function() {
return {tabIndex: 1};
},
render: function() {
return (
<Tabs selectedIndex={this.state.tabIndex}>
<Tab>ABC</Tab>
<Tab>DEF</Tab>
</Tabs>
);
}
});
let instance = ReactUtils.renderIntoDocument(<TestApp />),
findElements = ReactUtils.scryRenderedDOMComponentsWithClass,
paneEl;
// check default value
paneEl = findElements(instance, 'mui--is-active')[1];
assert.equal(paneEl.innerHTML, 'DEF');
// update state and check value
instance.setState({tabIndex: 0});
paneEl = findElements(instance, 'mui--is-active')[1];
assert.equal(paneEl.innerHTML, 'ABC');
});
it('can support list of tab elements', function() {
let instance = ReactUtils.renderIntoDocument(
<Tabs>
{
[1, 2, 3].map(function(val) {
return <Tab key={val}>{val}</Tab>;
})
}
</Tabs>
);
// get panes
let panes = ReactUtils
.scryRenderedDOMComponentsWithClass(instance, 'mui-tabs__pane');
// check number
assert.equal(panes.length, 3);
// check content
[1, 2, 3].map(function(val, i) {
assert.equal(panes[i].innerHTML, val);
});
});
it('can support mixed static and dynamic children', function() {
let instance = ReactUtils.renderIntoDocument(
<Tabs>
<Tab>0</Tab>
{
[1, 2, 3].map(function(val) {
return <Tab key={val}>{val}</Tab>;
})
}
</Tabs>
);
// get panes
let panes = ReactUtils
.scryRenderedDOMComponentsWithClass(instance, 'mui-tabs__pane');
// check number
assert.equal(panes.length, 4);
// check content
[0, 1, 2, 3].map(function(val, i) {
assert.equal(panes[i].innerHTML, val);
});
});
});