gram/packages/language-server/tests/code-lens.test.ts
abiwab de0dfce660
All checks were successful
CI / Build & Test (pull_request) Successful in 5m2s
fix(language-server): fall back to rootUri and localize the preview CodeLens
2026-11-22 15:34:25 +01:00

28 lines
1 KiB
TypeScript

import { describe, expect, it } from "bun:test";
import { parseDocument } from "../src/document-state";
import { provideCodeLenses } from "../src/features/code-lens";
const state = parseDocument("---\ntitle: Tart\n---\n\nMix @flour{200g}.\n");
const title = (locale?: string) =>
provideCodeLenses(state, locale)[0]?.command?.title;
// The lens is a command of the editor: it speaks the editor's language
// (`InitializeParams.locale`), not the recipe's.
describe("provideCodeLenses", () => {
it("opens the preview from the top of the recipe", () => {
const [lens] = provideCodeLenses(state);
expect(lens?.command?.command).toBe("gram.showPreview");
expect(lens?.range.start).toEqual({ line: 0, character: 0 });
});
it("speaks the editor's language", () => {
expect(title("en")).toBe("▶ Preview");
expect(title("fr")).toBe("▶ Aperçu");
expect(title("fr-CA")).toBe("▶ Aperçu");
});
it("falls back to English for an unknown or missing locale", () => {
expect(title()).toBe("▶ Preview");
expect(title("de")).toBe("▶ Preview");
});
});