import test from "node:test"; import assert from "node:assert/strict"; import { DESTINATIONS, destinationForView, destinationIndex, rovingTabindex, sectionModel, shellStatus, tabIndexForKey, } from "../src/shell.js"; test("the shell has exactly four destinations in order", () => { assert.deepEqual( DESTINATIONS.map((item) => item.key), ["pipelines", "runs", "chat", "settings"], ); for (const item of DESTINATIONS) { assert.equal(typeof item.label, "string"); assert.ok(item.label.length > 0); assert.equal(item.path, `/${item.key}`); } }); test("views map onto the destination that owns them", () => { assert.equal(destinationForView("pipelines"), "pipelines"); assert.equal(destinationForView("runs"), "runs"); assert.equal(destinationForView("chat"), "chat"); assert.equal(destinationForView("settings"), "settings"); // Templates is reached from Settings; it is a route but not a destination. assert.equal(destinationForView("templates"), "settings"); assert.equal(destinationIndex("chat"), 2); assert.equal(destinationIndex("missing"), 0); }); test("roving tabindex keeps exactly one tab in the tab order", () => { assert.equal(rovingTabindex(0, 0), "0"); assert.equal(rovingTabindex(0, 1), "-1"); assert.deepEqual( [0, 1, 2, 3].map((index) => rovingTabindex(2, index)), ["-1", "-1", "0", "-1"], ); }); test("tab keys move, wrap and jump to the ends", () => { assert.equal(tabIndexForKey("ArrowRight", 0, 4), 1); assert.equal(tabIndexForKey("ArrowRight", 3, 4), 0); assert.equal(tabIndexForKey("ArrowLeft", 0, 4), 3); assert.equal(tabIndexForKey("ArrowLeft", 2, 4), 1); assert.equal(tabIndexForKey("Home", 2, 4), 0); assert.equal(tabIndexForKey("End", 2, 4), 3); // Vertical tablists accept Up/Down as well; horizontal ones ignore them. assert.equal(tabIndexForKey("ArrowDown", 1, 4, { vertical: true }), 2); assert.equal(tabIndexForKey("ArrowUp", 0, 4, { vertical: true }), 3); assert.equal(tabIndexForKey("ArrowDown", 1, 4), -1); assert.equal(tabIndexForKey("Enter", 1, 4), -1); // A non-key or an impossible list never moves focus. assert.equal(tabIndexForKey("ArrowRight", 0, 0), -1); assert.equal(tabIndexForKey("ArrowRight", -1, 4), -1); }); test("the shell status names every connection state without colour", () => { assert.deepEqual(shellStatus({ kind: "connected" }), { text: "Connected", tone: "ok", state: "connected", }); assert.equal(shellStatus({ kind: "connecting", attempt: 2 }).text, "Connecting\u2026"); assert.equal(shellStatus({ kind: "disconnected", reason: "closed" }).text, "Disconnected"); assert.deepEqual(shellStatus({ kind: "idle" }, { hasEndpoint: true }), { text: "Not connected", tone: "idle", state: "idle", }); assert.deepEqual(shellStatus({ kind: "idle" }, { hasEndpoint: false }), { text: "Not configured", tone: "idle", state: "unconfigured", }); }); test("sectionModel keeps one active tab and no tablist without a detail", () => { const model = { tabs: [ { key: "summary", label: "Summary" }, { key: "graph", label: "Graph" }, ], active: "graph", }; assert.deepEqual(sectionModel(model), { tabs: model.tabs, active: 1 }); assert.deepEqual(sectionModel({ tabs: [], active: "summary" }), { tabs: [], active: -1 }); assert.deepEqual(sectionModel({ tabs: model.tabs, active: "missing" }), { tabs: model.tabs, active: 0, }); });