Skip to content

armgit / Pulse

Public Imported from GitHub
0

Real-time monitoring dashboard for Proxmox VE, PBS, Docker, Kubernetes, TrueNAS and vSphere. Self-hosted, with alerts for failed backups, full disks, unhealthy containers and offline nodes.

27.4 KB
Raw Blame
import { createRoot, createSignal } from 'solid-js';
import { describe, it, expect, afterEach, vi } from 'vitest';

import {
  useGroupedTableWindowing,
  type UseGroupedTableWindowingOptions,
  type UseGroupedTableWindowingResult,
} from '../useGroupedTableWindowing';
import { resolveWorkloadGuestIndexAtVirtualOffset } from '../useWorkloadsDerivedState';
import type { WorkloadGuest } from '@/types/workloads';

/** Build a minimal WorkloadGuest stub for slicing tests. */
function makeGuest(id: string): WorkloadGuest {
  return { id, name: `guest-${id}`, status: 'running' } as unknown as WorkloadGuest;
}

/** Helper: create the hook inside a reactive root, returning the result + dispose. */
function createHook(
  opts: Partial<UseGroupedTableWindowingOptions> & { totalRowCount: () => number },
): { result: UseGroupedTableWindowingResult; dispose: () => void } {
  let result!: UseGroupedTableWindowingResult;
  const dispose = createRoot((dispose) => {
    result = useGroupedTableWindowing({
      totalRowCount: opts.totalRowCount,
      windowSize: opts.windowSize,
      enableThreshold: opts.enableThreshold,
      enabled: opts.enabled,
      revealIndex: opts.revealIndex,
      rowIndexAtOffset: opts.rowIndexAtOffset,
    });
    return dispose;
  });
  return { result, dispose };
}

