Users can now create, edit, and delete SQL snippet templates from the settings dialog (new "Snippets" tab). Each template has a label, trigger prefix, and SQL body. Built-in defaults are modifiable and can be restored. Templates persist across sessions via the existing settings storage.
34 lines
1.2 KiB
TypeScript
34 lines
1.2 KiB
TypeScript
import { describe, it, expect } from "vitest";
|
|
import { buildSnippetItemsForTest } from "@/lib/sqlCompletion";
|
|
import type { SqlSnippet } from "@/types/database";
|
|
|
|
const TEST_SNIPPETS: SqlSnippet[] = [
|
|
{ id: "1", label: "select all", prefix: "sel", body: "SELECT *\nFROM my_table;" },
|
|
{ id: "2", label: "insert row", prefix: "ins", body: "INSERT INTO my_table VALUES (1);" },
|
|
];
|
|
|
|
describe("buildSnippetItems", () => {
|
|
it("returns matching snippet by prefix", () => {
|
|
const items = buildSnippetItemsForTest("sel", TEST_SNIPPETS);
|
|
expect(items).toHaveLength(1);
|
|
expect(items[0].label).toBe("select all");
|
|
expect(items[0].apply).toBe("SELECT *\nFROM my_table;");
|
|
});
|
|
|
|
it("returns matching snippet by label substring", () => {
|
|
const items = buildSnippetItemsForTest("select", TEST_SNIPPETS);
|
|
expect(items).toHaveLength(1);
|
|
expect(items[0].label).toBe("select all");
|
|
});
|
|
|
|
it("returns empty for no match", () => {
|
|
const items = buildSnippetItemsForTest("zzz", TEST_SNIPPETS);
|
|
expect(items).toEqual([]);
|
|
});
|
|
|
|
it("returns empty for empty prefix", () => {
|
|
const items = buildSnippetItemsForTest("", TEST_SNIPPETS);
|
|
expect(items).toEqual([]);
|
|
});
|
|
});
|