b6d555ab3b
Inside-LMS toolbox for registered students: callout-CSS, YAML-frontmatter, theme CSS-variables, Style Settings generators. Auth inherited from (student) route group; no public surface, no email gate. - Pure generators in src/lib/tools/* with Vitest (33 tests) - Shared YAML-safe scalar quoter (_shared/yaml.ts) used by frontmatter + style-settings: unquoted user input was silently breaking YAML (tags '#x' -> null, color default '#7C3AED' -> null, 'a: b' -> parse error) - hex validation in callout (no NaN), date input constrained, clipboard + analytics calls guarded - Prisma ToolUsage model + migration; logToolUsage Server Action (auth-first, 10-min dedup window per user/tool) - Tool index /tools + ToolCard (explicit lucide map, no import *) + header link Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
36 lines
2.0 KiB
TypeScript
36 lines
2.0 KiB
TypeScript
import { describe, it, expect } from "vitest";
|
|
import { buildStyleSettings } from "@/lib/tools/style-settings";
|
|
|
|
describe("buildStyleSettings", () => {
|
|
it("оборачивает в /* @settings ... */", () => {
|
|
const css = buildStyleSettings({ pluginName: "My Theme", settings: [] });
|
|
expect(css.startsWith("/* @settings")).toBe(true);
|
|
expect(css.trim().endsWith("*/")).toBe(true);
|
|
expect(css).toContain("name: My Theme");
|
|
expect(css).toContain("id: my-theme");
|
|
});
|
|
it("variable-color добавляет format", () => {
|
|
const css = buildStyleSettings({ pluginName: "T", settings: [{ id: "accent", title: "Accent", type: "variable-color", default: "#000", format: "hex" }] });
|
|
expect(css).toContain("type: variable-color");
|
|
expect(css).toContain("format: hex");
|
|
});
|
|
it("variable-select рендерит options списком", () => {
|
|
const css = buildStyleSettings({ pluginName: "T", settings: [{ id: "font", title: "Font", type: "variable-select", default: "a", options: "a, b" }] });
|
|
expect(css).toContain("options:");
|
|
expect(css).toContain("- a");
|
|
expect(css).toContain("- b");
|
|
});
|
|
it("heading не получает default", () => {
|
|
const css = buildStyleSettings({ pluginName: "T", settings: [{ id: "h", title: "H", type: "heading", default: "x" }] });
|
|
expect(css).not.toContain("default:");
|
|
});
|
|
it("квотит hex-дефолт цвета (иначе # = коммент YAML → null)", () => {
|
|
const css = buildStyleSettings({ pluginName: "T", settings: [{ id: "accent", title: "Accent", type: "variable-color", default: "#7C3AED", format: "hex" }] });
|
|
expect(css).toContain('default: "#7C3AED"');
|
|
});
|
|
it("квотит title с двоеточием+пробелом (иначе ломает весь блок)", () => {
|
|
const css = buildStyleSettings({ pluginName: "T", settings: [{ id: "s", title: "Шрифт: основной", type: "variable-text", default: "Inter" }] });
|
|
expect(css).toContain('title: "Шрифт: основной"');
|
|
});
|
|
});
|