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.
86 lines
5.2 KiB
JavaScript
86 lines
5.2 KiB
JavaScript
// Settings window title bar: scoped permissions, drag regions, minimize, maximize, restore, close, Escape, focus, errors, themes, and the browser fallback.
|
|
import { readFileSync } from "node:fs";
|
|
import assert from "node:assert/strict";
|
|
import path from "node:path";
|
|
import { mockTauri, openPage, outputDir, repoRoot, runSmoke, smokeUrl } from "../_harness/index.mjs";
|
|
|
|
await runSmoke("settings/titlebar", async ({ browser }) => {
|
|
const settingsCapability = JSON.parse(readFileSync(path.join(repoRoot, "src-tauri/capabilities/settings.json"), "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 output = await outputDir("settings/titlebar");
|
|
const context = await browser.newContext({ viewport: { width: 920, height: 650 } });
|
|
await mockTauri(context, {
|
|
label: "settings-main",
|
|
state: { maximized: false, failMinimize: false },
|
|
commands: test => ({
|
|
plugins_snapshot: () => ({ root: "D:\\SettingsTest\\plugins", plugins: [] }),
|
|
"plugin:window|is_maximized": () => test.state.maximized,
|
|
"plugin:window|toggle_maximize": () => { test.state.maximized = !test.state.maximized; },
|
|
"plugin:window|minimize": () => { if (test.state.failMinimize) throw new Error("Window action failed"); },
|
|
"plugin:window|close": () => null,
|
|
}),
|
|
});
|
|
const page = await openPage(context, { timeout: 5000 });
|
|
await page.goto(`${smokeUrl}/?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.map(call => call.command));
|
|
const closes = async () => (await calls()).filter(command => command === "plugin:window|close").length;
|
|
const button = name => page.getByRole("button", { name, exact: true });
|
|
await button("Minimize window").click();
|
|
assert((await calls()).includes("plugin:window|minimize"));
|
|
await button("Maximize window").click();
|
|
await button("Restore window").waitFor();
|
|
await button("Restore window").focus();
|
|
await page.keyboard.press("Enter");
|
|
await button("Maximize window").waitFor();
|
|
await page.evaluate(() => { window.__TEST__.state.maximized = true; window.__TEST__.emit("tauri://resize", {}); });
|
|
await button("Restore window").waitFor();
|
|
await button("Close window").focus();
|
|
await page.getByRole("tooltip", { name: "Close window", exact: true }).waitFor();
|
|
await page.keyboard.press("Space");
|
|
const beforeEscape = await closes();
|
|
assert.equal(beforeEscape, 1);
|
|
await page.getByRole("textbox", { name: "Search settings" }).focus();
|
|
await page.keyboard.press("Escape");
|
|
assert.equal(await closes(), 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 control = dialog.getByRole("button", { name: label, exact: true });
|
|
const bounds = await control.boundingBox();
|
|
assert(bounds.x >= 0 && bounds.x + bounds.width <= size.width && bounds.height >= 28);
|
|
assert.notEqual(await control.evaluate(element => getComputedStyle(element).borderTopLeftRadius), "0px");
|
|
}
|
|
await page.screenshot({ path: path.join(output, `${theme}-${size.width}.png`) });
|
|
}
|
|
}
|
|
await page.evaluate(() => { window.__TEST__.state.failMinimize = true; });
|
|
await button("Minimize window").click();
|
|
await dialog.getByRole("alert").filter({ hasText: "Window action failed" }).waitFor();
|
|
await page.evaluate(() => { window.__TEST__.state.failMinimize = false; });
|
|
await button("Minimize window").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");
|
|
|
|
// Without the Tauri mock, the page is a plain browser preview.
|
|
const web = await openPage(browser);
|
|
await web.goto(`${smokeUrl}/?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(page.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.");
|
|
});
|