import { describe, expect, test } from "bun:test"; import { createInitialAppState } from "@editor/initial-state"; import { commandPaletteCloseCommand, commandPaletteOpenCommand, commandPaletteSetQueryCommand, commandPaletteSetSelectedIndexCommand, } from "./palette"; describe("command palette commands", () => { test("opens with a reset query and selection", () => { const initial = commandPaletteSetQueryCommand.execute({ state: createInitialAppState("Test") }, { query: "brush" }); const next = commandPaletteOpenCommand.execute({ state: initial }, undefined); expect(next.editor.commandPalette).toEqual({ open: true, query: "", selectedIndex: 0 }); }); test("sets query and returns selected item to the first result", () => { const opened = commandPaletteOpenCommand.execute({ state: createInitialAppState("Test") }, { query: "layer", selectedIndex: 4 }); const next = commandPaletteSetQueryCommand.execute({ state: opened }, { query: "zoom" }); expect(next.editor.commandPalette).toEqual({ open: true, query: "zoom", selectedIndex: 0 }); }); test("clamps selected index to a non-negative integer", () => { const opened = commandPaletteOpenCommand.execute({ state: createInitialAppState("Test") }, undefined); const fractional = commandPaletteSetSelectedIndexCommand.execute({ state: opened }, { selectedIndex: 3.8 }); const negative = commandPaletteSetSelectedIndexCommand.execute({ state: opened }, { selectedIndex: -1 }); expect(fractional.editor.commandPalette.selectedIndex).toBe(3); expect(negative.editor.commandPalette.selectedIndex).toBe(0); }); test("closes and clears transient palette text", () => { const opened = commandPaletteOpenCommand.execute({ state: createInitialAppState("Test") }, { query: "debug", selectedIndex: 2 }); const next = commandPaletteCloseCommand.execute({ state: opened }, undefined); expect(next.editor.commandPalette).toEqual({ open: false, query: "", selectedIndex: 0 }); }); });