const { test, expect } = require('@playwright/test'); const { pathToFileURL } = require('node:url'); const { readFileSync } = require('node:fs'); const path = require('node:path'); // Phase P3/T3.6: the strictly-HTML simple report must open via file:// with zero console // errors, keep its CSS-only sticky header pinned on scroll, and pass an axe-core scan // with zero violations. The parity fixture (no disharmonies) exercises the empty state; // the Kotlin fixture report (generated by SampleReportGenerationTest) exercises the // fully-populated page with tables and the CSS-only sticky thead. const PARITY_REPORT_PATH = path.resolve( __dirname, '..', '..', 'target', 'e2e', 'refactor-first-report.simple.html', ); const KOTLIN_REPORT_PATH = path.resolve( __dirname, '..', '..', 'target', 'e2e', 'refactor-first-report.kt.simple.html', ); function loadAxeSource() { return readFileSync(require.resolve('axe-core/axe.min.js'), 'utf8'); } async function openReport(page, reportPath) { const consoleErrors = []; page.on('console', (message) => { if (message.type() === 'error') { consoleErrors.push(message.text()); } }); page.on('pageerror', (error) => consoleErrors.push(String(error))); const response = await page.goto(pathToFileURL(reportPath).href); expect(response.status()).toBe(200); return consoleErrors; } test.describe('simple report', () => { test('empty-state report opens via file:// with zero console errors and zero axe violations', async ({ page, }) => { const consoleErrors = await openReport(page, PARITY_REPORT_PATH); // The empty state renders exactly one h1 and no section tables await expect(page.getByRole('heading', { level: 1 })).toContainText('RefactorFirst'); await expect(page.getByRole('navigation')).toHaveCount(0); expect(consoleErrors).toEqual([]); await page.addScriptTag({ content: loadAxeSource() }); const results = await page.evaluate(() => axe.run(document)); expect(results.violations).toEqual([]); }); test('populated report pins its sticky header and table headers on scroll', async ({ page }) => { const consoleErrors = await openReport(page, KOTLIN_REPORT_PATH); expect(consoleErrors).toEqual([]); // CSS-only sticky contract: header and thead th are position: sticky const header = page.locator('header.rf-header'); await expect(header).toBeVisible(); expect(await header.evaluate((el) => getComputedStyle(el).position)).toBe('sticky'); const firstColumnHeader = page.locator('thead th').first(); await expect(firstColumnHeader).toBeVisible(); expect(await firstColumnHeader.evaluate((el) => getComputedStyle(el).position)).toBe('sticky'); // Scrolling leaves the header pinned to the viewport top await page.evaluate(() => window.scrollBy(0, 800)); await page.waitForTimeout(100); const box = await header.boundingBox(); expect(box.y).toBeLessThanOrEqual(1); }); test('populated report passes an axe-core scan with zero violations', async ({ page }) => { await openReport(page, KOTLIN_REPORT_PATH); await page.addScriptTag({ content: loadAxeSource() }); const results = await page.evaluate(() => axe.run(document)); expect(results.violations).toEqual([]); }); });