Files
MikrotikManager/tests/e2e/backups-context.spec.ts
T

21 lines
2.0 KiB
TypeScript

import { test, expect } from "@playwright/test"
import { backup, setupBackups } from "./fixtures/backups"
const headers = { "access-control-allow-origin": "*", "access-control-allow-methods": "GET,POST,PUT,DELETE,OPTIONS", "access-control-allow-headers": "Content-Type,Authorization" }
for (const change of ["backend", "mode"]) for (const fails of [false, true]) test("Бэкапы: позднее чтение/" + change + "/" + fails, async ({ page }) => {
await setupBackups(page, headers)
let started = false, completed = false, release!: () => void; const gate = new Promise<void>(r => release = r)
await page.route("**/api/backups", async r => {
if (new URL(r.request().url()).port !== "8000") return r.fallback()
started = true; await gate
try { await r.fulfill(fails ? { headers, status: 503, json: { error: "СТАРАЯ ОШИБКА БЭКАПА" } } : { headers, json: [{ ...backup, filename: "СТАРЫЙ БЭКАП.rsc" }] }) } catch {} finally { completed = true }
})
await page.goto("/backups"); await expect.poll(() => started).toBe(true); await page.goto("/settings")
if (change === "backend") { const input = page.getByPlaceholder("http://localhost:8000"); await input.fill("http://localhost:8101"); await input.press("Enter") }
else await page.getByRole("button", { name: "Моковые", exact: true }).click()
await page.goto("/backups"); release(); await expect.poll(() => completed).toBe(true)
if (change === "backend") await expect(page.getByText(backup.filename, { exact: true })).toBeVisible()
else { await expect(page.getByText("Демонстрационные данные. Операции и сохранение недоступны.", { exact: true })).toBeVisible(); await expect(page.getByRole("button", { name: "Новый бэкап", exact: true }).first()).toBeDisabled() }
await expect(page.getByText("СТАРЫЙ БЭКАП.rsc", { exact: true })).toHaveCount(0)
await expect(page.getByText(/СТАРАЯ ОШИБКА БЭКАПА/)).toHaveCount(0)
})