RuneStone 1.0.0
This commit is contained in:
@@ -0,0 +1,31 @@
|
||||
// Ctrl+Tab selects the next working tab and Ctrl+Shift+Tab returns to the previous one.
|
||||
import assert from "node:assert/strict";
|
||||
import { mockTauri, runSmoke, smokeUrl } from "../_harness/index.mjs";
|
||||
|
||||
await runSmoke("tabs/cycleShortcuts", async ({ page }) => {
|
||||
await mockTauri(page, {
|
||||
commands: test => ({
|
||||
...test.workspace({ root: "C:\\tab-cycle", files: { "a.md": "# Alpha\n", "b.md": "# Beta\n" } }),
|
||||
plugins_snapshot: () => ({ plugins: [], issues: [] }),
|
||||
spelling_menu_install: () => null,
|
||||
}),
|
||||
});
|
||||
async function open(name) {
|
||||
await page.keyboard.press("Control+p");
|
||||
await page.getByRole("textbox", { name: "Find a file" }).fill(name);
|
||||
await page.getByRole("dialog").getByRole("button").filter({ hasText: name }).first().click();
|
||||
await page.getByRole("tab", { name, exact: true }).waitFor();
|
||||
}
|
||||
const selected = () => page.getByRole("tab", { selected: true }).getAttribute("data-path");
|
||||
await page.goto(smokeUrl);
|
||||
await page.getByText("tab-cycle", { exact: true }).waitFor();
|
||||
await open("a.md");
|
||||
await open("b.md");
|
||||
await page.locator(".cm-content").click();
|
||||
const before = await selected();
|
||||
await page.keyboard.press("Control+Tab");
|
||||
assert.notEqual(await selected(), before);
|
||||
await page.keyboard.press("Control+Shift+Tab");
|
||||
assert.equal(await selected(), before);
|
||||
console.log("PASS: Ctrl+Tab and Ctrl+Shift+Tab cycle working tabs");
|
||||
});
|
||||
@@ -0,0 +1,335 @@
|
||||
// The last tab becomes a new tab, compact tab widths, site icons, mixed file and plugin tabs, close actions, plugin disable, and secondary windows.
|
||||
// @known-issue Without a workspace, plugin tabs cannot be dragged to reorder: they are native-draggable but get no drag data (Workbench.svelte workingTabDragData).
|
||||
import assert from "node:assert/strict";
|
||||
import path from "node:path";
|
||||
import { mockTauri, openPage, outputDir, runSmoke, settle as settleFrames, smokeUrl } from "../_harness/index.mjs";
|
||||
|
||||
const pluginCode = `export function activate(api) {
|
||||
window.tabTest.api = api;
|
||||
const mount = (id, container) => {
|
||||
window.tabTest.mounts[id] = (window.tabTest.mounts[id] || 0) + 1;
|
||||
const input = document.createElement("input");
|
||||
input.setAttribute("aria-label", id + " state");
|
||||
container.append(input);
|
||||
return () => {
|
||||
window.tabTest.disposals[id] = (window.tabTest.disposals[id] || 0) + 1;
|
||||
input.remove();
|
||||
};
|
||||
};
|
||||
for (const [id, title, icon] of [["overview", "Overview", "puzzle"], ["browser", "Browser", "globe"]]) {
|
||||
api.registerView({ id, title, icon, placement: "editor", navigation: true, mount: container => mount(id, container) });
|
||||
}
|
||||
api.registerDocumentType({
|
||||
id: "board", title: "Board", icon: "kanban", extensions: ["board"],
|
||||
identify: (path, source) => ({ id: source }),
|
||||
mount: (container, document) => mount(document.id, container),
|
||||
});
|
||||
}`;
|
||||
|
||||
// `?secondary` loads a secondary window. `?settingsWindow` loads the settings window, which sends its commands to the main page.
|
||||
function windowRoles(context) {
|
||||
return context.addInitScript(() => {
|
||||
const internals = window.__TAURI_INTERNALS__;
|
||||
if (location.search.includes("secondary")) internals.metadata = { currentWindow: { label: "workspace-2" }, currentWebview: { label: "workspace-2" } };
|
||||
if (!location.search.includes("settingsWindow")) return;
|
||||
const { invoke } = internals;
|
||||
internals.invoke = (command, args = {}) => command.startsWith("plugin:event|") || command.startsWith("plugin:window|")
|
||||
? invoke(command, args)
|
||||
: window.settingsHostInvoke(command, args);
|
||||
});
|
||||
}
|
||||
|
||||
await runSmoke("tabs/lastTabAndSiteIcons", async ({ browser }) => {
|
||||
const output = await outputDir("tabs/lastTabAndSiteIcons");
|
||||
const context = await browser.newContext({ viewport: { width: 1440, height: 1000 } });
|
||||
await mockTauri(context, {
|
||||
state: { pluginCode },
|
||||
commands: test => {
|
||||
localStorage.setItem("runestone.settings", JSON.stringify({ autosaveEnabled: false, autosaveSeconds: 5 }));
|
||||
const root = "C:\\plugin-tab-workspace";
|
||||
const files = Object.fromEntries(["a.md", "b.md", "c.md", ...Array.from({ length: 14 }, (_, index) => `note-${index}.md`)].map(name => [name, `# ${name}\n\nOriginal text.\n`]));
|
||||
files["project.board"] = "project-board";
|
||||
const manifest = { schemaVersion: 1, id: "test.tabs", name: "Tab fixtures", author: "Tests", description: "Test editor tabs.", version: "1.0.0", apiVersion: 1, entry: "main.js", access: "full-app" };
|
||||
let enabled = true;
|
||||
window.tabTest = { mounts: {}, disposals: {}, answer: "Cancel", prompts: 0, closeRequests: 0, destroys: 0 };
|
||||
const workspace = test.workspace({ root, files });
|
||||
return {
|
||||
...workspace,
|
||||
workspace_last_path: () => location.search.includes("no-workspace") ? null : root,
|
||||
settings_open_window: () => null,
|
||||
"plugin:window|is_maximized": () => false,
|
||||
"plugin:window|close": () => { window.tabTest.closeRequests++; test.emit("tauri://close-requested"); },
|
||||
"plugin:window|destroy": () => { window.tabTest.destroys++; },
|
||||
"plugin:dialog|message": () => { window.tabTest.prompts++; return window.tabTest.answer; },
|
||||
plugins_snapshot: () => ({ root, plugins: [{ manifest, hash: "test", enabled, path: root, error: null, removal: false }] }),
|
||||
plugins_load: () => test.state.pluginCode,
|
||||
plugins_release: () => null,
|
||||
plugins_set_enabled: args => { enabled = args.enabled; test.emit("plugins-changed"); },
|
||||
};
|
||||
},
|
||||
});
|
||||
await windowRoles(context);
|
||||
const page = await openPage(context);
|
||||
const pages = [page];
|
||||
await context.exposeBinding("settingsHostInvoke", (_source, command, args) =>
|
||||
page.evaluate(({ command, args }) => window.__TAURI_INTERNALS__.invoke(command, args), { command, args }));
|
||||
const tab = name => page.getByRole("tab", { name, exact: true });
|
||||
const bar = page.getByRole("tablist", { name: "Working tabs" });
|
||||
const order = () => bar.getByRole("tab").evaluateAll(nodes => nodes.map(node => node.textContent.trim()));
|
||||
const settle = () => settleFrames(page);
|
||||
async function openFile(name) {
|
||||
await page.keyboard.press("Control+p");
|
||||
await page.getByRole("textbox", { name: "Find a file" }).fill(name);
|
||||
await page.getByRole("dialog").getByRole("button").filter({ hasText: name }).first().click();
|
||||
await settle();
|
||||
}
|
||||
async function openView(name) {
|
||||
await page.getByRole("navigation", { name: "Plugin shortcuts" }).getByRole("button", { name, exact: true }).click();
|
||||
await tab(name).waitFor();
|
||||
}
|
||||
async function drag(from, to, side = "before", cancel) {
|
||||
const source = await tab(from).boundingBox(), target = await tab(to).boundingBox();
|
||||
await page.mouse.move(source.x + source.width / 2, source.y + source.height / 2);
|
||||
await page.mouse.down();
|
||||
await page.mouse.move(side === "before" ? target.x + 2 : target.x + target.width - 2, target.y + target.height / 2, { steps: 10 });
|
||||
if (cancel === "escape") await page.keyboard.press("Escape");
|
||||
if (cancel === "outside") await page.mouse.move(target.x, target.y + 100);
|
||||
await page.mouse.up();
|
||||
await settle();
|
||||
}
|
||||
async function menu(name) {
|
||||
await tab(name).click({ button: "right" });
|
||||
await page.getByRole("menu", { name: "Tab actions" }).waitFor();
|
||||
}
|
||||
|
||||
await page.goto(smokeUrl);
|
||||
await page.getByText("plugin-tab-workspace", { exact: true }).waitFor();
|
||||
await tab("New tab").waitFor();
|
||||
for (const close of ["button", "middle", "shortcut", "all"]) {
|
||||
const before = await tab("New tab").getAttribute("data-path");
|
||||
if (close === "button") await page.getByRole("button", { name: "Close New tab", exact: true }).click();
|
||||
if (close === "middle") await tab("New tab").click({ button: "middle" });
|
||||
if (close === "shortcut") await page.keyboard.press("Control+w");
|
||||
if (close === "all") {
|
||||
await menu("New tab");
|
||||
await page.getByRole("menuitem", { name: "Close all", exact: true }).click();
|
||||
}
|
||||
await page.waitForFunction(before => {
|
||||
const tabs = document.querySelectorAll('.header [role="tab"]');
|
||||
return tabs.length === 1 && tabs[0].getAttribute("data-path") !== before;
|
||||
}, before);
|
||||
assert.equal(await tab("New tab").getAttribute("aria-selected"), "true");
|
||||
}
|
||||
for (const name of ["a.md", "b.md", "c.md", "note-0.md"]) await openFile(name);
|
||||
await page.getByRole("textbox", { name: "Writing editor", exact: true }).filter({ hasText: "# note-0.md" }).waitFor();
|
||||
for (const width of [880, 1280, 1440]) {
|
||||
await page.setViewportSize({ width, height: 1000 });
|
||||
await settle();
|
||||
for (const theme of ["dark", "light"]) {
|
||||
await page.evaluate(theme => document.documentElement.dataset.theme = theme, theme);
|
||||
const dimensions = await page.locator(".header").evaluate(header => {
|
||||
const bar = header.querySelector('[role="tablist"]');
|
||||
const rows = [...bar.querySelectorAll(".tab")];
|
||||
const plus = header.querySelector('[aria-label="New tab (Ctrl+T)"]');
|
||||
const bounds = bar.getBoundingClientRect();
|
||||
return {
|
||||
overflow: bar.scrollWidth - bar.clientWidth,
|
||||
left: bounds.left,
|
||||
navigationRight: header.querySelector(".header-left").getBoundingClientRect().right,
|
||||
tabWidth: Math.min(...rows.map(row => row.getBoundingClientRect().width)),
|
||||
gap: plus.getBoundingClientRect().left - Math.min(bounds.right, rows.at(-1).getBoundingClientRect().right),
|
||||
fits: header.scrollWidth <= header.clientWidth,
|
||||
};
|
||||
});
|
||||
if (width >= 1280) assert.ok(dimensions.overflow <= 1, JSON.stringify(dimensions));
|
||||
assert.ok(Math.abs(dimensions.left - dimensions.navigationRight) <= 2, JSON.stringify(dimensions));
|
||||
assert.ok(dimensions.tabWidth >= 96, JSON.stringify(dimensions));
|
||||
assert.ok(dimensions.gap >= 0 && dimensions.gap <= 8, JSON.stringify(dimensions));
|
||||
assert.ok(dimensions.fits);
|
||||
const plus = page.getByRole("button", { name: "New tab (Ctrl+T)", exact: true });
|
||||
await plus.evaluate(button => button.blur());
|
||||
await plus.focus();
|
||||
await page.locator('[role="tooltip"]:popover-open').filter({ hasText: "New tab (Ctrl+T)" }).waitFor();
|
||||
await page.keyboard.press("Escape");
|
||||
await page.locator(".header").screenshot({ path: path.join(output, `compact-tabs-${width}-${theme}.png`) });
|
||||
}
|
||||
}
|
||||
await menu("note-0.md");
|
||||
await page.getByRole("menuitem", { name: "Close all", exact: true }).click();
|
||||
await tab("New tab").waitFor();
|
||||
assert.deepEqual(await order(), ["New tab"]);
|
||||
console.log("PASS: the last tab becomes a new tab, tabs retain usable widths, and the adjacent plus button has a focus tooltip");
|
||||
await openFile("a.md");
|
||||
await openFile("b.md");
|
||||
await openView("Overview");
|
||||
await page.getByRole("textbox", { name: "overview state" }).fill("Keep this state");
|
||||
await openView("Browser");
|
||||
const siteIcon = "data:image/svg+xml;base64," + Buffer.from('<svg xmlns="http://www.w3.org/2000/svg" width="16" height="16"><rect width="16" height="16" rx="3" fill="#e35336"/></svg>').toString('base64');
|
||||
await page.evaluate(image => window.tabTest.api.updateViewIcon("browser", image), siteIcon);
|
||||
await tab("Browser").locator("img.tab-icon").waitFor();
|
||||
await page.waitForFunction(() => document.querySelector('.header img.tab-icon')?.naturalWidth === 16);
|
||||
assert.equal(await tab("Browser").locator("img").getAttribute("alt"), "");
|
||||
assert.equal(await tab("Browser").locator("img").getAttribute("draggable"), "false");
|
||||
for (const theme of ["dark", "light"]) {
|
||||
await page.evaluate(theme => document.documentElement.dataset.theme = theme, theme);
|
||||
await page.locator(".header").screenshot({ path: path.join(output, `site-icon-${theme}.png`) });
|
||||
}
|
||||
await page.evaluate(() => window.tabTest.api.updateViewIcon("browser", "data:image/png;base64,aW1hZ2U="));
|
||||
await tab("Browser").locator("img").waitFor({ state: "detached" });
|
||||
assert.equal(await tab("Browser").locator("svg").count(), 1);
|
||||
await page.evaluate(image => window.tabTest.api.updateViewIcon("browser", image), siteIcon);
|
||||
await tab("Browser").locator("img").waitFor();
|
||||
await page.evaluate(() => window.tabTest.api.updateViewIcon("browser", null));
|
||||
await tab("Browser").locator("img").waitFor({ state: "detached" });
|
||||
assert.equal(await tab("Browser").locator("svg").count(), 1);
|
||||
console.log("PASS: site icons appear in both themes and missing or broken icons use the fallback");
|
||||
await openFile("project.board");
|
||||
await tab("project").waitFor();
|
||||
assert.equal(await page.locator(".header").getByRole("tablist").count(), 1);
|
||||
assert.deepEqual(await order(), ["a.md", "b.md", "Overview", "Browser", "project"]);
|
||||
await drag("Overview", "a.md");
|
||||
await drag("project", "b.md");
|
||||
await drag("a.md", "Browser", "after");
|
||||
const mixed = ["Overview", "project", "b.md", "Browser", "a.md"];
|
||||
assert.deepEqual(await order(), mixed);
|
||||
assert.equal(await tab("project").getAttribute("aria-selected"), "true");
|
||||
for (const cancel of ["escape", "outside"]) {
|
||||
await drag("Browser", "Overview", "before", cancel);
|
||||
assert.deepEqual(await order(), mixed);
|
||||
}
|
||||
await tab("Browser").press("Alt+Shift+Home");
|
||||
assert.equal((await order())[0], "Browser");
|
||||
await tab("Browser").press("ArrowRight");
|
||||
assert.equal(await tab("Overview").getAttribute("aria-selected"), "true");
|
||||
assert.equal(await page.getByRole("textbox", { name: "overview state" }).inputValue(), "Keep this state");
|
||||
await tab("Overview").press("ArrowRight");
|
||||
assert.equal(await tab("project").getAttribute("aria-selected"), "true");
|
||||
await page.evaluate(() => window.tabTest.api.updateViewTitle("browser", "Browser page"));
|
||||
await tab("Browser page").waitFor();
|
||||
assert.equal((await order())[0], "Browser page");
|
||||
assert.deepEqual(await page.evaluate(() => window.tabTest.mounts), { overview: 1, browser: 1, "project-board": 1 });
|
||||
assert.deepEqual(await page.evaluate(() => window.tabTest.disposals), {});
|
||||
assert.equal(await tab("project").getAttribute("aria-controls"), await page.getByRole("tabpanel", { name: "project" }).getAttribute("id"));
|
||||
for (const theme of ["dark", "light"]) {
|
||||
await page.evaluate(theme => document.documentElement.dataset.theme = theme, theme);
|
||||
await menu("Browser page");
|
||||
assert.equal(await page.getByRole("menuitem", { name: "Pin", exact: true }).count(), 1);
|
||||
await page.getByRole("menuitem", { name: "Move tab", exact: true }).click();
|
||||
await page.getByRole("menuitem", { name: "Move tab right", exact: true }).click();
|
||||
}
|
||||
console.log("PASS: mixed file, feature, and plugin document tabs move without remounting or changing selection");
|
||||
|
||||
await tab("Browser page").press("Alt+Shift+End");
|
||||
await tab("project").press("Alt+Shift+End");
|
||||
await tab("a.md").press("Alt+Shift+Home");
|
||||
await tab("Overview").press("Alt+Shift+Home");
|
||||
await tab("b.md").press("Alt+Shift+Home");
|
||||
await menu("b.md");
|
||||
await page.getByRole("menuitem", { name: "Pin", exact: true }).click();
|
||||
await tab("a.md").click();
|
||||
await page.locator(".cm-content").fill("Unsaved text");
|
||||
await tab("a.md •").waitFor();
|
||||
assert.deepEqual(await order(), ["b.md", "Overview", "a.md •", "Browser page", "project"]);
|
||||
await menu("Overview");
|
||||
await page.getByRole("menuitem", { name: "Close tabs after", exact: true }).click();
|
||||
await page.waitForFunction(() => window.tabTest.prompts === 1);
|
||||
assert.deepEqual(await order(), ["b.md", "Overview", "a.md •", "Browser page", "project"]);
|
||||
await page.evaluate(() => window.tabTest.answer = "Ok");
|
||||
await menu("Overview");
|
||||
await page.getByRole("menuitem", { name: "Close tabs after", exact: true }).click();
|
||||
await tab("project").waitFor({ state: "detached" });
|
||||
assert.deepEqual(await order(), ["b.md", "Overview"]);
|
||||
assert.equal(await tab("Overview").getAttribute("aria-selected"), "true");
|
||||
await menu("Overview");
|
||||
await page.getByRole("menuitem", { name: "Close all", exact: true }).click();
|
||||
await tab("Overview").waitFor({ state: "detached" });
|
||||
assert.deepEqual(await order(), ["b.md"]);
|
||||
assert.deepEqual(await page.evaluate(() => window.tabTest.disposals), { browser: 1, "project-board": 1, overview: 1 });
|
||||
console.log("PASS: mixed close actions follow visual order, preserve pins, and respect cancelled discards");
|
||||
|
||||
await openView("Overview");
|
||||
for (let index = 0; index < 14; index++) await openFile(`note-${index}.md`);
|
||||
await tab("Overview").press("Alt+Shift+Home");
|
||||
const source = await tab("Overview").boundingBox(), bounds = await bar.boundingBox();
|
||||
await page.mouse.move(source.x + source.width / 2, source.y + source.height / 2);
|
||||
await page.mouse.down();
|
||||
await page.mouse.move(bounds.x + bounds.width - 3, source.y + source.height / 2, { steps: 10 });
|
||||
await page.waitForFunction(() => {
|
||||
const bar = document.querySelector('[aria-label="Working tabs"]');
|
||||
return bar.scrollLeft >= bar.scrollWidth - bar.clientWidth - 2;
|
||||
});
|
||||
// Native drag needs a fresh pointer event after the strip scrolls beneath it, as in tabs/order.
|
||||
await page.mouse.move(bounds.x + bounds.width - 4, source.y + source.height / 2);
|
||||
await page.mouse.move(bounds.x + bounds.width - 3, source.y + source.height / 2);
|
||||
await page.mouse.up();
|
||||
await settle();
|
||||
assert.equal((await order()).at(-1), "Overview");
|
||||
await page.keyboard.press("Control+t");
|
||||
await tab("New tab").press("Alt+Shift+Home");
|
||||
await openFile("c.md");
|
||||
assert.equal((await order())[0], "c.md");
|
||||
const fileOrder = (await order()).filter(name => name !== "Overview");
|
||||
await page.keyboard.press("Control+,");
|
||||
const settingsPage = await openPage(context);
|
||||
pages.push(settingsPage);
|
||||
await settingsPage.goto(smokeUrl + '/?settingsWindow=true');
|
||||
await settingsPage.getByRole("button", { name: "Plug-ins", exact: true }).click();
|
||||
await settingsPage.getByRole("switch", { name: "Tab fixtures", exact: true }).click();
|
||||
await settingsPage.waitForFunction(() => document.getElementById("external-test.tabs")?.checked === false);
|
||||
await tab("Overview").waitFor({ state: "detached" });
|
||||
assert.deepEqual(await order(), fileOrder);
|
||||
console.log("PASS: plugin drag auto-scroll, empty-tab replacement, and plugin disable preserve the mixed order");
|
||||
await settingsPage.close();
|
||||
|
||||
await page.goto(`${smokeUrl}?no-workspace`);
|
||||
await tab("New tab").waitFor();
|
||||
await openView("Overview");
|
||||
await page.getByRole("button", { name: "Close New tab", exact: true }).click();
|
||||
await openView("Browser");
|
||||
await drag("Browser", "Overview");
|
||||
assert.deepEqual(await order(), ["Browser", "Overview"]);
|
||||
await page.setViewportSize({ width: 880, height: 700 });
|
||||
await page.screenshot({ path: path.join(output, "plugin-tab-order.png") });
|
||||
await tab("Browser").click({ button: "middle" });
|
||||
assert.deepEqual(await order(), ["Overview"]);
|
||||
await page.getByRole("button", { name: "Close Overview", exact: true }).click();
|
||||
await tab("New tab").waitFor();
|
||||
assert.deepEqual(await order(), ["New tab"]);
|
||||
assert.deepEqual(pages.flatMap(page => page.errors), []);
|
||||
console.log("PASS: plugin tabs reorder and close without an open workspace");
|
||||
for (const close of ["button", "middle", "shortcut", "all", "plugin", "dirty"]) {
|
||||
await page.goto(`${smokeUrl}?secondary`);
|
||||
await tab("New tab").waitFor();
|
||||
if (close === "plugin") {
|
||||
await openView("Overview");
|
||||
await page.getByRole("button", { name: "Close New tab", exact: true }).click();
|
||||
assert.equal(await page.evaluate(() => window.tabTest.closeRequests), 0);
|
||||
await page.getByRole("button", { name: "Close Overview", exact: true }).click();
|
||||
} else if (close === "dirty") {
|
||||
await openFile("a.md");
|
||||
await page.locator(".cm-content").fill("Keep these unsaved edits");
|
||||
await page.keyboard.press("Control+w");
|
||||
await page.waitForFunction(() => window.tabTest.prompts === 1);
|
||||
assert.equal(await page.evaluate(() => window.tabTest.destroys), 0);
|
||||
assert.match(await page.locator(".cm-content").innerText(), /Keep these unsaved edits/);
|
||||
await page.screenshot({ path: path.join(output, "secondary-last-tab-cancel.png") });
|
||||
await page.evaluate(() => window.tabTest.answer = "Ok");
|
||||
await page.keyboard.press("Control+w");
|
||||
} else if (close === "button") {
|
||||
await page.getByRole("button", { name: "Close New tab", exact: true }).click();
|
||||
} else if (close === "middle") {
|
||||
await tab("New tab").click({ button: "middle" });
|
||||
} else if (close === "shortcut") {
|
||||
await page.keyboard.press("Control+w");
|
||||
} else {
|
||||
await openFile("a.md");
|
||||
await openFile("b.md");
|
||||
await menu("b.md");
|
||||
await page.getByRole("menuitem", { name: "Close all", exact: true }).click();
|
||||
}
|
||||
await page.waitForFunction(() => window.tabTest.destroys === 1);
|
||||
assert.equal(await page.evaluate(() => window.tabTest.closeRequests), close === "dirty" ? 2 : 1);
|
||||
}
|
||||
assert.deepEqual(pages.flatMap(page => page.errors), []);
|
||||
console.log("PASS: secondary windows close through the window guard for the last empty, document, or plugin tab; Cancel preserves unsaved edits");
|
||||
});
|
||||
@@ -0,0 +1,169 @@
|
||||
// Tab sessions: restore after a normal close, missing files, cancelled closes, plugin documents, and plugin tab transfers between windows and workspaces.
|
||||
import assert from "node:assert/strict";
|
||||
import path from "node:path";
|
||||
import { mockTauri, openPage, outputDir, runSmoke, smokeUrl } from "../_harness/index.mjs";
|
||||
|
||||
const pluginCode = `export function activate(api) {
|
||||
let state = "Board state";
|
||||
api.registerView({ id: "board", title: "Board", icon: "kanban", placement: "editor", navigation: true,
|
||||
saveTabState: () => state, restoreTabState: value => { state = value; },
|
||||
mount(container) {
|
||||
const input = document.createElement("input"); input.setAttribute("aria-label", "Board state");
|
||||
input.value = state; input.oninput = () => { state = input.value; }; container.append(input);
|
||||
return () => input.remove();
|
||||
}
|
||||
});
|
||||
api.registerDocumentType({ id: "document", title: "Board document", extensions: ["board"], icon: "kanban",
|
||||
identify: (path, source) => source === "board document" ? { id: path } : null,
|
||||
mount(container) { container.textContent = "Saved board document"; return () => { container.textContent = ""; }; }
|
||||
});
|
||||
}`;
|
||||
|
||||
// `window.requestClose()` sends the native close request and waits for the async close guard, which the harness emit does not await.
|
||||
function closeRequests(target) {
|
||||
return target.addInitScript(() => {
|
||||
const internals = window.__TAURI_INTERNALS__;
|
||||
const { transformCallback, invoke } = internals;
|
||||
const callbacks = new Map(), handlers = [];
|
||||
internals.transformCallback = (callback, once) => { const id = transformCallback(callback, once); callbacks.set(id, callback); return id; };
|
||||
internals.invoke = (command, args = {}) => {
|
||||
if (command === "plugin:event|listen" && args.event === "tauri://close-requested") handlers.push(args.handler);
|
||||
return invoke(command, args);
|
||||
};
|
||||
window.requestClose = async () => {
|
||||
for (const id of handlers) await callbacks.get(id)?.({ event: "tauri://close-requested", id, payload: null });
|
||||
};
|
||||
});
|
||||
}
|
||||
|
||||
await runSmoke("tabs/lifecycle", async ({ browser }) => {
|
||||
const output = await outputDir("tabs/lifecycle");
|
||||
const context = await browser.newContext({ viewport: { width: 1400, height: 900 } });
|
||||
await mockTauri(context, {
|
||||
state: { pluginCode },
|
||||
commands: test => {
|
||||
localStorage.setItem("runestone.settings", JSON.stringify({ autosaveEnabled: false }));
|
||||
const params = new URLSearchParams(location.search);
|
||||
const root = params.has("other") ? "C:\\other-lifecycle" : params.has("plugins") ? "C:\\plugins-lifecycle" : "C:\\document-lifecycle";
|
||||
const files = Object.fromEntries(["a.md", "b.md", "c.md"].map(name => [name, `# ${name}\n\nSaved text.\n`]));
|
||||
files["saved.board"] = "board document";
|
||||
if (params.has("missing")) delete files["a.md"];
|
||||
const manifest = { schemaVersion: 1, id: "test.lifecycle", name: "Lifecycle", author: "Tests", description: "Tab fixture", version: "1.0.0", apiVersion: 1, entry: "main.js", access: "full-app" };
|
||||
Object.assign(test, { answer: "Cancel", root, transfer: null });
|
||||
return {
|
||||
...test.workspace({ root, name: "Lifecycle", files }),
|
||||
"plugin:window|is_maximized": () => false,
|
||||
"plugin:window|destroy": () => null,
|
||||
"plugin:dialog|message": () => test.answer,
|
||||
workspace_open_window: ({ transfer }) => { test.transfer = transfer; },
|
||||
plugins_snapshot: () => ({ root, plugins: params.has("disabled") ? [] : [{ manifest, hash: "test", enabled: true, path: root, error: null, removal: false }] }),
|
||||
plugins_load: () => test.state.pluginCode,
|
||||
};
|
||||
},
|
||||
});
|
||||
await closeRequests(context);
|
||||
const pages = [];
|
||||
const dragSources = new Map();
|
||||
const tab = (page, name) => page.getByRole("tab", { name, exact: true });
|
||||
const bar = page => page.getByRole("tablist", { name: "Working tabs" });
|
||||
const session = page => page.evaluate(() => JSON.parse(localStorage.getItem(`runestone.document-session.${encodeURIComponent(window.__TEST__.root)}`)));
|
||||
async function create(query = "") {
|
||||
const page = await openPage(context, { timeout: 15000 });
|
||||
pages.push(page);
|
||||
await page.goto(smokeUrl + query); await page.getByRole("tab").first().waitFor(); return page;
|
||||
}
|
||||
async function open(page, name) {
|
||||
await page.bringToFront(); await page.keyboard.press("Control+p");
|
||||
await page.getByRole("textbox", { name: "Find a file" }).fill(name);
|
||||
await page.getByRole("dialog").getByRole("button").filter({ hasText: name }).first().click();
|
||||
await tab(page, name === "saved.board" ? "saved" : name).waitFor();
|
||||
}
|
||||
async function openBoard(page) {
|
||||
await page.getByRole("navigation", { name: "Plugin shortcuts" }).getByRole("button", { name: "Board", exact: true }).click();
|
||||
await page.getByRole("textbox", { name: "Board state" }).waitFor();
|
||||
}
|
||||
async function pin(page, name) {
|
||||
await tab(page, name).click({ button: "right" }); await page.getByRole("menuitem", { name: "Pin", exact: true }).click();
|
||||
}
|
||||
async function start(page, name) {
|
||||
const data = await tab(page, name).evaluate(node => {
|
||||
if (node.getAttribute("draggable") !== "true") throw new Error("The tab must support native transfer.");
|
||||
const transfer = new DataTransfer(); node.dispatchEvent(new DragEvent("dragstart", { bubbles: true, dataTransfer: transfer }));
|
||||
return transfer.getData("application/x-runestone-tab");
|
||||
});
|
||||
dragSources.set(data, { page, name });
|
||||
return data;
|
||||
}
|
||||
async function drop(page, data) {
|
||||
await bar(page).evaluate((node, data) => {
|
||||
const transfer = new DataTransfer(); transfer.setData("application/x-runestone-tab", data);
|
||||
const options = { bubbles: true, cancelable: true, clientX: node.getBoundingClientRect().left, dataTransfer: transfer };
|
||||
node.dispatchEvent(new DragEvent("dragover", options)); node.dispatchEvent(new DragEvent("drop", options));
|
||||
}, data);
|
||||
const source = dragSources.get(data);
|
||||
if (source) {
|
||||
await tab(source.page, source.name).evaluateAll(nodes => nodes[0]?.dispatchEvent(new DragEvent("dragend", { bubbles: true })));
|
||||
}
|
||||
}
|
||||
async function screenshots(page, prefix) {
|
||||
for (const mode of ["dark", "light"]) {
|
||||
await page.evaluate(async mode => { const { applyAppearance } = await import("/src/lib/theme/appearance.ts"); await applyAppearance({ theme: "default", mode }); }, mode);
|
||||
await page.screenshot({ path: path.join(output, `${prefix}-${mode}.png`) });
|
||||
}
|
||||
await page.setViewportSize({ width: 700, height: 700 });
|
||||
await page.screenshot({ path: path.join(output, `${prefix}-narrow.png`) });
|
||||
await page.setViewportSize({ width: 1400, height: 900 });
|
||||
}
|
||||
|
||||
const page = await create();
|
||||
for (const name of ["a.md", "b.md", "c.md"]) await open(page, name);
|
||||
await tab(page, "c.md").focus(); await page.keyboard.press("Alt+Shift+ArrowLeft"); await page.keyboard.press("Alt+Shift+ArrowLeft");
|
||||
await pin(page, "b.md"); await tab(page, "b.md").click();
|
||||
await page.evaluate(() => window.requestClose());
|
||||
const saved = await session(page);
|
||||
assert.deepEqual(saved.documents.map(item => item.path), ["c.md", "a.md", "b.md"]);
|
||||
assert.equal(saved.activePath, "b.md"); assert.equal(saved.documents[2].pinned, true);
|
||||
assert.ok(!JSON.stringify(saved).includes("Saved text"));
|
||||
await page.goto(smokeUrl + "?missing"); await tab(page, "b.md").waitFor();
|
||||
assert.deepEqual(await bar(page).getByRole("tab").evaluateAll(nodes => nodes.map(node => node.dataset.path)), ["c.md", "b.md"]);
|
||||
assert.equal(await tab(page, "b.md").getAttribute("aria-selected"), "true");
|
||||
await tab(page, "b.md").click({ button: "right" }); await page.getByRole("menuitem", { name: "Unpin", exact: true }).waitFor(); await page.keyboard.press("Escape");
|
||||
await screenshots(page, "restored-documents");
|
||||
await page.locator(".cm-content").fill("Unsaved draft");
|
||||
await page.evaluate(() => window.requestClose());
|
||||
assert.deepEqual(await session(page), saved);
|
||||
await page.evaluate(() => { window.__TEST__.answer = "Ok"; return window.requestClose(); });
|
||||
page.on("dialog", dialog => dialog.accept());
|
||||
await page.reload(); await tab(page, "b.md").waitFor();
|
||||
assert.match(await page.locator(".cm-content").innerText(), /Saved text/);
|
||||
await open(page, "saved.board"); await page.getByText("Saved board document", { exact: true }).waitFor();
|
||||
await page.evaluate(() => window.requestClose()); await page.reload();
|
||||
await tab(page, "saved").waitFor(); await page.getByText("Saved board document", { exact: true }).waitFor();
|
||||
console.log("PASS: normal-close restore, order, active tab, pins, missing files, canceled close, disk-only restore, and plugin documents");
|
||||
|
||||
const source = await create("?plugins"), target = await create("?plugins"), other = await create("?other"), disabled = await create("?plugins&disabled");
|
||||
assert.equal(await tab(other, "New tab").count(), 1);
|
||||
await openBoard(source); await source.getByRole("textbox", { name: "Board state" }).fill("Transferred board state"); await pin(source, "Board");
|
||||
let data = await start(source, "Board"); assert.ok(JSON.parse(data).tabTransfer);
|
||||
await drop(other, data); await other.getByText("Move tabs only between windows of the same workspace.").waitFor();
|
||||
await drop(disabled, data); await disabled.getByText("Enable this tab's plugin before moving it to this window.").waitFor();
|
||||
assert.equal(await tab(source, "Board").count(), 1);
|
||||
await drop(target, data); await tab(target, "Board").waitFor(); await tab(source, "Board").waitFor({ state: "detached" });
|
||||
assert.equal(await target.getByRole("textbox", { name: "Board state" }).inputValue(), "Transferred board state");
|
||||
await tab(target, "Board").click({ button: "right" }); await target.getByRole("menuitem", { name: "Unpin", exact: true }).waitFor(); await target.keyboard.press("Escape");
|
||||
await screenshots(target, "joined-plugin");
|
||||
data = await start(target, "Board"); await drop(source, data); await tab(target, "Board").waitFor({ state: "detached" });
|
||||
await openBoard(target); await target.getByRole("textbox", { name: "Board state" }).fill("Destination state");
|
||||
data = await start(source, "Board"); await drop(target, data);
|
||||
await target.getByText("This tab is already open in this window. The source tab remains open.").waitFor();
|
||||
assert.equal(await target.getByRole("textbox", { name: "Board state" }).inputValue(), "Destination state"); assert.equal(await tab(source, "Board").count(), 1);
|
||||
await tab(source, "Board").evaluate(node => node.dispatchEvent(new DragEvent("dragend", { bubbles: true })));
|
||||
await tab(source, "Board").click({ button: "right" }); await source.getByRole("menuitem", { name: "Open in new window", exact: true }).click();
|
||||
const token = await source.evaluate(() => window.__TEST__.transfer); assert.ok(token);
|
||||
const detached = await create(`?plugins&tabTransfer=${token}`); await detached.getByRole("textbox", { name: "Board state" }).waitFor();
|
||||
await tab(source, "Board").waitFor({ state: "detached" });
|
||||
data = await start(detached, "Board"); await drop(source, data); await tab(detached, "Board").waitFor({ state: "detached" });
|
||||
assert.equal(await source.getByRole("textbox", { name: "Board state" }).inputValue(), "Transferred board state");
|
||||
assert.deepEqual(pages.flatMap(page => page.errors), []);
|
||||
console.log("PASS: workspace isolation, plugin join, duplicate protection, disabled plugin, and tear-out return");
|
||||
});
|
||||
@@ -0,0 +1,130 @@
|
||||
// Tab menus: active and inactive tabs, keyboard focus, pinning, view modes, file actions, ordered closes, cancelled discards, and empty tabs.
|
||||
import assert from "node:assert/strict";
|
||||
import path from "node:path";
|
||||
import { mockTauri, outputDir, runSmoke, smokeUrl } from "../_harness/index.mjs";
|
||||
|
||||
await runSmoke("tabs/menus", async ({ page }) => {
|
||||
const output = await outputDir("tabs/menus");
|
||||
await mockTauri(page, {
|
||||
commands: test => {
|
||||
test.prompts = [];
|
||||
test.answer = "Cancel";
|
||||
Object.defineProperty(navigator, "clipboard", { value: { writeText: async text => { test.clipboard = text; } } });
|
||||
return {
|
||||
...test.workspace({ root: "C:\\tab-menu-workspace", files: Object.fromEntries(["a.md", "b.md", "c.md", "d.md"].map(name => [name, `# ${name}\n\nOriginal text.\n`])) }),
|
||||
workspace_write: () => { throw new Error("Keep unsaved edits for the close test"); },
|
||||
workspace_reveal: ({ rel }) => { test.revealed = rel; },
|
||||
"plugin:dialog|message": ({ message }) => { test.prompts.push(message); return test.answer; },
|
||||
};
|
||||
},
|
||||
});
|
||||
const tab = name => page.getByRole("tab", { name, exact: true });
|
||||
const menu = () => page.getByRole("menu", { name: "Tab actions", exact: true });
|
||||
const item = name => page.getByRole("menuitem", { name, exact: true });
|
||||
const order = () => page.getByRole("tab").evaluateAll(nodes => nodes.map(node => node.dataset.path));
|
||||
async function open(name) {
|
||||
await page.keyboard.press("Control+p");
|
||||
await page.getByRole("textbox", { name: "Find a file" }).fill(name);
|
||||
await page.getByRole("dialog").getByRole("button").filter({ hasText: name }).first().click();
|
||||
await tab(name).waitFor();
|
||||
}
|
||||
async function show(name) { await tab(name).click({ button: "right" }); await menu().waitFor(); }
|
||||
|
||||
await page.goto(smokeUrl);
|
||||
await page.getByText("tab-menu-workspace", { exact: true }).waitFor();
|
||||
for (const name of ["a.md", "b.md", "c.md", "d.md"]) await open(name);
|
||||
await page.locator(".cm-content").filter({ hasText: "Original text." }).waitFor();
|
||||
await show("b.md");
|
||||
assert.equal(await tab("d.md").getAttribute("aria-selected"), "true");
|
||||
assert.equal(await item("Rename…").count(), 0);
|
||||
assert.equal(await item("View").count(), 0);
|
||||
assert.doesNotMatch(await menu().innerText(), /Alt|Shift|Ctrl/);
|
||||
await page.screenshot({ path: path.join(output, "inactive.png") });
|
||||
await item("Pin").click();
|
||||
assert.equal(await tab("d.md").getAttribute("aria-selected"), "true");
|
||||
assert.ok(await tab("b.md").getAttribute("aria-describedby"));
|
||||
await show("d.md");
|
||||
assert.equal(await item("Close tabs after").isDisabled(), true);
|
||||
await page.screenshot({ path: path.join(output, "active.png") });
|
||||
await page.keyboard.press("Escape");
|
||||
assert.equal(await tab("d.md").evaluate(node => node === document.activeElement), true);
|
||||
await tab("d.md").press("Shift+F10");
|
||||
assert.equal(await item("Close").evaluate(node => node === document.activeElement), true);
|
||||
await page.keyboard.press("End");
|
||||
await page.keyboard.press("ArrowRight");
|
||||
assert.equal(await item("Move tab left").evaluate(node => node === document.activeElement), true);
|
||||
await page.keyboard.press("ArrowLeft");
|
||||
await page.keyboard.press("Escape");
|
||||
// The View submenu has the same choices as the view control of the pane.
|
||||
const view = async name => {
|
||||
await show("d.md");
|
||||
await item("View").click();
|
||||
await page.getByRole(name === "Read beside" ? "menuitemcheckbox" : "menuitemradio", { name, exact: true }).click();
|
||||
};
|
||||
await show("d.md");
|
||||
await item("View").click();
|
||||
assert.equal(await page.getByRole("menuitemradio", { name: "Write", exact: true }).getAttribute("aria-checked"), "true");
|
||||
await page.keyboard.press("Escape");
|
||||
await page.keyboard.press("Escape");
|
||||
await view("Read");
|
||||
await page.locator(".md-page").waitFor();
|
||||
await view("Read beside");
|
||||
await page.locator(".body.split .md-page").waitFor();
|
||||
await view("Source");
|
||||
await page.locator(".body.split .source-editor .cm-content").waitFor();
|
||||
await view("Read beside");
|
||||
await page.locator(".md-page").waitFor({ state: "detached" });
|
||||
await view("Write");
|
||||
await page.locator(".live-writer .cm-editor").waitFor();
|
||||
await show("d.md");
|
||||
await item("Copy path").click();
|
||||
await item("Workspace path").click();
|
||||
assert.equal(await page.evaluate(() => window.__TEST__.clipboard), "d.md");
|
||||
await show("d.md");
|
||||
await item("Show in Explorer").click();
|
||||
assert.equal(await page.evaluate(() => window.__TEST__.revealed), "d.md");
|
||||
await show("d.md");
|
||||
await item("Rename…").click();
|
||||
await page.getByRole("dialog").getByRole("textbox").fill("renamed.md");
|
||||
await page.getByRole("dialog").getByRole("button", { name: "Continue", exact: true }).click();
|
||||
await tab("renamed.md").waitFor();
|
||||
await show("a.md");
|
||||
await item("Close tabs after").click();
|
||||
await tab("renamed.md").waitFor({ state: "detached" });
|
||||
assert.deepEqual(await order(), ["a.md", "b.md"]);
|
||||
await open("c.md");
|
||||
await show("c.md");
|
||||
await item("Close others").click();
|
||||
await tab("a.md").waitFor({ state: "detached" });
|
||||
assert.deepEqual(await order(), ["b.md", "c.md"]);
|
||||
await page.locator(".cm-content").click();
|
||||
await page.keyboard.press("Control+End");
|
||||
await page.keyboard.type("Unsaved text");
|
||||
await tab("c.md •").waitFor();
|
||||
await show("c.md •");
|
||||
await item("Close all").click();
|
||||
await page.waitForFunction(() => window.__TEST__.prompts.length === 1);
|
||||
assert.deepEqual(await order(), ["b.md", "c.md"]);
|
||||
// A changed tab asks Save, Don't save, or Cancel (src/lib/layout/Workbench.svelte).
|
||||
await page.evaluate(() => { window.__TEST__.answer = "Don't save"; });
|
||||
await show("c.md •");
|
||||
await item("Close all").click();
|
||||
await tab("c.md •").waitFor({ state: "detached" });
|
||||
assert.deepEqual(await order(), ["b.md"]);
|
||||
await show("b.md");
|
||||
assert.equal(await item("Close all").isDisabled(), true);
|
||||
await item("Unpin").click();
|
||||
await show("b.md");
|
||||
await item("Close").click();
|
||||
await tab("b.md").waitFor({ state: "detached" });
|
||||
// Closing the last tab leaves an empty tab (src/lib/layout/Workbench.svelte:291), so the plus button adds a second one.
|
||||
await tab("New tab").waitFor();
|
||||
await page.getByRole("button", { name: "New tab (Ctrl+T)", exact: true }).click();
|
||||
const added = page.getByRole("tab", { name: "New tab", exact: true, selected: true });
|
||||
await page.waitForFunction(() => document.querySelectorAll('[role="tab"][data-path^="empty:"]').length === 2);
|
||||
await added.click({ button: "right" });
|
||||
await menu().waitFor();
|
||||
assert.equal(await item("Rename…").count(), 0);
|
||||
assert.equal(await item("View").count(), 0);
|
||||
await page.keyboard.press("Escape");
|
||||
}, { timeout: 15000 });
|
||||
@@ -0,0 +1,105 @@
|
||||
// Tab order: pointer drags, cancellation, keyboard moves, tab menus, empty tabs, and an overflowing tab bar.
|
||||
import assert from "node:assert/strict";
|
||||
import { mockTauri, runSmoke, settle as settleFrames, smokeUrl } from "../_harness/index.mjs";
|
||||
|
||||
await runSmoke("tabs/order", async ({ page }) => {
|
||||
await mockTauri(page, {
|
||||
commands: test => {
|
||||
const files = new Map(Array.from({ length: 16 }, (_, i) => [`note-${String(i).padStart(2, "0")}.md`, `# Note ${i}\n\nKeep this text.\n`]));
|
||||
files.set("note-00.md", Array.from({ length: 200 }, (_, i) => `Paragraph ${i}.\n\n`).join(""));
|
||||
return {
|
||||
...test.workspace({ root: "C:\\tab-order-workspace", files }),
|
||||
workspace_search: () => [],
|
||||
"plugin:dialog|message": () => "Cancel",
|
||||
};
|
||||
},
|
||||
});
|
||||
const settle = () => settleFrames(page);
|
||||
const tab = name => page.getByRole("tab", { name, exact: true });
|
||||
const order = () => page.getByRole("tablist", { name: "Working tabs" }).getByRole("tab").evaluateAll(nodes => nodes.map(node => node.dataset.path));
|
||||
async function open(name) {
|
||||
await page.keyboard.press("Control+p");
|
||||
await page.getByRole("textbox", { name: "Find a file" }).fill(name);
|
||||
await page.getByRole("dialog").getByRole("button").filter({ hasText: name }).first().click();
|
||||
await tab(name).waitFor();
|
||||
}
|
||||
async function drag(from, to, side, cancel) {
|
||||
const source = await tab(from).boundingBox();
|
||||
const target = await tab(to).boundingBox();
|
||||
await page.mouse.move(source.x + source.width / 2, source.y + source.height / 2);
|
||||
await page.mouse.down();
|
||||
await page.mouse.move(side === "before" ? target.x + 2 : target.x + target.width - 2, target.y + target.height / 2, { steps: 10 });
|
||||
if (cancel === "escape") await page.keyboard.press("Escape");
|
||||
if (cancel === "outside") await page.mouse.move(target.x, target.y + 100);
|
||||
await page.mouse.up();
|
||||
await settle();
|
||||
}
|
||||
await page.goto(smokeUrl);
|
||||
await page.getByText("tab-order-workspace", { exact: true }).waitFor();
|
||||
for (const name of ["note-00.md", "note-01.md", "note-02.md"]) await open(name);
|
||||
await drag("note-00.md", "note-02.md", "after");
|
||||
assert.deepEqual(await order(), ["note-01.md", "note-02.md", "note-00.md"]);
|
||||
assert.equal(await tab("note-02.md").getAttribute("aria-selected"), "true");
|
||||
await drag("note-00.md", "note-01.md", "before");
|
||||
assert.deepEqual(await order(), ["note-00.md", "note-01.md", "note-02.md"]);
|
||||
for (const cancel of ["escape", "outside"]) {
|
||||
await drag("note-00.md", "note-02.md", "after", cancel);
|
||||
assert.deepEqual(await order(), ["note-00.md", "note-01.md", "note-02.md"]);
|
||||
}
|
||||
await tab("note-00.md").click();
|
||||
assert.equal(await tab("note-00.md").getAttribute("aria-selected"), "true");
|
||||
await page.locator(".cm-scroller").evaluate(node => { node.scrollTop = 1200; });
|
||||
await settle();
|
||||
const scrollTop = await page.locator(".cm-scroller").evaluate(node => node.scrollTop);
|
||||
assert.ok(scrollTop > 1000);
|
||||
await tab("note-00.md").press("Alt+Shift+ArrowRight");
|
||||
await settle();
|
||||
assert.deepEqual(await order(), ["note-01.md", "note-00.md", "note-02.md"]);
|
||||
assert.ok(Math.abs(await page.locator(".cm-scroller").evaluate(node => node.scrollTop) - scrollTop) < 5);
|
||||
assert.equal(await tab("note-00.md").evaluate(node => document.activeElement === node), true);
|
||||
await tab("note-00.md").press("ArrowRight");
|
||||
assert.equal(await tab("note-02.md").getAttribute("aria-selected"), "true");
|
||||
await tab("note-02.md").press("Shift+F10");
|
||||
await page.getByRole("menuitem", { name: "Move tab", exact: true }).click();
|
||||
assert.equal(await page.getByRole("menuitem", { name: /Move tab right/ }).isDisabled(), true);
|
||||
await page.getByRole("menuitem", { name: /Move tab left/ }).click();
|
||||
assert.deepEqual(await order(), ["note-01.md", "note-02.md", "note-00.md"]);
|
||||
await tab("note-01.md").click({ button: "right" });
|
||||
await page.getByRole("menuitem", { name: "Move tab", exact: true }).click();
|
||||
assert.equal(await page.getByRole("menuitem", { name: /Move tab left/ }).isDisabled(), true);
|
||||
await page.keyboard.press("Escape");
|
||||
assert.equal(await page.getByRole("menu", { name: "Tab actions" }).count(), 0);
|
||||
console.log("PASS: pointer moves, cancellation, keyboard moves, and tab menus");
|
||||
|
||||
await page.getByRole("button", { name: "New tab (Ctrl+T)", exact: true }).click();
|
||||
await tab("New tab").press("Alt+Shift+Home");
|
||||
assert.match((await order())[0], /^empty:/);
|
||||
await page.getByRole("button", { name: "Close New tab", exact: true }).click();
|
||||
await tab("note-01.md").click({ button: "middle" });
|
||||
assert.deepEqual(await order(), ["note-02.md", "note-00.md"]);
|
||||
console.log("PASS: empty tabs and middle-click close after reorder");
|
||||
|
||||
for (let i = 3; i < 16; i++) await open(`note-${String(i).padStart(2, "0")}.md`);
|
||||
const bar = page.getByRole("tablist", { name: "Working tabs" });
|
||||
assert.ok(await bar.evaluate(node => node.scrollLeft > 0));
|
||||
await tab("note-15.md").press("Alt+Shift+Home");
|
||||
assert.equal((await order())[0], "note-15.md");
|
||||
assert.equal(await bar.evaluate(node => node.scrollLeft), 0);
|
||||
const source = await tab("note-15.md").boundingBox();
|
||||
const bounds = await bar.boundingBox();
|
||||
await page.mouse.move(source.x + source.width / 2, source.y + source.height / 2);
|
||||
await page.mouse.down();
|
||||
await page.mouse.move(bounds.x + bounds.width - 3, source.y + source.height / 2, { steps: 10 });
|
||||
await page.waitForFunction(() => {
|
||||
const bar = document.querySelector('[aria-label="Working tabs"]');
|
||||
return bar.scrollLeft >= bar.scrollWidth - bar.clientWidth - 2;
|
||||
});
|
||||
// Native drag needs a fresh pointer event after the strip scrolls beneath it.
|
||||
await page.mouse.move(bounds.x + bounds.width - 4, source.y + source.height / 2);
|
||||
await page.mouse.move(bounds.x + bounds.width - 3, source.y + source.height / 2);
|
||||
await page.mouse.up();
|
||||
await settle();
|
||||
assert.equal((await order()).at(-1), "note-15.md");
|
||||
console.log("PASS: automatic scrolling and drag to the end of an overflowing tab bar");
|
||||
if (process.env.SCREENSHOT_PATH) await page.screenshot({ path: process.env.SCREENSHOT_PATH });
|
||||
});
|
||||
@@ -0,0 +1,149 @@
|
||||
// Tab drops on the titlebar ribbon: broad and nearby targets, exact ordering, rejected areas, ordinary drags, pinned unsaved documents, and plugin tabs.
|
||||
import assert from "node:assert/strict";
|
||||
import path from "node:path";
|
||||
import { mockTauri, openPage, outputDir, runSmoke, smokeUrl } from "../_harness/index.mjs";
|
||||
|
||||
const pluginCode = `export function activate(api) {
|
||||
let state = "Board state";
|
||||
api.registerView({ id: "board", title: "Board", icon: "kanban", placement: "editor", navigation: true,
|
||||
saveTabState: () => state, restoreTabState: value => { state = value; },
|
||||
mount(container) {
|
||||
const input = document.createElement("input"); input.setAttribute("aria-label", "Board state");
|
||||
input.value = state; input.oninput = () => { state = input.value; }; container.append(input);
|
||||
return () => input.remove();
|
||||
}
|
||||
});
|
||||
}`;
|
||||
|
||||
await runSmoke("tabs/ribbonDrop", async ({ browser }) => {
|
||||
const output = await outputDir("tabs/ribbonDrop");
|
||||
const context = await browser.newContext({ viewport: { width: 1400, height: 900 } });
|
||||
await mockTauri(context, {
|
||||
state: { pluginCode },
|
||||
commands: test => {
|
||||
localStorage.setItem("runestone.settings", JSON.stringify({ autosaveEnabled: false }));
|
||||
const root = "C:\\plugins-lifecycle";
|
||||
const manifest = { schemaVersion: 1, id: "test.lifecycle", name: "Lifecycle", author: "Tests", description: "Tab fixture", version: "1.0.0", apiVersion: 1, entry: "main.js", access: "full-app" };
|
||||
return {
|
||||
...test.workspace({ root, name: "Lifecycle", files: Object.fromEntries(["a.md", "b.md", "c.md"].map(name => [name, `# ${name}\n\nSaved text.\n`])) }),
|
||||
"plugin:window|is_maximized": () => false,
|
||||
plugins_snapshot: () => ({ root, plugins: [{ manifest, hash: "test", enabled: true, path: root, error: null, removal: false }] }),
|
||||
plugins_load: () => test.state.pluginCode,
|
||||
};
|
||||
},
|
||||
});
|
||||
const pages = [];
|
||||
const tab = (page, name) => page.getByRole("tab", { name, exact: true });
|
||||
const bar = page => page.getByRole("tablist", { name: "Working tabs" });
|
||||
const order = page => bar(page).getByRole("tab").evaluateAll(nodes => nodes.map(node => node.textContent.trim()));
|
||||
async function create() {
|
||||
const page = await openPage(context, { timeout: 15000 });
|
||||
pages.push(page);
|
||||
await page.goto(smokeUrl + "?plugins"); await page.getByRole("tab").first().waitFor(); return page;
|
||||
}
|
||||
async function open(page, name) {
|
||||
await page.bringToFront(); await page.keyboard.press("Control+p");
|
||||
await page.getByRole("textbox", { name: "Find a file" }).fill(name);
|
||||
await page.getByRole("dialog").getByRole("button").filter({ hasText: name }).first().click();
|
||||
await tab(page, name).waitFor();
|
||||
}
|
||||
async function openBoard(page) {
|
||||
await page.getByRole("navigation", { name: "Plugin shortcuts" }).getByRole("button", { name: "Board", exact: true }).click();
|
||||
await page.getByRole("textbox", { name: "Board state" }).waitFor();
|
||||
}
|
||||
async function pin(page, name) {
|
||||
await tab(page, name).click({ button: "right" }); await page.getByRole("menuitem", { name: "Pin", exact: true }).click();
|
||||
}
|
||||
function start(page, name) {
|
||||
return tab(page, name).evaluate(node => {
|
||||
if (node.getAttribute("draggable") !== "true") throw new Error("The tab must support native transfer.");
|
||||
const transfer = new DataTransfer(); node.dispatchEvent(new DragEvent("dragstart", { bubbles: true, dataTransfer: transfer }));
|
||||
return transfer.getData("application/x-runestone-tab");
|
||||
});
|
||||
}
|
||||
async function setTheme(page, mode) {
|
||||
await page.evaluate(async mode => { const { applyAppearance } = await import("/src/lib/theme/appearance.ts"); await applyAppearance({ theme: "default", mode }); }, mode);
|
||||
}
|
||||
async function screenshots(page, prefix) {
|
||||
for (const mode of ["dark", "light"]) {
|
||||
await setTheme(page, mode);
|
||||
await page.screenshot({ path: path.join(output, `${prefix}-${mode}.png`) });
|
||||
}
|
||||
await page.setViewportSize({ width: 700, height: 700 });
|
||||
await page.screenshot({ path: path.join(output, `${prefix}-narrow.png`) });
|
||||
await page.setViewportSize({ width: 1400, height: 900 });
|
||||
}
|
||||
async function eventAt(page, data, point, type = "dragover", mime = "application/x-runestone-tab") {
|
||||
return page.evaluate(({ data, point, type, mime }) => {
|
||||
const transfer = new DataTransfer(); transfer.setData(mime, data);
|
||||
const node = document.elementFromPoint(point.x, point.y) || document.body;
|
||||
const event = new DragEvent(type, { bubbles: true, cancelable: true, clientX: point.x, clientY: point.y, dataTransfer: transfer });
|
||||
node.dispatchEvent(event);
|
||||
return event.defaultPrevented;
|
||||
}, { data, point, type, mime });
|
||||
}
|
||||
async function receive(page, data, point) {
|
||||
assert.equal(await eventAt(page, data, point), true);
|
||||
assert.equal(await eventAt(page, data, point, "drop"), true);
|
||||
}
|
||||
async function point(page, kind) {
|
||||
return page.locator(".header").evaluate((header, kind) => {
|
||||
const bounds = header.getBoundingClientRect();
|
||||
const bar = header.querySelector('[role="tablist"]').getBoundingClientRect();
|
||||
const plus = header.querySelector('[aria-label="New tab (Ctrl+T)"]').getBoundingClientRect();
|
||||
const first = header.querySelector('.tab').getBoundingClientRect();
|
||||
if (kind === "near") return { x: first.left + first.width / 2, y: bounds.bottom + 18 };
|
||||
if (kind === "outside") return { x: first.left + first.width / 2, y: bounds.bottom + 80 };
|
||||
if (kind === "precise") return { x: bar.left + 2, y: bar.top + bar.height / 2 };
|
||||
if (kind === "controls") { const controls = header.querySelector('.window-controls').getBoundingClientRect(); return { x: controls.left + 10, y: controls.top + controls.height / 2 }; }
|
||||
if (kind === "blank") return { x: plus.right + 16, y: bounds.top + bounds.height / 2 };
|
||||
return { x: plus.left + plus.width / 2, y: plus.top + plus.height / 2 };
|
||||
}, kind);
|
||||
}
|
||||
|
||||
const source = await create(), target = await create();
|
||||
await open(target, "b.md");
|
||||
await open(source, "a.md"); await pin(source, "a.md");
|
||||
await source.locator(".cm-content").fill("Unsaved ribbon transfer");
|
||||
let data = await start(source, "a.md •");
|
||||
const broad = await point(target, "blank");
|
||||
assert.equal(await eventAt(target, data, broad), true, "Blank titlebar space accepts transferred tabs");
|
||||
assert.equal(await bar(target).evaluate(node => node.classList.contains("receiving")), true);
|
||||
assert.equal(await eventAt(target, data, await point(target, "outside")), false, "The document body stays outside the drop target");
|
||||
assert.equal(await bar(target).evaluate(node => node.classList.contains("receiving")), false);
|
||||
assert.equal(await eventAt(target, data, await point(target, "controls")), false, "Window controls stay outside the drop target");
|
||||
assert.equal(await eventAt(target, data, broad, "dragover", "text/plain"), false, "Ordinary file and text drags retain their behavior");
|
||||
for (const mode of ["light", "dark"]) {
|
||||
await setTheme(target, mode);
|
||||
await eventAt(target, data, broad);
|
||||
await target.screenshot({ path: path.join(output, `${mode}-blank-receiving.png`) });
|
||||
}
|
||||
await receive(target, data, broad);
|
||||
await tab(target, "a.md •").waitFor(); await tab(source, "a.md •").waitFor({ state: "detached" });
|
||||
assert.deepEqual(await order(target), ["b.md", "a.md •"]);
|
||||
assert.match(await target.locator(".cm-content").innerText(), /Unsaved ribbon transfer/);
|
||||
assert.ok(await tab(target, "a.md •").getAttribute("aria-describedby"));
|
||||
await open(source, "c.md"); data = await start(source, "c.md");
|
||||
await receive(target, data, await point(target, "precise"));
|
||||
await tab(target, "c.md").waitFor(); await tab(source, "c.md").waitFor({ state: "detached" });
|
||||
assert.deepEqual(await order(target), ["c.md", "b.md", "a.md •"]);
|
||||
await openBoard(source); await pin(source, "Board"); await source.getByRole("textbox", { name: "Board state" }).fill("Plugin ribbon state");
|
||||
data = await start(source, "Board");
|
||||
await target.setViewportSize({ width: 700, height: 700 });
|
||||
const nearby = await point(target, "near");
|
||||
await eventAt(target, data, nearby);
|
||||
await bar(target).and(target.locator('.receiving')).waitFor();
|
||||
await target.screenshot({ path: path.join(output, "narrow-near-receiving.png") });
|
||||
await receive(target, data, nearby);
|
||||
await tab(target, "Board").waitFor(); await tab(source, "Board").waitFor({ state: "detached" });
|
||||
assert.deepEqual(await order(target), ["c.md", "b.md", "a.md •", "Board"]);
|
||||
assert.equal(await target.getByRole("textbox", { name: "Board state" }).inputValue(), "Plugin ribbon state");
|
||||
assert.ok(await tab(target, "Board").getAttribute("aria-describedby"));
|
||||
await screenshots(target, "ribbon-plugin-pinned");
|
||||
data = await start(target, "Board");
|
||||
assert.equal(await eventAt(target, data, await point(target, "near")), false, "Same-window reordering stays precise");
|
||||
await receive(target, data, await point(target, "precise"));
|
||||
assert.deepEqual(await order(target), ["Board", "c.md", "b.md", "a.md •"]);
|
||||
await tab(target, "Board").evaluate(node => node.dispatchEvent(new DragEvent("dragend", { bubbles: true })));
|
||||
assert.deepEqual(pages.flatMap(page => page.errors), []);
|
||||
});
|
||||
@@ -0,0 +1,76 @@
|
||||
// Each tab keeps its own scroll position in the Writing, Reading, Split, and Source layouts.
|
||||
import assert from "node:assert/strict";
|
||||
import { chooseView, mockTauri, runSmoke, settle as settleFrames, smokeUrl } from "../_harness/index.mjs";
|
||||
|
||||
await runSmoke("tabs/scroll", async ({ page }) => {
|
||||
await mockTauri(page, {
|
||||
commands: test => test.workspace({
|
||||
root: "C:\\smoke-workspace",
|
||||
files: Object.fromEntries(["scroll-a.md", "scroll-b.md"].map(name => [name, Array.from({ length: 200 }, (_, i) => `Paragraph ${i} of ${name}.\n\n`).join("")])),
|
||||
}),
|
||||
});
|
||||
const settle = () => settleFrames(page);
|
||||
async function open(name) {
|
||||
await page.keyboard.press('Control+p');
|
||||
await page.getByRole('textbox', { name: 'Find a file' }).fill(name);
|
||||
await page.getByRole('dialog').getByRole('button').filter({ hasText: name }).first().click();
|
||||
}
|
||||
async function roundTrip(selector, label) {
|
||||
const scroller = page.locator(selector);
|
||||
const position = async (top) => scroller.evaluate((el, top) => {
|
||||
if (top !== undefined) el.scrollTop = top;
|
||||
return el.scrollTop;
|
||||
}, top);
|
||||
// The Writing layout restores a line-anchored CodeMirror scrollSnapshot (src/lib/editor/DocumentEditor.svelte:304-305).
|
||||
// Re-estimated heights of the lines above can move scrollTop, so compare the top visible line and its offset.
|
||||
const visibleTop = () => label === 'Writing'
|
||||
? scroller.evaluate(async el => {
|
||||
const { EditorView } = await import('/node_modules/@codemirror/view/dist/index.js');
|
||||
const view = EditorView.findFromDOM(el.querySelector('.cm-content'));
|
||||
const top = el.getBoundingClientRect().top - view.documentTop;
|
||||
const block = view.lineBlockAtHeight(top);
|
||||
return { line: view.state.doc.lineAt(block.from).number, offset: top - block.top };
|
||||
})
|
||||
: position().then(top => ({ line: 0, offset: top }));
|
||||
await scroller.waitFor({ state: 'visible' });
|
||||
await settle();
|
||||
await position(1800);
|
||||
await settle();
|
||||
assert.ok(await position() > 1000, `${label}: first document is scrollable`);
|
||||
const first = await visibleTop();
|
||||
await page.getByRole('tab', { name: 'scroll-b.md', exact: true }).click();
|
||||
await scroller.waitFor({ state: 'visible' });
|
||||
await settle();
|
||||
await position(650);
|
||||
await settle();
|
||||
const second = await visibleTop();
|
||||
for (let repeat = 0; repeat < 2; repeat++) {
|
||||
for (const [name, expected] of [['scroll-a.md', first], ['scroll-b.md', second]]) {
|
||||
await page.getByRole('tab', { name, exact: true }).click();
|
||||
await scroller.waitFor({ state: 'visible' });
|
||||
await settle();
|
||||
const actual = await visibleTop();
|
||||
assert.ok(actual.line === expected.line && Math.abs(actual.offset - expected.offset) < 5, `${label}: ${name} expected ${JSON.stringify(expected)}, got ${JSON.stringify(actual)}`);
|
||||
}
|
||||
}
|
||||
console.log(`PASS: ${label} retains independent tab scroll positions`);
|
||||
await page.getByRole('tab', { name: 'scroll-a.md', exact: true }).click();
|
||||
}
|
||||
|
||||
await page.goto(smokeUrl);
|
||||
await page.getByText('smoke-workspace', { exact: true }).waitFor();
|
||||
await open('scroll-b.md');
|
||||
await open('scroll-a.md');
|
||||
await chooseView(page, 'Write');
|
||||
await roundTrip('.cm-scroller', 'Writing');
|
||||
await chooseView(page, 'Read');
|
||||
await roundTrip('.md-page', 'Reading');
|
||||
await chooseView(page, 'Read beside');
|
||||
await roundTrip('.md-page', 'Split preview');
|
||||
await chooseView(page, 'Read beside');
|
||||
await chooseView(page, 'Source');
|
||||
await page.getByRole('tab', { name: 'scroll-b.md', exact: true }).click();
|
||||
await chooseView(page, 'Source');
|
||||
await page.getByRole('tab', { name: 'scroll-a.md', exact: true }).click();
|
||||
await roundTrip('.source-editor .cm-scroller', 'Source');
|
||||
});
|
||||
@@ -0,0 +1,110 @@
|
||||
// Tab transfer between windows: same-workspace moves with unsaved text and pins, insertion order, other-workspace rejection, duplicates, and source edits during a transfer.
|
||||
import assert from "node:assert/strict";
|
||||
import path from "node:path";
|
||||
import { mockTauri, openPage, outputDir, runSmoke, smokeUrl } from "../_harness/index.mjs";
|
||||
|
||||
await runSmoke("tabs/transfer", async ({ browser }) => {
|
||||
const output = await outputDir("tabs/transfer");
|
||||
const context = await browser.newContext({ viewport: { width: 1440, height: 900 } });
|
||||
await mockTauri(context, {
|
||||
commands: test => {
|
||||
localStorage.setItem("runestone.settings", JSON.stringify({ autosaveEnabled: false }));
|
||||
const root = location.search.includes("other") ? "C:\\other" : "C:\\transfer";
|
||||
const workspace = test.workspace({ root, name: "transfer", files: Object.fromEntries(["a.md", "b.md"].map(name => [name, `# ${name}\n\nOriginal text.\n`])) });
|
||||
return {
|
||||
...workspace,
|
||||
plugins_snapshot: () => ({ root, plugins: [] }),
|
||||
"plugin:window|is_maximized": () => false,
|
||||
};
|
||||
},
|
||||
});
|
||||
const pages = [];
|
||||
async function newPage() {
|
||||
const page = await openPage(context);
|
||||
pages.push(page);
|
||||
return page;
|
||||
}
|
||||
const source = await newPage(), target = await newPage(), other = await newPage();
|
||||
const tab = (page, name) => page.locator('[role="tab"]').filter({ hasText: name });
|
||||
async function open(page, name) {
|
||||
await page.bringToFront();
|
||||
await page.getByRole("tablist", { name: "Working tabs" }).waitFor();
|
||||
await page.getByRole("tab").first().waitFor();
|
||||
await page.keyboard.press("Control+p");
|
||||
await page.getByRole("textbox", { name: "Find a file" }).fill(name);
|
||||
await page.getByRole("dialog").getByRole("button").filter({ hasText: name }).first().click();
|
||||
await tab(page, name).waitFor();
|
||||
}
|
||||
async function start(page, name) {
|
||||
return tab(page, name).evaluate(node => {
|
||||
const transfer = new DataTransfer();
|
||||
node.dispatchEvent(new DragEvent("dragstart", { bubbles: true, dataTransfer: transfer }));
|
||||
return transfer.getData("application/x-runestone-tab");
|
||||
});
|
||||
}
|
||||
function dragOver(page, data, drop) {
|
||||
return page.getByRole("tablist", { name: "Working tabs" }).evaluate((node, { data, drop }) => {
|
||||
const transfer = new DataTransfer();
|
||||
transfer.setData("application/x-runestone-tab", data);
|
||||
const options = { bubbles: true, cancelable: true, clientX: node.getBoundingClientRect().left, dataTransfer: transfer };
|
||||
node.dispatchEvent(new DragEvent("dragover", options));
|
||||
if (drop) node.dispatchEvent(new DragEvent("drop", options));
|
||||
}, { data, drop });
|
||||
}
|
||||
const drop = (page, data) => dragOver(page, data, true);
|
||||
async function setTheme(page, mode) {
|
||||
await page.evaluate(async mode => {
|
||||
const { applyAppearance } = await import('/src/lib/theme/appearance.ts');
|
||||
await applyAppearance({ theme: 'default', mode });
|
||||
}, mode);
|
||||
}
|
||||
async function captureTransfer(page, data) {
|
||||
for (const theme of ["light", "dark"]) {
|
||||
await setTheme(page, theme);
|
||||
await dragOver(page, data, false);
|
||||
await page.screenshot({ path: path.join(output, `${theme}-receiving.png`) });
|
||||
}
|
||||
}
|
||||
|
||||
await Promise.all([source.goto(smokeUrl), target.goto(smokeUrl), other.goto(smokeUrl + "/?other")]);
|
||||
await open(source, "a.md");
|
||||
await open(target, "b.md");
|
||||
await tab(source, "a.md").click({ button: "right" });
|
||||
await source.getByRole("menuitem", { name: "Pin", exact: true }).click();
|
||||
await source.locator(".cm-content").fill("Unsaved transfer text");
|
||||
let data = await start(source, "a.md");
|
||||
assert.ok(JSON.parse(data).tabTransfer);
|
||||
await drop(other, data);
|
||||
await other.getByText("Move tabs only between windows of the same workspace.").waitFor();
|
||||
assert.equal(await tab(source, "a.md").count(), 1);
|
||||
await captureTransfer(target, data);
|
||||
await drop(target, data);
|
||||
await tab(target, "a.md").waitFor();
|
||||
await tab(source, "a.md").waitFor({ state: "detached" });
|
||||
assert.match(await target.locator(".cm-content").innerText(), /Unsaved transfer text/);
|
||||
const changedTarget = await newPage();
|
||||
await changedTarget.goto(smokeUrl);
|
||||
await changedTarget.getByRole("tab").first().waitFor();
|
||||
await open(source, "a.md");
|
||||
data = await start(source, "a.md");
|
||||
await source.locator(".cm-content").fill("Changed during transfer");
|
||||
await drop(changedTarget, data);
|
||||
await tab(changedTarget, "a.md").waitFor();
|
||||
assert.equal(await tab(source, "a.md").count(), 1);
|
||||
assert.match(await source.locator(".cm-content").innerText(), /Changed during transfer/);
|
||||
assert.ok(await tab(target, "a.md").getAttribute("aria-describedby"));
|
||||
assert.deepEqual(await target.getByRole("tablist", { name: "Working tabs" }).getByRole("tab").evaluateAll(nodes => nodes.map(node => node.dataset.path)), ["a.md", "b.md"]);
|
||||
await open(source, "a.md");
|
||||
data = await start(source, "a.md");
|
||||
await drop(target, data);
|
||||
await target.getByText("This tab is already open in this window. The source tab remains open.").waitFor();
|
||||
assert.equal(await tab(source, "a.md").count(), 1);
|
||||
assert.match(await target.locator(".cm-content").innerText(), /Unsaved transfer text/);
|
||||
for (const theme of ["light", "dark"]) {
|
||||
await setTheme(target, theme);
|
||||
await target.screenshot({ path: path.join(output, `${theme}.png`) });
|
||||
}
|
||||
await target.setViewportSize({ width: 700, height: 700 });
|
||||
await target.screenshot({ path: path.join(output, "narrow.png") });
|
||||
assert.deepEqual(pages.flatMap(page => page.errors), []);
|
||||
});
|
||||
@@ -0,0 +1,56 @@
|
||||
// Move a tab to a new window: Open in new window carries unsaved text, and a tab dragged out stays until the new window accepts it.
|
||||
import assert from "node:assert/strict";
|
||||
import { mockTauri, openPage, runSmoke, smokeUrl } from "../_harness/index.mjs";
|
||||
|
||||
await runSmoke("tabs/windowTransfer", async ({ browser }) => {
|
||||
// The mock host shares its transfer offers in one context, so the source and target windows need one context.
|
||||
const context = await browser.newContext({ viewport: { width: 1440, height: 1000 } });
|
||||
await mockTauri(context, {
|
||||
commands: test => ({
|
||||
...test.workspace({ root: "C:\\window-transfer", files: { "a.md": "# Alpha\n", "b.md": "# Beta\n" } }),
|
||||
workspace_open_window: ({ transfer }) => { test.transfer = transfer; },
|
||||
plugins_snapshot: () => ({ plugins: [], issues: [] }),
|
||||
spelling_menu_install: () => null,
|
||||
}),
|
||||
});
|
||||
const page = await openPage(context, { timeout: 15000 });
|
||||
const tab = name => page.getByRole("tab", { name, exact: true });
|
||||
async function open(name) {
|
||||
await page.keyboard.press("Control+p");
|
||||
await page.getByRole("textbox", { name: "Find a file" }).fill(name);
|
||||
await page.getByRole("dialog").getByRole("button").filter({ hasText: name }).first().click();
|
||||
await tab(name).waitFor();
|
||||
}
|
||||
await page.goto(smokeUrl);
|
||||
await page.getByText("window-transfer", { exact: true }).waitFor();
|
||||
await open("a.md");
|
||||
await open("b.md");
|
||||
const editor = page.locator(".cm-content");
|
||||
await editor.click();
|
||||
await page.keyboard.press("Control+End");
|
||||
await page.keyboard.type("Unsaved transfer");
|
||||
await tab("b.md").click({ button: "right" });
|
||||
await page.getByRole("menuitem", { name: "Open in new window", exact: true }).click();
|
||||
await page.waitForFunction(() => window.__TEST__.transfer);
|
||||
const token = await page.evaluate(() => window.__TEST__.transfer);
|
||||
const target = await openPage(context, { timeout: 15000 });
|
||||
await target.goto(smokeUrl + "/?tabTransfer=" + token);
|
||||
await target.getByRole("tab", { name: "b.md", exact: true }).waitFor();
|
||||
await target.waitForFunction(() => document.querySelector(".cm-content")?.textContent.includes("Unsaved transfer"));
|
||||
await tab("b.md").waitFor({ state: "detached" });
|
||||
console.log("PASS: Open in new window carries unsaved text and removes the source tab");
|
||||
|
||||
await page.evaluate(() => { window.__TEST__.transfer = null; });
|
||||
const draggedTab = page.getByRole("tab").first();
|
||||
const draggedPath = await draggedTab.getAttribute("data-path");
|
||||
const tabBox = await draggedTab.boundingBox();
|
||||
await page.mouse.move(tabBox.x + tabBox.width / 2, tabBox.y + tabBox.height / 2);
|
||||
await page.mouse.down();
|
||||
await page.mouse.move(1480, 180, { steps: 12 });
|
||||
await page.mouse.up();
|
||||
await page.waitForFunction(() => window.__TEST__.transfer);
|
||||
assert.notEqual(await page.evaluate(() => window.__TEST__.transfer), token);
|
||||
assert.equal(await page.locator(`[role="tab"][data-path="${draggedPath}"]`).count(), 1, "Keep the source tab until the new window accepts it");
|
||||
assert.equal([...page.errors, ...target.errors].length, 0, [...page.errors, ...target.errors].join("\n"));
|
||||
console.log("PASS: a tab dragged out of the window stays until the new window accepts it");
|
||||
});
|
||||
Reference in New Issue
Block a user