-
Notifications
You must be signed in to change notification settings - Fork 94
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Signed-off-by: grnd-alt <github@belakkaf.net>
- Loading branch information
Showing
3 changed files
with
109 additions
and
74 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,93 @@ | ||
/** | ||
* SPDX-FileCopyrightText: 2024 Nextcloud GmbH and Nextcloud contributors | ||
* SPDX-License-Identifier: AGPL-3.0-or-later | ||
*/ | ||
import Link from './../../marks/Link.js' | ||
import Underline from '../../marks/Underline.js' | ||
import createCustomEditor from '../testHelpers/createCustomEditor.ts' | ||
|
||
describe('Link extension integrated in the editor', () => { | ||
it('should have link available in commands', () => { | ||
const editor = createCustomEditor('<p><a href="nextcloud.com">Test</a> HELLO WORLD</p>', [Link]) | ||
expect(editor.commands).toHaveProperty('insertOrSetLink') | ||
}) | ||
|
||
it('should update link if anchor has mark', () => { | ||
const editor = createCustomEditor( | ||
'<p><a href="nextcloud.com">Te<u>s</u>t</a> HELLO WORLD</p>', | ||
[Link, Underline], | ||
) | ||
editor.commands.setTextSelection(3) | ||
editor.commands.insertOrSetLink('updated.de', { href: 'updated.de' }) | ||
expect(editor.getJSON()).toEqual({ | ||
content: [ | ||
{ | ||
content: [ | ||
{ | ||
marks: [ | ||
{ attrs: { href: 'updated.de', title: null }, type: 'link' }, | ||
], | ||
text: 'updated.de', | ||
type: 'text', | ||
}, | ||
{ text: ' HELLO WORLD', type: 'text' }, | ||
], | ||
type: 'paragraph', | ||
}, | ||
], | ||
type: 'doc', | ||
}) | ||
}) | ||
|
||
it('Should only update the anchor is on', () => { | ||
const editor = createCustomEditor( | ||
'<p><a href="nextcloud.com">Test</a><a href="nextcloud.com">Test</a></p>', | ||
[Link], | ||
) | ||
editor.commands.setTextSelection(3) | ||
editor.commands.insertOrSetLink('updated.de', { href: 'updated.de' }) | ||
expect(editor.getJSON()).toEqual({ | ||
content: [ | ||
{ | ||
content: [ | ||
{ | ||
marks: [ | ||
{ attrs: { href: 'updated.de', title: null }, type: 'link' }, | ||
], | ||
text: 'updated.de', | ||
type: 'text', | ||
}, | ||
], | ||
type: 'paragraph', | ||
}, | ||
], | ||
type: 'doc', | ||
}) | ||
}) | ||
|
||
it('should insert new link if none at anchor', () => { | ||
const editor = createCustomEditor( | ||
'<p><a href="nextcloud.com">Test</a> HELLO WORLD</p>', | ||
[Link], | ||
) | ||
editor.commands.setTextSelection(10) | ||
expect(editor.getJSON()).toEqual({ | ||
content: [ | ||
{ | ||
content: [ | ||
{ | ||
marks: [ | ||
{ attrs: { href: 'nextcloud.com', title: null }, type: 'link' }, | ||
], | ||
text: 'Test', | ||
type: 'text', | ||
}, | ||
{ text: ' HELLO WORLD', type: 'text' }, | ||
], | ||
type: 'paragraph', | ||
}, | ||
], | ||
type: 'doc', | ||
}) | ||
}) | ||
}) |