1// @vitest-environment jsdom
2
3import { RunAttemptId, RunId } from "@t3tools/contracts";
4import { afterEach, expect, it, vi } from "vite-plus/test";
5
6afterEach(() => {
7 sessionStorage.clear();
8 vi.resetModules();
9});
10
11it("restores the reading anchor, expanded work and nested scroll after a module reload", async () => {
12 const timeline = await import("./timelineScrollAnchoring");
13 const reading = {
14 rowId: "message-50",
15 offsetWithinRow: 23,
16 scrollOffset: 800,
17 atEnd: false,
18 disclosures: {
19 runs: new Set([RunId.make("run-a")]),
20 workGroups: new Set(["work-a"]),
21 attempts: new Set([RunAttemptId.make("attempt-a")]),
22 workGroupState: {
23 scrollPositions: new Map([["work-a", { entryId: "tool-3", offset: 20 }]]),
24 expandedEntries: new Set(["tool-3"]),
25 },
26 },
27 };
28 timeline.rememberTimelinePosition("environment:thread", reading, false);
29 timeline.persistTimelinePositionsForReload();
30 vi.resetModules();
31 const refreshed = await import("./timelineScrollAnchoring");
32 expect(refreshed.readTimelinePosition("environment:thread")).toEqual(reading);
33 vi.resetModules();
34 const later = await import("./timelineScrollAnchoring");
35 expect(later.readTimelinePosition("environment:thread")).toBeUndefined();
36});