Files
khb_microservices/packages/reports/src/reports.test.ts
Yuri Yaryshev 6cd15331f5
All checks were successful
ci / test (push) Successful in 18s
ci / deploy (push) Successful in 1m17s
Страница отчётов reports и встраивание визуализатора под /viz/ за входом Keycloak
Новый package reports: статический список ссылок (khbuild_process - Гант и
ARIS), порт 8087, добавлен в deploy.sh. Визуализатор открывается под префиксом
/viz/ (относительные адреса, ?view=gantt|aris, возврат к списку). Для хоста
reports.khbuild.freeddns.org: nginx, oauth2-proxy и клиент Keycloak
reports-proxy настроены под root, справочные копии - deploy/infra/.

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
2026-10-14 08:57:58 +03:00

52 lines
2.5 KiB
TypeScript
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

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: "<b>&", ru: "<b>&" }, description: { en: "d", ru: "d" }, href: "/x", badge: "X" }]);
expect(html).not.toContain("<b>&<");
expect(html).toContain("&lt;b&gt;&amp;");
});
});
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);
});
});