3 dispatchKeydownEventForNode, expectEditorStateJSONPropToEqual,
5 } from "lexical/__tests__/utils";
11 import {registerAutoLinks} from "../auto-links";
13 describe('Auto-link service tests', () => {
14 test('space after link in text', async () => {
15 const {editor} = createTestContext();
16 registerAutoLinks(editor);
17 let pNode!: ParagraphNode;
19 editor.updateAndCommit(() => {
20 pNode = new ParagraphNode();
21 const text = new TextNode('Some https://example.com?test=true text');
23 $getRoot().append(pNode);
28 dispatchKeydownEventForNode(pNode, editor, ' ');
30 expectEditorStateJSONPropToEqual(editor, '0.1.url', 'https://example.com?test=true');
31 expectEditorStateJSONPropToEqual(editor, '0.1.0.text', 'https://example.com?test=true');
34 test('space after link at end of line', async () => {
35 const {editor} = createTestContext();
36 registerAutoLinks(editor);
37 let pNode!: ParagraphNode;
39 editor.updateAndCommit(() => {
40 pNode = new ParagraphNode();
41 const text = new TextNode('Some https://example.com?test=true');
43 $getRoot().append(pNode);
48 dispatchKeydownEventForNode(pNode, editor, ' ');
50 expectNodeShapeToMatch(editor, [{type: 'paragraph', children: [
52 {type: 'link', children: [{text: 'https://example.com?test=true'}]}
54 expectEditorStateJSONPropToEqual(editor, '0.1.url', 'https://example.com?test=true');
57 test('enter after link in text', async () => {
58 const {editor} = createTestContext();
59 registerAutoLinks(editor);
60 let pNode!: ParagraphNode;
62 editor.updateAndCommit(() => {
63 pNode = new ParagraphNode();
64 const text = new TextNode('Some https://example.com?test=true text');
66 $getRoot().append(pNode);
71 dispatchKeydownEventForNode(pNode, editor, 'Enter');
73 expectEditorStateJSONPropToEqual(editor, '0.1.url', 'https://example.com?test=true');
74 expectEditorStateJSONPropToEqual(editor, '0.1.0.text', 'https://example.com?test=true');