40 lines
1.9 KiB
TypeScript
40 lines
1.9 KiB
TypeScript
import { describe, expect, it } from "vitest";
|
|
import { DEFAULT_SHORTCUT_SETTINGS, SHORTCUT_DEFINITIONS, findShortcutConflict, normalizeShortcutSettings, type ShortcutActionId } from "@/lib/shortcutRegistry";
|
|
|
|
describe("shortcutRegistry editor actions", () => {
|
|
const formatterEditorActionIds: ShortcutActionId[] = ["formatSql", "indentMore", "indentLess", "duplicateLine", "deleteLine", "moveLineUp", "moveLineDown", "copyLineUp", "copyLineDown", "undo", "redo", "selectAll"];
|
|
|
|
it("registers formatter editor shortcuts in the generic editor scope", () => {
|
|
for (const actionId of formatterEditorActionIds) {
|
|
const definition = SHORTCUT_DEFINITIONS.find((item) => item.id === actionId);
|
|
|
|
expect(definition?.scope).toBe("editor");
|
|
expect(DEFAULT_SHORTCUT_SETTINGS[actionId]).toBe(definition?.defaultShortcut);
|
|
}
|
|
});
|
|
|
|
it("normalizes missing formatter editor shortcuts to their generic defaults", () => {
|
|
const shortcuts = normalizeShortcutSettings({ executeSql: "Mod+Shift+Enter" });
|
|
|
|
expect(shortcuts.executeSql).toBe("Mod+Shift+Enter");
|
|
expect(shortcuts.formatSql).toBe("Shift+Mod+F");
|
|
expect(shortcuts.indentMore).toBe("");
|
|
expect(shortcuts.indentLess).toBe("Shift+Tab");
|
|
expect(shortcuts.duplicateLine).toBe("Mod+D");
|
|
expect(shortcuts.deleteLine).toBe("Shift+Mod+K");
|
|
expect(shortcuts.moveLineUp).toBe("Alt+ArrowUp");
|
|
expect(shortcuts.moveLineDown).toBe("Alt+ArrowDown");
|
|
expect(shortcuts.copyLineUp).toBe("Shift+Alt+ArrowUp");
|
|
expect(shortcuts.copyLineDown).toBe("Shift+Alt+ArrowDown");
|
|
expect(shortcuts.undo).toBe("Mod+Z");
|
|
expect(shortcuts.redo).toBe("Shift+Mod+Z");
|
|
expect(shortcuts.selectAll).toBe("Mod+A");
|
|
});
|
|
|
|
it("detects conflicts between formatter editor shortcuts and other editor shortcuts", () => {
|
|
const shortcuts = normalizeShortcutSettings({ duplicateLine: "Mod+F" });
|
|
|
|
expect(findShortcutConflict("duplicateLine", shortcuts.duplicateLine, shortcuts)).toBe("find");
|
|
});
|
|
});
|