pcbjam/tests/e2e/dialog.spec.ts
Viktor Vaczi 26181bb929 Refactor test logging into shared utilities
- Extract common logging code to tests/e2e/utils/
  - fixtures.ts: Playwright fixture with automatic log capture
  - test-utils.ts: Logging utilities and helper functions
- Each test now automatically captures:
  - Console logs with timestamps and log levels
  - Page errors with full stack traces
- Log files written per test to tests/logs/
  - <test-name>.log for all console output
  - <test-name>.errors.log only when errors occur
- Update all 13 spec files to use shared fixtures
- Update README with test structure and logging docs
- Net reduction of ~700 lines by removing duplicated code

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude <noreply@anthropic.com>
2025-11-29 20:54:54 +01:00

107 lines
3.5 KiB
TypeScript

import { test, expect, MAIN_CANVAS, tryLoadApp, getCanvasBox } from './utils/fixtures';
test.describe('wxDialog/wxMessageBox Tests', () => {
test('Dialog test app loads successfully', async ({ page, testLogger }) => {
await page.goto('/standalone/dialog/dialog_test.html');
const loaded = await tryLoadApp(page);
await page.screenshot({ path: 'test-results/dialog-01-loaded.png', fullPage: true });
const hasStartupLog = testLogger.consoleLogs.some(log =>
log.includes('DIALOG_TEST') && log.includes('started successfully')
);
expect(loaded, 'Canvas should be visible').toBe(true);
expect(testLogger.errors.filter(e => !e.includes('favicon'))).toHaveLength(0);
});
test('Info dialog button can be clicked', async ({ page, testLogger }) => {
await page.goto('/standalone/dialog/dialog_test.html');
const loaded = await tryLoadApp(page);
if (!loaded) {
test.skip();
return;
}
const box = await getCanvasBox(page);
// Info Dialog button is first in the wxMessageBox row
const centerX = box.width / 2;
await page.mouse.click(box.x + centerX - 110, box.y + 115);
await page.waitForTimeout(500);
await page.screenshot({ path: 'test-results/dialog-02-info-clicked.png', fullPage: true });
const hasInfoEvent = testLogger.consoleLogs.some(log =>
log.includes('Opening Info dialog')
);
expect(hasInfoEvent, 'Info dialog should open').toBe(true);
});
test('Yes/No dialog button can be clicked', async ({ page, testLogger }) => {
await page.goto('/standalone/dialog/dialog_test.html');
const loaded = await tryLoadApp(page);
if (!loaded) {
test.skip();
return;
}
const box = await getCanvasBox(page);
// Yes/No Dialog button is second (center) in the wxMessageBox row
const centerX = box.width / 2;
await page.mouse.click(box.x + centerX, box.y + 115);
await page.waitForTimeout(500);
await page.screenshot({ path: 'test-results/dialog-03-yesno-clicked.png', fullPage: true });
const hasYesNoEvent = testLogger.consoleLogs.some(log =>
log.includes('Opening Yes/No dialog')
);
expect(hasYesNoEvent, 'Yes/No dialog should open').toBe(true);
});
test('Error dialog button can be clicked', async ({ page, testLogger }) => {
await page.goto('/standalone/dialog/dialog_test.html');
const loaded = await tryLoadApp(page);
if (!loaded) {
test.skip();
return;
}
const box = await getCanvasBox(page);
// Error Dialog button is third (rightmost) in the wxMessageBox row
const centerX = box.width / 2;
await page.mouse.click(box.x + centerX + 110, box.y + 115);
await page.waitForTimeout(500);
await page.screenshot({ path: 'test-results/dialog-04-error-clicked.png', fullPage: true });
const hasErrorEvent = testLogger.consoleLogs.some(log =>
log.includes('Opening Error dialog')
);
expect(hasErrorEvent, 'Error dialog should open').toBe(true);
});
test('Custom dialog button can be clicked', async ({ page, testLogger }) => {
await page.goto('/standalone/dialog/dialog_test.html');
const loaded = await tryLoadApp(page);
if (!loaded) {
test.skip();
return;
}
const box = await getCanvasBox(page);
// Custom Dialog button is first in the wxDialog row (row 2)
const centerX = box.width / 2;
await page.mouse.click(box.x + centerX - 60, box.y + 175);
await page.waitForTimeout(500);
await page.screenshot({ path: 'test-results/dialog-05-custom-clicked.png', fullPage: true });
expect(true).toBe(true);
});
});