81 lines
6.0 KiB
JavaScript
81 lines
6.0 KiB
JavaScript
// Render the real wizard views with isolated models; never submit import forms.
|
|
const { chromium } = require('playwright');
|
|
const assert = require('node:assert/strict');
|
|
const fs = require('node:fs');
|
|
const base = process.env.PD_BROWSER_FIXTURE_URL || 'http://127.0.0.1:5238';
|
|
(async () => {
|
|
const installed = process.argv.includes('--installed');
|
|
const context = await chromium.launchPersistentContext(fs.mkdtempSync('/tmp/pd-onboarding-theme-'), {
|
|
headless: !installed, viewport: { width: 1440, height: 1100 }
|
|
});
|
|
try {
|
|
let page = context.pages()[0];
|
|
let writes = 0;
|
|
await context.route('**/hubs/**', r => r.abort());
|
|
await context.route('**/native-companion/status*', r => r.fulfill({ json: [] }));
|
|
await context.route('https://cdn.jsdelivr.net/**', r => r.abort());
|
|
await context.route('**/*', r => {
|
|
if (r.request().method() !== 'GET') {
|
|
if (/\/(onboarding|native-companion\/import|manuscript)\//.test(new URL(r.request().url()).pathname)) writes++;
|
|
return r.abort();
|
|
}
|
|
return r.fallback();
|
|
});
|
|
if (installed) {
|
|
await page.goto(base + '/onboarding-fixture/3');
|
|
const session = await context.browser().newBrowserCDPSession();
|
|
await session.send('PWA.install', { manifestId: base + '/Projects', installUrlOrBundleUrl: base + '/onboarding-fixture/3' });
|
|
await session.send('PWA.changeAppUserSettings', { manifestId: base + '/Projects', displayMode: 'standalone' });
|
|
const opened = context.waitForEvent('page');
|
|
await session.send('PWA.launch', { manifestId: base + '/Projects', url: base + '/onboarding-fixture/3' });
|
|
page = await opened;
|
|
await page.waitForLoadState();
|
|
assert(await page.evaluate(() => matchMedia('(display-mode: standalone)').matches));
|
|
}
|
|
for (const theme of ['warm-light', 'warm-dark', 'modern-light', 'modern-dark']) {
|
|
for (let step = 1; step <= 11; step++) {
|
|
const response = await page.goto(`${base}/onboarding-fixture/${step}`);
|
|
assert.equal(response.status(), 200, `step ${step}`);
|
|
await page.evaluate(theme => {
|
|
document.documentElement.dataset.appTheme = theme;
|
|
document.documentElement.dataset.theme = theme.endsWith('dark') ? 'dark' : 'light';
|
|
document.documentElement.dataset.bsTheme = theme.endsWith('dark') ? 'dark' : 'light';
|
|
}, theme);
|
|
assert(await page.locator('.onboarding-panel').isVisible());
|
|
assert((await page.locator('.onboarding-progress').innerText()).includes(`Step ${step} of 11`));
|
|
if (step === 3) {
|
|
const contrast = await page.locator('.onboarding-option-card strong, .onboarding-option-card small, .onboarding-option-card em, .onboarding-panel .btn-primary').evaluateAll(nodes => {
|
|
const canvas = document.createElement('canvas'), ctx = canvas.getContext('2d');
|
|
const rgba = value => { ctx.clearRect(0, 0, 1, 1); ctx.fillStyle = value; ctx.fillRect(0, 0, 1, 1); return [...ctx.getImageData(0, 0, 1, 1).data].map((v, i) => i === 3 ? v / 255 : v); };
|
|
const blend = (fg, bg) => fg.slice(0, 3).map((v, i) => v * fg[3] + bg[i] * (1 - fg[3]));
|
|
const background = el => !el ? [255, 255, 255] : blend(rgba(getComputedStyle(el).backgroundColor), background(el.parentElement));
|
|
const lum = rgb => rgb.map(v => { v /= 255; return v <= .04045 ? v / 12.92 : ((v + .055) / 1.055) ** 2.4; }).reduce((s, v, i) => s + v * [.2126, .7152, .0722][i], 0);
|
|
return nodes.map(el => { const a = lum(background(el)), b = lum(blend(rgba(getComputedStyle(el).color), background(el))); return { text: el.textContent.trim(), ratio: (Math.max(a, b) + .05) / (Math.min(a, b) + .05) }; });
|
|
});
|
|
for (const item of contrast) assert(item.ratio >= 4.5, `${theme}: ${item.text}: ${item.ratio}`);
|
|
const first = page.locator('.onboarding-option-card input').first();
|
|
const second = page.locator('.onboarding-option-card input').nth(1);
|
|
await page.keyboard.press('Tab');
|
|
await second.focus();
|
|
assert(await second.evaluate(el => el.matches(':focus-visible')));
|
|
assert.equal(await second.evaluate(el => getComputedStyle(el.nextElementSibling).outlineStyle), 'solid');
|
|
await second.press('Space');
|
|
assert(await second.isChecked());
|
|
assert(!(await first.isChecked()));
|
|
assert.notEqual(await first.evaluate(el => getComputedStyle(el.nextElementSibling).borderColor),
|
|
await second.evaluate(el => getComputedStyle(el.nextElementSibling).borderColor));
|
|
await page.locator('.onboarding-option-card').first().hover();
|
|
await page.waitForTimeout(180);
|
|
assert.notEqual(await first.evaluate(el => getComputedStyle(el.nextElementSibling).transform), 'none');
|
|
await first.evaluate(el => el.disabled = true);
|
|
assert.equal(await first.evaluate(el => getComputedStyle(el.nextElementSibling).borderTopStyle), 'dashed');
|
|
if (process.env.PD_THEME_SCREENSHOTS) await page.screenshot({ path: `${process.env.PD_THEME_SCREENSHOTS}/${theme}-${installed ? 'pwa' : 'browser'}.png` });
|
|
console.log(`PASS ${theme}: software text >=4.5:1; selection, keyboard focus, hover and disabled states`);
|
|
}
|
|
}
|
|
console.log(`PASS ${theme}: all 11 compiled wizard steps (${installed ? 'installed PWA' : 'browser'})`);
|
|
}
|
|
assert.equal(writes, 0, 'fixtures never post manuscript or onboarding changes');
|
|
} finally { await context.close(); }
|
|
})().catch(error => { console.error(error); process.exitCode = 1; });
|