66 lines
3.7 KiB
TypeScript
66 lines
3.7 KiB
TypeScript
import { test, expect } from "@playwright/test"
|
||
import { server } from "./fixtures/users"
|
||
|
||
for (const confirmedStatus of ["done", "error"] as const) {
|
||
test(`Speed: unknown receipt сохраняет snapshot и сверяется по runId/${confirmedStatus}`, async ({ page }) => {
|
||
let runId = ""
|
||
let confirmed = false
|
||
let writes = 0
|
||
const probe = {
|
||
id: "probe-unknown", srcServerId: "1", dstServerId: "2",
|
||
srcInterface: "ether1", dstInterface: "ether1", protocol: "tcp", direction: "transmit",
|
||
durationSec: "3", enabled: true, lastStatus: "done", lastRunAt: "2026-10-03T00:00:00Z",
|
||
lastTxAvgMbps: 42, lastRxAvgMbps: null, lastError: null,
|
||
}
|
||
await page.route("**/health", route => route.fulfill({ json: { ok: true } }))
|
||
await page.route("**/api/**", route => {
|
||
const path = new URL(route.request().url()).pathname
|
||
if (path === "/api/uptime/speed-test" && route.request().method() === "POST") {
|
||
writes++
|
||
runId = route.request().postDataJSON().runId
|
||
return route.fulfill({ status: 502, json: {
|
||
outcome: "unknown", runId,
|
||
error: `Сетевой тест завершён, сохранение результата не подтверждено. Проверьте историю по runId ${runId} перед повтором`,
|
||
} })
|
||
}
|
||
return route.fulfill({ json:
|
||
path === "/api/auth/config" ? { required: false } :
|
||
path === "/api/servers" ? [server, { ...server, id: 2, name: "Приёмник", host: "192.0.2.2" }] :
|
||
path === "/api/uptime/overview" ? { probes: [], resources: [] } :
|
||
path === "/api/uptime/speed-probes" ? { probes: [probe] } :
|
||
path === "/api/uptime/speed-test/runs" ? { runs: confirmed ? [{
|
||
id: runId, srcServerId: "1", dstServerId: "2", srcInterface: "ether1", dstInterface: "ether1",
|
||
protocol: "tcp", direction: "transmit", durationSec: 3, status: confirmedStatus,
|
||
txAvgMbps: confirmedStatus === "done" ? 84 : null, rxAvgMbps: null,
|
||
error: confirmedStatus === "error" ? "Подтверждённая ошибка" : null,
|
||
createdAt: new Date().toISOString(),
|
||
}] : [] } : {},
|
||
})
|
||
})
|
||
await page.goto("/uptime?tab=speed")
|
||
await page.getByRole("button", { name: "Пауза", exact: true }).click()
|
||
const launch = page.getByRole("button", { name: "Запустить", exact: true })
|
||
const card = launch.locator("xpath=../../..")
|
||
await expect(card).toContainText("42 Мбит/с")
|
||
await launch.click()
|
||
await expect(page.getByText("Сохранение не подтверждено", { exact: true })).toBeVisible()
|
||
const row = page.locator(`tr[data-row-id="${runId}"]`)
|
||
await expect(row).toContainText(`runId: ${runId}`)
|
||
await expect(row).not.toContainText("error")
|
||
await expect(card).toContainText("42 Мбит/с")
|
||
await page.setViewportSize({ width: 320, height: 1000 })
|
||
expect(await page.evaluate(() => document.documentElement.scrollWidth <= innerWidth)).toBe(true)
|
||
await page.getByRole("button", { name: "Обновить", exact: true }).click()
|
||
await expect(row).toContainText("Сохранение не подтверждено")
|
||
await expect(card).toContainText("42 Мбит/с")
|
||
expect(writes).toBe(1)
|
||
confirmed = true
|
||
await page.getByRole("button", { name: "Обновить", exact: true }).click()
|
||
await expect(row).toContainText(confirmedStatus)
|
||
await expect(page.getByText("Сохранение не подтверждено", { exact: true })).toHaveCount(0)
|
||
await expect(page.getByText(/Проверьте историю по runId/)).toHaveCount(0)
|
||
if (confirmedStatus === "done") await expect(row).toContainText("84 Мбит/с")
|
||
expect(writes).toBe(1)
|
||
})
|
||
}
|