Skip to content

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

1.3 KB
Raw Blame
import assert from "node:assert/strict";
import test from "node:test";
import {mergeAVBatchRelationValue} from "../src/protyle/render/av/batchValue";

const relationValue = (blockIDs: string[]): IAVCellRelationValue => ({
    blockIDs,
    contents: blockIDs.map(itemID => ({
        type: "block",
        block: {
            id: itemID,
            content: itemID,
        }
    }))
});

test("adds only the relation introduced by the current batch edit", () => {
    const result = mergeAVBatchRelationValue(
        relationValue(["original", "previous"]),
        relationValue(["previous"]),
        relationValue(["previous", "added"]),
        "add"
    );

    assert.deepEqual(result.blockIDs, ["original", "previous", "added"]);
    assert.deepEqual(result.contents?.map(item => item.block.id), ["original", "previous", "added"]);
});

test("removes only the relation cleared by the current batch edit", () => {
    const result = mergeAVBatchRelationValue(
        relationValue(["kept-by-row", "removed"]),
        relationValue(["kept-by-display", "removed"]),
        relationValue(["kept-by-display"]),
        "remove"
    );

    assert.deepEqual(result.blockIDs, ["kept-by-row"]);
    assert.deepEqual(result.contents?.map(item => item.block.id), ["kept-by-row"]);
});