describe('useGroupedTableWindowing', () => {
  const disposers: (() => void)[] = [];

  afterEach(() => {
    disposers.forEach((d) => d());
    disposers.length = 0;
  });

  function setup(opts: Partial<UseGroupedTableWindowingOptions> & { totalRowCount: () => number }) {
    const { result, dispose } = createHook(opts);
    disposers.push(dispose);
    return result;
  }

  // ──────────────────────────────────────────────────────────────
  // isWindowed
  // ──────────────────────────────────────────────────────────────
  describe('isWindowed', () => {
    it('returns false when total rows are below the default mounted-row budget', () => {
      const hook = setup({ totalRowCount: () => 140 });
      expect(hook.isWindowed()).toBe(false);
    });

    it('returns true when total rows exceed default threshold', () => {
      const hook = setup({ totalRowCount: () => 300 });
      expect(hook.isWindowed()).toBe(true);
    });

    it('returns false when total rows equal threshold (not exceeded)', () => {
      const hook = setup({ totalRowCount: () => 140 });
      expect(hook.isWindowed()).toBe(false);
    });

    it('respects explicit enabled=true even below threshold', () => {
      const hook = setup({ totalRowCount: () => 50, enabled: () => true });
      expect(hook.isWindowed()).toBe(true);
    });

    it('respects explicit enabled=false even above threshold', () => {
      const hook = setup({ totalRowCount: () => 1000, enabled: () => false });
      expect(hook.isWindowed()).toBe(false);
    });

    it('returns false when total is 0 even if enabled=true', () => {
      const hook = setup({ totalRowCount: () => 0, enabled: () => true });
      expect(hook.isWindowed()).toBe(false);
    });

    it('respects a custom activation threshold', () => {
      const hook = setup({ totalRowCount: () => 73, enableThreshold: 72 });
      expect(hook.isWindowed()).toBe(true);
    });
  });

  // ──────────────────────────────────────────────────────────────
  // startIndex / endIndex basics
  // ──────────────────────────────────────────────────────────────
  describe('startIndex / endIndex (not windowed)', () => {
    it('start is 0 and end equals total when not windowed', () => {
      const hook = setup({ totalRowCount: () => 100 });
      expect(hook.isWindowed()).toBe(false);
      expect(hook.startIndex()).toBe(0);
      expect(hook.endIndex()).toBe(100);
    });
  });

  describe('startIndex / endIndex (windowed)', () => {
    it('initial window starts at 0 with size capped to default (140)', () => {
      const hook = setup({ totalRowCount: () => 1000, enabled: () => true });
      expect(hook.startIndex()).toBe(0);
      expect(hook.endIndex()).toBe(140);
    });

    it('uses custom windowSize', () => {
      const hook = setup({
        totalRowCount: () => 1000,
        enabled: () => true,
        windowSize: 50,
      });
      expect(hook.endIndex()).toBe(50);
    });

    it('clamps window size to at least 1', () => {
      const hook = setup({
        totalRowCount: () => 1000,
        enabled: () => true,
        windowSize: 0,
      });
      // windowSize floored to 1
      expect(hook.endIndex()).toBe(1);
    });

    it('clamps negative windowSize to 1', () => {
      const hook = setup({
        totalRowCount: () => 1000,
        enabled: () => true,
        windowSize: -5,
      });
      expect(hook.endIndex()).toBe(1);
    });

    it('endIndex does not exceed totalRowCount', () => {
      const hook = setup({
        totalRowCount: () => 50,
        enabled: () => true,
        windowSize: 100,
      });
      expect(hook.endIndex()).toBe(50);
    });
  });

  // ──────────────────────────────────────────────────────────────
  // mountedCount
  // ──────────────────────────────────────────────────────────────
  describe('mountedCount', () => {
    it('equals total when not windowed', () => {
      const hook = setup({ totalRowCount: () => 100 });
      expect(hook.mountedCount()).toBe(100);
    });

    it('equals window size when windowed and total > windowSize', () => {
      const hook = setup({
        totalRowCount: () => 1000,
        enabled: () => true,
        windowSize: 80,
      });
      expect(hook.mountedCount()).toBe(80);
    });

    it('equals total when windowed but total < windowSize', () => {
      const hook = setup({
        totalRowCount: () => 30,
        enabled: () => true,
        windowSize: 100,
      });
      expect(hook.mountedCount()).toBe(30);
    });
  });

  // ──────────────────────────────────────────────────────────────
  // onScroll
  // ──────────────────────────────────────────────────────────────
  describe('onScroll', () => {
    it('keeps the current window while both runways meet the target', () => {
      const hook = setup({
        totalRowCount: () => 1000,
        enabled: () => true,
        windowSize: 100,
      });

      // scrollTop=1800, containerHeight=400, rowHeight=40
      // firstVisibleRow = 45, rowsInView = 10, targetRunway = floor(90/2) = 45
      // leading = 45, trailing = 100 - 55 = 45 → both at target, no churn.
      hook.onScroll(1800, 400, 40);
      expect(hook.startIndex()).toBe(0);
      expect(hook.endIndex()).toBe(100);
    });

    it('tops up the trailing runway by the full deficit once it clears the dead-band', () => {
      const hook = setup({
        totalRowCount: () => 1000,
        enabled: () => true,
        windowSize: 100,
      });

      // firstVisible = 80, trailing = 100 - 90 = 10, target = 45 → shift 35.
      hook.onScroll(3200, 400, 40);
      expect(hook.startIndex()).toBe(35);
      expect(hook.endIndex()).toBe(135);

      // firstVisible = 90, trailing = 135 - 100 = 35 → the 10-row deficit
      // clears the 8-row dead-band, so the window shifts by the full deficit.
      hook.onScroll(3600, 400, 40);
      expect(hook.startIndex()).toBe(45);
      expect(hook.endIndex()).toBe(145);

      // Same position again: both runways sit at target → no further movement.
      hook.onScroll(3600, 400, 40);
      expect(hook.startIndex()).toBe(45);
      expect(hook.endIndex()).toBe(145);
    });

    it('re-centers on a teleport and tops up the leading runway while scrolling upward', () => {
      const hook = setup({
        totalRowCount: () => 1000,
        enabled: () => true,
        windowSize: 100,
      });

      // firstVisible = 200 is fully outside [0, 100) → teleport to 200 - 45.
      hook.onScroll(8000, 400, 40);
      expect(hook.startIndex()).toBe(155);

      // firstVisible = 170, leading = 15, target = 45 → shift up by 30.
      hook.onScroll(6800, 400, 40);
      expect(hook.startIndex()).toBe(125);
      expect(hook.endIndex()).toBe(225);
    });

    it('clamps start to 0 when scrolled near top', () => {
      const hook = setup({
        totalRowCount: () => 1000,
        enabled: () => true,
        windowSize: 100,
      });

      // scrollTop=100 → firstVisible = 2, leading deficit clamps at start 0
      hook.onScroll(100, 400, 40);
      expect(hook.startIndex()).toBe(0);
    });

    it('clamps end to totalRowCount when scrolled near bottom', () => {
      const hook = setup({
        totalRowCount: () => 200,
        enabled: () => true,
        windowSize: 100,
      });

      // scrollTop = 6000, firstVisible = 150 is outside [0, 100) → teleport
      // to 150-45 = 105, clamped to maxStart = 200-100 = 100
      hook.onScroll(6000, 400, 40);
      expect(hook.startIndex()).toBe(100);
      expect(hook.endIndex()).toBe(200);
    });

    it('does nothing when not windowed', () => {
      const hook = setup({ totalRowCount: () => 100 });
      hook.onScroll(5000, 400, 40);
      expect(hook.startIndex()).toBe(0);
      expect(hook.endIndex()).toBe(100);
    });

    it('handles zero rowHeight gracefully (falls back to 40)', () => {
      const hook = setup({
        totalRowCount: () => 1000,
        enabled: () => true,
        windowSize: 100,
      });
      // rowHeight=0 → safeRowHeight=40, same calc as normal:
      // firstVisible = 50, trailing deficit is 5, inside the dead-band → hold.
      hook.onScroll(2000, 400, 0);
      expect(hook.startIndex()).toBe(0);
    });

    it('handles negative scrollTop gracefully', () => {
      const hook = setup({
        totalRowCount: () => 1000,
        enabled: () => true,
        windowSize: 100,
      });
      hook.onScroll(-100, 400, 40);
      expect(hook.startIndex()).toBe(0);
    });

    it('handles zero containerHeight gracefully', () => {
      const hook = setup({
        totalRowCount: () => 1000,
        enabled: () => true,
        windowSize: 100,
      });
      // containerHeight=0 → safeContainerHeight=40 (fallback to rowHeight)
      // rowsInView = ceil(40/40) = 1, target = floor(99/2) = 49
      hook.onScroll(800, 0, 40);
      // firstVisible = 20, leading deficit of 29 clamps at start 0
      expect(hook.startIndex()).toBe(0);
    });

    it('uses grouped virtual geometry when decorations add height between rows', () => {
      const rowIndexAtOffset = vi.fn(() => 80);
      const hook = setup({
        totalRowCount: () => 1000,
        enabled: () => true,
        windowSize: 100,
        rowIndexAtOffset,
      });

      hook.onScroll(3200, 400, 32);

      expect(rowIndexAtOffset).toHaveBeenCalledWith(3200, 32);
      // firstVisible = 80 (resolver), rowsInView = 13, target = floor(87/2) = 43
      // trailing = 100 - 93 = 7 → shift the 36-row deficit.
      expect(hook.startIndex()).toBe(36);
      expect(hook.endIndex()).toBe(136);
    });

    it('falls back to fixed row math when the grouped offset resolver is non-finite', () => {
      const hook = setup({
        totalRowCount: () => 1000,
        enabled: () => true,
        windowSize: 100,
        rowIndexAtOffset: () => Number.NaN,
      });

      // firstVisible = 50 via fixed math; the 5-row trailing deficit sits
      // inside the dead-band, so the window holds.
      hook.onScroll(2000, 400, 40);

      expect(hook.startIndex()).toBe(0);
    });
  });

  // ──────────────────────────────────────────────────────────────
  // revealIndex
  // ──────────────────────────────────────────────────────────────
  describe('revealIndex', () => {
    it('centers window on revealed index', () => {
      const hook = setup({
        totalRowCount: () => 1000,
        enabled: () => true,
        windowSize: 100,
      });

      // Reveal row 500 → centeredStart = 500 - 50 = 450
      hook.revealIndex(500);
      expect(hook.startIndex()).toBe(450);
      expect(hook.endIndex()).toBe(550);
    });

    it('does nothing if index is already visible', () => {
      const hook = setup({
        totalRowCount: () => 1000,
        enabled: () => true,
        windowSize: 100,
      });

      // Initially window is [0, 100), row 50 is already visible
      hook.revealIndex(50);
      expect(hook.startIndex()).toBe(0);
    });

    it('clamps to start when revealing near beginning', () => {
      const hook = setup({
        totalRowCount: () => 1000,
        enabled: () => true,
        windowSize: 100,
      });

      // First scroll away, then reveal index 10
      hook.onScroll(10000, 400, 40);
      hook.revealIndex(10);
      // centeredStart = 10 - 50 = -40 → clamped to 0
      expect(hook.startIndex()).toBe(0);
    });

    it('clamps to end when revealing near the last row', () => {
      const hook = setup({
        totalRowCount: () => 1000,
        enabled: () => true,
        windowSize: 100,
      });

      hook.revealIndex(999);
      // centeredStart = 999 - 50 = 949, maxStart = 1000-100 = 900
      expect(hook.startIndex()).toBe(900);
      expect(hook.endIndex()).toBe(1000);
    });

    it('does nothing when not windowed', () => {
      const hook = setup({ totalRowCount: () => 100 });
      hook.revealIndex(50);
      expect(hook.startIndex()).toBe(0);
      expect(hook.endIndex()).toBe(100);
    });

    it('handles non-finite index (NaN)', () => {
      const hook = setup({
        totalRowCount: () => 1000,
        enabled: () => true,
        windowSize: 100,
      });
      hook.revealIndex(NaN);
      // Should not move window
      expect(hook.startIndex()).toBe(0);
    });

    it('handles Infinity', () => {
      const hook = setup({
        totalRowCount: () => 1000,
        enabled: () => true,
        windowSize: 100,
      });
      hook.revealIndex(Infinity);
      expect(hook.startIndex()).toBe(0);
    });

    it('handles negative index by clamping to 0', () => {
      const hook = setup({
        totalRowCount: () => 1000,
        enabled: () => true,
        windowSize: 100,
      });
      // Scroll away first
      hook.onScroll(10000, 400, 40);
      hook.revealIndex(-5);
      // normalizedIndex = max(0, ...) = 0 → centeredStart = 0 - 50 = -50 → clamped to 0
      expect(hook.startIndex()).toBe(0);
    });

    it('handles fractional index by flooring', () => {
      const hook = setup({
        totalRowCount: () => 1000,
        enabled: () => true,
        windowSize: 100,
      });
      hook.revealIndex(500.7);
      // floor(500.7) = 500, centeredStart = 500 - 50 = 450
      expect(hook.startIndex()).toBe(450);
    });
  });

  // ──────────────────────────────────────────────────────────────
  // revealIndex option (reactive)
  // ──────────────────────────────────────────────────────────────
  describe('revealIndex option (reactive signal)', () => {
    it('reveals target when revealIndex signal changes', () => {
      const [revealIdx, setRevealIdx] = createSignal<number | null>(null);
      let result!: UseGroupedTableWindowingResult;
      const dispose = createRoot((dispose) => {
        result = useGroupedTableWindowing({
          totalRowCount: () => 1000,
          enabled: () => true,
          windowSize: 100,
          revealIndex: revealIdx,
        });
        return dispose;
      });
      disposers.push(dispose);

      expect(result.startIndex()).toBe(0);
      setRevealIdx(500);
      // centeredStart = 500 - 50 = 450
      expect(result.startIndex()).toBe(450);
    });

    it('ignores negative revealIndex signal values', () => {
      const [revealIdx, setRevealIdx] = createSignal<number | null>(null);
      let result!: UseGroupedTableWindowingResult;
      const dispose = createRoot((dispose) => {
        result = useGroupedTableWindowing({
          totalRowCount: () => 1000,
          enabled: () => true,
          windowSize: 100,
          revealIndex: revealIdx,
        });
        return dispose;
      });
      disposers.push(dispose);

      setRevealIdx(-1);
      expect(result.startIndex()).toBe(0);
    });
  });

  // ──────────────────────────────────────────────────────────────
  // getVisibleSlice
  // ──────────────────────────────────────────────────────────────
  describe('getVisibleSlice', () => {
    const guests = Array.from({ length: 50 }, (_, i) => makeGuest(String(i)));

    it('returns full array when not windowed', () => {
      const hook = setup({ totalRowCount: () => 100 });
      const slice = hook.getVisibleSlice('group-a', guests, 0);
      expect(slice).toBe(guests); // same reference — no copy
    });

    it('returns empty array for group entirely after window', () => {
      const hook = setup({
        totalRowCount: () => 1000,
        enabled: () => true,
        windowSize: 100,
      });
      // Window [0, 100). Group at index 200..250 is fully after the window.
      const slice = hook.getVisibleSlice('group-x', guests, 200);
      expect(slice).toEqual([]);
    });

    it('returns empty array for group entirely before window', () => {
      const hook = setup({
        totalRowCount: () => 1000,
        enabled: () => true,
        windowSize: 100,
      });
      // Teleport far down. Group at index 0..50 is fully before the window.
      hook.onScroll(16800, 400, 40);
      // firstVisible = 420 → teleport to 420-45 = 375, window [375, 475)
      const slice = hook.getVisibleSlice('group-early', guests, 0);
      expect(slice).toEqual([]);
    });

    it('returns full group when entirely within window', () => {
      const hook = setup({
        totalRowCount: () => 1000,
        enabled: () => true,
        windowSize: 100,
      });
      // Window [0, 100). Group at index 10..60 (50 items) is entirely within.
      const slice = hook.getVisibleSlice('group-inside', guests, 10);
      expect(slice).toHaveLength(50);
      expect(slice[0].id).toBe('0');
      expect(slice[49].id).toBe('49');
    });

    it('returns partial slice when group starts before window', () => {
      const hook = setup({
        totalRowCount: () => 1000,
        enabled: () => true,
        windowSize: 100,
      });
      // Reveal a row that centers the window at 30.
      hook.revealIndex(500);
      hook.revealIndex(80);
      // startIndex=30, endIndex=130
      // Group at index 10..60 → sliceStart = max(0, 30-10) = 20, sliceEnd = min(50, 130-10) = 50
      const slice = hook.getVisibleSlice('group-partial', guests, 10);
      expect(slice).toHaveLength(30);
      expect(slice[0].id).toBe('20'); // guests[20]
    });

    it('returns partial slice when group extends past window end', () => {
      const hook = setup({
        totalRowCount: () => 1000,
        enabled: () => true,
        windowSize: 100,
      });
      // Window [0, 100). Group at index 80..130 → sliceStart=0, sliceEnd = min(50, 100-80) = 20
      const slice = hook.getVisibleSlice('group-overlap-end', guests, 80);
      expect(slice).toHaveLength(20);
      expect(slice[0].id).toBe('0');
      expect(slice[19].id).toBe('19');
    });

    it('handles group starting exactly at window start', () => {
      const hook = setup({
        totalRowCount: () => 1000,
        enabled: () => true,
        windowSize: 100,
      });
      // Window [0, 100). Group at 0..50
      const slice = hook.getVisibleSlice('group-at-start', guests, 0);
      expect(slice).toHaveLength(50);
    });

    it('handles group ending exactly at window end', () => {
      const hook = setup({
        totalRowCount: () => 1000,
        enabled: () => true,
        windowSize: 100,
      });
      // Window [0, 100). Group at 50..100 (50 guests starting at index 50)
      const slice = hook.getVisibleSlice('group-at-end', guests, 50);
      expect(slice).toHaveLength(50);
    });

    it('returns empty when group starts exactly at endIndex', () => {
      const hook = setup({
        totalRowCount: () => 1000,
        enabled: () => true,
        windowSize: 100,
      });
      // Window [0, 100). Group starts at 100 → fully outside.
      const slice = hook.getVisibleSlice('group-boundary', guests, 100);
      expect(slice).toEqual([]);
    });

    it('returns empty for empty guest array', () => {
      const hook = setup({
        totalRowCount: () => 1000,
        enabled: () => true,
        windowSize: 100,
      });
      const slice = hook.getVisibleSlice('empty', [], 0);
      expect(slice).toEqual([]);
    });
  });

  // ──────────────────────────────────────────────────────────────
  // Edge cases
  // ──────────────────────────────────────────────────────────────
  describe('edge cases', () => {
    it('handles totalRowCount of 0 gracefully', () => {
      const hook = setup({ totalRowCount: () => 0, enabled: () => true });
      expect(hook.isWindowed()).toBe(false);
      expect(hook.startIndex()).toBe(0);
      expect(hook.endIndex()).toBe(0);
      expect(hook.mountedCount()).toBe(0);
    });

    it('handles totalRowCount of 1', () => {
      const hook = setup({ totalRowCount: () => 1, enabled: () => true });
      expect(hook.isWindowed()).toBe(true);
      expect(hook.startIndex()).toBe(0);
      expect(hook.endIndex()).toBe(1);
      expect(hook.mountedCount()).toBe(1);
    });

    it('window resets to 0 when windowing is disabled', () => {
      const [enabled, setEnabled] = createSignal(true);
      let result!: UseGroupedTableWindowingResult;
      const dispose = createRoot((dispose) => {
        result = useGroupedTableWindowing({
          totalRowCount: () => 1000,
          enabled,
          windowSize: 100,
        });
        return dispose;
      });
      disposers.push(dispose);

      // Scroll somewhere
      result.onScroll(4000, 400, 40);
      expect(result.startIndex()).toBeGreaterThan(0);

      // Disable windowing
      setEnabled(false);
      expect(result.isWindowed()).toBe(false);
      expect(result.startIndex()).toBe(0);
      expect(result.endIndex()).toBe(1000);
    });

    it('fractional windowSize is floored', () => {
      const hook = setup({
        totalRowCount: () => 1000,
        enabled: () => true,
        windowSize: 50.9,
      });
      expect(hook.endIndex()).toBe(50);
    });

    it('re-clamps when totalRowCount shrinks', () => {
      const [total, setTotal] = createSignal(1000);
      let result!: UseGroupedTableWindowingResult;
      const dispose = createRoot((dispose) => {
        result = useGroupedTableWindowing({
          totalRowCount: total,
          enabled: () => true,
          windowSize: 100,
        });
        return dispose;
      });
      disposers.push(dispose);

      // Scroll to end
      result.onScroll(40000, 400, 40);
      expect(result.startIndex()).toBe(900);

      // Shrink total → maxStart = 200-100 = 100, so start clamps to 100
      setTotal(200);
      expect(result.startIndex()).toBe(100);
      expect(result.endIndex()).toBe(200);
    });

    it('auto-enables windowing when totalRowCount crosses threshold upward', () => {
      const [total, setTotal] = createSignal(100);
      let result!: UseGroupedTableWindowingResult;
      const dispose = createRoot((dispose) => {
        result = useGroupedTableWindowing({ totalRowCount: total });
        return dispose;
      });
      disposers.push(dispose);

      expect(result.isWindowed()).toBe(false);
      setTotal(600);
      expect(result.isWindowed()).toBe(true);
    });

    it('auto-disables windowing when totalRowCount drops below threshold', () => {
      const [total, setTotal] = createSignal(600);
      let result!: UseGroupedTableWindowingResult;
      const dispose = createRoot((dispose) => {
        result = useGroupedTableWindowing({ totalRowCount: total });
        return dispose;
      });
      disposers.push(dispose);

      expect(result.isWindowed()).toBe(true);
      setTotal(100);
      expect(result.isWindowed()).toBe(false);
      expect(result.startIndex()).toBe(0);
      expect(result.endIndex()).toBe(100);
    });

    it('pins the window to the viewport start when rowsInView >= windowSize', () => {
      const hook = setup({
        totalRowCount: () => 1000,
        enabled: () => true,
        windowSize: 5,
      });
      // containerHeight=400, rowHeight=40 → rowsInView = 10 > windowSize 5,
      // so buffer/target are 0 and the teleport path lands on firstVisible.
      // firstVisible = floor(2000/40) = 50, start = 50 - 0 = 50
      hook.onScroll(2000, 400, 40);
      expect(hook.startIndex()).toBe(50);
      expect(hook.endIndex()).toBe(55);
    });

    it('revealIndex for index beyond totalRowCount clamps to last row', () => {
      const hook = setup({
        totalRowCount: () => 100,
        enabled: () => true,
        windowSize: 20,
      });
      // Index 200 → normalizedIndex = min(floor(200), 99) = 99
      // centeredStart = 99 - 10 = 89, maxStart = 100-20 = 80
      hook.revealIndex(200);
      expect(hook.startIndex()).toBe(80);
      expect(hook.endIndex()).toBe(100);
    });
  });

  describe('expanded detail scrolling', () => {
    it('treats the expanded detail height as part of the selected guest virtual row', () => {
      const geometry = {
        detailHeight: 900,
        detailRowIndex: 10,
        groupHeaderHeight: 28,
        groupStartIndices: [0],
        rowHeight: 37,
        totalRows: 100,
      };

      expect(
        resolveWorkloadGuestIndexAtVirtualOffset({ ...geometry, offset: 10 * 37 + 28 + 600 }),
      ).toBe(10);
      expect(
        resolveWorkloadGuestIndexAtVirtualOffset({ ...geometry, offset: 11 * 37 + 28 + 900 }),
      ).toBe(11);
    });

    it('uses a reveal target once without pinning later scroll-driven windows to it', () => {
      const [revealIndex] = createSignal<number | null>(500);
      const hook = setup({
        totalRowCount: () => 1000,
        enabled: () => true,
        windowSize: 100,
        revealIndex,
      });

      expect(hook.startIndex()).toBe(450);

      hook.onScroll(28000, 400, 40);

      expect(hook.startIndex()).toBeGreaterThan(600);
      expect(hook.startIndex()).not.toBe(450);
    });
  });
});