import { chromium } from "playwright"; import assert from "node:assert/strict"; import { mkdir, writeFile } from "node:fs/promises"; import { concepts } from "../concepts/registry.js"; const base = process.env.BASE_URL || "http://127.0.0.1:4173"; const executablePath = process.env.PLAYWRIGHT_EXECUTABLE_PATH || (process.platform === "win32" ? "C:/Program Files (x86)/Microsoft/Edge/Application/msedge.exe" : undefined); const browser = await chromium.launch({ executablePath, headless: true }); const context = await browser.newContext({ acceptDownloads: true }); const page = await context.newPage(); page.setDefaultTimeout(8000); const errors = [], failures = [], cases = []; page.on("pageerror", (e) => errors.push(e.message)); await mkdir("test-results/screenshots", { recursive: true }); const url = (c, p = "dashboard", theme = "light", locale = "ru") => `${base}/playground/frame.html?${new URLSearchParams({ concept: c, page: p, theme, locale })}`; async function check(name, fn) { try { await fn(); cases.push({ name, status: "pass" }); } catch (e) { failures.push({ name, error: e.message }); console.log("FAIL", name, e.message); } } try { await check("HTTP root and gallery", async () => { const r = await page.goto(base); assert.equal(r.status(), 200); await page.locator("#concepts button").first().waitFor(); assert.equal(await page.locator("#concepts button").count(), 6); await page.frameLocator("#preview-a").locator("h1").waitFor(); await page.screenshot({ path: "references/gallery.png", fullPage: true }); }); for (const c of concepts) for (const theme of ["light", "dark"]) for (const [device, width, height] of [ ["desktop", 1440, 900], ["tablet", 768, 1024], ["mobile", 390, 844], ]) { await page.setViewportSize({ width, height }); for (const p of [ "dashboard", "users", "settings", "auth", "components", "tokens", ]) { await check(`${c.id}/${theme}/${device}/${p}`, async () => { await page.goto(url(c.id, p, theme)); await page.locator("h1").waitFor(); const overflow = await page.evaluate(() => ({ scroll: document.documentElement.scrollWidth, client: document.documentElement.clientWidth, })); assert.ok( overflow.scroll <= overflow.client + 1, JSON.stringify(overflow), ); if ( p === "dashboard" || (device === "desktop" && theme === "light" && ["users", "settings", "auth"].includes(p)) ) await page.screenshot({ path: `test-results/screenshots/${c.id}-${theme}-${device}-${p}.png`, fullPage: true, }); if (p === "dashboard") { await page.locator("[data-action=invite]").first().click(); assert.ok(await page.locator("#dialog").evaluate((d) => d.open)); if (device === "desktop") await page.screenshot({ path: `test-results/screenshots/${c.id}-${theme}-modal.png`, }); await page.keyboard.press("Escape"); assert.equal( await page.locator("#dialog").evaluate((d) => d.open), false, ); } }); } } await page.setViewportSize({ width: 1280, height: 900 }); await check( "User search, filter, pagination, sorting, empty state", async () => { await page.goto(url("relay", "users")); await page.locator("#user-search").fill("anna"); assert.equal(await page.locator("tbody tr").count(), 1); await page.locator("#user-search").fill("no-such-person"); await page.locator("[data-action=clear-filters]").click(); await page.locator("[data-action=next]").click(); assert.equal(await page.locator("tbody tr").count(), 3); await page.locator("#role-filter").selectOption("admin"); assert.equal(await page.locator("tbody tr").count(), 2); await page.locator("[data-sort=name]").click(); await page.locator("[data-action=reset-users]").click(); }, ); await check("Invite validation, creation, duplicate detection", async () => { await page.locator("[data-action=invite]:visible").click(); await page.locator("#invite-form input[name=name]").fill("Test Member"); await page .locator("#invite-form input[name=email]") .fill("test@example.com"); await page.locator("#invite-form button[type=submit]").click(); await page.locator("#user-search").fill("test@example.com"); assert.equal(await page.locator("tbody tr").count(), 1); await page.locator("[data-action=invite]:visible").click(); await page.locator("#invite-form input[name=name]").fill("Duplicate"); await page .locator("#invite-form input[name=email]") .fill("test@example.com"); await page.locator("#invite-form button[type=submit]").click(); assert.ok(await page.locator("#invite-error").innerText()); await page.keyboard.press("Escape"); }); await check("Edit, selection and confirmed bulk suspension", async () => { await page.locator("[data-edit]").first().click(); await page.locator("#edit-user select[name=role]").selectOption("admin"); await page.locator("#edit-user button[type=submit]").click(); await page.locator("[data-select]").first().check(); await page.locator("[data-action=bulk-suspend]").click(); await page.locator("[data-action=confirm-suspend]").click(); assert.match(await page.locator("tbody").innerText(), /Заблокирован/); await page.locator("[data-action=reset-users]").click(); }); await check("Settings persistence and keyboard tabs", async () => { await page.goto(url("grid", "settings")); await page.locator("input[name=name]").fill("Anidev Test"); await page.locator("#settings-form button[type=submit]").click(); await page.reload(); assert.equal( await page.locator("input[name=name]").inputValue(), "Anidev Test", ); await page.locator("#tab-general").focus(); await page.keyboard.press("ArrowRight"); assert.equal( await page.locator("#tab-security").getAttribute("aria-selected"), "true", ); await page.locator("#mfa").uncheck(); await page.locator("#settings-form button[type=submit]").click(); await page.reload(); await page.locator("#tab-security").click(); assert.equal(await page.locator("#mfa").isChecked(), false); }); await check("Auth native validation and demo sign in", async () => { await page.goto(url("axis", "auth")); await page.locator("input[name=email]").fill("test@example.com"); await page.locator("input[name=password]").fill("short"); await page.locator("#auth-form button[type=submit]").click(); assert.equal(await page.locator("#auth-form").count(), 1); await page.locator("input[name=password]").fill("long-password"); await page.locator("#auth-form button[type=submit]").click(); await page.locator("#identity-profile").waitFor(); }); await check("Command palette keyboard and modal focus trap", async () => { await page.keyboard.press("Control+k"); await page.locator("#command-search").fill("Пользователи"); await page.keyboard.press("Enter"); await page.locator("#user-search").waitFor(); await page.locator("[data-action=invite]:visible").click(); for (let i = 0; i < 12; i++) await page.keyboard.press("Tab"); assert.equal( await page.evaluate(() => document.activeElement.closest("dialog")?.id), "dialog", ); await page.keyboard.press("Escape"); assert.equal( await page .locator("[data-action=invite]:visible") .evaluate((e) => e === document.activeElement), true, ); }); await check( "Drawer, dropdown, tooltip, context menu and recovery states", async () => { await page.goto(url("dock", "components")); await page.locator("[data-action=drawer]").click(); assert.match( await page.locator("#dialog").getAttribute("class"), /drawer/, ); await page.keyboard.press("Escape"); await page.locator("details:not(.chart-data) > summary").click(); await page.locator("[data-action=rename]").click(); await page.keyboard.press("Escape"); await page.locator(".tooltip-wrap button").focus(); assert.equal(await page.locator(".tooltip").isVisible(), true); await page.locator(".context-target").focus(); await page.keyboard.press("Shift+F10"); await page.locator(".context-menu").waitFor(); await page.keyboard.press("ArrowDown"); await page.keyboard.press("Enter"); await page.locator("dialog.drawer").waitFor(); await page.keyboard.press("Escape"); await page.locator("[data-action=retry]").click(); assert.match( await page.locator(".error-state").innerText(), /Журнал загружен/, ); }, ); await check("EN localization for each screen and concept", async () => { for (const c of concepts) for (const p of [ "dashboard", "users", "settings", "auth", "components", "tokens", ]) { await page.goto(url(c.id, p, "dark", "en")); await page.locator("h1").waitFor(); assert.equal(await page.locator("html").getAttribute("lang"), "en"); const text = await page.locator("body").innerText(); assert.equal( /[А-Яа-яЁё]/.test(text), false, `${c.id}/${p}: Russian text in EN`, ); } }); await check( "Gallery controls, comparison and actual mobile viewport", async () => { await page.goto(base); await page.locator("[data-concept=ledger]").click(); await page.locator("#theme").selectOption("dark"); await page.locator("#density").selectOption("compact"); await page.locator("#page").selectOption("users"); await page.locator("[data-size=mobile]").click(); await page.locator("#compare").check(); await page.locator("#second").selectOption("signal"); await page.frameLocator("#preview-b").locator("#user-search").waitFor(); assert.equal( await page .frameLocator("#preview-a") .locator("body") .getAttribute("data-concept"), "ledger", ); assert.ok( await page.locator("#preview-a").evaluate((e) => e.clientWidth <= 390), ); await page.locator("#accent").fill("#ffcc00"); await page.locator("#accent").dispatchEvent("change"); await page.frameLocator("#preview-a").locator("h1").waitFor(); }, ); await check("Mobile navigation and density variants", async () => { await page.setViewportSize({ width: 390, height: 844 }); for (const c of concepts) { await page.goto(url(c.id)); await page .locator( c.id === "dock" ? "[data-action=dock-toggle]" : "[data-action=mobile-menu]", ) .click(); await page.locator(".nav-links [data-page=users]").click(); await page.locator("#user-search").waitFor(); for (const density of ["compact", "relaxed"]) { await page.goto(url(c.id, "settings") + "&density=" + density); await page.locator("h1").waitFor(); assert.ok( await page.evaluate( () => document.documentElement.scrollWidth <= innerWidth + 1, ), ); } } await page.setViewportSize({ width: 1280, height: 900 }); await page.goto(base); await page.locator("[data-concept=ledger]").click(); }); await check("Export archive download", async () => { const download = page.waitForEvent("download"); await page.locator("#export").click(); const d = await download; await d.saveAs("test-results/anidev-export.zip"); assert.match(d.suggestedFilename(), /anidev-ledger.zip/); }); await check("Gallery mobile overflow", async () => { await page.setViewportSize({ width: 390, height: 844 }); await page.goto(base); await page.locator("#concepts button").first().waitFor(); assert.ok( await page.evaluate( () => document.documentElement.scrollWidth <= innerWidth + 1, ), ); await page.screenshot({ path: "test-results/screenshots/gallery-mobile.png", fullPage: true, }); }); await check("No runtime errors", async () => assert.deepEqual(errors, [])); } finally { await writeFile( "test-results/report.json", JSON.stringify( { date: new Date().toISOString(), browser: await browser.version(), passed: cases.length, failed: failures.length, cases, failures, errors, }, null, 2, ), ); await context.close(); await browser.close(); } console.log(`Browser QA: ${cases.length} passed, ${failures.length} failed`); if (failures.length) process.exitCode = 1;