diff --git a/apps/web/src/components/chat/ThreadRelationshipsControl.test.tsx b/apps/web/src/components/chat/ThreadRelationshipsControl.test.tsx index 809fa8cd76..6e6c20436e 100644 --- a/apps/web/src/components/chat/ThreadRelationshipsControl.test.tsx +++ b/apps/web/src/components/chat/ThreadRelationshipsControl.test.tsx @@ -11,6 +11,7 @@ const testState = vi.hoisted(() => ({ vi.mock("@t3tools/client-runtime/state/thread-relationships", () => ({ deriveThreadRelationshipGraph: () => ({ nodes: new Map() }), immediateThreadRelationships: () => testState.relationships, + orderWebThreadLineageRows: ({ rows }: { readonly rows: ReadonlyArray }) => rows, resolveMergeBackTargetThreadId: () => null, })); vi.mock("@t3tools/client-runtime/state/thread-workflows", () => ({ @@ -39,7 +40,11 @@ vi.mock("../ui/menu", () => ({ MenuItem: ({ children }: { readonly children: ReactNode }) => <>{children}, })); -import { ThreadRelationshipsPanel } from "./ThreadRelationshipsControl"; +import { + resolveThreadLineageWindow, + ThreadLineageRowList, + ThreadRelationshipsPanel, +} from "./ThreadRelationshipsControl"; const environmentId = "environment:relationships" as EnvironmentId; const threadId = "thread:relationships" as ThreadId; @@ -80,3 +85,48 @@ describe("ThreadRelationshipsPanel", () => { expect(renderPanel()).toBe(""); }); }); + +const rows = Array.from({ length: 20 }, (_, index) => `row-${index}`); + +function renderRowList(visibleCount: number) { + const { visibleRows, hiddenCount } = resolveThreadLineageWindow(rows, visibleCount); + return renderToStaticMarkup( + {}}> + {visibleRows.map((row) => ( +
  • {row}
  • + ))} +
    , + ); +} + +describe("thread lineage row list", () => { + it("shows six rows before the first expansion", () => { + const { visibleRows, hiddenCount } = resolveThreadLineageWindow(rows, 6); + + expect(visibleRows).toEqual(rows.slice(0, 6)); + expect(hiddenCount).toBe(14); + }); + + it("offers one page at a time", () => { + expect(renderRowList(6)).toContain("Show 12 more"); + expect(renderRowList(6 + 12)).toContain("Show 2 more"); + }); + + it("omits the expansion affordance when everything fits", () => { + const markup = renderRowList(rows.length); + + expect(markup).not.toContain("more"); + expect(resolveThreadLineageWindow(rows.slice(0, 6), 6).hiddenCount).toBe(0); + }); + + it("keeps the rows in a bounded, labelled scroll region and the button outside it", () => { + const markup = renderRowList(6); + const list = /]*)>/.exec(markup)?.[1] ?? ""; + + expect(list).toContain('aria-label="Related threads"'); + expect(list).toContain("max-h-[13.5rem]"); + expect(list).toContain("overflow-y-auto"); + expect(list).toContain("overscroll-contain"); + expect(markup.indexOf("")).toBeLessThan(markup.indexOf("