Files
mnote/scripts/task106-document-runtime-slash-reference-smoke.js
T

103 lines
3.2 KiB
JavaScript
Raw Normal View History

"use strict";
const { chromium } = require("playwright");
const {
BASE_URL,
UI_TIMEOUT_MS,
assert,
cleanupDocuments,
ensureAuthenticated,
prepareTempTreeFixture,
openDocument,
requireMnoteWebSmokeBaseUrl,
} = require("./tree-shell-smoke-helpers");
async function openRuntimeDebug(page, fixture) {
const runtimeBaseUrl = requireMnoteWebSmokeBaseUrl();
await page.goto(`${BASE_URL}/api/auth/mnote-web-token`, { waitUntil: "commit", timeout: UI_TIMEOUT_MS });
await page.goto(
`${runtimeBaseUrl}/document-debug?documentId=${fixture.parentId}&workspaceId=${fixture.workspaceId}&host=task106-smoke`,
{ waitUntil: "commit", timeout: UI_TIMEOUT_MS },
);
await page.getByText("Document Runtime Debug").waitFor({ state: "visible", timeout: UI_TIMEOUT_MS });
}
async function main() {
const browser = await chromium.launch({ headless: true });
const context = await browser.newContext({
viewport: { width: 1440, height: 960 },
});
const page = await context.newPage();
let fixture = null;
let caughtError = null;
try {
await ensureAuthenticated(page, context.request);
fixture = await prepareTempTreeFixture(context.request);
await openDocument(page, fixture.workspaceId, fixture.parentId);
await openRuntimeDebug(page, fixture);
const textarea = page.locator("textarea[data-block-input-id]").first();
await textarea.waitFor({ state: "visible", timeout: UI_TIMEOUT_MS });
await textarea.fill("Command", { timeout: UI_TIMEOUT_MS });
await page.locator("#editor-command-slash").click({ timeout: UI_TIMEOUT_MS });
await page.locator('[data-slash-action="heading"]').click({ timeout: UI_TIMEOUT_MS });
await page.locator("#editor-command-page-ref").click({ timeout: UI_TIMEOUT_MS });
await page.locator("#editor-command-block-ref").click({ timeout: UI_TIMEOUT_MS });
await page.locator("#editor-save-status").getByText("saved").waitFor({
state: "visible",
timeout: UI_TIMEOUT_MS,
});
const value = await textarea.inputValue();
assert(
value.includes("[[page]]") && value.includes("((block))"),
`引用 token 未写入真实输入器:${value}`,
);
const title = (await page.locator(".editor-row-title").first().textContent()) || "";
assert(title.includes("Heading"), `slash 切块后未变成 heading${title}`);
console.log(
JSON.stringify(
{
ok: true,
baseUrl: BASE_URL,
workspaceId: fixture.workspaceId,
documentId: fixture.parentId,
value,
},
null,
2,
),
);
} catch (error) {
caughtError = error;
} finally {
if (fixture) {
try {
await cleanupDocuments(context.request, fixture.createdIds);
} catch (cleanupError) {
if (!caughtError) {
caughtError = cleanupError;
}
}
}
await page.close().catch(() => undefined);
await context.close().catch(() => undefined);
await browser.close().catch(() => undefined);
}
if (caughtError) {
throw caughtError;
}
}
main().catch((error) => {
console.error(error instanceof Error ? error.stack || error.message : String(error));
process.exit(1);
});