119 lines
6.7 KiB
JavaScript
119 lines
6.7 KiB
JavaScript
// 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, showSavedImage, smokeUrl } from "../_harness/index.mjs";
|
|
|
|
await runSmoke("appearance/tooltipsAndSelection", async ({ page }) => {
|
|
const output = await outputDir("appearance/tooltipsAndSelection");
|
|
page.on("console", message => { if (message.type() === "error" || message.type() === "warning") console.log(message.type(), message.text()); });
|
|
await mockTauri(page, {
|
|
commands: test => ({
|
|
...test.workspace({
|
|
root: "C:\\smoke-workspace",
|
|
writeEvents: true,
|
|
files: {
|
|
"notes/welcome.md": "---\ntitle: Welcome\n---\n\n# Working notes\n\nFirst paragraph.\n\n- [ ] A task\n\n[[second]]\n",
|
|
"notes/second.md": "# Second note\n",
|
|
"src/hello.py": "print('hello')\n",
|
|
},
|
|
}),
|
|
plugins_snapshot: () => ({ root: "C:/theme-test-plugins", plugins: [] }),
|
|
"plugin:window|is_maximized": () => false,
|
|
spelling_menu_install: () => null,
|
|
}),
|
|
});
|
|
const tooltip = page.locator(".rs-tooltip:popover-open");
|
|
try {
|
|
await page.goto(smokeUrl);
|
|
await page.getByText("smoke-workspace", { exact: true }).waitFor();
|
|
await page.keyboard.press("Control+p");
|
|
await page.getByRole("textbox", { name: "Find a file" }).fill("welcome.md");
|
|
await page.getByRole("dialog").getByRole("button").filter({ hasText: "welcome.md" }).first().click();
|
|
await page.getByRole("textbox", { name: "Writing editor", exact: true }).waitFor();
|
|
for (const mode of ["dark", "light"]) {
|
|
await page.evaluate(async mode => {
|
|
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);
|
|
await tab.hover();
|
|
await tooltip.waitFor();
|
|
assert.match(await tooltip.innerText(), /welcome\.md/);
|
|
await page.screenshot({ path: path.join(output, `${mode}-tab-tooltip.png`) });
|
|
await page.keyboard.press("Escape");
|
|
assert.equal(await tooltip.count(), 0);
|
|
await tab.focus();
|
|
await tooltip.waitFor();
|
|
await page.keyboard.press("Escape");
|
|
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), 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: 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/);
|
|
assert.notEqual(colors.image.trim(), "none");
|
|
assert.equal(colors.pluginBg.trim(), "transparent");
|
|
console.log(mode, colors);
|
|
await page.screenshot({ path: path.join(output, `${mode}-selection.png`) });
|
|
await page.getByRole("button", { name: "New tab (Ctrl+T)", exact: true }).click();
|
|
await page.locator(".empty").waitFor();
|
|
await page.screenshot({ path: path.join(output, `${mode}-zero-background.png`) });
|
|
await page.getByRole("tab", { name: /welcome\.md/ }).click();
|
|
}
|
|
|
|
await page.goto(`${smokeUrl}/?settingsWindow=true`);
|
|
await page.getByRole("button", { name: "Appearance", exact: true }).click();
|
|
for (const mode of ["dark", "light"]) {
|
|
await page.evaluate(async mode => {
|
|
(await import("/src/lib/theme/appearance.ts")).saveAppearance({ theme: "default", mode });
|
|
window.dispatchEvent(new Event("focus"));
|
|
}, mode);
|
|
const slider = page.locator("#surface-transparency");
|
|
for (const width of [1100, 390]) {
|
|
await page.setViewportSize({ width, height: 800 });
|
|
await slider.fill("0"); const zero = await slider.boundingBox();
|
|
for (const amount of ["1", "9", "11", "18", "99", "100"]) {
|
|
await slider.fill(amount); const current = await slider.boundingBox();
|
|
assert.equal(current.x, zero.x); assert.equal(current.width, zero.width);
|
|
}
|
|
await page.screenshot({ path: path.join(output, `${mode}-${width}-slider.png`) });
|
|
}
|
|
}
|
|
|
|
await page.evaluate(() => {
|
|
const invoke = window.__TAURI_INTERNALS__.invoke;
|
|
window.__TAURI_INTERNALS__.invoke = (command, args) => command === "plugins_choose"
|
|
? Promise.resolve([{ token: "theme-test", source: "C:/Downloads/example.zip", error: null,
|
|
manifest: { id: "example", name: "Theme example", version: "0.1.0", description: "Theme control test", author: "RuneStone", entry: "main.js" } }])
|
|
: invoke(command, args);
|
|
});
|
|
await page.getByRole("button", { name: "Plug-ins", exact: true }).click();
|
|
for (const [theme, mode] of [["harvest-moon", "dark"], ["default", "light"]]) {
|
|
await page.evaluate(async ({ theme, mode }) => {
|
|
(await import("/src/lib/theme/appearance.ts")).saveAppearance({ theme, mode }); window.dispatchEvent(new Event("focus"));
|
|
}, { theme, mode });
|
|
await page.getByRole("button", { name: "Install plugin ZIP", exact: true }).click();
|
|
const checkbox = page.getByRole("checkbox", { name: "Theme example", exact: true });
|
|
await checkbox.waitFor();
|
|
assert.equal(await checkbox.evaluate(node => getComputedStyle(node).accentColor), await page.evaluate(() => {
|
|
const probe = document.createElement("span"); probe.style.color = "var(--rs-accent)"; document.body.append(probe);
|
|
const color = getComputedStyle(probe).color; probe.remove(); return color;
|
|
}));
|
|
await checkbox.focus();
|
|
await page.screenshot({ path: path.join(output, `${theme}-${mode}-install-checkbox.png`) });
|
|
await page.getByRole("button", { name: "Cancel", exact: true }).click();
|
|
}
|
|
console.log("PASS: exact tab tooltips, translucent text selection, retained zero-transparency background, stable slider, themed installation checkbox.");
|
|
} catch (error) {
|
|
await page.screenshot({ path: path.join(output, "failure.png") });
|
|
throw error;
|
|
}
|
|
});
|