RuneStone 1.0.0
This commit is contained in:
@@ -0,0 +1,79 @@
|
||||
// Settings window: browser preview fallback, standalone layout, two-way save sync, failed saves, native open requests, and close. The OS title bar is not tested.
|
||||
import assert from "node:assert/strict";
|
||||
import path from "node:path";
|
||||
import { mockTauri, openPage, outputDir, runSmoke, smokeUrl } from "../_harness/index.mjs";
|
||||
|
||||
await runSmoke("settings/window", async ({ browser }) => {
|
||||
const output = await outputDir("settings/window");
|
||||
const context = await browser.newContext({ viewport: { width: 1100, height: 760 } });
|
||||
const autosaveSeconds = page => page.evaluate(() => JSON.parse(localStorage.getItem("runestone.settings")).autosaveSeconds);
|
||||
|
||||
// The main window and settings run as browser previews, without the Tauri mock.
|
||||
const main = await openPage(context);
|
||||
await main.goto(smokeUrl);
|
||||
await main.getByRole("button", { name: "Settings (Ctrl+,)", exact: true }).click();
|
||||
assert.equal(await main.locator("dialog:modal").count(), 1, "Browser preview retains the settings dialog");
|
||||
const settings = await openPage(context);
|
||||
await settings.goto(`${smokeUrl}/?settingsWindow=true`);
|
||||
await settings.getByRole("heading", { name: "General", exact: true }).waitFor();
|
||||
assert.equal(await settings.locator(".workbench").count(), 0);
|
||||
const interval = settings.getByRole("spinbutton", { name: "Auto-save interval" });
|
||||
await interval.fill("17"); await interval.press("Tab");
|
||||
await main.waitForFunction(() => document.querySelector("#autosave-seconds")?.value === "17");
|
||||
await main.getByRole("spinbutton", { name: "Auto-save interval" }).fill("29");
|
||||
await main.getByRole("spinbutton", { name: "Auto-save interval" }).press("Tab");
|
||||
await settings.waitForFunction(() => document.querySelector("#autosave-seconds")?.value === "29");
|
||||
await settings.reload();
|
||||
await settings.waitForFunction(() => document.querySelector("#autosave-seconds")?.value === "29");
|
||||
await interval.fill("301"); await interval.press("Tab");
|
||||
await settings.getByRole("alert").filter({ hasText: "Choose a whole number" }).waitFor();
|
||||
assert.equal(await autosaveSeconds(settings), 29);
|
||||
await settings.evaluate(() => { Storage.prototype.setItem = () => { throw new Error("Storage full"); }; });
|
||||
await interval.fill("40"); await interval.press("Tab");
|
||||
await settings.getByRole("alert").filter({ hasText: "Could not save these settings" }).waitFor();
|
||||
assert.equal(await autosaveSeconds(settings), 29);
|
||||
await settings.reload();
|
||||
await settings.getByRole("button", { name: "Plug-ins", exact: true }).click();
|
||||
await settings.getByRole("heading", { name: "Plug-ins", exact: true }).waitFor();
|
||||
await settings.getByRole("button", { name: "General", exact: true }).click();
|
||||
await settings.screenshot({ path: path.join(output, "settings-window.png") });
|
||||
await settings.setViewportSize({ width: 540, height: 420 });
|
||||
assert.equal(await settings.evaluate(() => document.documentElement.scrollWidth <= innerWidth), true);
|
||||
await settings.keyboard.press("Escape");
|
||||
await settings.waitForURL(`${smokeUrl}/`);
|
||||
|
||||
// A desktop window with the Tauri mock opens settings in a native window.
|
||||
const desktop = await openPage(context);
|
||||
await mockTauri(desktop, {
|
||||
state: { opens: 0, fail: false, closes: 0 },
|
||||
commands: test => ({
|
||||
settings_open_window: async () => {
|
||||
test.state.opens++;
|
||||
if (test.state.fail) throw new Error("Native window creation failed");
|
||||
await new Promise(resolve => setTimeout(resolve, 150));
|
||||
},
|
||||
plugins_snapshot: () => ({ root: "C:/plugins", plugins: [] }),
|
||||
workspace_last_path: () => null,
|
||||
"plugin:window|is_maximized": () => false,
|
||||
"plugin:window|close": () => { test.state.closes++; },
|
||||
}),
|
||||
});
|
||||
const desktopState = () => desktop.evaluate(() => window.__TEST__.state);
|
||||
await desktop.goto(smokeUrl);
|
||||
await desktop.getByRole("button", { name: "Settings (Ctrl+,)", exact: true }).dblclick();
|
||||
assert.equal((await desktopState()).opens, 1, "Rapid requests share the pending native open");
|
||||
assert.equal(await desktop.locator("dialog:modal").count(), 0, "Native open does not block the workbench");
|
||||
await desktop.waitForTimeout(180);
|
||||
await desktop.keyboard.press("Control+,");
|
||||
await desktop.waitForFunction(() => window.__TEST__.state.opens === 2);
|
||||
await desktop.waitForTimeout(180);
|
||||
await desktop.evaluate(() => { window.__TEST__.state.fail = true; });
|
||||
await desktop.keyboard.press("Control+,");
|
||||
await desktop.getByText(/Could not open settings: .*Native window creation failed/).waitFor();
|
||||
await desktop.goto(`${smokeUrl}/?settingsWindow=true`);
|
||||
await desktop.getByRole("heading", { name: "General", exact: true }).waitFor();
|
||||
await desktop.getByRole("button", { name: "Close window", exact: true }).click();
|
||||
assert.equal((await desktopState()).closes, 1);
|
||||
assert.deepEqual([main, settings, desktop].flatMap(page => page.errors), []);
|
||||
console.log("Settings window smoke passed: preview fallback, standalone layout, two-way save sync, persistence, failed saves, native open requests, and close.");
|
||||
});
|
||||
Reference in New Issue
Block a user