42 lines · 1.3 KB · TypeScript
RawDownload
import { describe, expect, it } from "vite-plus/test"; import { CHAT_LIST_ANCHOR_OFFSET, resolveChatListAnchoredEndSpace } from "./chatList.js"; interface Row {  readonly id: string;  readonly anchorable: boolean;} const rows: ReadonlyArray<Row> = [  { id: "first", anchorable: true },  { id: "ignored", anchorable: false },  { id: "latest", anchorable: true },]; const getAnchorId = (row: Row) => (row.anchorable ? row.id : null); describe("resolveChatListAnchoredEndSpace", () => {  it("anchors the matching row using its measured height", () => {    expect(resolveChatListAnchoredEndSpace(rows, "latest", getAnchorId)).toEqual({      anchorIndex: 2,      anchorOffset: CHAT_LIST_ANCHOR_OFFSET,    });  });   it("allows a surface to keep the anchor below its own header", () => {    expect(      resolveChatListAnchoredEndSpace(rows, "latest", getAnchorId, {        anchorOffset: 132,      }),    ).toEqual({      anchorIndex: 2,      anchorOffset: 132,    });  });   it("ignores ineligible rows and missing anchors", () => {    expect(resolveChatListAnchoredEndSpace(rows, "ignored", getAnchorId)).toBeUndefined();    expect(resolveChatListAnchoredEndSpace(rows, "missing", getAnchorId)).toBeUndefined();    expect(resolveChatListAnchoredEndSpace(rows, null, getAnchorId)).toBeUndefined();  });});