Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
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,37 @@ 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();
});

describe('When display text is provided', () => {
it('should insert the display text as a link', async () => {
wrapper.vm.setLink('https://example.com', 'Example', linkOptions, supportedProtocols, defaultPrefix);
await wrapper.vm.$nextTick();
const output = wrapper.vm.getOutput();
expect(output).toContain('href="https://example.com"');
expect(output).toContain('Example');
});
});

describe('When display text is empty', () => {
it('should use the URL as the display text', async () => {
wrapper.vm.setLink('https://example.com', '', linkOptions, supportedProtocols, defaultPrefix);
await wrapper.vm.$nextTick();
const output = wrapper.vm.getOutput();
expect(output).toContain('href="https://example.com"');
expect(output).toContain('https://example.com');
});
Comment thread
coderabbitai[bot] marked this conversation as resolved.
Outdated
});
});

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