Files
RuneStone/scripts/overlayPercentage.smoke.mjs
T

78 lines
4.2 KiB
JavaScript

import assert from 'node:assert/strict';
import { createRequire } from 'node:module';
import { mkdir, writeFile } from 'node:fs/promises';
const { chromium } = createRequire(import.meta.url)(process.env.PLAYWRIGHT_MODULE || 'playwright');
const browser = await chromium.launch({ headless: true, ...(process.env.CHROME_PATH ? { executablePath: process.env.CHROME_PATH } : { channel: 'chrome' }) });
const context = await browser.newContext({ viewport: { width: 1100, height: 780 } });
await context.addInitScript(() => {
window.isTauri = true;
let sequence = 0;
window.__TAURI_INTERNALS__ = {
metadata: { currentWindow: { label: 'main' }, currentWebview: { label: 'main' } },
transformCallback: () => ++sequence, unregisterCallback: () => {},
invoke: async command => {
if (command === 'plugins_snapshot') return { root: 'C:/plugins', plugins: [] };
if (command === 'plugin:window|is_maximized') return false;
if (command === 'plugin:event|listen') return ++sequence;
return null;
},
};
window.__TAURI_EVENT_PLUGIN_INTERNALS__ = { unregisterListener: () => {} };
});
const origin = process.env.SMOKE_URL || 'http://127.0.0.1:5187';
const settings = await context.newPage();
const errors = [];
settings.on('pageerror', error => errors.push(error.message));
await mkdir('output/round4-overlay', { recursive: true });
try {
await settings.goto(origin + '/?settingsWindow=true');
await settings.getByRole('button', { name: 'Appearance', exact: true }).click();
await settings.getByLabel('Background image file', { exact: true }).setInputFiles({
name: 'image.png', mimeType: 'image/png',
buffer: Buffer.from('iVBORw0KGgoAAAANSUhEUgAAAAEAAAABCAQAAAC1HAwCAAAAC0lEQVR42mP8/x8AAwMCAO+jM1sAAAAASUVORK5CYII=', 'base64'),
});
const input = settings.getByRole('spinbutton', { name: 'Image overlay percentage' });
const slider = settings.getByRole('slider', { name: 'Image overlay', exact: true });
const saved = () => settings.evaluate(() => JSON.parse(localStorage.getItem('runestone.appearance')).newTabBackground.overlay);
await input.fill('-37');
assert.equal(await slider.inputValue(), '-37');
assert.equal(await saved(), -0.37);
await settings.reload();
await settings.getByRole('button', { name: 'Appearance', exact: true }).click();
assert.equal(await input.inputValue(), '-37');
await input.fill('');
assert.equal(await saved(), -0.37);
await input.blur();
assert.equal(await input.inputValue(), '-37');
await input.fill('150');
await input.blur();
assert.equal(await input.inputValue(), '100');
assert.equal(await saved(), 1);
await slider.fill('24');
assert.equal(await input.inputValue(), '24');
assert.equal(await saved(), 0.24);
for (const mode of ['light', 'dark']) {
await settings.evaluate(async mode => {
const appearance = await import('/src/lib/theme/appearance.ts');
appearance.saveAppearance({ ...appearance.parseAppearance(localStorage.getItem(appearance.APPEARANCE_KEY)), mode });
window.dispatchEvent(new Event('focus'));
}, mode);
for (const width of [1100, 360]) {
await settings.setViewportSize({ width, height: 780 });
await input.focus();
assert.equal(await input.evaluate(node => node === document.activeElement), true);
assert.equal(await settings.locator('.content').evaluate(node => node.scrollWidth <= node.clientWidth + 1), true);
await settings.screenshot({ path: `output/round4-overlay/${mode}-${width}.png` });
}
}
assert.deepEqual(errors, []);
await writeFile('output/round4-overlay-report.json', JSON.stringify({
card: '2d1ae11e-8142-4840-bf0a-70f682e90e53',
hostChecks: ['Signed numeric entry and slider synchronization', 'Persistence after reload', 'Empty input retains saved value', 'Values clamp to -100 through 100', 'Both themes, keyboard focus, 360px and 1100px settings'],
shared: ['--rs-settings-control-height', '--rs-settings-gap', '--rs-control-radius'],
screenshotFolder: 'output/round4-overlay',
native: 'Native desktop acceptance remains pending.',
}, null, 2));
console.log('PASS: numeric overlay, slider, persistence, bounds, themes, narrow settings, keyboard focus.');
} finally { await browser.close(); }