forked from mui/material-ui
-
Notifications
You must be signed in to change notification settings - Fork 1
/
GridList.test.js
201 lines (180 loc) · 5.18 KB
/
GridList.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
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
import * as React from 'react';
import { assert } from 'chai';
import { createMount, createShallow, getClasses } from '@material-ui/core/test-utils';
import describeConformance from '../test-utils/describeConformance';
import GridList from './GridList';
import consoleErrorMock from 'test/utils/consoleErrorMock';
const tilesData = [
{
img: 'images/grid-list/00-52-29-429_640.jpg',
title: 'Breakfast',
author: 'jill111',
},
{
img: 'images/grid-list/burger-827309_640.jpg',
title: 'Tasty burger',
author: 'director90',
},
];
describe('<GridList />', () => {
let classes;
let mount;
let shallow;
before(() => {
classes = getClasses(<GridList />);
mount = createMount({ strict: true });
shallow = createShallow({ dive: true });
});
after(() => {
mount.cleanUp();
});
describeConformance(
<GridList>
<div />
</GridList>,
() => ({
classes,
inheritComponent: 'ul',
mount,
refInstanceof: window.HTMLUListElement,
testComponentPropWith: 'li',
}),
);
it('should render children and change cellHeight', () => {
const cellHeight = 250;
const wrapper = shallow(
<GridList cellHeight={cellHeight}>
{tilesData.map((tile) => (
<span
key={tile.img}
className="grid-tile"
title={tile.title}
subtitle={<span>by: {tile.author}</span>}
>
<img src={tile.img} alt="foo" />
</span>
))}
</GridList>,
);
assert.strictEqual(wrapper.find('.grid-tile').length, 2, 'should contain the children');
assert.strictEqual(
wrapper.children().at(0).props().style.height,
cellHeight + 4,
'should have height to 254',
);
});
it('renders children by default', () => {
const wrapper = shallow(
<GridList>
{tilesData.map((tile) => (
<span
key={tile.img}
className="grid-tile"
title={tile.title}
subtitle={<span>by: {tile.author}</span>}
>
<img src={tile.img} alt="foo" />
</span>
))}
{false && <span>this is a null child</span>}
</GridList>,
);
assert.strictEqual(wrapper.find('.grid-tile').length, 2, 'should contain the children');
});
it('renders children and change cols', () => {
const wrapper = shallow(
<GridList cols={4}>
{tilesData.map((tile) => (
<span
key={tile.img}
className="grid-tile"
title={tile.title}
subtitle={<span>by: {tile.author}</span>}
>
<img src={tile.img} alt="foo" />
</span>
))}
</GridList>,
);
assert.strictEqual(wrapper.find('.grid-tile').length, 2, 'should contain the children');
assert.strictEqual(
wrapper.children().at(0).props().style.width,
'25%',
'should have 25% of width',
);
});
it('renders children and change spacing', () => {
const spacing = 10;
const wrapper = shallow(
<GridList spacing={spacing}>
{tilesData.map((tile) => (
<span
key={tile.img}
className="grid-tile"
title={tile.title}
subtitle={<span>by: {tile.author}</span>}
>
<img src={tile.img} alt="foo" />
</span>
))}
</GridList>,
);
assert.strictEqual(wrapper.find('.grid-tile').length, 2, 'should contain the children');
assert.strictEqual(
wrapper.children().at(0).props().style.padding,
spacing / 2,
'should have 5 of padding',
);
});
it('should render children and overwrite style', () => {
const style = { backgroundColor: 'red' };
const wrapper = shallow(
<GridList style={style}>
{tilesData.map((tile) => (
<span
key={tile.img}
className="grid-tile"
title={tile.title}
subtitle={<span>by: {tile.author}</span>}
>
<img src={tile.img} alt="foo" />
</span>
))}
</GridList>,
);
assert.strictEqual(wrapper.find('.grid-tile').length, 2, 'should contain the children');
assert.strictEqual(wrapper.props().style.backgroundColor, style.backgroundColor);
});
describe('prop: cellHeight', () => {
it('should accept auto as a property', () => {
const wrapper = shallow(
<GridList cellHeight="auto">
<br />
</GridList>,
);
assert.strictEqual(wrapper.children().at(0).props().style.height, 'auto');
});
});
describe('warnings', () => {
before(() => {
consoleErrorMock.spy();
});
after(() => {
consoleErrorMock.reset();
});
it('warns a Fragment is passed as a child', () => {
mount(
<GridList>
<React.Fragment />
</GridList>,
);
assert.strictEqual(consoleErrorMock.callCount(), 2);
assert.include(
consoleErrorMock.messages()[0],
"Material-UI: the GridList component doesn't accept a Fragment as a child.",
);
// one error per render (twice rendered in StrictMode)
assert.strictEqual(consoleErrorMock.messages()[0], consoleErrorMock.messages()[1]);
});
});
});