fix(scheduler): различать неизвестную историю и подтверждённые запуски

This commit is contained in:
Denozordec committed 2026-10-01 21:47:10 +07:00
1 parent 933a4eaf57
commit 1f75bc5cea
6 files changed
+95 -18

No files matched your search

+39
View File
@@ -0,0 +1,39 @@
import { test, expect } from "@playwright/test"
import { geoip } from "./fixtures/geoip"
const row = { id: "confirmed-run", jobKey: "backups", startedAt: "2026-10-01T00:00:00Z", finishedAt: "2026-10-01T00:00:00Z", status: "ok", error: null, durationMs: 100, resultJson: 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" } })
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("Журнал: первоначальная ошибка не становится empty/" + malformed, async ({ page }) => {
await setup(page); await page.route("**/api/scheduler/runs?**", r => r.fulfill(malformed ? { json: {} } : { status: 503, json: { error: "history unavailable" } }))
await page.goto("/data-collection"); await expect(page.getByText("История не получена", { exact: true }).first()).toBeVisible()
await expect(page.getByText("Пока нет прогонов", { exact: true })).toHaveCount(0)
await expect(page.getByText("Журнал (в списке)", { exact: true }).locator("../..")).toContainText("—")
})
test("Журнал: background error сохраняет строки и время последнего чтения", async ({ page }) => {
await setup(page); let fails = false
await page.route("**/api/scheduler/runs?**", r => r.fulfill(fails ? { status: 503, json: { error: "history refresh unavailable" } } : { json: { runs: [row] } }))
await page.goto("/data-collection"); await page.getByRole("button", { name: /Бэкапы.*100 мс/ }).click(); await expect(page.getByText("confirmed-run", { exact: true })).toBeVisible()
const received = await page.getByText(/^История получена:/).textContent(); fails = true
await page.getByRole("button", { name: "Обновить", exact: true }).click(); await expect(page.getByText("История не обновлена", { exact: true })).toBeVisible()
await expect(page.getByText("confirmed-run", { exact: true })).toBeVisible(); await expect(page.getByText(/^История получена:/)).toHaveText(received!)
})
test("Журнал: подтверждённый пустой список имеет ноль и время получения", async ({ page }) => {
await setup(page); await page.route("**/api/scheduler/runs?**", r => r.fulfill({ json: { runs: [] } }))
await page.goto("/data-collection"); await expect(page.getByText("Пока нет прогонов", { exact: true })).toBeVisible(); await expect(page.getByText(/^История получена:/)).toBeVisible()
await expect(page.getByText("Журнал (в списке)", { exact: true }).locator("../..")).toContainText("0")
})
test("Журнал: смена среза не выдаёт прежние строки за новый фильтр", async ({ page }) => {
await setup(page); await page.route("**/api/scheduler/runs?**", r => r.fulfill(new URL(r.request().url()).searchParams.get("jobKey") === "traffic" ? { status: 503, json: { error: "traffic history unavailable" } } : { json: { runs: [row] } }))
await page.goto("/data-collection"); await expect(page.getByRole("button", { name: /Бэкапы.*100 мс/ })).toBeVisible()
await page.getByLabel("Задача", { exact: true }).selectOption("traffic"); await expect(page.getByText("История не получена", { exact: true }).first()).toBeVisible()
await expect(page.getByRole("button", { name: /Бэкапы.*100 мс/ })).toHaveCount(0); await expect(page.getByText(/^История получена:/)).toHaveCount(0)
})