33 lines
3.6 KiB
TypeScript
33 lines
3.6 KiB
TypeScript
import { test, expect } from "@playwright/test"
|
|
import { geoip } from "./fixtures/geoip"
|
|
const job = { jobKey: "backups", enabled: false, intervalSec: 60, running: false, lastFinishedAt: null, lastStatus: null, lastDurationMs: 0, lastError: null }
|
|
async function setup(page: import("@playwright/test").Page) {
|
|
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/auth/config") return r.fulfill({ json: { required: false } })
|
|
if (path === "/api/geoip") return r.fulfill({ json: geoip })
|
|
if (path === "/api/traffic/flow/settings") return r.fulfill({ status: 503, json: { error: "NetFlow outside fixture" } })
|
|
if (path === "/api/scheduler/runs") return r.fulfill({ json: { runs: [] } })
|
|
return r.fulfill({ json: { enabled: false, intervalSec: 300, retentionDays: 14, lastCollectedAt: null, lastDurationMs: null, lastError: null, scheduler: { jobs: [] } } })
|
|
})
|
|
}
|
|
for (const malformed of [true, false]) test("Статус: initial failure не подменяется drafts/" + malformed, async ({ page }) => {
|
|
await setup(page); await page.route("**/api/scheduler/status", r => r.fulfill(malformed ? { json: {} } : { status: 503, json: { error: "status unavailable" } }))
|
|
await page.goto("/data-collection"); await expect(page.getByText("Статус планировщика не получен", { exact: true })).toBeVisible()
|
|
for (const label of ["Включено задач", "Сейчас выполняется"]) await expect(page.getByText(label, { exact: true }).locator("../..")).toContainText("—")
|
|
})
|
|
test("Статус и история появляются до медленной зависимости uptime", async ({ page }) => {
|
|
await setup(page); let started = false, release!: () => void; const gate = new Promise<void>(resolve => release = resolve)
|
|
await page.route("**/api/uptime/settings", async r => { started = true; await gate; try { await r.fulfill({ status: 503, json: { error: "uptime unavailable" } }) } catch {} })
|
|
await page.route("**/api/scheduler/status", r => r.fulfill({ json: { jobs: [job] } }))
|
|
try { await page.goto("/data-collection"); await expect.poll(() => started).toBe(true); await expect(page.getByText("Включено задач", { exact: true }).locator("../..")).toContainText("0 / 1"); await expect(page.getByText("Пока нет прогонов", { exact: true })).toBeVisible(); await expect(page.getByText(/^Статус получен:/)).toBeVisible() } finally { release() }
|
|
})
|
|
test("Статус: background failure сохраняет последний статус и время", async ({ page }) => {
|
|
await setup(page); let fails = false
|
|
await page.route("**/api/scheduler/status", r => r.fulfill(fails ? { status: 503, json: { error: "status refresh unavailable" } } : { json: { jobs: [job] } }))
|
|
await page.goto("/data-collection"); await expect(page.getByText(/^Статус получен:/)).toBeVisible(); const received = await page.getByText(/^Статус получен:/).textContent(); fails = true
|
|
await expect(page.getByRole("button", { name: "Обновить", exact: true })).toBeEnabled(); await page.getByRole("button", { name: "Обновить", exact: true }).click()
|
|
await expect(page.getByText("Статус планировщика не обновлён", { exact: true })).toBeVisible(); await expect(page.getByText("Включено задач", { exact: true }).locator("../..")).toContainText("0 / 1"); await expect(page.getByText(/^Статус получен:/)).toHaveText(received!)
|
|
})
|