refactor(desktop): organize lib modules by domain
This commit is contained in:
1 parent
90f0594e93
commit
7e7c4944e9
700 files changed
+1292
-1264
No files matched your search
@@ -0,0 +1,17 @@
|
||||
import { describe, expect, it } from "vitest";
|
||||
import { PostgreSQL } from "@codemirror/lang-sql";
|
||||
import { postgresKeywordSyntaxTerms } from "@/lib/editor/codemirrorSqlDialect";
|
||||
|
||||
describe("codemirrorSqlDialect", () => {
|
||||
it("keeps common PostgreSQL identifier names out of keyword highlighting", () => {
|
||||
const keywords = new Set(postgresKeywordSyntaxTerms(PostgreSQL.spec.keywords || "").split(/\s+/));
|
||||
|
||||
expect(keywords.has("select")).toBe(true);
|
||||
expect(keywords.has("from")).toBe(true);
|
||||
expect(keywords.has("where")).toBe(true);
|
||||
expect(keywords.has("id")).toBe(false);
|
||||
expect(keywords.has("name")).toBe(false);
|
||||
expect(keywords.has("user")).toBe(false);
|
||||
expect(keywords.has("count")).toBe(false);
|
||||
});
|
||||
});
|
||||
@@ -0,0 +1,56 @@
|
||||
import { describe, expect, it } from "vitest";
|
||||
import { DEFAULT_SHORTCUT_SETTINGS, SHORTCUT_DEFINITIONS, findShortcutConflict, normalizeShortcutSettings, type ShortcutActionId } from "@/lib/editor/shortcutRegistry";
|
||||
|
||||
describe("shortcutRegistry editor actions", () => {
|
||||
const formatterEditorActionIds: ShortcutActionId[] = ["formatSql", "indentMore", "indentLess", "duplicateLine", "deleteLine", "moveLineUp", "moveLineDown", "copyLineUp", "copyLineDown", "undo", "redo", "selectAll"];
|
||||
const sidebarShortcutActionIds: ShortcutActionId[] = ["copySidebarSelection", "pasteSidebarSelection", "editSidebarConnection"];
|
||||
|
||||
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");
|
||||
});
|
||||
|
||||
it("registers sidebar shortcuts in the sidebar scope", () => {
|
||||
for (const actionId of sidebarShortcutActionIds) {
|
||||
const definition = SHORTCUT_DEFINITIONS.find((item) => item.id === actionId);
|
||||
|
||||
expect(definition?.scope).toBe("sidebar");
|
||||
expect(DEFAULT_SHORTCUT_SETTINGS[actionId]).toBe(definition?.defaultShortcut);
|
||||
}
|
||||
});
|
||||
|
||||
it("detects conflicts only within sidebar shortcuts", () => {
|
||||
const shortcuts = normalizeShortcutSettings({ copySidebarSelection: "Mod+E" });
|
||||
|
||||
expect(findShortcutConflict("copySidebarSelection", shortcuts.copySidebarSelection, shortcuts)).toBe("editSidebarConnection");
|
||||
expect(findShortcutConflict("copyCurrentRow", shortcuts.copyCurrentRow, shortcuts)).toBe(null);
|
||||
});
|
||||
});
|
||||
Reference in new issue
Block a user