144 lines
10 KiB
JavaScript
144 lines
10 KiB
JavaScript
// Workarea backgrounds in both themes: splash, writer, reader, split, Source, narrow layouts, fades, reduced motion, and removal.
|
|
// The saved image shows through the Background feature (src/lib/features/background/). The test also sets its own frames.
|
|
import assert from 'node:assert/strict';
|
|
import { writeFile } from 'node:fs/promises';
|
|
import { chooseView, mockTauri, openPage, outputDir, runSmoke, showSavedImage, 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' } });
|
|
// Decode the data URLs without fetch: the content security policy does not permit `data:` in connect-src.
|
|
const blob = url => new Blob([Uint8Array.from(atob(url.split(',')[1]), character => character.charCodeAt(0))], { type: 'image/png' });
|
|
const urls = [make('#bd486c', '#438f67'), make('#286f9b', '#725ea2')].map(url => URL.createObjectURL(blob(url)));
|
|
window.backgroundTest = { hub: backgroundHub, owner: Symbol(), urls, saved, theme };
|
|
}, theme);
|
|
await showSavedImage(page);
|
|
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 chooseView(page, 'Read');
|
|
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` });
|
|
// Split shows the Write editor beside Read.
|
|
await chooseView(page, 'Split');
|
|
await page.locator('.live-writer .cm-content').waitFor();
|
|
assert.equal(await style(page.locator('.live-writer .cm-editor').first(), 'backgroundColor'), 'rgba(0, 0, 0, 0)');
|
|
await page.screenshot({ path: `${output}/${theme}-split.png` });
|
|
await chooseView(page, 'Split');
|
|
await chooseView(page, 'Source');
|
|
await page.locator('.source-editor .cm-content').waitFor();
|
|
await page.screenshot({ path: `${output}/${theme}-ide.png` });
|
|
await page.setViewportSize({ width: 680, height: 720 });
|
|
// The side panes give way in a narrow window and come back in a wide one (src/lib/layout/Workbench.svelte).
|
|
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({ subtree: true }).length), 0);
|
|
await page.evaluate(() => { const { hub, owner, urls } = window.backgroundTest; hub.removeOwner(owner); urls.forEach(URL.revokeObjectURL); });
|
|
// The frame of Background (the saved image) shows again, without a fade.
|
|
assert.equal(await page.evaluate(() => document.body.style.getPropertyValue('--rs-background-previous-image')), 'none');
|
|
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 }); });
|
|
await page.waitForFunction(() => getComputedStyle(document.querySelector('.workarea-background')).backgroundImage === 'none');
|
|
assert.equal(await page.evaluate(() => document.body.style.getPropertyValue('--rs-background-image')), '', 'Without an image, the body has no background properties');
|
|
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', 'Source 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));
|
|
});
|