import { test, expect } from "@playwright/test" import { certificate, certificateState, server } from "./fixtures/certificates" test.beforeEach(async ({ page }) => { await page.route("**/health", r => r.fulfill({ json: { ok: true } })) await page.route("**/api/**", r => { const path = new URL(r.request().url()).pathname return r.fulfill({ json: path === "/api/auth/config" ? { required: false } : path === "/api/servers" ? [server] : path === "/api/certificates/state" ? certificateState() : { directoryUrl: "https://acme.example.test/directory", tokenConfigured: false, enabled: false, intervalSec: 300, renewBeforeDays: 30 } }) }) }) for (const query of ["server=bad", "server=1&server=2", "status=bad", "q=a&q=b"]) test("Сертификаты URL: неверный контекст " + query, async ({ page }) => { await page.goto("/certificates?" + query + "&keep=map#detail") await expect(page.getByRole("alert", { name: "Контекст сертификатов", exact: true })).toBeVisible() await expect(page.getByText(certificate.name, { exact: true })).toHaveCount(0) await page.getByRole("button", { name: "Сбросить контекст", exact: true }).click() expect(new URL(page.url()).search).toBe("?keep=map") expect(new URL(page.url()).hash).toBe("#detail") await expect(page.getByText(certificate.name, { exact: true })).toBeVisible() }) test("Сертификаты URL: фильтр, reload и Back", async ({ page }) => { await page.goto("/certificates?server=1&status=unknown&q=certificate&keep=map#detail") await expect(page.getByText(certificate.name, { exact: true })).toBeVisible() await page.getByRole("button", { name: "Действующие", exact: true }).click() await expect(page.getByText("Нет совпадений", { exact: true })).toBeVisible() expect(new URL(page.url()).searchParams.get("status")).toBe("valid") await page.goBack(); await expect(page.getByText(certificate.name, { exact: true })).toBeVisible() await page.reload(); await expect(page.getByRole("textbox", { name: "Поиск по имени, CN, эмитенту…" })).toHaveValue("certificate") await expect(page.getByRole("button", { name: "Неизвестные", exact: true })).toHaveAttribute("aria-pressed", "true") expect(new URL(page.url()).hash).toBe("#detail") }) test("Сертификаты URL: недоступный сервер не заменяется всеми", async ({ page }) => { await page.goto("/certificates?server=2&keep=map") await expect(page.getByRole("alert").filter({ hasText: "Выбранный сервер недоступен" })).toBeVisible() await expect(page.getByText(certificate.name, { exact: true })).toHaveCount(0) await expect(page.getByText("Нет сертификатов", { exact: true })).toHaveCount(0) expect(new URL(page.url()).searchParams.get("server")).toBe("2") })