Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -1633,6 +1633,26 @@ describe('DtRichTextEditor tests', () => {
});
});

describe('setLink method', () => {
const linkOptions = { class: 'd-link' };
const supportedProtocols = [/^https?:\/\//, /^ftp?:\/\//, /mailto:/];
const defaultPrefix = 'https://';

beforeEach(async () => {
await wrapper.setProps({ link: true, outputFormat: 'html' });
wrapper.vm.editor.commands.focus();
});

it.each([
['https://example.com', 'Example', 'Example'],
['https://example.com', '', 'https://example.com'],
])('should render link correctly (url=%s, displayText=%s)', async (url, displayText, expectedSubstring) => {
wrapper.vm.setLink(url, displayText, linkOptions, supportedProtocols, defaultPrefix);
await wrapper.vm.$nextTick();
expect(wrapper.vm.getOutput()).toContain(expectedSubstring);
});
});

describe('Link keyboard shortcut functionality', () => {
describe('When Mod+K is pressed and link is enabled', () => {
it('should emit edit-link event', async () => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -974,12 +974,13 @@ export default {
.run();

const selection = this.editor?.view?.state?.selection;
const displayText = linkText || linkInput;

this.editor
.chain()
.focus()
.insertContent(linkText)
.setTextSelection({ from: selection.from, to: selection.from + linkText.length })
.insertContent(displayText)
.setTextSelection({ from: selection.from, to: selection.from + displayText.length })
.setLink({ href: linkInput, class: linkOptions.class })
.run();
},
Expand Down
Loading