Skip to content

Commit

Permalink
Test: Removing link from node(children)
Browse files Browse the repository at this point in the history
  • Loading branch information
vantage-ola committed Nov 13, 2024
1 parent 2d76d1c commit d79f6ad
Showing 1 changed file with 77 additions and 2 deletions.
79 changes: 77 additions & 2 deletions packages/lexical-link/src/__tests__/unit/LexicalLinkNode.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ import {
LinkNode,
SerializedLinkNode,
} from '@lexical/link';
import {MarkNode} from '@lexical/mark';
import {
$getRoot,
$selectAll,
Expand Down Expand Up @@ -409,7 +410,81 @@ describe('LexicalLinkNode tests', () => {
const link = paragraph.children[0] as SerializedLinkNode;
expect(link.title).toBe('Lexical Website');
});
});

test('LinkNode removes correctly and preserves descendants', async () => {});
test('$toggleLink correctly removes link when textnode has children(like marknode)', async () => {
const {editor} = testEnv;
await editor.update(() => {
const paragraph = new ParagraphNode();
const precedingText = new TextNode('some '); // space after
const textNode = new TextNode('text');

paragraph.append(precedingText, textNode);

const linkNode = $createLinkNode('https://example.com/foo', {
rel: 'noreferrer',
});
textNode.insertAfter(linkNode);
linkNode.append(textNode);

const markNode = new MarkNode(['knetk']);
textNode.insertBefore(markNode);
markNode.append(textNode);
$getRoot().append(paragraph);
});
// Verify structure after all steps
expect(editor.getEditorState().toJSON().root.children[0]).toMatchObject({
children: [
{
text: 'some ',
type: 'text',
},
{
children: [
{
children: [
{
text: 'text',
type: 'text',
},
],
ids: ['knetk'],
type: 'mark',
},
],
rel: 'noreferrer',
type: 'link',
url: 'https://example.com/foo',
},
],
type: 'paragraph',
});

// 4. Remove the link
await editor.update(() => {
$selectAll();
$toggleLink(null);
});

// Verify link is removed but mark remains
expect(editor.getEditorState().toJSON().root.children[0]).toMatchObject({
children: [
{
text: 'some ',
type: 'text',
},
{
children: [
{
text: 'text',
type: 'text',
},
],
ids: ['knetk'],
type: 'mark',
},
],
type: 'paragraph',
});
});
});
});

0 comments on commit d79f6ad

Please sign in to comment.