#!/usr/bin/env node "use strict"; const assert = require("node:assert/strict"); const fs = require("node:fs"); const path = require("node:path"); const ROOT = process.cwd(); const CONVERSION_RUNTIME = path.join(ROOT, "rust/crates/mnote-web/browser/document-tiptap-conversion-runtime.js"); const SESSION_RUNTIME = fs.readFileSync(path.join(ROOT, "rust/crates/mnote-web/browser/document-session-runtime.js"), "utf8"); const ADAPTER_RUNTIME = fs.readFileSync(path.join(ROOT, "rust/crates/mnote-web/browser/document-editor-adapter-runtime.js"), "utf8"); async function main() { global.window = { location: { origin: "http://127.0.0.1:3000" } }; const runtime = await import(`file://${CONVERSION_RUNTIME}?t=${Date.now()}`); const href = "/documents/local-md:liaibo~E7~9A~84~E4~B8~AA~E4~BA~BA~E7~A9~BA~E9~97~B4~2F~E9~A1~B9~E7~9B~AE~2F~E5~AE~8C~E7~BB~93~E9~A1~B9~E7~9B~AE.md?sourceKind=local_folder&rootUri=file%3A%2F%2F%2Fmnt%2FData1T%2FMnote_data%2Fusers%2Fliaibo%2Fworkspaces%2Fmy-space&treeView=filetree"; const block = runtime.tiptapNodeToEditorBlock({ type: "paragraph", attrs: { blockId: "local-block-1" }, content: [{ type: "text", text: "完结项目", marks: [{ type: "link", attrs: { href, target: "_self", rel: "noopener noreferrer nofollow", class: "mnote-page-block-link", }, }], }], }, 0); assert.equal(block.blockType, "page_reference"); assert.equal(block.props.title, "完结项目"); assert.equal(block.props.sourcePath, "liaibo的个人空间/项目/完结项目.md"); assert.match(SESSION_RUNTIME, /userReadOnlyMode/); assert.match(SESSION_RUNTIME, /setDocumentSessionUserReadOnlyMode/); assert.match( SESSION_RUNTIME, /userReadOnlyMode:\s*true/, "普通文档打开后必须默认只读;编辑只能由用户显式切换", ); assert.doesNotMatch( SESSION_RUNTIME, /userReadOnlyMode:\s*false/, "不能把用户编辑模式作为默认态,否则页面首屏不是只读浏览", ); assert.match(ADAPTER_RUNTIME, /data-document-edit-mode-toggle/); assert.match(ADAPTER_RUNTIME, /开始编辑/); assert.match(ADAPTER_RUNTIME, /退出编辑/); } main().catch((error) => { console.error(error && error.stack ? error.stack : error); process.exit(1); });