|
| 1 | +/** |
| 2 | + * SPDX-FileCopyrightText: 2024 Nextcloud GmbH and Nextcloud contributors |
| 3 | + * SPDX-License-Identifier: AGPL-3.0-or-later |
| 4 | + */ |
| 5 | + |
| 6 | +import Markdown from './../../../src/extensions/Markdown.js' |
| 7 | +import { Italic, Link } from './../../../src/marks/index.js' |
| 8 | +import { createCustomEditor } from './../../support/components.js' |
| 9 | +import { loadMarkdown, expectMarkdown } from '../nodes/helpers.js' |
| 10 | + |
| 11 | +describe('Link marks', { retries: 0 }, () => { |
| 12 | + const editor = createCustomEditor({ |
| 13 | + content: '', |
| 14 | + extensions: [Markdown, Link, Italic], |
| 15 | + }) |
| 16 | + |
| 17 | + describe('insertOrSetLink command', { retries: 0 }, () => { |
| 18 | + it('is available in commands', () => { |
| 19 | + expect(editor.commands).to.have.property('insertOrSetLink') |
| 20 | + }) |
| 21 | + |
| 22 | + it('can run on normal paragraph', () => { |
| 23 | + prepareEditor('hello\n', 3) |
| 24 | + expect(editor.can().insertOrSetLink().run()).to.equal(true) |
| 25 | + }) |
| 26 | + |
| 27 | + it('will insert a link in a normal paragraph', () => { |
| 28 | + prepareEditor('hello\n', 3) |
| 29 | + editor.commands.insertOrSetLink('https://nextcloud.com', { |
| 30 | + href: 'https://nextcloud.com', |
| 31 | + }) |
| 32 | + expectMarkdown(editor, 'he\n\n<https://nextcloud.com>\n\nllo') |
| 33 | + }) |
| 34 | + }) |
| 35 | + |
| 36 | + /** |
| 37 | + * |
| 38 | + * @param {*} input markdown content |
| 39 | + * @param {*} position cursor pos |
| 40 | + */ |
| 41 | + function prepareEditor(input, position = 1) { |
| 42 | + loadMarkdown(editor, input) |
| 43 | + editor.commands.setTextSelection(position) |
| 44 | + } |
| 45 | +}) |
0 commit comments