a1956deb63
Co-authored-by: Cursor <cursoragent@cursor.com>
50 lines
2.2 KiB
TypeScript
50 lines
2.2 KiB
TypeScript
import assert from "node:assert/strict";
|
|
import test from "node:test";
|
|
import {
|
|
defaultSidebarOpen,
|
|
shouldHandleSidebarShortcut,
|
|
sidebarViewportForWidth,
|
|
} from "../src/lib/sidebar-state.ts";
|
|
import { beginSessionPageLoad, mergeSessionPage } from "../src/lib/session-groups.ts";
|
|
import { homeSurface } from "./home-surface.ts";
|
|
|
|
test("classifies the exact sidebar breakpoints", () => {
|
|
assert.equal(sidebarViewportForWidth(0), "mobile");
|
|
assert.equal(sidebarViewportForWidth(767), "mobile");
|
|
assert.equal(sidebarViewportForWidth(768), "tablet");
|
|
assert.equal(sidebarViewportForWidth(1023), "tablet");
|
|
assert.equal(sidebarViewportForWidth(1024), "desktop");
|
|
});
|
|
|
|
test("uses the approved reload defaults", () => {
|
|
assert.equal(defaultSidebarOpen("mobile"), false);
|
|
assert.equal(defaultSidebarOpen("tablet"), false);
|
|
assert.equal(defaultSidebarOpen("desktop"), true);
|
|
});
|
|
|
|
test("accepts Command or Control B only outside editable controls", () => {
|
|
const shortcut = { key: "b", metaKey: true, ctrlKey: false, altKey: false, shiftKey: false };
|
|
|
|
assert.equal(shouldHandleSidebarShortcut({ ...shortcut, target: null }), true);
|
|
assert.equal(shouldHandleSidebarShortcut({ ...shortcut, target: { tagName: "TEXTAREA" } }), false);
|
|
assert.equal(shouldHandleSidebarShortcut({ ...shortcut, target: { isContentEditable: true } }), false);
|
|
assert.equal(shouldHandleSidebarShortcut({ ...shortcut, key: "k", target: null }), false);
|
|
});
|
|
|
|
test("renaming a session does not bump updatedAt", () => {
|
|
assert.match(homeSurface, /const nextSession = \{ \.\.\.session, title \};/);
|
|
assert.doesNotMatch(homeSurface, /const nextSession = \{ \.\.\.session, title, updatedAt: timestamp\(\) \};/);
|
|
});
|
|
|
|
test("loadMoreSessions merges by id and only starts one in-flight request", () => {
|
|
const inFlight = { current: false };
|
|
assert.equal(beginSessionPageLoad(inFlight, "cursor-1"), true);
|
|
assert.equal(beginSessionPageLoad(inFlight, "cursor-1"), false);
|
|
const merged = mergeSessionPage(
|
|
[{ id: "keep", updatedAt: 900 }],
|
|
[{ id: "keep", updatedAt: 1 }, { id: "next", updatedAt: 2 }],
|
|
);
|
|
assert.deepEqual(merged.map((item) => item.id), ["keep", "next"]);
|
|
assert.equal(merged[0]?.updatedAt, 900);
|
|
});
|