]> BookStack Code Mirror - bookstack/blob - resources/js/wysiwyg/services/__tests__/auto-links.test.ts
Opensearch: Fixed XML declaration when php short tags enabled
[bookstack] / resources / js / wysiwyg / services / __tests__ / auto-links.test.ts
1 import {
2     createTestContext,
3     dispatchKeydownEventForNode, expectEditorStateJSONPropToEqual,
4     expectNodeShapeToMatch
5 } from "lexical/__tests__/utils";
6 import {
7     $getRoot,
8     ParagraphNode,
9     TextNode
10 } from "lexical";
11 import {registerAutoLinks} from "../auto-links";
12
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;
18
19         editor.updateAndCommit(() => {
20             pNode = new ParagraphNode();
21             const text = new TextNode('Some https://example.com?test=true text');
22             pNode.append(text);
23             $getRoot().append(pNode);
24
25             text.select(34, 34);
26         });
27
28         dispatchKeydownEventForNode(pNode, editor, ' ');
29
30         expectEditorStateJSONPropToEqual(editor, '0.1.url', 'https://example.com?test=true');
31         expectEditorStateJSONPropToEqual(editor, '0.1.0.text', 'https://example.com?test=true');
32     });
33
34     test('space after link at end of line', async () => {
35         const {editor} = createTestContext();
36         registerAutoLinks(editor);
37         let pNode!: ParagraphNode;
38
39         editor.updateAndCommit(() => {
40             pNode = new ParagraphNode();
41             const text = new TextNode('Some https://example.com?test=true');
42             pNode.append(text);
43             $getRoot().append(pNode);
44
45             text.selectEnd();
46         });
47
48         dispatchKeydownEventForNode(pNode, editor, ' ');
49
50         expectNodeShapeToMatch(editor, [{type: 'paragraph', children: [
51                 {text: 'Some '},
52                 {type: 'link', children: [{text: 'https://example.com?test=true'}]}
53             ]}]);
54         expectEditorStateJSONPropToEqual(editor, '0.1.url', 'https://example.com?test=true');
55     });
56
57     test('enter after link in text', async () => {
58         const {editor} = createTestContext();
59         registerAutoLinks(editor);
60         let pNode!: ParagraphNode;
61
62         editor.updateAndCommit(() => {
63             pNode = new ParagraphNode();
64             const text = new TextNode('Some https://example.com?test=true text');
65             pNode.append(text);
66             $getRoot().append(pNode);
67
68             text.select(34, 34);
69         });
70
71         dispatchKeydownEventForNode(pNode, editor, 'Enter');
72
73         expectEditorStateJSONPropToEqual(editor, '0.1.url', 'https://example.com?test=true');
74         expectEditorStateJSONPropToEqual(editor, '0.1.0.text', 'https://example.com?test=true');
75     });
76 });