- Implemented command palette with keyboard shortcut (⌘K) for opening. - Added commands for opening, closing, setting query, and selecting items in the command palette. - Created tests for command palette commands and input handling. - Enhanced layer actions with functions for adding, grouping, and deleting layers. - Updated UI components to integrate command palette and shortcuts.
41 lines
2.0 KiB
TypeScript
41 lines
2.0 KiB
TypeScript
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 });
|
|
});
|
|
});
|