AkurAI Build
Menu

Public repository / 3aae9f4e85241bcb775c31f5c03094becd3da56a

AkurAI-Framework / tests/js/virtual-list.test.mjs

Latest change f77b709bd5d10a720dc73afb8db12765666bb659 - OLI-244: virtual-list and rich-text islands with sanitizer, node tests, docs by Ólafur Búi Ólafsson

import test from "node:test";
import assert from "node:assert/strict";
import { computeWindow } from "../../site/frontend/virtual-list.js";

test("windows 10k rows to viewport plus overscan", () => {
  const w = computeWindow({ count: 10000, rowHeight: 40, scrollTop: 4000, viewport: 400, overscan: 3 });
  assert.equal(w.start, 97);
  assert.equal(w.end, 113);
  assert.equal(w.offsetTop, 97 * 40);
  assert.equal(w.totalHeight, 400000);
});
test("clamps at the top and bottom", () => {
  assert.equal(computeWindow({ count: 100, rowHeight: 10, scrollTop: 0, viewport: 50, overscan: 5 }).start, 0);
  assert.equal(computeWindow({ count: 100, rowHeight: 10, scrollTop: 99999, viewport: 50, overscan: 5 }).end, 100);
});
test("empty list", () => {
  const w = computeWindow({ count: 0, rowHeight: 10, scrollTop: 0, viewport: 50, overscan: 5 });
  assert.deepEqual([w.start, w.end, w.totalHeight], [0, 0, 0]);
});