forked from mui/material-ui
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathListItem.spec.js
More file actions
115 lines (102 loc) · 3.32 KB
/
ListItem.spec.js
File metadata and controls
115 lines (102 loc) · 3.32 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
/* eslint-env mocha */
import React from 'react';
import {shallow} from 'enzyme';
import {assert} from 'chai';
import ListItem from './ListItem';
import getMuiTheme from '../styles/getMuiTheme';
describe('<ListItem />', () => {
const muiTheme = getMuiTheme();
const shallowWithContext = (node) => shallow(node, {context: {muiTheme}});
it('should render an EnhancedButton', () => {
const wrapper = shallowWithContext(
<ListItem />
);
const enhancedButton = wrapper.find('EnhancedButton');
assert.ok(enhancedButton.length);
});
it('should display a list-item with text if primaryText is specified', () => {
const testText = 'Primary Text';
const wrapper = shallowWithContext(
<ListItem
primaryText={testText}
/>
);
const enhancedButton = wrapper.find('EnhancedButton');
assert.strictEqual(enhancedButton.children().text(), testText);
});
it('should display a list-item elment with a class if specified', () => {
const testClass = 'test-class';
const wrapper = shallowWithContext(
<ListItem
className={testClass}
/>
);
const enhancedButton = wrapper.find('EnhancedButton');
assert.strictEqual(enhancedButton.prop('className'), testClass);
});
it('should display a disabled list-item if specified.', () => {
const wrapper = shallowWithContext(
<ListItem
disabled={true}
/>
);
assert.notOk(wrapper.find('EnhancedButton').length, 'should not have an EnhancedButton');
});
it('should display a disabled list-item with a class if specified.', () => {
const testClass = 'test-class';
const wrapper = shallowWithContext(
<ListItem
className={testClass}
disabled={true}
/>
);
assert.notOk(wrapper.find('EnhancedButton').length, 'should not have an EnhancedButton');
assert.strictEqual(wrapper.find(`.${testClass}`).length, 1, 'should have a div with the test class');
});
it('should display a checkbox in the list-item if specified.', () => {
const testClass = 'test-class';
const wrapper = shallowWithContext(
<ListItem
leftCheckbox={<div className="test-checkbox" />}
className={testClass}
/>
);
assert.ok(wrapper.find('.test-checkbox').length);
assert.strictEqual(wrapper.find(`.${testClass}`).length, 1, 'should have a div with the test class');
});
it('should initially open nested list', () => {
const testClass = 'test-class';
const wrapper = shallowWithContext(
<ListItem
className={testClass}
initiallyOpen={true}
nestedItems={[
<ListItem
key={1}
/>,
]}
/>
);
assert.ok(wrapper.find('NestedList').length);
assert.ok(wrapper.find('.test-class').parent().children().nodes[1].props.open === true);
});
it('should toggle nested list', () => {
const testClass = 'test-class';
const wrapper = shallowWithContext(
<ListItem
className={testClass}
open={false}
nestedItems={[
<ListItem
key={1}
/>,
]}
/>
);
assert.ok(wrapper.find('.test-class').parent().children().nodes[1].props.open === false);
wrapper.setProps({
open: true,
});
assert.ok(wrapper.find('.test-class').parent().children().nodes[1].props.open === true);
});
});