36 lines
2.0 KiB
JavaScript
36 lines
2.0 KiB
JavaScript
const { chromium } = require('playwright');
|
|
const assert = require('node:assert/strict');
|
|
(async () => {
|
|
const browser = await chromium.launch({ executablePath: process.env.CHROMIUM_PATH });
|
|
try {
|
|
for (const standalone of [false, true]) {
|
|
const context = await browser.newContext({ viewport: { width: 1440, height: 1000 } });
|
|
if (standalone) await context.addInitScript(() => Object.defineProperty(navigator, 'standalone', { value: true }));
|
|
const page = await context.newPage();
|
|
for (const [surface, cardSelector, openLabel] of [['projects', '.project-card', 'Open'], ['dashboard', '.dashboard-book-card', 'Open Book']]) {
|
|
await page.goto(`http://127.0.0.1:5238/fixture?page=${surface}`);
|
|
const cards = page.locator(cardSelector);
|
|
assert.ok(await cards.count());
|
|
for (const card of await cards.all()) {
|
|
const cover = card.locator('a.cover-navigation');
|
|
const open = card.getByRole('link', { name: openLabel, exact: true });
|
|
const title = card.locator('h2 a, h3 a');
|
|
const href = await open.getAttribute('href');
|
|
assert.equal(await cover.getAttribute('href'), href);
|
|
assert.equal(await title.getAttribute('href'), href);
|
|
assert.equal(await cover.locator('a, button, form').count(), 0, 'No nested actions');
|
|
await cover.focus();
|
|
assert.equal(await cover.evaluate(node => node.matches(':focus-visible')), true);
|
|
assert.equal(await cover.evaluate(node => getComputedStyle(node).cursor), 'pointer');
|
|
await page.route('**' + href, route => route.fulfill({ body: '<p>Opened</p>' }));
|
|
await cover.press('Enter');
|
|
await page.waitForURL('**' + href);
|
|
await page.goBack();
|
|
}
|
|
}
|
|
await context.close();
|
|
}
|
|
console.log('PASS project/book covers, placeholders and titles share Open routes, keyboard focus and activation in browser/PWA');
|
|
} finally { await browser.close(); }
|
|
})().catch(error => { console.error(error); process.exitCode = 1; });
|