| 5 | |
| 6 | // Verifies that rendered rows cover the region of the table body that is visible (without gaps) |
| 7 | async function getTableState(page: Page, isWindow: boolean) { |
| 8 | return page.evaluate((isWindow) => { |
| 9 | const tbody = document.querySelector("tbody")!; |
| 10 | const tbodyRect = tbody.getBoundingClientRect(); |
| 11 | const scroller = document.querySelector('[data-testid="scroller"]'); |
| 12 | const viewTop = isWindow ? 0 : scroller!.getBoundingClientRect().top; |
| 13 | const viewBottom = isWindow |
| 14 | ? document.documentElement.clientHeight |
| 15 | : viewTop + scroller!.clientHeight; |
| 16 | |
| 17 | const visibleTop = Math.max(tbodyRect.top, viewTop); |
| 18 | const visibleBottom = Math.min(tbodyRect.bottom, viewBottom); |
| 19 | |
| 20 | const rows = Array.from( |
| 21 | tbody.querySelectorAll<HTMLElement>("tr[data-index]") |
| 22 | ); |
| 23 | const rects = rows.map((row) => row.getBoundingClientRect()); |
| 24 | |
| 25 | return { |
| 26 | covered: |
| 27 | visibleBottom <= visibleTop || |
| 28 | (rects.length > 0 && |
| 29 | rects[0].top <= visibleTop + 0.5 && |
| 30 | rects[rects.length - 1].bottom >= visibleBottom - 0.5), |
| 31 | headerTop: |
| 32 | document.querySelector("thead")!.getBoundingClientRect().top - viewTop, |
| 33 | renderedRows: rows.length, |
| 34 | // Rows are rendered in order, without gaps between them |
| 35 | contiguous: rows.every( |
| 36 | (row, index) => |
| 37 | index === 0 || |
| 38 | Number(row.dataset.index) === |
| 39 | Number(rows[index - 1].dataset.index) + 1 |
| 40 | ) |
| 41 | }; |
| 42 | }, isWindow); |
| 43 | } |
| 44 | |
| 45 | async function getRowCenter(page: Page, index: number, isWindow: boolean) { |
| 46 | return page.evaluate( |