import assert from 'node:assert/strict'; import { mkdtemp, readFile, writeFile } from 'node:fs/promises'; import { tmpdir } from 'node:os'; import { join } from 'node:path'; import { fileURLToPath } from 'node:url'; import { chromium } from 'playwright'; import { expect } from '@playwright/test'; import { createFixtureServer, openFixture } from './browser-fixture.mjs'; const root = fileURLToPath(new URL('../../', import.meta.url)); const artifacts = await mkdtemp(join(tmpdir(), 'passport-evoke-')); const entry = 'src/tests/passport-evoke-fixture/index.html'; const server = await createFixtureServer({ root, artifacts, entry }); let browser; try { browser = await chromium.launch({ headless: true, args: ['--no-sandbox'] }); for (const width of [1440, 390]) for (const theme of ['light', 'dark']) { const page = await browser.newPage({ viewport: { width, height: 1000 } }); page.on('dialog', dialog => dialog.accept()); const issue = page.getByRole('button', { name: 'Выдать паспорт', exact: true }); const fixture = await openFixture({ server, page, entry: `${entry}?theme=${theme}`, ready: issue }); const input = page.getByRole('textbox', { name: 'Сообщение', exact: true }); await page.getByLabel('Основная инструкция').fill('Unsaved instructions'); await input.fill('Draft @'); await expect(page.getByRole('button', { name: /Human/ })).toHaveCSS('box-shadow', 'rgb(161, 98, 7) 4px 0px 0px 0px inset'); await issue.click(); await expect(page.getByRole('button', { name: 'Паспорт выдан', exact: true })).toBeDisabled(); await expect(input).toHaveValue('Draft @'); await input.fill('Draft @audit'); await expect(page.getByText('Нет совпадений по запросу «@audit»')).toBeVisible(); await page.getByRole('button', { name: 'Изменить участие в спейсе' }).click(); await input.fill('Draft @'); await input.fill('Draft @audit'); const choice = page.getByRole('button', { name: /Quality Reviewer/ }).filter({ hasText: 'AI Agent' }); await expect(choice).toHaveCSS('box-shadow', 'rgb(15, 118, 110) 4px 0px 0px 0px inset'); await expect(choice).toContainText('🔍'); await input.press('Enter'); await expect(input).toHaveValue('Draft <<@audit-reviewer>> '); await expect(page.getByRole('button', { name: /@audit-reviewer/ })).toContainText('🔍'); await expect(page.getByLabel('Основная инструкция')).toHaveValue('Unsaved instructions'); await page.getByRole('button', { name: 'Действия: Quality Reviewer' }).click(); await page.getByRole('menuitem', { name: 'Отозвать паспорт' }).click(); await expect(issue).toBeEnabled(); await page.getByRole('button', { name: 'Изменить участие в спейсе' }).click(); await input.fill('Draft @audit'); await expect(page.getByText('Нет совпадений по запросу «@audit»')).toBeVisible(); await page.getByRole('button', { name: 'Сбой следующей выдачи' }).click(); await issue.click(); await expect(page.getByRole('alert')).toContainText('Fixture issuance unavailable'); await expect(input).toHaveValue('Draft @audit'); await input.press('Escape'); await page.getByRole('button', { name: 'Действия: Quality Reviewer' }).click(); await page.getByRole('menuitem', { name: 'Выдать паспорт' }).click(); await expect(page.getByRole('button', { name: 'Паспорт выдан', exact: true })).toBeDisabled(); await expect(page.getByRole('alert')).toHaveCount(0); await input.fill('Draft @'); await input.fill('Draft @audit'); await expect(page.getByText('Нет совпадений по запросу «@audit»')).toBeVisible(); await page.getByRole('button', { name: 'Изменить участие в спейсе' }).click(); await input.fill('Draft @'); await expect(choice).toBeVisible(); await page.addScriptTag({ content: await readFile(join(root, 'node_modules/axe-core/axe.min.js'), 'utf8') }); const audit = await page.evaluate(async () => (await window.axe.run(document, { runOnly: { type: 'tag', values: ['wcag2a', 'wcag2aa', 'wcag21aa'] } })).violations); await writeFile(join(artifacts, `${width}-${theme}-axe.json`), JSON.stringify(audit, null, 2)); assert.deepEqual(audit.map(({ id, nodes }) => ({ id, targets: nodes.map(node => node.target) })), []); assert.equal(await page.evaluate(() => document.documentElement.scrollWidth > innerWidth), false); await page.screenshot({ path: join(artifacts, `${width}-${theme}.png`), fullPage: true }); await input.press('Escape'); await expect(choice).toHaveCount(0); await fixture.assertStable(); process.stdout.write(`${width} ${theme}: issue/revoke/retry, live picker, handle, draft, stripes, keyboard, axe PASS\n`); await page.close(); } } finally { await browser?.close(); await server.close(); process.stdout.write(`Artifacts: ${artifacts}\n`); }