import { test, expect } from "@playwright/test" import { geoip } from "./fixtures/geoip" const snapshot = { v: 1, job: "backups", sampledAt: "2026-10-01T00:00:00Z", due: true, created: 2, failures: 0, pruned: 1, errors: ["S3 upload unavailable"] } for (const representation of ["jsonb", "legacy", "invalid", "foreign"] as const) test("Сбор данных: snapshot/" + representation, async ({ page }) => { const pageErrors: string[] = []; page.on("pageerror", error => pageErrors.push(error.message)) await page.route("**/health", r => r.fulfill({ json: { ok: true } })) await page.route("**/api/**", r => { const path = new URL(r.request().url()).pathname if (path === "/api/traffic/flow/settings") return r.fulfill({ status: 503, json: { error: "NetFlow is outside this snapshot fixture" } }) const settings = { enabled: false, intervalSec: 300, retentionDays: 14, lastCollectedAt: null, lastDurationMs: null, lastError: null, scheduler: { jobs: [] } } return r.fulfill({ json: path === "/api/auth/config" ? { required: false } : path === "/api/geoip" ? geoip : path === "/api/scheduler/runs" ? { runs: [{ id: "run-jsonb", jobKey: "backups", startedAt: snapshot.sampledAt, finishedAt: snapshot.sampledAt, status: "error", error: "Завершено с ограничениями", durationMs: 100, resultJson: representation === "legacy" ? JSON.stringify(snapshot) : representation === "invalid" ? { ...snapshot, created: undefined } : representation === "foreign" ? { v: 1, job: "traffic", sampledAt: snapshot.sampledAt, servers: [] } : snapshot }] } : settings }) }) await page.goto("/data-collection") await page.getByRole("button", { name: /Бэкапы.*100 мс/ }).click() await expect(page.getByText("run-jsonb", { exact: true })).toBeVisible() if (representation === "invalid" || representation === "foreign") { await expect(page.getByText("Слот расписания", { exact: true })).toHaveCount(0); await expect(page.getByText("Снимок недоступен", { exact: true })).toBeVisible() } else { await expect(page.getByText("Слот расписания", { exact: true })).toBeVisible(); await expect(page.getByText("S3 upload unavailable", { exact: true })).toBeVisible(); await expect(page.getByText("Создано", { exact: true }).locator("..")).toContainText("2") } expect(pageErrors).toEqual([]) })