(
page: Page,
{
grid,
indexAttribute = "data-row-index",
row = "[data-row-index]",
rowCount,
rowHeight = ROW_HEIGHT,
scroller
}: {
grid: string;
indexAttribute?: string;
row?: string;
rowCount: number;
rowHeight?: number;
scroller: Scroller;
}
)
| 60 | * - `indexAttribute`: attribute of a row containing its index (`aria-rowindex` is 1-based) |
| 61 | */ |
| 62 | export async function getRowsInfo( |
| 63 | page: Page, |
| 64 | { |
| 65 | grid, |
| 66 | indexAttribute = "data-row-index", |
| 67 | row = "[data-row-index]", |
| 68 | rowCount, |
| 69 | rowHeight = ROW_HEIGHT, |
| 70 | scroller |
| 71 | }: { |
| 72 | grid: string; |
| 73 | indexAttribute?: string; |
| 74 | row?: string; |
| 75 | rowCount: number; |
| 76 | rowHeight?: number; |
| 77 | scroller: Scroller; |
| 78 | } |
| 79 | ): Promise<RowsInfo> { |
| 80 | return page.evaluate( |
| 81 | ({ grid, indexAttribute, row, rowCount, rowHeight, scroller }) => { |
| 82 | let viewportTop = 0; |
| 83 | let viewportBottom = window.innerHeight; |
| 84 | if (scroller !== "window") { |
| 85 | const element = document.querySelector(scroller)!; |
| 86 | viewportTop = element.getBoundingClientRect().top + element.clientTop; |
| 87 | viewportBottom = viewportTop + element.clientHeight; |
| 88 | } |
| 89 | |
| 90 | const gridElement = document.querySelector(grid)!; |
| 91 | const gridTop = gridElement.getBoundingClientRect().top; |
| 92 | |
| 93 | const visible: number[] = []; |
| 94 | const first = Math.max( |
| 95 | 0, |
| 96 | Math.floor((viewportTop - gridTop) / rowHeight) |
| 97 | ); |
| 98 | const last = Math.min( |
| 99 | rowCount - 1, |
| 100 | Math.ceil((viewportBottom - gridTop) / rowHeight) - 1 |
| 101 | ); |
| 102 | for (let index = first; index <= last; index++) { |
| 103 | visible.push(index); |
| 104 | } |
| 105 | |
| 106 | const rendered = new Set<number>(); |
| 107 | const misplaced: number[] = []; |
| 108 | gridElement.querySelectorAll(row).forEach((element) => { |
| 109 | let index = Number(element.getAttribute(indexAttribute)); |
| 110 | if (indexAttribute === "aria-rowindex") { |
| 111 | index--; |
| 112 | } |
| 113 | rendered.add(index); |
| 114 | |
| 115 | const top = element.getBoundingClientRect().top; |
| 116 | if (Math.abs(top - (gridTop + index * rowHeight)) > 1) { |
| 117 | misplaced.push(index); |
| 118 | } |
| 119 | }); |
no outgoing calls
no test coverage detected