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.
69 lines
4.6 KiB
JavaScript
69 lines
4.6 KiB
JavaScript
// Custom window controls: maximize, restore, minimize, the terminal close guard, the keyboard tooltip, and the header at 1400 and 880 px.
|
|
// @requires plugin:terminal plugin:table-formulas
|
|
import assert from "node:assert/strict";
|
|
import { readFile } from "node:fs/promises";
|
|
import path from "node:path";
|
|
import { mockTauri, outputDir, repoRoot, runSmoke, smokeUrl } from "../_harness/index.mjs";
|
|
import { mockFeaturePlugins } from "../_harness/pluginMocks.mjs";
|
|
|
|
await runSmoke("layout/windowControls", async ({ page }) => {
|
|
const output = await outputDir("layout/windowControls");
|
|
await mockTauri(page, {
|
|
state: { maximized: false, confirm: "Cancel" },
|
|
commands: test => ({
|
|
workspace_last_path: () => null,
|
|
"plugin:window|is_maximized": () => test.state.maximized,
|
|
"plugin:window|toggle_maximize": () => { test.state.maximized = !test.state.maximized; test.emit("tauri://resize", { width: 1400, height: 900 }); },
|
|
"plugin:window|minimize": () => {},
|
|
"plugin:window|destroy": () => {},
|
|
"plugin:window|close": () => { test.emit("tauri://close-requested"); },
|
|
"plugin:dialog|message": () => test.state.confirm,
|
|
}),
|
|
});
|
|
// The Terminal button belongs to the terminal plug-in (src/lib/layout/Workbench.svelte:1305).
|
|
await mockFeaturePlugins(page);
|
|
const called = command => page.evaluate(command => window.__TEST__.calls.some(call => call.command === command), command);
|
|
|
|
const config = JSON.parse(await readFile(path.join(repoRoot, "src-tauri/tauri.conf.json"), "utf8"));
|
|
assert.equal(config.app.windows[0].decorations, false);
|
|
const capability = JSON.parse(await readFile(path.join(repoRoot, "src-tauri/capabilities/default.json"), "utf8"));
|
|
for (const permission of ["close", "minimize", "toggle-maximize", "start-dragging"]) {
|
|
assert.ok(capability.permissions.includes(`core:window:allow-${permission}`));
|
|
}
|
|
await page.goto(smokeUrl);
|
|
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 }).click();
|
|
await page.getByRole("button", { name: "Maximize window", exact: true }).waitFor();
|
|
// Native maximize/restore (e.g. double-clicking the drag region) updates the button too.
|
|
await page.evaluate(() => { window.__TEST__.state.maximized = true; window.__TEST__.emit("tauri://resize", { width: 1920, height: 1080 }); });
|
|
await page.getByRole("button", { name: "Restore window", exact: true }).waitFor();
|
|
await page.getByRole("button", { name: "Minimize window", exact: true }).click();
|
|
assert.ok(await called("plugin:window|minimize"));
|
|
await page.getByRole("button", { name: "Close window", exact: true }).focus();
|
|
await page.getByRole("tooltip", { name: "Close window", exact: true }).waitFor();
|
|
// Opening the terminal engages the existing close guard; cancellation must not destroy the window.
|
|
await page.getByRole("button", { name: "Terminal", exact: true }).click();
|
|
await page.getByRole("button", { name: "Close window", exact: true }).click();
|
|
await page.waitForFunction(() => window.__TEST__.calls.some(call => call.command === "plugin:dialog|message"));
|
|
assert.equal(await called("plugin:window|destroy"), false);
|
|
await page.evaluate(() => window.__TEST__.state.confirm = "Ok");
|
|
await page.getByRole("button", { name: "Close window", exact: true }).click();
|
|
await page.waitForFunction(() => window.__TEST__.calls.some(call => call.command === "plugin:window|destroy"));
|
|
await page.getByRole("button", { name: "Terminal", exact: true }).click();
|
|
for (const width of [1400, 880]) {
|
|
await page.setViewportSize({ width, height: 900 });
|
|
const layout = await page.evaluate(() => {
|
|
const header = document.querySelector(".header").getBoundingClientRect();
|
|
const controls = [...document.querySelectorAll(".header button")].map(el => el.getBoundingClientRect());
|
|
return { height: header.height, top: header.top, fits: controls.every(rect => rect.x >= 0 && rect.right <= innerWidth && rect.y >= header.y && rect.bottom <= header.bottom), drag: document.querySelector(".window-drag-space").getBoundingClientRect().width };
|
|
});
|
|
assert.equal(layout.height, 36);
|
|
assert.equal(layout.top, 0);
|
|
assert.ok(layout.fits);
|
|
assert.ok(layout.drag >= 40);
|
|
await page.screenshot({ path: path.join(output, `window-controls-${width}.png`) });
|
|
}
|
|
console.log("Window controls smoke passed: actions, restore state, close guard, keyboard tooltip, and 1400/880px layouts.");
|
|
}, { viewport: { width: 1400, height: 900 }, timeout: 30000 });
|