|
1 | 1 | import { expect } from '@esm-bundle/chai'; |
2 | 2 | import { aTimeout, fixtureSync, nextFrame, oneEvent } from '@vaadin/testing-helpers'; |
| 3 | +import sinon from 'sinon'; |
3 | 4 | import '../vaadin-grid.js'; |
4 | 5 | import '../vaadin-grid-column-group.js'; |
5 | 6 | import { html, PolymerElement } from '@polymer/polymer/polymer-element.js'; |
6 | 7 | import { |
7 | 8 | flushGrid, |
8 | 9 | getContainerCellContent, |
9 | 10 | getHeaderCellContent, |
| 11 | + getLastVisibleItem, |
10 | 12 | getPhysicalItems, |
11 | 13 | getRowCells, |
12 | 14 | getRows, |
@@ -213,4 +215,73 @@ describe('all rows visible', () => { |
213 | 215 | expect(getPhysicalItems(grid).length).to.be.above(0); |
214 | 216 | }); |
215 | 217 | }); |
| 218 | + |
| 219 | + describe('max-height', () => { |
| 220 | + let wrapper; |
| 221 | + |
| 222 | + beforeEach(() => { |
| 223 | + wrapper = fixtureSync(` |
| 224 | + <div> |
| 225 | + <vaadin-grid> |
| 226 | + <vaadin-grid-column path="value"></vaadin-grid-column> |
| 227 | + </vaadin-grid> |
| 228 | + </div> |
| 229 | + `); |
| 230 | + grid = wrapper.firstElementChild; |
| 231 | + grid.allRowsVisible = true; |
| 232 | + grid.style.maxHeight = '300px'; |
| 233 | + grid.items = [...Array(100)].map((_, idx) => ({ value: idx })); |
| 234 | + grid.dataProvider = sinon.spy(grid.dataProvider); |
| 235 | + flushGrid(grid); |
| 236 | + }); |
| 237 | + |
| 238 | + it('should include rows', () => { |
| 239 | + const lastRowRect = getLastVisibleItem(grid).getBoundingClientRect(); |
| 240 | + const gridRect = grid.getBoundingClientRect(); |
| 241 | + expect(lastRowRect.top).to.be.below(gridRect.bottom); |
| 242 | + expect(lastRowRect.bottom).to.be.above(gridRect.bottom); |
| 243 | + }); |
| 244 | + |
| 245 | + it('should not overflow rows', () => { |
| 246 | + const gridRect = grid.getBoundingClientRect(); |
| 247 | + const belowGrid = document.elementFromPoint(gridRect.left + 1, gridRect.bottom + 1); |
| 248 | + expect(grid.contains(belowGrid)).to.be.false; |
| 249 | + }); |
| 250 | + |
| 251 | + it('should not grow beyond max-height', () => { |
| 252 | + expect(grid.getBoundingClientRect().height).to.equal(300); |
| 253 | + }); |
| 254 | + |
| 255 | + it('should shrink below max-height', () => { |
| 256 | + grid.items = [{ value: 0 }]; |
| 257 | + flushGrid(grid); |
| 258 | + expect(grid.getBoundingClientRect().height).to.be.below(100); |
| 259 | + }); |
| 260 | + |
| 261 | + it('should have requested first page initially', () => { |
| 262 | + const calls = grid.dataProvider.getCalls(); |
| 263 | + expect(calls.some((call) => call.firstArg.page === 0)).to.be.true; |
| 264 | + }); |
| 265 | + |
| 266 | + it('should not have requested second page initially', () => { |
| 267 | + const calls = grid.dataProvider.getCalls(); |
| 268 | + expect(calls.some((call) => call.firstArg.page === 1)).to.be.false; |
| 269 | + }); |
| 270 | + |
| 271 | + it('should request second page when max-height is reset', () => { |
| 272 | + grid.style.maxHeight = ''; |
| 273 | + flushGrid(grid); |
| 274 | + const calls = grid.dataProvider.getCalls(); |
| 275 | + expect(calls.some((call) => call.firstArg.page === 1)).to.be.true; |
| 276 | + }); |
| 277 | + |
| 278 | + it('should not overflow rows when using relative max-height', () => { |
| 279 | + wrapper.style.height = '600px'; |
| 280 | + grid.style.maxHeight = '50%'; |
| 281 | + |
| 282 | + const gridRect = grid.getBoundingClientRect(); |
| 283 | + const belowGrid = document.elementFromPoint(gridRect.left + 1, gridRect.bottom + 1); |
| 284 | + expect(grid.contains(belowGrid)).to.be.false; |
| 285 | + }); |
| 286 | + }); |
216 | 287 | }); |
0 commit comments