Files
RuneStone/tests/smoke/appearance/backgroundFrames.smoke.mjs
T
Knotty Wyvern 69f90df571 Move the smoke tests onto the shared harness
Each smoke test now uses tests/smoke/_harness/ for Playwright, the Tauri
IPC mock, the in-memory workspace, and output folders, instead of its
own copy. The tests keep their interactions and assertions. Mock
handlers that the app never calls are gone.

- Split the four mixed regression scripts into 18 feature tests.
- Update tests that broke when the app changed on purpose. Each update
  cites the app source that shows the new behavior.
- Mark two real app defects with @known-issue: the settings window
  controls are 1px shorter than the main window controls, and plugin
  tabs cannot be reordered by dragging without a workspace.
- Merge three palette unit tests into one table-driven test.
- The native tests load Playwright through the harness and read
  NATIVE_CDP_URL, with their old variable names as fallbacks.
- A failed smoke test saves a screenshot and prints the console errors.
- The runner runs failed tests once more, alone, and reports a test
  that then passes as flaky.

Result: 89 passed, 1 flaky, 2 known issues, 0 failed. Before, 45 of 78
passed.
2026-10-27 20:58:55 -07:00

140 lines
9.6 KiB
JavaScript

// Workarea backgrounds in both themes: splash, writer, reader, split, IDE, narrow layouts, fades, reduced motion, and removal.
import assert from 'node:assert/strict';
import { writeFile } from 'node:fs/promises';
import { mockTauri, openPage, outputDir, runSmoke, smokeUrl } from '../_harness/index.mjs';
const viewport = { width: 1280, height: 820 };
await runSmoke('appearance/backgroundFrames', async ({ browser }) => {
const output = await outputDir('appearance/backgroundFrames');
const report = [];
for (const theme of ['light', 'dark']) {
const page = await openPage(browser, { viewport });
await mockTauri(page, {
commands: test => ({
...test.workspace({
root: 'C:/background-test',
files: {
'welcome.md': '# Working notes\n\nKeep the image quiet behind readable text.\n\n## Next steps\n\n- Write a note\n- Review the code\n\n' + 'A paragraph with **bold text** and a [link](https://example.com).\n\n'.repeat(24),
'hello.ts': '// A focused code view\nexport function greet(name: string) {\n const message = `Hello ${name}`;\n return message;\n}\n',
},
}),
plugins_snapshot: () => ({ root: 'C:/background-test', plugins: [] }),
}),
});
await page.goto(smokeUrl);
await page.locator('.welcome-actions button').first().waitFor();
await page.getByText('background-test', { exact: true }).waitFor();
await page.evaluate(async theme => {
const { saveAppearance } = await import('/src/lib/theme/appearance.ts');
const { backgroundHub } = await import('/src/lib/plugins/backgrounds.ts');
const make = (first, second) => {
const canvas = document.createElement('canvas'); canvas.width = 1200; canvas.height = 800;
const ctx = canvas.getContext('2d'); const gradient = ctx.createLinearGradient(0, 0, 1200, 800);
gradient.addColorStop(0, first); gradient.addColorStop(1, second); ctx.fillStyle = gradient; ctx.fillRect(0, 0, 1200, 800);
ctx.strokeStyle = '#ffffff88'; ctx.lineWidth = 12;
for (let x = 0; x < 1400; x += 200) { ctx.beginPath(); ctx.moveTo(x, 0); ctx.lineTo(x - 300, 800); ctx.stroke(); }
return canvas.toDataURL();
};
const saved = make('#bd486c', '#438f67');
saveAppearance({ theme: 'default', mode: theme, newTabBackground: { image: saved, overlay: 0.15, position: 'center', size: 'cover' } });
const urls = await Promise.all([make('#bd486c', '#438f67'), make('#286f9b', '#725ea2')].map(async url => URL.createObjectURL(await (await fetch(url)).blob())));
window.backgroundTest = { hub: backgroundHub, owner: Symbol(), urls, saved, theme };
}, theme);
const background = page.locator('.workarea-background');
const style = (locator, property, pseudo) => locator.evaluate((node, [property, pseudo]) => getComputedStyle(node, pseudo)[property], [property, pseudo]);
async function openWelcome() {
await page.keyboard.press('Control+p');
await page.getByRole('textbox', { name: 'Find a file' }).fill('welcome');
await page.getByRole('dialog').getByRole('button').filter({ hasText: 'welcome.md' }).first().click();
}
assert.equal(await background.count(), 1);
assert.equal(await page.locator('.empty h1, .empty > p').count(), 0);
assert.equal(await style(page.locator('.empty'), 'backgroundImage'), 'none');
const bounds = await background.boundingBox();
assert.equal(bounds.x, 0); assert.equal(bounds.y, 36); assert.equal(bounds.width, 1280); assert.equal(bounds.height, 762);
assert.match(await style(background, 'backgroundImage'), /blob:/);
assert.match(await style(page.locator('.left'), 'backgroundColor'), /(?:0\.82|82%)/);
assert.match(await style(page.locator('.right'), 'backgroundColor'), /(?:0\.82|82%)/);
assert.match(await style(page.locator('.welcome-actions button').first(), 'backgroundColor'), /(?:0\.82|82%)/);
assert.doesNotMatch(await style(page.locator('header.header'), 'backgroundColor'), /(?:0\.82|82%)/);
await page.locator('.welcome-actions button').first().focus();
await page.keyboard.press('Tab');
assert(await page.locator('.welcome-actions').evaluate(node => node.contains(document.activeElement)));
await page.screenshot({ path: `${output}/${theme}-splash.png` });
await page.evaluate(() => {
const { hub, owner, urls } = window.backgroundTest;
hub.set(owner, 'app', { url: urls[0], blurredUrl: urls[1], overlay: 0.15, position: 'top', size: 'contain' });
});
assert.equal(await style(background, 'backgroundSize'), '100% 100%, contain, cover');
assert.equal(await style(background, 'backgroundPosition'), '50% 50%, 50% 0%, 50% 50%');
await page.screenshot({ path: `${output}/${theme}-portrait-layers.png` });
await page.setViewportSize({ width: 390, height: 700 });
assert.equal(await style(background, 'backgroundSize'), '100% 100%, contain, cover');
await page.screenshot({ path: `${output}/${theme}-portrait-layers-narrow.png` });
await page.setViewportSize(viewport);
await page.evaluate(() => {
const { hub, owner, urls } = window.backgroundTest;
hub.set(owner, 'app', { url: urls[1], overlay: 0.2, position: 'center', size: 'cover', previous: { url: urls[0], overlay: 0.15, position: 'center', size: 'cover' }, transitionMs: 2000 });
});
await page.waitForTimeout(180);
const opacity = Number(await style(background, 'opacity', '::after'));
assert(opacity > 0 && opacity < 1, `Fade has an intermediate opacity: ${opacity}`);
await page.waitForTimeout(900);
assert.ok(Number(await style(background, 'opacity', '::after')) < 1, 'The fade remains active after one second');
await page.waitForTimeout(1100);
assert.equal(await style(background, 'opacity', '::after'), '1');
await openWelcome();
await page.getByRole('textbox', { name: 'Writing editor', exact: true }).waitFor();
assert.match(await style(page.locator('.editor > .body'), 'backgroundColor'), /(?:0\.9|90%)/);
await page.screenshot({ path: `${output}/${theme}-writer.png` });
await page.getByRole('group', { name: 'Document view', exact: true }).hover();
await page.getByRole('button', { name: 'Read', exact: true }).click();
await page.locator('.md-page').waitFor();
const beforeScroll = await background.boundingBox();
await page.locator('.md-page').evaluate(node => { node.scrollTop = 600; });
assert.deepEqual(await background.boundingBox(), beforeScroll);
await page.screenshot({ path: `${output}/${theme}-reader.png` });
await page.getByRole('button', { name: 'Split', exact: true }).click();
await page.locator('.monaco-editor').waitFor();
assert.equal(await style(page.locator('.monaco-editor-background').first(), 'backgroundColor'), 'rgba(0, 0, 0, 0)');
await page.screenshot({ path: `${output}/${theme}-split.png` });
await page.getByRole('button', { name: 'Edit', exact: true }).click();
await page.getByRole('group', { name: 'Editor layout', exact: true }).hover();
await page.getByRole('button', { name: 'IDE', exact: true }).click();
await page.locator('.monaco-editor').waitFor();
await page.screenshot({ path: `${output}/${theme}-ide.png` });
await page.setViewportSize({ width: 680, height: 720 });
await page.getByRole('button', { name: 'Files', exact: true }).click();
await page.getByRole('button', { name: 'Hide outline', exact: true }).click();
await page.screenshot({ path: `${output}/${theme}-ide-narrow.png` });
await page.keyboard.press('Control+t');
await page.locator('.welcome-actions').waitFor();
await page.setViewportSize({ width: 480, height: 640 });
assert(await page.locator('.empty').evaluate(node => node.scrollWidth <= node.clientWidth));
await page.screenshot({ path: `${output}/${theme}-splash-narrow.png` });
await page.emulateMedia({ reducedMotion: 'reduce' });
await page.evaluate(() => { const { hub, owner, urls } = window.backgroundTest; hub.set(owner, 'app', { url: urls[0], overlay: 0.2, position: 'center', size: 'cover', previous: { url: urls[1], overlay: 0.2, position: 'center', size: 'cover' }, transitionMs: 2000 }); });
assert.equal(await background.evaluate(node => node.getAnimations().length), 0);
await page.evaluate(() => { const { hub, owner, urls } = window.backgroundTest; hub.removeOwner(owner); urls.forEach(URL.revokeObjectURL); });
assert.equal(await page.evaluate(() => document.body.style.getPropertyValue('--rs-background-previous-image')), '');
assert.match(await style(background, 'backgroundImage'), /blob:/);
await page.evaluate(async () => { const { saveAppearance } = await import('/src/lib/theme/appearance.ts'); saveAppearance({ theme: 'default', mode: window.backgroundTest.theme }); });
assert.equal(await style(background, 'backgroundImage'), 'none');
await openWelcome();
await page.locator('.editor > .body').waitFor();
assert.equal(await style(page.locator('.editor > .body'), 'backgroundColor'), await style(page.locator('.shell'), 'backgroundColor'));
await page.screenshot({ path: `${output}/${theme}-removed.png` });
assert.deepEqual(page.errors, []);
report.push({ theme, passed: ['saved image', 'continuous workarea', 'sidebar transparency', 'button-only splash', 'keyboard focus', 'writer', 'reader scrolling', 'split', 'IDE transparency', 'narrow layout', 'fade', 'reduced motion', 'slideshow removal', 'saved image removal'], screenshots: `${output}/${theme}-*.png`, nativeDesktop: 'not tested' });
await page.close();
console.log(`PASS: ${theme} workarea backgrounds, editors, keyboard, narrow layout, fade, and restoration`);
}
await writeFile(`${output}/report.json`, JSON.stringify(report, null, 2));
});