Spaces:
Paused
Paused
File size: 1,386 Bytes
b152fd5 | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 | import { describe, expect, it } from "vitest";
import { $createLinkNode } from "@lexical/link";
import { createEditor } from "lexical";
import {
MentionAwareLinkNode,
getMentionAwareLinkNodeInit,
mentionAwareLinkNodeReplacement,
} from "./mention-aware-link-node";
function createTestEditor() {
return createEditor({
namespace: "mention-aware-link-node-test",
nodes: [MentionAwareLinkNode, mentionAwareLinkNodeReplacement],
onError(error: Error) {
throw error;
},
});
}
describe("getMentionAwareLinkNodeInit", () => {
it("copies link attributes without carrying over a node key", () => {
const init = getMentionAwareLinkNodeInit({
getURL: () => "agent://agent-123",
getRel: () => "noreferrer",
getTarget: () => "_blank",
getTitle: () => "Agent mention",
});
expect(Object.keys(init)).toEqual(["url", "attributes"]);
expect(init).toEqual({
url: "agent://agent-123",
attributes: {
rel: "noreferrer",
target: "_blank",
title: "Agent mention",
},
});
});
it("replaces LinkNode creation with MentionAwareLinkNode without throwing", () => {
const editor = createTestEditor();
let created: unknown;
editor.update(() => {
created = $createLinkNode("agent://agent-123");
});
expect(created).toBeInstanceOf(MentionAwareLinkNode);
});
});
|