import { describe, expect, it } from "vitest"; import { buildApi } from "./http-api.js"; import { REPORT_LINKS } from "./links.js"; import { renderIndex } from "./page.js"; import { reportsSchema } from "./settings.js"; describe("список отчётов", () => { it("содержит Гант и ARIS процесса khbuild_process, оба на странице визуализатора", () => { const g = REPORT_LINKS.find((l) => l.id === "khbuild_process_gantt"); const a = REPORT_LINKS.find((l) => l.id === "khbuild_process_aris"); expect(g?.group).toBe("visualizations"); expect(g?.href).toBe("/viz/?view=gantt"); expect(a?.href).toBe("/viz/?view=aris"); }); it("все ссылки относительные и id уникальны", () => { expect(REPORT_LINKS.every((l) => l.href.startsWith("/") && !l.href.startsWith("//"))).toBe(true); expect(new Set(REPORT_LINKS.map((l) => l.id)).size).toBe(REPORT_LINKS.length); }); it("страница открывает каждую ссылку в новой вкладке, есть оба языка и обе группы", () => { const html = renderIndex(); expect(html.match(/target="_blank"/g)?.length).toBe(REPORT_LINKS.length); expect(html).toContain('href="/viz/?view=gantt"'); expect(html).toContain("Гант"); expect(html).toContain("Reports"); expect(html).toContain("Visualizations"); expect(html).toContain("No items yet."); // группа отчётов пока пуста }); it("экранирует разметку в названиях", () => { const html = renderIndex([{ id: "x", group: "reports", title: { en: "&", ru: "&" }, description: { en: "d", ru: "d" }, href: "/x", badge: "X" }]); expect(html).not.toContain("&<"); expect(html).toContain("<b>&"); }); }); describe("http-api и настройки", () => { const app = buildApi(); it("healthz, страница и json", async () => { expect((await app.inject("/healthz")).json()).toMatchObject({ ok: true, links: REPORT_LINKS.length }); const page = await app.inject("/"); expect(page.statusCode).toBe(200); expect(page.headers["content-type"]).toContain("text/html"); expect((await app.inject("/api/links")).json()).toHaveLength(REPORT_LINKS.length); }); it("секция настроек необязательна", () => { expect(reportsSchema.parse(undefined)).toEqual({ http: { host: "0.0.0.0", port: 8087 } }); expect(reportsSchema.parse({ http: { port: 9000 } }).http.port).toBe(9000); }); });