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("Сбор данных: адаптивность/" + width, async ({ page }) => { await page.setViewportSize({ width, height: 1000 }); await setup(page) await page.goto("/data-collection"); await expect(page.getByTestId("settings-traffic")).toContainText("настройки получены") await expect(page.getByRole("textbox", { name: "Интервал: Трафик", exact: true })).toHaveValue("45") expect(await page.evaluate(() => document.documentElement.scrollWidth <= window.innerWidth)).toBe(true) await page.getByRole("button", { name: "Обновить", exact: true }).scrollIntoViewIfNeeded() await page.screenshot({ path: "docs/ux-ui/screens/data-collection-" + width + ".png", fullPage: true }) await page.getByRole("button", { name: "Сохранить настройки планировщика" }).scrollIntoViewIfNeeded() await expect(page.getByRole("textbox", { name: "Хранение трафика", exact: true })).toBeVisible() await page.screenshot({ path: "docs/ux-ui/screens/data-collection-settings-" + width + ".png", fullPage: true }) })