Files
MikrotikManager/tests/e2e/uptime-links.spec.ts
T

86 lines
5.6 KiB
TypeScript
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
import { test, expect, type Page } from "@playwright/test"
async function setup(page: Page, url: string, failed = 0) {
const control = { failed, posts: [] as { path: string; body: unknown }[] }
const servers = [{ id: 1, name: "Источник", host: "192.0.2.1", type: "exit-node", enabled: true, country: "RU", site: "TEST", asn: "64512", status: "online", latency: 1, os: "7", model: "CHR", wanUplinks: [] }]
const probes = ["p1", "p/2"].map(id => ({ id, srcServerId: "1", name: "Проверка сети", target: "192.0.2.10", filter: "main", rtt: null, loss: 100, status: "down", series: [0], enabled: true, showOnDashboard: false }))
await page.route("**/health", route => route.fulfill({ json: { ok: true } }))
await page.route("**/api/**", route => {
const request = route.request()
const path = new URL(request.url()).pathname
if (request.method() === "POST") control.posts.push({ path, body: request.postDataJSON() })
if (path === "/api/uptime/overview" && control.failed) return route.fulfill({ status: control.failed, json: { error: "Мониторинг недоступен" } })
const json = path === "/api/auth/config" ? { required: false }
: path === "/api/evobgp/settings" ? { enabled: false, baseUrl: "", secretConfigured: false }
: path === "/api/servers" ? servers
: path === "/api/uptime/overview" ? { probes, resources: [] }
: path === "/api/uptime/speed-probes" ? { probes: [] }
: path === "/api/uptime/speed-test/runs" ? { runs: [] }
: path === "/api/bgp/sessions" ? []
: path === "/api/filters/gre-tunnels" || path === "/api/vxlan" ? { tunnels: [] }
: path === "/api/wireguard" ? { interfaces: [], peers: [] }
: path === "/api/traffic/servers" ? { servers: [] }
: path === "/api/events" ? { events: [] }
: path === "/api/internet-path/latest" ? { snapshot: { sampledAt: "2026-09-20T00:00:00Z", servers, greTunnels: [], filtersRulesets: [], speedProbes: [], routeLookupByServerId: {}, wanRuntimeByHomeId: {} } }
: {}
return route.fulfill({ json })
})
await page.goto(url)
return control
}
test("очередь проверок: точный ID, чтение без ping, ручной ping только выбранной проверки", async ({ page }) => {
const control = await setup(page, "/dashboard")
const queue = page.getByRole("region", { name: "Требует внимания", exact: true })
const link = queue.locator('a[href="/uptime?probe=p%2F2"]')
await expect(link).toBeVisible()
await link.click()
await expect(page).toHaveURL(/\/uptime\?probe=p%2F2$/)
const context = page.getByRole("status", { name: "Проверка по ссылке" })
await expect(context).toContainText("Выбрана проверка: Проверка сети")
await expect(page.locator("[data-probe-id]")).toHaveCount(1)
await expect(page.locator('[data-probe-id="p/2"]')).toBeVisible()
expect(control.posts).toEqual([])
await page.getByRole("button", { name: "Обновить данные", exact: true }).click()
await expect(context).toContainText("Список ограничен")
expect(control.posts).toEqual([])
await page.getByRole("button", { name: "Обновить", exact: true }).click()
await expect.poll(() => control.posts).toEqual([{ path: "/api/uptime/probes/collect-group", body: { probeIds: ["p/2"] } }])
await context.getByRole("link", { name: "К дашборду", exact: true }).click()
await expect(queue).toBeVisible()
})
test("проверка по прямой ссылке: сброс, возврат, перезагрузка и частичный сбой", async ({ page }) => {
const control = await setup(page, "/uptime?probe=p%2F2&keep=1")
const context = page.getByRole("status", { name: "Проверка по ссылке" })
await expect(context).toContainText("Выбрана проверка")
await context.getByRole("link", { name: "Все проверки", exact: true }).click()
await expect(page).toHaveURL(/\/uptime\?keep=1$/)
await expect(page.locator("[data-probe-id]")).toHaveCount(2)
await page.goBack()
await expect(page.locator("[data-probe-id]")).toHaveCount(1)
await page.reload()
await expect(context).toContainText("Выбрана проверка")
control.failed = 503
await page.getByRole("button", { name: "Обновить данные", exact: true }).click()
await expect(context).toContainText("сохранённые данные могут быть устаревшими")
await expect(page.locator('[data-probe-id="p/2"]')).toBeVisible()
control.failed = 0
await page.getByRole("button", { name: "Обновить данные", exact: true }).click()
await expect(context).toContainText("Список ограничен")
await page.setViewportSize({ width: 390, height: 844 })
await context.scrollIntoViewIfNeeded()
const box = await context.boundingBox()
expect(box!.x + box!.width).toBeLessThanOrEqual(390)
await page.screenshot({ path: "test-results/uptime-link-mobile.png", animations: "disabled" })
})
for (const failed of [0, 403, 500]) {
test(`недоступная проверка: ${failed || "не найден ID"}`, async ({ page }) => {
const control = await setup(page, "/uptime?probe=missing", failed)
await expect(page.getByRole("status", { name: "Проверка по ссылке" })).toContainText(failed ? "Не удалось обновить данные проверки" : "Проверка не найдена или недоступна")
await expect(page.locator("[data-probe-id]")).toHaveCount(0)
expect(control.posts).toEqual([])
})
}