Make Background a native feature
- Background replaces the Background Slideshow plugin and the background image of Appearance. It shows a folder as a slideshow, or one image. - It is on by default. Its module loads at launch only when a folder or an image is chosen. - Rust keeps the one folder in background-folder.json. The interface never sends a path. Eight background_* commands replace the six deprecated backgrounds_* commands. - The first start moves the slideshow folder and settings, and keeps the saved image as the image source. - One blur worker with a cache, fewer folder reads, and a decode before each fade. The hub writes only the changed properties. - Remove the deprecated folder methods of api.backgrounds. set, get, and subscribe stay for the Project Management plugin. - Show the view buttons in the workbench test without text, after UI-056. - Update the tests, the measurement tool, the docs, and UI-057.
This commit is contained in:
@@ -88,6 +88,18 @@ export async function chooseView(scope, name) {
|
||||
return scope.getByRole("radiogroup", { name: "View", exact: true }).getByRole("radio", { name, exact: true }).click();
|
||||
}
|
||||
|
||||
/**
|
||||
* Select the image source of Background, so that the saved image of `appearance.newTabBackground` shows
|
||||
* (src/lib/features/backgroundSettings.ts). Call it after the test saves an image. It waits until the frame is on the body.
|
||||
*/
|
||||
export async function showSavedImage(page) {
|
||||
await page.evaluate(async () => {
|
||||
const { readBackground, writeBackground } = await import("/src/lib/features/backgroundSettings.ts");
|
||||
await writeBackground({ ...readBackground(), source: "image" });
|
||||
});
|
||||
await page.waitForFunction(() => document.body.style.getPropertyValue("--rs-background-image").includes("blob:"));
|
||||
}
|
||||
|
||||
/**
|
||||
* Mock the Tauri IPC layer before the app loads. The mock handles the event plugin.
|
||||
*
|
||||
@@ -195,7 +207,7 @@ function installMock(options, commands) {
|
||||
if (target !== pageId) channel.postMessage({ event, payload, target });
|
||||
};
|
||||
const SETTINGS_FILE = "runestone.smoke.settings-file", TRANSFERS = "runestone.smoke.tab-transfers";
|
||||
const SECTIONS = ["general", "appearance", "customThemes", "customThemesLegacy", "language", "features"];
|
||||
const SECTIONS = ["general", "appearance", "customThemes", "customThemesLegacy", "language", "features", "background"];
|
||||
const readJson = (key, fallback) => { try { return JSON.parse(localStorage.getItem(key)) ?? fallback; } catch { return fallback; } };
|
||||
const settingsFile = () => readJson(SETTINGS_FILE, null);
|
||||
const snapshot = () => {
|
||||
@@ -227,6 +239,9 @@ function installMock(options, commands) {
|
||||
features_legacy: () => [],
|
||||
// The editor asks for the Git line of the cursor while the Git feature is on. Tests of Git replace it.
|
||||
git_blame: () => null,
|
||||
// src-tauri/src/backgrounds.rs: the host has no background folder. Tests of the Background folder replace these.
|
||||
background_folder: () => null,
|
||||
background_migrate: () => null,
|
||||
settings_migrate: ({ sections }) => {
|
||||
if (!settingsFile()) localStorage.setItem(SETTINGS_FILE, JSON.stringify({ schema: 1, revision: 1, ...sections }));
|
||||
return snapshot();
|
||||
|
||||
@@ -1,7 +1,8 @@
|
||||
// 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, smokeUrl } from '../_harness/index.mjs';
|
||||
import { chooseView, mockTauri, openPage, outputDir, runSmoke, showSavedImage, smokeUrl } from '../_harness/index.mjs';
|
||||
|
||||
const viewport = { width: 1280, height: 820 };
|
||||
|
||||
@@ -43,6 +44,7 @@ await runSmoke('appearance/backgroundFrames', async ({ browser }) => {
|
||||
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() {
|
||||
@@ -120,12 +122,14 @@ await runSmoke('appearance/backgroundFrames', async ({ browser }) => {
|
||||
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);
|
||||
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); });
|
||||
assert.equal(await page.evaluate(() => document.body.style.getPropertyValue('--rs-background-previous-image')), '');
|
||||
// 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 }); });
|
||||
assert.equal(await style(background, 'backgroundImage'), 'none');
|
||||
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'));
|
||||
|
||||
@@ -4,7 +4,9 @@ import { writeFile } from 'node:fs/promises';
|
||||
import path from 'node:path';
|
||||
import { mockTauri, openPage, outputDir, runSmoke, smokeUrl } from '../_harness/index.mjs';
|
||||
|
||||
// The image is painted on .workarea-background, not on the empty tab (src/lib/layout/Workbench.svelte:1258, 1543).
|
||||
// The image is painted on .workarea-background, not on the empty tab (src/lib/theme/background.css).
|
||||
// Background (src/lib/features/background/) loads after the first render, so each check waits for the image.
|
||||
const waitForImage = page => page.waitForFunction(() => getComputedStyle(document.querySelector('.workarea-background')).backgroundImage.includes('blob:'));
|
||||
|
||||
await runSmoke('appearance/backgroundImages', async ({ browser }) => {
|
||||
const output = await outputDir('appearance/backgroundImages');
|
||||
@@ -50,7 +52,7 @@ await runSmoke('appearance/backgroundImages', async ({ browser }) => {
|
||||
await main.waitForFunction(() => getComputedStyle(document.querySelector('.workarea-background')).backgroundImage.includes('blob:'));
|
||||
let url = await background();
|
||||
assert.equal(await decoded(main, url), 700, 'The actual new-tab image decodes');
|
||||
await main.reload(); await main.locator('.empty').waitFor();
|
||||
await main.reload(); await main.locator('.empty').waitFor(); await waitForImage(main);
|
||||
url = await background(); assert.equal(await decoded(main, url), 700, 'The saved image survives reload');
|
||||
|
||||
const pixel = Buffer.from('iVBORw0KGgoAAAANSUhEUgAAAAEAAAABCAQAAAC1HAwCAAAAC0lEQVR42mP8/x8AAwMCAO+jM1sAAAAASUVORK5CYII=', 'base64');
|
||||
@@ -60,8 +62,7 @@ await runSmoke('appearance/backgroundImages', async ({ browser }) => {
|
||||
await main.waitForFunction(old => /url\("(blob:[^"]+)"\)/.exec(getComputedStyle(document.querySelector('.workarea-background')).backgroundImage)?.[1] !== old, url);
|
||||
url = await background(); assert.equal(await decoded(main, url), 1, '50 MiB image decodes');
|
||||
assert.ok(await settings.evaluate(() => JSON.stringify(window.__TEST__.settings('appearance')).length < 500), 'Image bytes stay outside the settings file');
|
||||
await main.reload(); await main.locator('.empty').waitFor();
|
||||
await main.waitForFunction(() => getComputedStyle(document.querySelector('.workarea-background')).backgroundImage.includes('blob:'));
|
||||
await main.reload(); await main.locator('.empty').waitFor(); await waitForImage(main);
|
||||
url = await background(); assert.equal(await decoded(main, url), 1, '50 MiB image survives reload');
|
||||
|
||||
const acceptedId = await savedImageId();
|
||||
|
||||
@@ -4,7 +4,8 @@ import { writeFile } from 'node:fs/promises';
|
||||
import path from 'node:path';
|
||||
import { mockTauri, openPage, outputDir, runSmoke, smokeUrl } from '../_harness/index.mjs';
|
||||
|
||||
// The image is painted on .workarea-background, not on the empty tab (src/lib/layout/Workbench.svelte:1258, 1543).
|
||||
// The image is painted on .workarea-background, not on the empty tab (src/lib/theme/background.css).
|
||||
// The controls are in Appearance → Background (src/lib/features/background/BackgroundSettings.svelte).
|
||||
await runSmoke('appearance/backgroundLayout', async ({ browser }) => {
|
||||
const output = await outputDir('appearance/backgroundLayout');
|
||||
const context = await browser.newContext({ viewport: { width: 1100, height: 780 } });
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
// The empty tab background image: set it in Settings, keep it after a reload, remove it, and leave Reset background disabled.
|
||||
// The empty tab background image: set it in Settings, keep it after a reload, and remove it. The source stays Image.
|
||||
import assert from "node:assert/strict";
|
||||
import path from "node:path";
|
||||
import { mockTauri, openPage, outputDir, runSmoke, smokeUrl } from "../_harness/index.mjs";
|
||||
@@ -24,13 +24,14 @@ await runSmoke(name, async ({ browser }) => {
|
||||
await settings.goto(smokeUrl + "/?settingsWindow=true");
|
||||
await settings.getByRole("button", { name: "Appearance", exact: true }).click();
|
||||
const png = Buffer.from("iVBORw0KGgoAAAANSUhEUgAAAAEAAAABCAQAAAC1HAwCAAAAC0lEQVR42mP8/x8AAwMCAO+jM1sAAAAASUVORK5CYII=", "base64");
|
||||
// The image now lives on the work area layer behind the empty tab (src/lib/layout/Workbench.svelte:1258, :1543-1549).
|
||||
// The image lives on the work area layer behind the empty tab (src/lib/theme/background.css).
|
||||
const layer = ".workarea-background";
|
||||
await settings.getByLabel("Background image file", { exact: true }).setInputFiles({ name: "test.png", mimeType: "image/png", buffer: png });
|
||||
await page.waitForFunction(layer => getComputedStyle(document.querySelector(layer)).backgroundImage.includes("blob:"), layer);
|
||||
assert.equal(await page.evaluate(() => window.__TEST__.settings("background").source), "image", "A chosen image selects the image source");
|
||||
await page.reload();
|
||||
await page.locator(".empty").waitFor();
|
||||
assert.ok(await page.locator(layer).evaluate(node => getComputedStyle(node).backgroundImage.includes("blob:")), "Background survives restart");
|
||||
await page.waitForFunction(layer => getComputedStyle(document.querySelector(layer)).backgroundImage.includes("blob:"), layer);
|
||||
await settings.getByRole("button", { name: "Remove image", exact: true }).click();
|
||||
await page.waitForFunction(layer => getComputedStyle(document.querySelector(layer)).backgroundImage === "none", layer);
|
||||
for (const mode of ["light", "dark"]) {
|
||||
@@ -42,8 +43,10 @@ await runSmoke(name, async ({ browser }) => {
|
||||
await settings.setViewportSize({ width: 650, height: 760 });
|
||||
await settings.screenshot({ path: path.join(output, `appearance-${mode}-narrow.png`) });
|
||||
}
|
||||
assert.equal(await settings.getByRole("button", { name: "Reset background", exact: true }).isDisabled(), true);
|
||||
assert.equal(await settings.getByRole("button", { name: "Reset background", exact: true }).count(), 0);
|
||||
assert.equal(await settings.getByRole("button", { name: "Background source", exact: true }).innerText(), "Image");
|
||||
assert.equal(await settings.getByRole("button", { name: "Choose image…", exact: true }).count(), 1);
|
||||
await page.waitForFunction(() => !window.__TEST__.settings("appearance").newTabBackground);
|
||||
assert.deepEqual([...page.errors, ...settings.errors], []);
|
||||
console.log("PASS: background image applies, survives a reload, and is removed; Reset background is disabled");
|
||||
console.log("PASS: background image applies, survives a reload, and is removed; the image source stays selected");
|
||||
});
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
// Theme variants: transparency slider in eight variants, custom theme fonts, a single tooltip, and slideshow command icons.
|
||||
// Theme variants: transparency slider in eight variants, custom theme fonts, a single tooltip, plugin command icons,
|
||||
// and the native Background commands in the command palette.
|
||||
import assert from 'node:assert/strict';
|
||||
import path from 'node:path';
|
||||
import { mockTauri, openPage, outputDir, runSmoke, smokeUrl } from '../_harness/index.mjs';
|
||||
@@ -53,13 +54,21 @@ await runSmoke('appearance/themeVariants', async ({ browser }) => {
|
||||
const main = await openPage(context); await main.goto(smokeUrl);
|
||||
await main.bringToFront();
|
||||
await main.getByRole('button', { name: 'Files', exact: true }).waitFor();
|
||||
// The commands of the native Background feature (src/lib/features/catalog.ts) are in the command palette, without the feature code.
|
||||
await main.keyboard.press('Control+Shift+P');
|
||||
const palette = main.getByRole('dialog', { name: 'Commands', exact: true });
|
||||
await palette.getByRole('textbox', { name: 'Find a command', exact: true }).fill('background');
|
||||
for (const title of ['Next background image', 'Pause background']) await palette.getByRole('button').filter({ hasText: title }).first().waitFor();
|
||||
assert.equal(await main.evaluate(async () => (await import('/src/lib/features/loader.ts')).featureRequested('background')), false, 'The palette lists the commands without the feature code');
|
||||
await main.keyboard.press('Escape');
|
||||
// A third-party plugin with command icons. The Commands menu lists plugin commands only (src/lib/plugins/PluginAccessMenu.svelte).
|
||||
await main.evaluate(async () => {
|
||||
const loaded = performance.getEntriesByType('resource').map(entry => entry.name).find(name => new URL(name).pathname === '/src/lib/plugins/external.ts');
|
||||
const { pluginTools, refreshPlugins } = await import(loaded || '/src/lib/plugins/external.ts');
|
||||
await refreshPlugins();
|
||||
const invoke = window.__TAURI_INTERNALS__.invoke;
|
||||
window.__TAURI_INTERNALS__.invoke = (command, args) => command === 'plugins_snapshot' ? Promise.resolve(null) : invoke(command, args);
|
||||
const commands = [{ owner: 'runestone.background-slideshow', id: 'next-image', title: 'Next background image', kind: 'command', surface: 'commands', icon: 'skip-forward' }, { owner: 'runestone.background-slideshow', id: 'pause-resume', title: 'Pause or resume background slideshow', kind: 'command', surface: 'commands', icon: 'pause' }];
|
||||
const commands = [{ owner: 'org.test.slideshow', id: 'next-image', title: 'Next test image', kind: 'command', surface: 'commands', icon: 'skip-forward' }, { owner: 'org.test.slideshow', id: 'pause-resume', title: 'Pause or resume test slideshow', kind: 'command', surface: 'commands', icon: 'pause' }];
|
||||
pluginTools.set(commands);
|
||||
});
|
||||
const visibleTooltips = () => main.locator('[role=tooltip]:visible').count();
|
||||
@@ -77,7 +86,7 @@ await runSmoke('appearance/themeVariants', async ({ browser }) => {
|
||||
await button.click(); await main.getByRole('menu').waitFor();
|
||||
const paths = await main.locator('.rs-menu svg').evaluateAll(nodes => nodes.map(node => node.innerHTML));
|
||||
assert(paths.some(path => path.includes('M7 4v16'))); assert(paths.some(path => path.includes('m4 4 12 8')));
|
||||
await main.screenshot({ path: path.join(output, `${mode}-slideshow-command-icons.png`) }); await main.keyboard.press('Escape');
|
||||
await main.screenshot({ path: path.join(output, `${mode}-plugin-command-icons.png`) }); await main.keyboard.press('Escape');
|
||||
}
|
||||
assert.deepEqual([...page.errors, ...main.errors], []);
|
||||
console.log('PASS: eight theme variants, slider endpoints, persistence, disabled states, narrow layout, font import/export, single tooltip, and command icons.');
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
// Tab tooltips, translucent text selection, zero-transparency backgrounds, a stable transparency slider, and the themed install checkbox.
|
||||
import assert from "node:assert/strict";
|
||||
import path from "node:path";
|
||||
import { mockTauri, outputDir, runSmoke, smokeUrl } from "../_harness/index.mjs";
|
||||
import { mockTauri, outputDir, runSmoke, showSavedImage, smokeUrl } from "../_harness/index.mjs";
|
||||
|
||||
await runSmoke("appearance/tooltipsAndSelection", async ({ page }) => {
|
||||
const output = await outputDir("appearance/tooltipsAndSelection");
|
||||
@@ -35,6 +35,7 @@ await runSmoke("appearance/tooltipsAndSelection", async ({ page }) => {
|
||||
const { saveAppearance } = await import("/src/lib/theme/appearance.ts");
|
||||
saveAppearance({ theme: "default", mode, transparency: { enabled: true, amount: 0 }, newTabBackground: { image: "data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAAEAAAABCAQAAAC1HAwCAAAAC0lEQVR42mP8/x8AAwMCAO+jM1sAAAAASUVORK5CYII=" } });
|
||||
}, mode);
|
||||
await showSavedImage(page);
|
||||
const tab = page.getByRole("tab", { name: /welcome\.md/ });
|
||||
assert.equal(await tab.getAttribute("title"), null);
|
||||
await page.mouse.move(600, 600);
|
||||
@@ -50,9 +51,10 @@ await runSmoke("appearance/tooltipsAndSelection", async ({ page }) => {
|
||||
const writer = page.getByRole("textbox", { name: "Writing editor", exact: true });
|
||||
await writer.click(); await page.keyboard.press("Control+a");
|
||||
const colors = await writer.evaluate(node => {
|
||||
const root = getComputedStyle(document.documentElement);
|
||||
const root = getComputedStyle(document.documentElement), body = getComputedStyle(document.body);
|
||||
// Background sets the image and the surfaces on the body (src/lib/plugins/backgrounds.ts).
|
||||
return { selection: root.getPropertyValue("--rs-selection"), bg: getComputedStyle(node, "::selection").backgroundColor,
|
||||
text: getComputedStyle(node).color, image: root.getPropertyValue("--rs-new-tab-image"), pluginBg: root.getPropertyValue("--rs-workarea-plugin-bg") };
|
||||
text: getComputedStyle(node).color, image: body.getPropertyValue("--rs-background-image"), pluginBg: body.getPropertyValue("--rs-workarea-plugin-bg") };
|
||||
});
|
||||
assert.match(colors.selection.trim(), /^#[0-9a-f]{6}a6$/i);
|
||||
assert.match(colors.bg, /0\.65/);
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
// Editor menu surfaces: Writer, spelling, Source, and code menus share the file menu styles; and the code tint match in both themes.
|
||||
import assert from "node:assert/strict";
|
||||
import { chooseView, mockTauri, outputDir, runSmoke, smokeUrl } from "../_harness/index.mjs";
|
||||
import { chooseView, mockTauri, outputDir, runSmoke, showSavedImage, smokeUrl } from "../_harness/index.mjs";
|
||||
|
||||
await runSmoke("editor/surfaces", async ({ page }) => {
|
||||
await mockTauri(page, {
|
||||
@@ -42,6 +42,7 @@ await runSmoke("editor/surfaces", async ({ page }) => {
|
||||
c.fillStyle = g; c.fillRect(0, 0, 800, 600);
|
||||
saveAppearance({ theme: 'default', mode, newTabBackground: { image: canvas.toDataURL(), overlay: .15, position: 'center', size: 'cover' } });
|
||||
}, theme);
|
||||
await showSavedImage(page);
|
||||
await page.locator('[data-tree-rel="a.md"]').click({ button: 'right' });
|
||||
const reference = await styles(menu('File actions'));
|
||||
await dismiss();
|
||||
|
||||
@@ -0,0 +1,212 @@
|
||||
// The native Background feature (src/lib/features/background/): a folder slideshow with mocked host commands, a fade,
|
||||
// reduced motion, Next and Pause from the command palette, the targets, menus at 92% with an image and opaque with
|
||||
// Background off, a browser window, the settings section in both themes and at 360 pixels, the image source,
|
||||
// and the first-start migration from seeded plugin settings and from a seeded image.
|
||||
import assert from "node:assert/strict";
|
||||
import { readFile } from "node:fs/promises";
|
||||
import path from "node:path";
|
||||
import { mockTauri, openPage, outputDir, repoRoot, runSmoke, smokeUrl } from "../_harness/index.mjs";
|
||||
|
||||
const SETTINGS_FILE = "runestone.smoke.settings-file";
|
||||
const PNG = "iVBORw0KGgoAAAANSUhEUgAAAAEAAAABCAQAAAC1HAwCAAAAC0lEQVR42mP8/x8AAwMCAO+jM1sAAAAASUVORK5CYII=";
|
||||
|
||||
/**
|
||||
* The host commands of the image folder (src-tauri/src/backgrounds.rs). Each image is a PNG of one color.
|
||||
* The mock runs this function in the page, so it uses only `test`. `test.state.legacy` is an old plugin package.
|
||||
*/
|
||||
function folderCommands(test) {
|
||||
const snapshot = { profiles: [{ id: "user", name: "User" }], tabs: [], bookmarks: [], settings: { search: "duckduckgo", adblock: true, linkDestination: "internal", personalRules: "", homepage: "", filterLists: [] } };
|
||||
return {
|
||||
...test.workspace({ root: "C:\\background-feature", files: { "note.md": "# Note\n\nText." } }),
|
||||
plugins_snapshot: () => ({ root: "C:/plugins", plugins: [] }),
|
||||
"plugin:window|is_maximized": () => false,
|
||||
spelling_menu_install: () => null,
|
||||
spelling_menu_uninstall: () => null,
|
||||
background_folder: () => test.state.folder,
|
||||
background_choose_folder: () => test.state.folder,
|
||||
background_clear_folder: () => { test.state.folder = null; return null; },
|
||||
background_list: () => test.state.names,
|
||||
background_read: async ({ name }) => {
|
||||
const [width, height] = name.startsWith("portrait") ? [300, 600] : [640, 400];
|
||||
const canvas = new OffscreenCanvas(width, height);
|
||||
const context = canvas.getContext("2d");
|
||||
context.fillStyle = test.state.colors[name] ?? "#808080"; context.fillRect(0, 0, width, height);
|
||||
return (await canvas.convertToBlob({ type: "image/png" })).arrayBuffer();
|
||||
},
|
||||
background_read_sidecar: () => test.state.sidecar,
|
||||
background_write_sidecar: ({ contents, expected }) => {
|
||||
if (expected !== test.state.sidecar) throw "The sidecar file changed. Read it again before you save.";
|
||||
test.state.sidecar = contents;
|
||||
return null;
|
||||
},
|
||||
background_migrate: () => test.state.folder,
|
||||
features_legacy: ({ ids }) => test.state.legacy ? ids.filter(id => id === test.state.legacy.id).map(() => test.state.legacy) : [],
|
||||
browser_connect: () => "background-session",
|
||||
browser_stop: () => null,
|
||||
browser_request: () => structuredClone(snapshot),
|
||||
};
|
||||
}
|
||||
|
||||
const folderState = { folder: "D:\\Backgrounds", names: ["a.png", "b.png", "portrait.png"], colors: { "a.png": "#3a6ea5", "b.png": "#a5533a", "portrait.png": "#4f8a4b" }, sidecar: null };
|
||||
const image = page => page.evaluate(() => document.body.style.getPropertyValue("--rs-background-image"));
|
||||
const waitForChange = (page, old) => page.waitForFunction(old => { const value = document.body.style.getPropertyValue("--rs-background-image"); return value.includes("blob:") && value !== old; }, old, { timeout: 15000 });
|
||||
async function command(page, title) {
|
||||
await page.keyboard.press("Control+Shift+P");
|
||||
const palette = page.getByRole("dialog", { name: "Commands", exact: true });
|
||||
await palette.getByRole("textbox", { name: "Find a command", exact: true }).fill(title);
|
||||
await palette.getByRole("button").filter({ hasText: title }).first().waitFor();
|
||||
await page.keyboard.press("Enter");
|
||||
}
|
||||
async function menuBackground(page) {
|
||||
await page.locator('[data-tree-rel="note.md"]').click({ button: "right" });
|
||||
const menu = page.getByRole("menu", { name: "File actions", exact: true });
|
||||
await menu.waitFor();
|
||||
const color = await menu.evaluate(node => getComputedStyle(node).backgroundColor);
|
||||
await page.keyboard.press("Escape");
|
||||
return color;
|
||||
}
|
||||
|
||||
await runSmoke("features/background", async ({ browser }) => {
|
||||
const output = await outputDir("features/background");
|
||||
|
||||
// A folder slideshow of 2 seconds, from a settings file that exists before the start.
|
||||
const context = await browser.newContext({ viewport: { width: 1200, height: 820 } });
|
||||
await mockTauri(context, { state: folderState, commands: folderCommands });
|
||||
await context.addInitScript(([key, file]) => { if (!localStorage.getItem(key)) localStorage.setItem(key, JSON.stringify(file)); }, [SETTINGS_FILE, {
|
||||
schema: 1, revision: 1, features: { git: true, background: true },
|
||||
background: { source: "folder", seconds: 2, order: "name", paused: false, targets: ["app"], overlay: 0.1, position: "center", size: "cover" },
|
||||
}]);
|
||||
const main = await openPage(context);
|
||||
await main.goto(smokeUrl);
|
||||
await main.locator('[data-tree-rel="note.md"]').waitFor();
|
||||
await waitForChange(main, "");
|
||||
const first = await image(main);
|
||||
assert.match(first, /rgba\(0,0,0,0\.1\)/, "The folder overlay applies");
|
||||
|
||||
// The timer shows the next image with a fade of 2 seconds.
|
||||
await waitForChange(main, first);
|
||||
assert.equal(await main.locator(".workarea-background").evaluate(node => node.getAnimations({ subtree: true }).length), 1, "The image fades in");
|
||||
assert.notEqual(await main.evaluate(() => document.body.style.getPropertyValue("--rs-background-previous-image")), "none");
|
||||
await main.screenshot({ path: path.join(output, "folder-fade.png") });
|
||||
|
||||
// Pause keeps the image. Next still works. The same command resumes.
|
||||
await command(main, "Pause background");
|
||||
await main.waitForFunction(() => window.__TEST__.settings("background").paused === true);
|
||||
const paused = await image(main);
|
||||
await main.waitForTimeout(3000);
|
||||
assert.equal(await image(main), paused, "A paused slideshow keeps its image");
|
||||
await command(main, "Next background image");
|
||||
await waitForChange(main, paused);
|
||||
// The folder has a portrait image after b.png. It shows in full over a blurred fill.
|
||||
await main.waitForFunction(() => document.body.style.getPropertyValue("--rs-background-layer-sizes") === "100% 100%, contain, cover", null, { timeout: 15000 });
|
||||
await main.screenshot({ path: path.join(output, "portrait.png") });
|
||||
await command(main, "Pause background");
|
||||
await main.waitForFunction(() => window.__TEST__.settings("background").paused === false);
|
||||
|
||||
// Reduced motion: the next image shows without a fade.
|
||||
await main.emulateMedia({ reducedMotion: "reduce" });
|
||||
const before = await image(main);
|
||||
await command(main, "Next background image");
|
||||
await waitForChange(main, before);
|
||||
assert.equal(await main.locator(".workarea-background").evaluate(node => node.getAnimations({ subtree: true }).length), 0, "Reduced motion has no fade");
|
||||
await main.emulateMedia({ reducedMotion: "no-preference" });
|
||||
|
||||
// With an image, menus are at least 92% opaque and blur it (UI-043).
|
||||
assert.match(await menuBackground(main), /0\.92/);
|
||||
|
||||
// Targets: only the boards removes the workspace frame. The frame of all boards stays for Project Management.
|
||||
await main.evaluate(() => window.__TEST__.writeSettings("background", { ...window.__TEST__.settings("background"), targets: ["pm-all"] }));
|
||||
await main.waitForFunction(() => document.body.style.getPropertyValue("--rs-background-image") === "");
|
||||
assert.equal(await main.evaluate(async () => !!(await import("/src/lib/plugins/backgrounds.ts")).backgroundHub.get("pm-all")), true);
|
||||
assert.match(await menuBackground(main), /^rgb\(/, "Without a workspace image, menus are opaque");
|
||||
await main.evaluate(() => window.__TEST__.writeSettings("background", { ...window.__TEST__.settings("background"), targets: ["app"] }));
|
||||
await waitForChange(main, "");
|
||||
|
||||
// A browser window shows the background behind a blank tab, and calls only the commands that browser.json grants.
|
||||
const browserPage = await openPage(context);
|
||||
await mockTauri(browserPage, { label: "browser-background", state: folderState, commands: folderCommands });
|
||||
await browserPage.goto(smokeUrl + "/?browserWindow=true");
|
||||
await browserPage.getByRole("application", { name: "RuneStone browser" }).waitFor();
|
||||
assert.equal(await browserPage.evaluate(() => window.__TEST__.label), "browser-background");
|
||||
await browserPage.waitForFunction(() => getComputedStyle(document.querySelector(".workarea-background")).backgroundImage.includes("blob:"), null, { timeout: 15000 });
|
||||
await browserPage.screenshot({ path: path.join(output, "browser-window.png") });
|
||||
const granted = new Set(JSON.parse(await readFile(path.join(repoRoot, "src-tauri/capabilities/browser.json"), "utf8")).permissions);
|
||||
const calls = await browserPage.evaluate(() => [...new Set(window.__TEST__.calls.map(call => call.command))]);
|
||||
for (const call of calls.filter(name => name.startsWith("background_"))) assert(granted.has(`allow-${call.replaceAll("_", "-")}`), `browser.json grants ${call}`);
|
||||
assert(calls.includes("background_read"), "The browser window reads the folder images");
|
||||
await browserPage.close();
|
||||
|
||||
// The settings section in both themes and at 360 pixels.
|
||||
const settings = await openPage(context);
|
||||
await settings.goto(`${smokeUrl}/?settingsWindow=true`);
|
||||
await settings.getByRole("button", { name: "Appearance", exact: true }).click();
|
||||
const section = settings.locator(".background-settings");
|
||||
await section.waitFor();
|
||||
assert.equal(await settings.getByRole("button", { name: "Background source", exact: true }).innerText(), "Folder");
|
||||
assert.equal(await settings.getByRole("textbox", { name: "Image folder", exact: true }).inputValue(), "D:\\Backgrounds");
|
||||
await settings.getByRole("status").filter({ hasText: "3 images." }).waitFor();
|
||||
assert.equal(await settings.evaluate(async () => (await import("/src/lib/features/loader.ts")).featureRequested("background")), true, "The section loads the feature module");
|
||||
assert.equal(await settings.evaluate(() => document.body.style.getPropertyValue("--rs-background-image")), "", "The slideshow does not run in the settings window");
|
||||
await settings.locator("summary").filter({ hasText: "Per-image appearance" }).click();
|
||||
await settings.getByRole("button", { name: "Image fit", exact: true }).waitFor();
|
||||
await settings.waitForFunction(() => !document.querySelector('button[aria-label="Image fit"]').disabled);
|
||||
for (const theme of ["dark", "light"]) {
|
||||
await settings.evaluate(async mode => { const { saveAppearance, readAppearance } = await import("/src/lib/theme/appearance.ts"); saveAppearance({ ...readAppearance(), theme: "default", mode }); }, theme);
|
||||
for (const width of [1100, 360]) {
|
||||
// A tall window shows the whole section, also the targets below the per-image editor.
|
||||
await settings.setViewportSize({ width, height: 1800 });
|
||||
await section.scrollIntoViewIfNeeded();
|
||||
assert.equal(await settings.locator(".content").evaluate(node => node.scrollWidth <= node.clientWidth + 1), true, `No horizontal scroll at ${width} pixels`);
|
||||
await section.screenshot({ path: path.join(output, `settings-${theme}-${width}.png`) });
|
||||
}
|
||||
}
|
||||
await settings.setViewportSize({ width: 1100, height: 900 });
|
||||
// The per-image editor saves only the changed values of the selected image.
|
||||
await settings.getByRole("button", { name: "Image fit", exact: true }).click();
|
||||
await settings.getByRole("menuitemradio", { name: "Fit", exact: true }).click();
|
||||
await settings.getByRole("button", { name: "Save image appearance", exact: true }).click();
|
||||
await settings.getByRole("status").filter({ hasText: "Image appearance saved." }).waitFor();
|
||||
assert.deepEqual(JSON.parse(await settings.evaluate(() => window.__TEST__.state.sidecar)), { schema: 1, images: { "a.png": { fit: "contain" } } });
|
||||
|
||||
// Off applies at once in every window: the image goes away, and menus are opaque again.
|
||||
await settings.getByRole("button", { name: "Features", exact: true }).click();
|
||||
await settings.getByRole("switch", { name: "Background", exact: true }).click();
|
||||
await main.waitForFunction(() => document.body.style.getPropertyValue("--rs-background-image") === "");
|
||||
assert.match(await menuBackground(main), /^rgb\(/, "With Background off, menus are opaque");
|
||||
await settings.getByRole("button", { name: "Appearance", exact: true }).click();
|
||||
await settings.getByText("Background is off. Turn it on in Settings → Features.", { exact: true }).waitFor();
|
||||
await settings.screenshot({ path: path.join(output, "settings-off.png") });
|
||||
await settings.getByRole("button", { name: "Features", exact: true }).click();
|
||||
await settings.getByRole("switch", { name: "Background", exact: true }).click();
|
||||
await waitForChange(main, "");
|
||||
assert.deepEqual([...main.errors, ...settings.errors], []);
|
||||
await context.close();
|
||||
|
||||
// The image source and the migration from a seeded image: the old image of Appearance shows without a timer.
|
||||
const imageContext = await browser.newContext({ viewport: { width: 1000, height: 700 } });
|
||||
await mockTauri(imageContext, { commands: test => ({ ...test.workspace({ root: "C:\\background-image", files: { "note.md": "# Note" } }), plugins_snapshot: () => ({ root: "C:/plugins", plugins: [] }) }) });
|
||||
await imageContext.addInitScript(image => { if (!localStorage.getItem("runestone.smoke.settings-file")) localStorage.setItem("runestone.appearance", JSON.stringify({ theme: "default", mode: "dark", newTabBackground: { image, overlay: 0.2, position: "top", size: "contain" } })); }, `data:image/png;base64,${PNG}`);
|
||||
const imagePage = await openPage(imageContext);
|
||||
await imagePage.goto(smokeUrl);
|
||||
await waitForChange(imagePage, "");
|
||||
assert.deepEqual(await imagePage.evaluate(() => window.__TEST__.settings("background")), { source: "image", seconds: 60, order: "name", paused: false, targets: ["app"], overlay: 0, position: "center", size: "cover" });
|
||||
assert.equal(await imagePage.evaluate(() => document.body.style.getPropertyValue("--rs-background-position")), "top", "The image keeps its own layout");
|
||||
assert.equal(await imagePage.evaluate(() => window.__TEST__.calls.some(call => call.command === "background_migrate")), false, "Without a plugin grant, no folder migrates");
|
||||
assert.deepEqual(imagePage.errors, []);
|
||||
await imageContext.close();
|
||||
|
||||
// The migration from the kept settings of an enabled Background Slideshow plugin.
|
||||
const migrationContext = await browser.newContext({ viewport: { width: 1000, height: 700 } });
|
||||
const legacy = { id: "runestone.bg-slideshow", installed: true, enabled: true,
|
||||
settings: { grant: "6f0c7a8e-5b1d-4c2e-9a3f-2d7b8e1c4a90", folder: "D:\\Old", enabled: true, seconds: 7, order: "random", targets: ["app", "pm-all"], overlay: 0.3, position: "top", size: "contain" } };
|
||||
await mockTauri(migrationContext, { state: { ...folderState, folder: "D:\\Old", legacy }, commands: folderCommands });
|
||||
const migrated = await openPage(migrationContext);
|
||||
await migrated.goto(smokeUrl);
|
||||
await waitForChange(migrated, "");
|
||||
assert.deepEqual(await migrated.evaluate(() => window.__TEST__.settings("background")), { source: "folder", seconds: 7, order: "random", paused: false, targets: ["app", "pm-all"], overlay: 0.3, position: "top", size: "contain" });
|
||||
assert.deepEqual(await migrated.evaluate(() => window.__TEST__.settings("features")), { git: true, background: true });
|
||||
assert.equal(await migrated.evaluate(() => window.__TEST__.calls.filter(call => call.command === "background_migrate").length), 1);
|
||||
assert.deepEqual(migrated.errors, []);
|
||||
await migrationContext.close();
|
||||
console.log("PASS: folder slideshow, fade, pause and next, portrait fill, reduced motion, menus, targets, browser window, settings section, off switch, image source, and migrations.");
|
||||
});
|
||||
@@ -20,7 +20,7 @@ await runSmoke("features/settings", async ({ browser }) => {
|
||||
const sourceControl = main.locator(".header-left").getByRole("button", { name: "Source control", exact: true });
|
||||
await sourceControl.waitFor();
|
||||
// Without an old package, the migration stores the default of each feature.
|
||||
assert.deepEqual(await main.evaluate(() => window.__TEST__.settings("features")), { git: true });
|
||||
assert.deepEqual(await main.evaluate(() => window.__TEST__.settings("features")), { git: true, background: true });
|
||||
|
||||
const settings = await openPage(context, { timeout: 10000 });
|
||||
await settings.goto(`${smokeUrl}/?settingsWindow=true`);
|
||||
@@ -33,7 +33,7 @@ await runSmoke("features/settings", async ({ browser }) => {
|
||||
|
||||
await git.click();
|
||||
await sourceControl.waitFor({ state: "detached" });
|
||||
assert.deepEqual(await main.evaluate(() => window.__TEST__.settings("features")), { git: false });
|
||||
assert.deepEqual(await main.evaluate(() => window.__TEST__.settings("features")), { git: false, background: true });
|
||||
assert.equal(await settings.getByRole("status").innerText(), "Changes saved.");
|
||||
await git.focus();
|
||||
await settings.keyboard.press("Space");
|
||||
|
||||
@@ -137,10 +137,10 @@ await runSmoke("layout/workbench", async ({ page }) => {
|
||||
window.__TEST__.emit("workspace-event", { root: window.__TEST__.root, kind: "create", paths: ["reader-showcase.md"] });
|
||||
}, showcase);
|
||||
await quickOpen("reader-showcase.md");
|
||||
// Each view choice shows an icon and its name. The tooltip adds the shortcut (src/lib/layout/ViewModes.svelte).
|
||||
// Each view choice shows only an icon (UI-056). The accessible name and the tooltip give its name and shortcut (src/lib/layout/ViewModes.svelte).
|
||||
const read = page.getByRole("radiogroup", { name: "View", exact: true }).getByRole("radio", { name: "Read", exact: true });
|
||||
const readTip = page.getByRole("tooltip").filter({ hasText: "Read (Ctrl+Shift+E)" });
|
||||
assert.equal(await read.innerText(), "Read");
|
||||
assert.equal(await read.innerText(), "");
|
||||
assert.equal(await read.locator("svg").count(), 1);
|
||||
await read.hover();
|
||||
await readTip.waitFor({ state: "visible" });
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
// Shared menu design: styles, themes, icons, disabled rows, focus return, submenus, spelling menus, scrolling, and viewport edges.
|
||||
import assert from "node:assert/strict";
|
||||
import path from "node:path";
|
||||
import { mockTauri, outputDir, runSmoke, smokeUrl } from "../_harness/index.mjs";
|
||||
import { mockTauri, outputDir, runSmoke, showSavedImage, smokeUrl } from "../_harness/index.mjs";
|
||||
|
||||
await runSmoke("menus/consistency", async ({ page }) => {
|
||||
const output = await outputDir("menus/consistency");
|
||||
@@ -69,6 +69,7 @@ await runSmoke("menus/consistency", async ({ page }) => {
|
||||
context.fillStyle = gradient; context.fillRect(0, 0, 800, 600);
|
||||
saveAppearance({ theme: 'default', mode, newTabBackground: { image: canvas.toDataURL(), overlay: 0.15, position: 'center', size: 'cover' } });
|
||||
}, theme);
|
||||
await showSavedImage(page);
|
||||
await row.focus();
|
||||
await row.click({ button: "right" });
|
||||
const file = menu("File actions");
|
||||
|
||||
Reference in New Issue
Block a user