RuneStone 1.0.0

This commit is contained in:
Knotty Wyvern
2026-11-03 00:23:07 -07:00
commit 5557443ed1
818 changed files with 239368 additions and 0 deletions
+110
View File
@@ -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), []);
});