Files
MikrotikManager/tests/e2e/traffic-peer-warning.spec.ts

33 lines
2.5 KiB
TypeScript
Raw Permalink 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"
const at = new Date("2026-10-12T12:00:00Z")
async function setup(page: Page, state: "error" | "current" | "legacy", status = "online") {
let calls = 0
const observations = { rxNow: state === "current", txNow: state === "current", rxSeries: [false, true], txSeries: [false, true],
sampledAt: at.toISOString(), lastAttemptAt: at.toISOString(), lastSucceededAt: at.toISOString(),
expiresAt: new Date(at.getTime()+90_000).toISOString(), currentState: state === "legacy" ? "unknown" : state,
error: state === "error" ? "CHR: HTTP 401 — опрос не выполнен" : "Измерения WireGuard peers недоступны: HTTP 401" }
const server = { id: "1", name: "История CHR", site: "TEST", country: "RU", status,
rxNow: state === "current" ? 0 : 17, txNow: 0, rxPeak: 5, txPeak: 6, rxTotal: 1, txTotal: 2, sessions: 1,
rxSeries: [0,5], txSeries: [0,6], ...(state !== "legacy" ? {observations} : {}) }
await page.clock.install({time:at})
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.endsWith("/live")) return r.fulfill({status:503,json:{error:"Live недоступен"}})
if(path==="/api/traffic/servers")calls++
return r.fulfill({json:path==="/api/auth/config"?{required:false}:path==="/api/traffic/servers"?{servers:[server]}:
path==="/api/traffic/servers/1"?{server}:path.endsWith("/interfaces")||path==="/api/traffic/bound-interfaces"?{interfaces:[]}:
path==="/api/traffic/users"?{users:[]}:path==="/api/servers"?[]:{}})
})
await page.goto("/traffic")
await expect(page.getByRole("heading",{name:"История CHR",exact:true})).toBeVisible()
return ()=>calls
}
for(const width of[1440,320])test(`Ошибка peers сохраняет подтверждённые interface rates ${width}`,async({page})=>{
await page.setViewportSize({width,height:1000});await setup(page,"current")
await expect(page.getByRole("status").filter({hasText:"Часть измерений недоступна"})).toContainText("WireGuard peers недоступны: HTTP 401")
await expect(page.getByLabel("Скорость выбранного сервера").getByText("0 Кбит/с",{exact:true})).toHaveCount(2)
await expect(page.getByRole("region",{name:"История RX/TX"})).toBeVisible()
expect(await page.evaluate(()=>document.documentElement.scrollWidth<=innerWidth+1)).toBe(true)
})