mirror of
https://github.com/alkimake/paperclip.git
synced 2026-06-17 19:20:39 +09:00
Extract mention-aware link node helper and add tests
Co-Authored-By: Paperclip <noreply@paperclip.ing>
This commit is contained in:
parent
eeb7e1a91a
commit
7c54b6e9e3
3 changed files with 119 additions and 42 deletions
50
ui/src/lib/mention-aware-link-node.test.ts
Normal file
50
ui/src/lib/mention-aware-link-node.test.ts
Normal file
|
|
@ -0,0 +1,50 @@
|
|||
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);
|
||||
});
|
||||
});
|
||||
Loading…
Add table
Add a link
Reference in a new issue