Files
MikrotikManager/tests/e2e/collector-probes-tables.spec.ts
T

69 lines
4.2 KiB
TypeScript

import { test, expect, type Page } from "@playwright/test"
import type { SpeedProbeApiRow } from "../../components/data-grids/probes-speed-probes-data-grid"
async function setup(page: Page, path: string) {
const probes: SpeedProbeApiRow[] = Array.from({ length: 12 }, (_, i) => ({
id: String(i + 1), srcServerId: `Источник ${i + 1}`, dstServerId: "Цель", srcInterface: "ether1",
dstInterface: "ether1", protocol: "tcp", direction: "both", durationSec: "10", enabled: true,
lastRunAt: null, lastTxAvgMbps: null, lastRxAvgMbps: null, lastStatus: null, lastError: null,
}))
const calls: string[] = []
await page.route("**/health", route => route.fulfill({ json: { ok: true } }))
await page.route("**/api/**", route => {
const path = new URL(route.request().url()).pathname
if (route.request().method() === "POST") calls.push(path)
return route.fulfill({ json: path === "/api/uptime/speed-probes" ? { probes }
: path === "/api/auth/config" ? { required: false } : path === "/api/servers" ? []
: path === "/api/evobgp/settings" ? { enabled: false, baseUrl: "", secretConfigured: false }
: path === "/api/traffic/flow/settings" ? {
enabled: false, collectorIp: "10.0.0.1", flowListenPort: 2055, wgListenPort: 51820,
prefix: "10.0.0.0/24", publicEndpoint: "", hostPublicKey: "", hasHostPrivateKey: false,
hubServerId: null, retentionHours: 24, topN: 10, mapServiceMinSharePct: 1,
lastDatagramAt: null, lastExporterIp: null, lastError: null, packetsReceived: 0,
listenerBound: false, listenerAddress: null, peers: [],
}
: path === "/api/geoip" ? { ready: false, running: false, countryFile: "", asnFile: "", countryLoaded: false, asnLoaded: false, dir: "storage/geoip", settings: { enabled: false, updateIntervalSec: 86400, lastCheckAt: null, lastSuccessAt: null, lastError: null, countryBuildAt: null, asnBuildAt: null, updatedAt: "2026-09-14" } }
: path === "/api/scheduler/runs" ? { runs: [] }
: path.endsWith("/settings") || path.endsWith("/renew-settings") ? {
enabled: true, intervalSec: 300, retentionDays: 7, probeIntervalSec: 15, speedIntervalSec: 60,
renewBeforeDays: 30, scheduler: { jobs: [] },
} : {} })
})
await page.goto(path)
return calls
}
test("Speed probes: 12 записей и сортировка источника", async ({ page }) => {
await setup(page, "/probes")
await page.getByRole("button", { name: "Расписание", exact: true }).click()
const rows = page.locator("tr[data-row-id]")
await expect(rows).toHaveCount(12)
await page.getByRole("button", { name: "Источник", exact: true }).click()
await expect(rows.first()).toContainText("Источник 1")
await page.getByRole("button", { name: "Источник", exact: true }).click()
await expect(rows.first()).toContainText("Источник 12")
})
test("Сбор данных: все 11 задач и запуск выбранной задачи через API", async ({ page }) => {
const calls = await setup(page, "/data-collection")
const rows = page.locator("tr[data-row-id]")
await expect(rows).toHaveCount(11)
await expect(rows.last()).toContainText("Оповещения")
await page.getByRole("button", { name: "Запустить: Оповещения", exact: true }).click()
await expect.poll(() => calls).toContain("/api/scheduler/jobs/alert_engine/run-now")
await expect(rows).toHaveCount(11)
})
test("Демо-расписание: сортировка интервала и удаление выбранного правила", async ({ page }) => {
await page.addInitScript(() => localStorage.setItem("routerlists:data-source", "mock"))
await setup(page, "/probes")
await page.getByRole("button", { name: "Расписание", exact: true }).click()
const rows = page.locator("tr[data-row-id]")
await expect(rows).toHaveCount(3)
await page.getByRole("button", { name: "Интервал", exact: true }).click()
await expect(rows.first()).toHaveAttribute("data-row-id", "r3")
await rows.first().getByRole("button", { name: "Удалить правило", exact: true }).click()
await expect(rows).toHaveCount(2)
await expect(page.locator('tr[data-row-id="r3"]')).toHaveCount(0)
})