Skip to content

An open-source, privacy-first, self-hosted knowledge workspace where humans and AI agents work together 开源、隐私优先、自托管的知识工作空间,让人与智能体在此协作

1.5 KB
Raw Blame
import * as assert from "node:assert/strict";
import {test} from "node:test";
import {ScriptTarget} from "typescript";
import {loadModule} from "../../testSupport/loadModule";
const {createMockRequire} = require("../../../tests/fixtures/mockModules.cjs");

const {isEmptyTabPlaceholder} = loadModule<typeof import("./tabsList")>("src/protyle/wysiwyg/tabsList.ts", {
    require: createMockRequire({
        "../render/tabsRender": {},
        "../render/listMindmap/model": {},
        "../render/listMindmap/preferences": {},
    }),
}, ScriptTarget.ES2021);

const paragraph = (attrs: Record<string, string>, text = "", rich = false) => ({
    attributes: Object.entries(attrs).map(([name, value]) => ({name, value})),
    getAttribute: (name: string) => attrs[name],
    querySelector: () => ({textContent: text, querySelector: () => rich ? {} : null}),
}) as unknown as Element;

test("only untouched conversion placeholders can be omitted when restoring a list", () => {
    assert.equal(isEmptyTabPlaceholder(paragraph({})), false);
    assert.equal(isEmptyTabPlaceholder(paragraph({"tabs-placeholder": "true"})), true);
    assert.equal(isEmptyTabPlaceholder(paragraph({"tabs-placeholder": "true"}, "12")), false);
    assert.equal(isEmptyTabPlaceholder(paragraph({"tabs-placeholder": "true"}, "", true)), false);
    for (const name of ["custom-test", "name", "alias", "memo", "bookmark", "style", "refcount"]) {
        assert.equal(isEmptyTabPlaceholder(paragraph({"tabs-placeholder": "true", [name]: "kept"})), false);
    }
});