|
1 | 1 | import { expect } from '@vaadin/chai-plugins'; |
2 | | -import { aTimeout, fixtureSync, nextFrame } from '@vaadin/testing-helpers'; |
| 2 | +import { aTimeout, fixtureSync, nextFrame, nextResize } from '@vaadin/testing-helpers'; |
3 | 3 | import sinon from 'sinon'; |
4 | 4 | import { Virtualizer } from '../src/virtualizer.js'; |
5 | 5 |
|
@@ -413,6 +413,43 @@ describe('virtualizer - item height - lazy rendering', () => { |
413 | 413 | }); |
414 | 414 | }); |
415 | 415 |
|
| 416 | +describe('virtualizer - item padding', () => { |
| 417 | + let virtualizer; |
| 418 | + let scrollTarget; |
| 419 | + let item0, item1; |
| 420 | + |
| 421 | + beforeEach(async () => { |
| 422 | + scrollTarget = fixtureSync(` |
| 423 | + <div style="height: 200px;"> |
| 424 | + <div class="container"></div> |
| 425 | + </div> |
| 426 | + `); |
| 427 | + |
| 428 | + virtualizer = new Virtualizer({ |
| 429 | + createElements: (count) => Array.from({ length: count }, () => document.createElement('div')), |
| 430 | + updateElement: (el, index) => { |
| 431 | + el.style.paddingBottom = '20px'; |
| 432 | + el.style.boxSizing = 'border-box'; |
| 433 | + el.id = `item-${index}`; |
| 434 | + }, |
| 435 | + scrollTarget, |
| 436 | + scrollContainer: scrollTarget.firstElementChild, |
| 437 | + }); |
| 438 | + virtualizer.size = 2; |
| 439 | + await nextResize(scrollTarget); |
| 440 | + await nextFrame(); |
| 441 | + }); |
| 442 | + |
| 443 | + it('should adjust item positions after an item padding box changes', async () => { |
| 444 | + item0 = document.querySelector('#item-0'); |
| 445 | + item1 = document.querySelector('#item-1'); |
| 446 | + item0.style.paddingBottom = '50px'; |
| 447 | + await nextResize(scrollTarget); |
| 448 | + await nextFrame(); |
| 449 | + expect(item1.getBoundingClientRect().top).to.equal(item0.getBoundingClientRect().bottom); |
| 450 | + }); |
| 451 | +}); |
| 452 | + |
416 | 453 | describe('virtualizer - item height - placeholders are disabled', () => { |
417 | 454 | let virtualizer; |
418 | 455 | let scrollTarget; |
|
0 commit comments