Official
sidebar
Built-in sidebar UI (JavaScript UI plugin).
The app opens the listing; nothing installs until an agent in your Plugins workspace has read the files and you enable the plugin. In a terminal: dvg install divergence/sidebar@0.2.7
Permissions in 0.2.7
Files
dock.test.ts5.8 KB
// The docked sections at the foot of the chat list: each scrolls its rows in
// a box as tall as its first five rows, the dock's edge drags that height,
// and Complete starts folded. Against the fake host in testing.ts.
import assert from "node:assert/strict";
import { afterEach, mock, test } from "node:test";
import activate from "./main.ts";
import { COLLAPSED_KEY, DOCK_HEIGHT_KEY, shareDock } from "./sections.ts";
import { fakeHost } from "./testing.ts";
afterEach(() => mock.timers.reset());
const day = (n: number) => `2026-10-${String(n).padStart(2, "0")}T00:00:00.000Z`;
type Node = {
id?: string;
type?: string;
children?: Node[];
maxHeight?: number;
onResize?: (e: { width: number; height: number }) => void;
onPress?: () => void;
onPointerMove?: (e: { x: number; y: number; button: number | null }) => void;
onPointerUp?: () => void;
};
// An open chat and `done` checked-off ones, Complete unfolded unless `folded` is saved.
function setup(done: number, folded: string[] | null = []) {
const fake = fakeHost([
{ id: "c1", title: "Open", at: day(20) },
...Array.from({ length: done }, (_, i) => ({ id: `d${i}`, title: `Done ${i}`, at: day(1), done: day(i + 2) })),
]);
if (folded) fake.storage.set(COLLAPSED_KEY, folded);
// Complete's box, and the two heights it measures: all its rows, and its first five.
const box = () => fake.node("dock-rows-settled") as Node;
const rows = () => box().children![0]!.children![0]!;
const page = () => box().children![0]!.children![1]!;
const measure = async (pageHeight: number, rowsHeight: number) => {
page().children![0]!.onResize!({ width: 1, height: pageHeight });
rows().onResize!({ width: 1, height: rowsHeight });
await fake.settle();
};
const move = async (y: number, button: number | null = 0) => {
(fake.node("dock-resize") as Node).onPointerMove!({ x: 10, y, button });
await fake.settle();
};
return { fake, box, page, measure, move };
}
test("Complete starts folded", async () => {
const { fake } = setup(2, null);
const dispose = activate(fake.api);
try {
await fake.settle();
assert.ok(fake.node("heading-settled"));
assert.equal(fake.node("row-d0"), undefined, "Complete's rows are folded under its heading");
assert.ok(fake.node("row-c1"));
} finally {
await dispose();
}
});
test("a folded set the user saved takes the default's place", async () => {
const { fake } = setup(2, ["open"]);
const dispose = activate(fake.api);
try {
await fake.settle();
assert.ok(fake.node("row-d0"), "Complete was not among the folded sections saved");
assert.equal(fake.node("row-c1"), undefined);
} finally {
await dispose();
}
});
test("a docked section scrolls its rows in a box as tall as its first five rows", async () => {
const { fake, box, page, measure } = setup(8);
const dispose = activate(fake.api);
try {
await fake.settle();
const ids = (node: Node) => (node.children ?? []).flatMap((child) => (child.id ? [child.id] : []));
assert.deepEqual(ids(page()), ["row-d7", "row-d6", "row-d5", "row-d4", "row-d3"], "the newest five measure the box");
assert.deepEqual(ids(box().children![0]!), ["row-d2", "row-d1", "row-d0"], "the rest scroll under them");
await measure(180, 288);
assert.equal(box().maxHeight, 180);
assert.equal(fake.node("more-settled"), undefined, "eight chats scroll and need no Show more");
// The edge stands at the foot of the room above the dock, right on the first docked heading, which takes no room of its own.
const lead = fake.node("dock-lead") as Node;
assert.equal(lead.children!.at(-1)!.id, "dock-edge");
assert.equal((fake.node("heading-settled") as { paddingTop?: unknown }).paddingTop, 0);
} finally {
await dispose();
}
});
test("dragging the dock's edge gives the docked rows that height, from a row to all of them, and keeps it", async () => {
const { fake, box, measure, move } = setup(8);
const dispose = activate(fake.api);
try {
await fake.settle();
await measure(180, 288);
assert.equal(fake.node("dock-resize"), undefined, "the sidebar hears the pointer only while the edge is dragged");
(fake.node("dock-edge") as Node).onPress!();
await fake.settle();
// The first move marks where the drag starts; the next moves take the rows with them.
await move(500);
assert.equal(box().maxHeight, 180);
await move(440);
assert.equal(box().maxHeight, 240);
await move(0);
assert.equal(box().maxHeight, 288, "no taller than all the rows");
await move(900);
assert.equal(box().maxHeight, 36, "no shorter than one row");
await move(460);
(fake.node("dock-resize") as Node).onPointerUp!();
await fake.settle();
assert.equal(fake.node("dock-resize"), undefined);
assert.equal(fake.storage.get(DOCK_HEIGHT_KEY), 220);
// Let go off the sidebar, the next move over it (no button held) ends the drag there.
(fake.node("dock-edge") as Node).onPress!();
await fake.settle();
await move(300);
await move(280);
await move(280, null);
assert.equal(fake.node("dock-resize"), undefined);
assert.equal(fake.storage.get(DOCK_HEIGHT_KEY), 240);
} finally {
await dispose();
}
});
test("the height the dock was dragged to comes back after a restart", async () => {
const { fake, box, measure } = setup(8);
fake.storage.set(DOCK_HEIGHT_KEY, 100);
const dispose = activate(fake.api);
try {
await fake.settle();
await measure(180, 288);
assert.equal(box().maxHeight, 100);
} finally {
await dispose();
}
});
test("the docked sections share the dragged height evenly, and one that needs less leaves the rest to the others", () => {
assert.deepEqual(shareDock(300, [80, 500, 400]), [80, 110, 110]);
assert.deepEqual(shareDock(1000, [80, 500, 400]), [80, 500, 400]);
assert.deepEqual(shareDock(90, [500, 400]), [45, 45]);
});
No comments yet.