import Delta from 'quill-delta'; import Editor from '../../../core/editor'; import Link from '../../../formats/link'; describe('Link', function() { it('add', function() { const editor = this.initialize(Editor, '

0123

'); editor.formatText(1, 2, { link: 'https://quilljs.com' }); expect(editor.getDelta()).toEqual( new Delta() .insert('0') .insert('12', { link: 'https://quilljs.com' }) .insert('3\n'), ); expect(editor.scroll.domNode).toEqualHTML( '

0123

', ); }); it('add invalid', function() { const editor = this.initialize(Editor, '

0123

'); editor.formatText(1, 2, { link: 'javascript:alert(0);' }); // eslint-disable-line no-script-url expect(editor.getDelta()).toEqual( new Delta() .insert('0') .insert('12', { link: Link.SANITIZED_URL }) .insert('3\n'), ); }); it('add non-whitelisted protocol', function() { const editor = this.initialize(Editor, '

0123

'); editor.formatText(1, 2, { link: 'gopher://quilljs.com' }); expect(editor.getDelta()).toEqual( new Delta() .insert('0') .insert('12', { link: Link.SANITIZED_URL }) .insert('3\n'), ); expect(editor.scroll.domNode).toEqualHTML( '

0123

', ); }); it('change', function() { const editor = this.initialize( Editor, '

0123

', ); editor.formatText(1, 2, { link: 'https://quilljs.com' }); expect(editor.getDelta()).toEqual( new Delta() .insert('0') .insert('12', { link: 'https://quilljs.com' }) .insert('3\n'), ); expect(editor.scroll.domNode).toEqualHTML( '

0123

', ); }); it('remove', function() { const editor = this.initialize( Editor, '

0123

', ); editor.formatText(1, 2, { link: false }); const delta = new Delta() .insert('0') .insert('12', { size: 'large' }) .insert('3\n'); expect(editor.getDelta()).toEqual(delta); expect(editor.scroll.domNode).toEqualHTML( '

0123

', ); }); });