import { test, expect, type Page } from "@playwright/test" import { geoip } from "./fixtures/geoip" const common = { enabled: true, intervalSec: 300, retentionDays: 14, lastCollectedAt: null, lastDurationMs: 0, lastError: null } const values: Record = { "/api/traffic/settings": { ...common, intervalSec: 45 }, "/api/servers-api-ping/settings": { ...common, enabled: false, intervalSec: 120 }, "/api/uptime/settings": { ...common, resourcesEnabled: true, pingEnabled: false, speedEnabled: false, probeIntervalSec: 15, speedIntervalSec: 60 }, "/api/internet-path/settings": common, "/api/certificates/renew-settings": { enabled: false, intervalSec: 21600, renewBeforeDays: 30 }, } async function setup(page: 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/scheduler/status") return r.fulfill({ json: { jobs: [] } }) if (path === "/api/scheduler/runs") return r.fulfill({ json: { runs: [] } }) if (path === "/api/traffic/flow/settings") return r.fulfill({ json: { enabled: false, collectorIp: "10.255.254.1", flowListenPort: 4739, wgListenPort: 51821, prefix: "10.255.254.0/24", publicEndpoint: "", hostPublicKey: "", hasHostPrivateKey: false, hubServerId: null, retentionHours: 24, topN: 200, mapServiceMinSharePct: 5, lastDatagramAt: null, lastExporterIp: null, lastError: null, packetsReceived: 0, listenerBound: false, listenerAddress: null, peers: [] } }) if (values[path]) return r.fulfill({ json: values[path] }) return r.fulfill({ status: 503, json: { error: "outside settings fixture" } }) }) } for (const width of [1440, 390, 320]) test("GeoIP: адаптивность/" + width, async ({ page }) => { await page.setViewportSize({ width, height: 1000 }); await setup(page); await page.goto("/data-collection") const section = page.getByText("GeoIP-базы (GeoLite2)", { exact: true }).locator("xpath=ancestor::*[@data-slot='frame'][1]") await expect(page.getByRole("textbox", { name: "Интервал GeoIP в часах", exact: true })).toHaveValue("168") await section.scrollIntoViewIfNeeded() expect(await section.evaluate(element => element.scrollWidth <= element.clientWidth + 2)).toBe(true) expect(await page.evaluate(() => document.documentElement.scrollWidth <= window.innerWidth)).toBe(true) await page.screenshot({ path: "docs/ux-ui/screens/geoip-" + width + ".png", fullPage: true }) })