Skip to content
Source
Sign inSign up
pingdotgg/t3code
Open History to see the last commit

chatList.test.ts

42 lines1.3 KB

1import { describe, expect, it } from "vite-plus/test";
2​
3import { CHAT_LIST_ANCHOR_OFFSET, resolveChatListAnchoredEndSpace } from "./chatList.js";
4​
5interface Row {
6 readonly id: string;
7 readonly anchorable: boolean;
8}
9​
10const rows: ReadonlyArray<Row> = [
11 { id: "first", anchorable: true },
12 { id: "ignored", anchorable: false },
13 { id: "latest", anchorable: true },
14];
15​
16const getAnchorId = (row: Row) => (row.anchorable ? row.id : null);
17​
18describe("resolveChatListAnchoredEndSpace", () => {
19 it("anchors the matching row using its measured height", () => {
20 expect(resolveChatListAnchoredEndSpace(rows, "latest", getAnchorId)).toEqual({
21 anchorIndex: 2,
22 anchorOffset: CHAT_LIST_ANCHOR_OFFSET,
23 });
24 });
25​
26 it("allows a surface to keep the anchor below its own header", () => {
27 expect(
28 resolveChatListAnchoredEndSpace(rows, "latest", getAnchorId, {
29 anchorOffset: 132,
30 }),
31 ).toEqual({
32 anchorIndex: 2,
33 anchorOffset: 132,
34 });
35 });
36​
37 it("ignores ineligible rows and missing anchors", () => {
38 expect(resolveChatListAnchoredEndSpace(rows, "ignored", getAnchorId)).toBeUndefined();
39 expect(resolveChatListAnchoredEndSpace(rows, "missing", getAnchorId)).toBeUndefined();
40 expect(resolveChatListAnchoredEndSpace(rows, null, getAnchorId)).toBeUndefined();
41 });
42});