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

0123

5678

0123

`, ); editor.formatText(9, 1, { list: 'ordered' }); expect(editor.getDelta()).toEqual( new Delta() .insert('0123\n5678') .insert('\n', { list: 'ordered' }) .insert('0123\n'), ); expect(this.container).toEqualHTML(`

0123

  1. 5678

0123

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

0123

5678

0123

`, ); editor.scroll.domNode.classList.add('ql-editor'); editor.formatText(4, 1, { list: 'checked' }); editor.formatText(9, 1, { list: 'unchecked' }); expect(editor.getDelta()).toEqual( new Delta() .insert('0123') .insert('\n', { list: 'checked' }) .insert('5678') .insert('\n', { list: 'unchecked' }) .insert('0123\n'), ); expect(this.container).toEqualHTML(`
  1. 0123
  2. 5678

0123

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

0123

  1. 5678

0123

`, ); editor.formatText(9, 1, { list: null }); expect(editor.getDelta()).toEqual(new Delta().insert('0123\n5678\n0123\n')); expect(this.container).toEqualHTML(`

0123

5678

0123

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

0123

  1. 5678

0123

`, ); editor.formatText(9, 1, { list: 'bullet' }); expect(editor.getDelta()).toEqual( new Delta() .insert('0123\n5678') .insert('\n', { list: 'bullet' }) .insert('0123\n'), ); expect(this.container).toEqualHTML(`

0123

  1. 5678

0123

`); }); it('replace checklist with bullet', function() { const editor = this.initialize( Editor, `
  1. 0123
`, ); editor.formatText(4, 1, { list: 'bullet' }); expect(editor.getDelta()).toEqual( new Delta().insert('0123').insert('\n', { list: 'bullet' }), ); expect(this.container).toEqualHTML(`
  1. 0123
`); }); it('replace with attributes', function() { const editor = this.initialize( Editor, '
  1. 0123
', ); editor.formatText(4, 1, { list: 'bullet' }); expect(editor.getDelta()).toEqual( new Delta() .insert('0123') .insert('\n', { align: 'center', list: 'bullet' }), ); expect(this.container).toEqualHTML( '
  1. 0123
', ); }); it('format merge', function() { const editor = this.initialize( Editor, `
  1. 0123

5678

  1. 0123
`, ); editor.formatText(9, 1, { list: 'ordered' }); expect(editor.getDelta()).toEqual( new Delta() .insert('0123') .insert('\n', { list: 'ordered' }) .insert('5678') .insert('\n', { list: 'ordered' }) .insert('0123') .insert('\n', { list: 'ordered' }), ); expect(this.container).toEqualHTML(`
  1. 0123
  2. 5678
  3. 0123
`); }); it('delete merge', function() { const editor = this.initialize( Editor, `
  1. 0123

5678

  1. 0123
`, ); editor.deleteText(5, 5); expect(editor.getDelta()).toEqual( new Delta() .insert('0123') .insert('\n', { list: 'ordered' }) .insert('0123') .insert('\n', { list: 'ordered' }), ); expect(this.container).toEqualHTML(`
  1. 0123
  2. 0123
`); }); it('merge checklist', function() { const editor = this.initialize( Editor, `
  1. 0123

5678

  1. 0123
`, ); editor.formatText(9, 1, { list: 'checked' }); expect(editor.getDelta()).toEqual( new Delta() .insert('0123') .insert('\n', { list: 'checked' }) .insert('5678') .insert('\n', { list: 'checked' }) .insert('0123') .insert('\n', { list: 'checked' }), ); expect(this.container).toEqualHTML(`
  1. 0123
  2. 5678
  3. 0123
`); }); it('empty line interop', function() { const editor = this.initialize( Editor, '

', ); editor.insertText(0, 'Test'); expect(this.container).toEqualHTML( '
  1. Test
', ); editor.deleteText(0, 4); expect(this.container).toEqualHTML( '

', ); }); it('delete multiple items', function() { const editor = this.initialize( Editor, `
  1. 0123
  2. 5678
  3. 0123
`, ); editor.deleteText(2, 5); expect(this.container).toEqualHTML(`
  1. 0178
  2. 0123
`); }); it('delete across last item', function() { const editor = this.initialize( Editor, `
  1. 0123

5678

`, ); editor.deleteText(2, 5); expect(this.container).toEqualHTML('

0178

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

0123

  1. 5678
', ); editor.deleteText(2, 5); expect(this.container).toEqualHTML( '
  1. 0178
', ); }); it('nested list replacement', function() { const editor = this.initialize( Editor, `
  1. One
  2. Alpha
  3. Two
`, ); editor.formatLine(1, 10, { list: 'bullet' }); expect(this.container).toEqualHTML(`
  1. One
  2. Alpha
  3. Two
`); }); it('copy atttributes', function() { const editor = this.initialize( Editor, '

Test

', ); editor.formatLine(4, 1, { list: 'bullet' }); expect(this.container).toEqualHTML( '
  1. Test
', ); }); it('insert block embed', function() { const editor = this.initialize( Editor, '
  1. Test
', ); editor.insertEmbed( 2, 'video', 'https://www.youtube.com/embed/QHH3iSeDBLo?showinfo=0', ); expect(this.container).toEqualHTML(`
  1. Te
  1. st
`); }); it('insert block embed at beginning', function() { const editor = this.initialize( Editor, '
  1. Test
', ); editor.insertEmbed( 0, 'video', 'https://www.youtube.com/embed/QHH3iSeDBLo?showinfo=0', ); expect(this.container).toEqualHTML(`
  1. Test
`); }); it('insert block embed at end', function() { const editor = this.initialize( Editor, '
  1. Test
', ); editor.insertEmbed( 4, 'video', 'https://www.youtube.com/embed/QHH3iSeDBLo?showinfo=0', ); expect(this.container).toEqualHTML(`
  1. Test

`); }); });