mirror of
https://github.com/BookStackApp/BookStack.git
synced 2026-07-15 21:31:36 +03:00
Lexical: Added a little testing coverage for DiagramNode
This commit is contained in:
@@ -208,9 +208,9 @@ export class LexicalNode {
|
||||
}
|
||||
|
||||
/**
|
||||
* Clones this node, creating a new node with a different key
|
||||
* and adding it to the EditorState (but not attaching it anywhere!). All nodes must
|
||||
* implement this method.
|
||||
* Clones this node, creating a new matching instance.
|
||||
* Should be created with the existing node key if it exists.
|
||||
* All nodes must implement this method.
|
||||
*
|
||||
*/
|
||||
static clone(_data: unknown): LexicalNode {
|
||||
|
||||
@@ -39,6 +39,8 @@ import {EditorUiContext} from "../../../../ui/framework/core";
|
||||
import {EditorUIManager} from "../../../../ui/framework/manager";
|
||||
import {ImageNode} from "@lexical/rich-text/LexicalImageNode";
|
||||
import {MediaNode} from "@lexical/rich-text/LexicalMediaNode";
|
||||
import {DiagramNode} from "@lexical/rich-text/LexicalDiagramNode";
|
||||
import {DiagramDecorator} from "../../../../ui/decorators/DiagramDecorator";
|
||||
|
||||
type TestEnv = {
|
||||
readonly container: HTMLDivElement;
|
||||
@@ -489,6 +491,7 @@ export function createTestContext(): EditorUiContext {
|
||||
nodes: [
|
||||
ImageNode,
|
||||
MediaNode,
|
||||
DiagramNode,
|
||||
]
|
||||
});
|
||||
|
||||
@@ -509,6 +512,7 @@ export function createTestContext(): EditorUiContext {
|
||||
};
|
||||
|
||||
context.manager.setContext(context);
|
||||
context.manager.registerDecoratorType('diagram', DiagramDecorator);
|
||||
|
||||
return context;
|
||||
}
|
||||
|
||||
@@ -0,0 +1,33 @@
|
||||
import {createTestContext} from "lexical/__tests__/utils";
|
||||
import {$createDiagramNode, DiagramNode} from "@lexical/rich-text/LexicalDiagramNode";
|
||||
import {$getHtmlContent} from "@lexical/clipboard";
|
||||
import {getEditorContentAsHtml} from "../../../../utils/actions";
|
||||
import {$getRoot} from "lexical";
|
||||
|
||||
|
||||
describe('LexicalDiagramNode', () => {
|
||||
|
||||
test('clone creates new instance with same key', () => {
|
||||
const {editor} = createTestContext();
|
||||
editor.updateAndCommit(() => {
|
||||
const node = $createDiagramNode('10', 'https://example.com/barry.png');
|
||||
const clone = DiagramNode.clone(node);
|
||||
|
||||
expect(node).not.toBe(clone);
|
||||
expect(node.getKey()).toBe(clone.getKey());
|
||||
});
|
||||
});
|
||||
|
||||
test('output HTML format', async () => {
|
||||
const {editor} = createTestContext();
|
||||
editor.updateAndCommit(() => {
|
||||
const node = $createDiagramNode('10', 'https://example.com/barry.png');
|
||||
node.setId('cat-123');
|
||||
$getRoot().append(node);
|
||||
});
|
||||
|
||||
const html = await getEditorContentAsHtml(editor);
|
||||
expect(html).toBe(`<div id="cat-123" drawio-diagram="10"><img src="https://example.com/barry.png"></div>`);
|
||||
});
|
||||
|
||||
});
|
||||
Reference in New Issue
Block a user