-
-
Notifications
You must be signed in to change notification settings - Fork 31.6k
/
ListItem.test.js
172 lines (153 loc) · 5.33 KB
/
ListItem.test.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
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
import React from 'react';
import { assert } from 'chai';
import { createShallow, getClasses } from '../test-utils';
import ListItemText from '../ListItemText';
import ListItemSecondaryAction from '../ListItemSecondaryAction';
import ListItem from './ListItem';
import ListItemAvatar from '../ListItemAvatar';
import Avatar from '../Avatar';
import ButtonBase from '../ButtonBase';
describe('<ListItem />', () => {
let shallow;
let classes;
before(() => {
shallow = createShallow({ dive: true });
classes = getClasses(<ListItem />);
});
it('should render a div', () => {
const wrapper = shallow(<ListItem component="div" />);
assert.strictEqual(wrapper.name(), 'div');
});
it('should render a li', () => {
const wrapper = shallow(<ListItem />);
assert.strictEqual(wrapper.name(), 'li');
});
it('should render with the user, root and gutters classes', () => {
const wrapper = shallow(<ListItem className="woofListItem" />);
assert.strictEqual(wrapper.hasClass('woofListItem'), true);
assert.strictEqual(wrapper.hasClass(classes.root), true);
assert.strictEqual(wrapper.hasClass(classes.gutters), true, 'should have the gutters class');
});
it('should disable the gutters', () => {
const wrapper = shallow(<ListItem disableGutters />);
assert.strictEqual(wrapper.hasClass(classes.root), true);
assert.strictEqual(
wrapper.hasClass(classes.gutters),
false,
'should not have the gutters class',
);
});
it('should use dense class when ListItemAvatar is present', () => {
const wrapper = shallow(
<ListItem>
<ListItemAvatar>
<Avatar />
</ListItemAvatar>
</ListItem>,
{
context: {
dense: false,
},
},
);
assert.strictEqual(wrapper.hasClass(classes.dense), true);
});
describe('prop: button', () => {
it('should render a div', () => {
const wrapper = shallow(<ListItem button />);
assert.strictEqual(wrapper.props().component, 'div');
});
});
describe('prop: component', () => {
it('should change the component', () => {
const wrapper = shallow(<ListItem button component="a" />);
assert.strictEqual(wrapper.props().component, 'a');
});
it('should change the component', () => {
const wrapper = shallow(<ListItem button component="li" />);
assert.strictEqual(wrapper.props().component, 'li');
});
});
describe('context: dense', () => {
it('should forward the context', () => {
const wrapper = shallow(<ListItem />);
assert.strictEqual(
wrapper.instance().getChildContext().dense,
false,
'dense should be false by default',
);
wrapper.setProps({ dense: true });
assert.strictEqual(
wrapper.instance().getChildContext().dense,
true,
'dense should be true when set',
);
});
});
describe('secondary action', () => {
it('should wrap with a container', () => {
const wrapper = shallow(
<ListItem>
<ListItemText primary="primary" />
<ListItemSecondaryAction />
</ListItem>,
);
assert.strictEqual(wrapper.hasClass(classes.container), true);
assert.strictEqual(wrapper.type(), 'li');
assert.strictEqual(wrapper.childAt(0).type(), 'div');
});
it('should accept a component property', () => {
const wrapper = shallow(
<ListItem component="span">
<ListItemText primary="primary" />
<ListItemSecondaryAction />
</ListItem>,
);
assert.strictEqual(wrapper.hasClass(classes.container), true);
assert.strictEqual(wrapper.type(), 'li');
assert.strictEqual(wrapper.childAt(0).type(), 'span');
});
it('should accet a button property', () => {
const wrapper = shallow(
<ListItem button>
<ListItemText primary="primary" />
<ListItemSecondaryAction />
</ListItem>,
);
assert.strictEqual(wrapper.hasClass(classes.container), true);
assert.strictEqual(wrapper.type(), 'li');
assert.strictEqual(wrapper.childAt(0).type(), ButtonBase);
});
it('should accept a ContainerComponent property', () => {
const wrapper = shallow(
<ListItem ContainerComponent="div">
<ListItemText primary="primary" />
<ListItemSecondaryAction />
</ListItem>,
);
assert.strictEqual(wrapper.hasClass(classes.container), true);
assert.strictEqual(wrapper.type(), 'div');
assert.strictEqual(wrapper.childAt(0).type(), 'div');
});
it('should allow customization of the wrapper', () => {
const wrapper = shallow(
<ListItem ContainerProps={{ className: 'bubu' }}>
<ListItemText primary="primary" />
<ListItemSecondaryAction />
</ListItem>,
);
assert.strictEqual(wrapper.hasClass(classes.container), true);
assert.strictEqual(wrapper.hasClass('bubu'), true);
});
});
describe('prop: focusVisibleClassName', () => {
it('should merge the class names', () => {
const wrapper = shallow(<ListItem button focusVisibleClassName="focusVisibleClassName" />);
assert.strictEqual(wrapper.props().component, 'div');
assert.strictEqual(
wrapper.props().focusVisibleClassName,
`${classes.focusVisible} focusVisibleClassName`,
);
});
});
});