1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677 |
- 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, '<p>0123</p>');
- 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(
- '<p>0<a href="https://quilljs.com" target="_blank" rel="noopener noreferrer">12</a>3</p>',
- );
- });
- it('add invalid', function() {
- const editor = this.initialize(Editor, '<p>0123</p>');
- 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, '<p>0123</p>');
- 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(
- '<p>0<a href="about:blank" target="_blank" rel="noopener noreferrer">12</a>3</p>',
- );
- });
- it('change', function() {
- const editor = this.initialize(
- Editor,
- '<p>0<a href="https://github.com" target="_blank" rel="noopener noreferrer">12</a>3</p>',
- );
- 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(
- '<p>0<a href="https://quilljs.com" target="_blank" rel="noopener noreferrer">12</a>3</p>',
- );
- });
- it('remove', function() {
- const editor = this.initialize(
- Editor,
- '<p>0<a class="ql-size-large" href="https://quilljs.com" target="_blank" rel="noopener noreferrer">12</a>3</p>',
- );
- 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(
- '<p>0<span class="ql-size-large">12</span>3</p>',
- );
- });
- });
|