Unit tests go to tests/unit/<area>/, browser smoke tests to tests/smoke/<area>/, and tests against a running desktop app to tests/native/. Files named after dates, work passes, or Kanban cards get feature names, for example editorOctober12 -> editor/footnotes. scripts/ keeps the build, release, and package tools. Plugin repositories import scripts/packagePlugin.mjs, and the Terminal smoke test imports scripts/pluginMocks.mjs, which now re-exports the harness copy. The unit tests get their own type check (tests/tsconfig.json) with Node types. pnpm check runs it after the app check. Add @types/node and fix the three test mocks that it reported.
97 lines
6.3 KiB
JavaScript
97 lines
6.3 KiB
JavaScript
// Run against pnpm dev with PLAYWRIGHT_MODULE and CHROME_PATH if needed.
|
|
import { createRequire } from "node:module";
|
|
import { mkdirSync, readFileSync } from "node:fs";
|
|
import assert from "node:assert/strict";
|
|
const require = createRequire(import.meta.url);
|
|
const { chromium } = require(process.env.PLAYWRIGHT_MODULE || "playwright");
|
|
const browser = await chromium.launch({ headless: true, ...(process.env.CHROME_PATH ? { executablePath: process.env.CHROME_PATH } : {}) });
|
|
const url = process.env.SMOKE_URL || "http://127.0.0.1:1420";
|
|
mkdirSync(".audit", { recursive: true });
|
|
const settingsCapability = JSON.parse(readFileSync(new URL("../../../src-tauri/capabilities/settings.json", import.meta.url), "utf8"));
|
|
assert.deepEqual(settingsCapability.windows, ["settings-main", "settings-workspace-*"]);
|
|
for (const action of ["close", "minimize", "toggle-maximize", "start-dragging"]) {
|
|
assert(settingsCapability.permissions.includes(`core:window:allow-${action}`));
|
|
}
|
|
const errors = [];
|
|
try {
|
|
const context = await browser.newContext({ viewport: { width: 920, height: 650 } });
|
|
await context.addInitScript(() => {
|
|
window.isTauri = true;
|
|
const callbacks = new Map();
|
|
const listeners = new Map();
|
|
window.__TEST__ = { calls: [], maximized: false, fail: "", resize: () => callbacks.get(listeners.get("tauri://resize"))?.({ payload: {} }) };
|
|
window.__TAURI_INTERNALS__ = {
|
|
metadata: { currentWindow: { label: "settings-main" }, currentWebview: { label: "settings-main" } },
|
|
transformCallback: callback => { const id = callbacks.size + 1; callbacks.set(id, callback); return id; },
|
|
unregisterCallback: id => callbacks.delete(id),
|
|
invoke: async (command, args = {}) => {
|
|
window.__TEST__.calls.push(command);
|
|
if (window.__TEST__.fail === command) throw new Error("Window action failed");
|
|
if (command === "plugins_snapshot") return { root: "D:\\SettingsTest\\plugins", plugins: [] };
|
|
if (command === "plugin:event|listen") { listeners.set(args.event, args.handler); return args.handler; }
|
|
if (command === "plugin:window|is_maximized") return window.__TEST__.maximized;
|
|
if (command === "plugin:window|toggle_maximize") window.__TEST__.maximized = !window.__TEST__.maximized;
|
|
return null;
|
|
},
|
|
};
|
|
window.__TAURI_EVENT_PLUGIN_INTERNALS__ = { unregisterListener: () => {} };
|
|
});
|
|
const page = await context.newPage();
|
|
page.on("pageerror", error => errors.push(error.message));
|
|
page.setDefaultTimeout(5000);
|
|
await page.goto(`${url}/?settingsWindow=true`);
|
|
const dialog = page.getByRole("dialog", { name: "Settings", exact: true });
|
|
await dialog.waitFor();
|
|
assert.equal(await dialog.getByRole("button", { name: /^Close/ }).count(), 1);
|
|
assert(await dialog.locator("header[data-tauri-drag-region] h1[data-tauri-drag-region]").isVisible());
|
|
assert.equal(await dialog.locator(".window-controls [data-tauri-drag-region]").count(), 0);
|
|
const calls = () => page.evaluate(() => window.__TEST__.calls);
|
|
await page.getByRole("button", { name: "Minimize window", exact: true }).click();
|
|
assert((await calls()).includes("plugin:window|minimize"));
|
|
await page.getByRole("button", { name: "Maximize window", exact: true }).click();
|
|
await page.getByRole("button", { name: "Restore window", exact: true }).waitFor();
|
|
await page.getByRole("button", { name: "Restore window", exact: true }).focus();
|
|
await page.keyboard.press("Enter");
|
|
await page.getByRole("button", { name: "Maximize window", exact: true }).waitFor();
|
|
await page.evaluate(() => { window.__TEST__.maximized = true; window.__TEST__.resize(); });
|
|
await page.getByRole("button", { name: "Restore window", exact: true }).waitFor();
|
|
await page.getByRole("button", { name: "Close window", exact: true }).focus();
|
|
await page.getByRole("tooltip", { name: "Close window", exact: true }).waitFor();
|
|
await page.keyboard.press("Space");
|
|
const beforeEscape = (await calls()).filter(command => command === "plugin:window|close").length;
|
|
assert.equal(beforeEscape, 1);
|
|
await page.getByRole("textbox", { name: "Search settings" }).focus();
|
|
await page.keyboard.press("Escape");
|
|
assert.equal((await calls()).filter(command => command === "plugin:window|close").length, beforeEscape + 1);
|
|
await page.mouse.move(400, 180);
|
|
for (const theme of ["dark", "light"]) {
|
|
await page.evaluate(value => document.documentElement.setAttribute("data-theme", value), theme);
|
|
for (const size of [{ width: 920, height: 650 }, { width: 540, height: 420 }]) {
|
|
await page.setViewportSize(size);
|
|
assert(await dialog.evaluate(element => element.scrollWidth === element.clientWidth));
|
|
for (const label of ["Minimize window", "Restore window", "Close window"]) {
|
|
const button = dialog.getByRole("button", { name: label, exact: true });
|
|
const bounds = await button.boundingBox();
|
|
assert(bounds.x >= 0 && bounds.x + bounds.width <= size.width && bounds.height >= 28);
|
|
assert.notEqual(await button.evaluate(element => getComputedStyle(element).borderTopLeftRadius), "0px");
|
|
}
|
|
await page.screenshot({ path: `.audit/settings-window-${theme}-${size.width}.png` });
|
|
}
|
|
}
|
|
await page.evaluate(() => { window.__TEST__.fail = "plugin:window|minimize"; });
|
|
await page.getByRole("button", { name: "Minimize window", exact: true }).click();
|
|
await dialog.getByRole("alert").filter({ hasText: "Window action failed" }).waitFor();
|
|
await page.evaluate(() => { window.__TEST__.fail = ""; });
|
|
await page.getByRole("button", { name: "Minimize window", exact: true }).focus();
|
|
await page.keyboard.press("Shift+Tab");
|
|
assert.equal(await page.evaluate(() => document.activeElement?.textContent), "Restore defaults");
|
|
await page.keyboard.press("Tab");
|
|
assert.equal(await page.evaluate(() => document.activeElement?.getAttribute("aria-label")), "Minimize window");
|
|
const web = await browser.newPage();
|
|
await web.goto(`${url}/?settingsWindow=true`);
|
|
await web.getByRole("button", { name: "Close settings", exact: true }).waitFor();
|
|
assert.equal(await web.getByRole("group", { name: "Window controls" }).count(), 0);
|
|
assert.deepEqual(errors, []);
|
|
console.log("Settings window smoke passed: scoped permissions, drag regions, minimize, maximize, restore, resize, close, Escape, keyboard focus, tooltips, errors, both themes, narrow layout, and browser fallback.");
|
|
} finally { await browser.close(); }
|