import Delta from 'quill-delta'; import Editor from '../../../core/editor'; const tableDelta = new Delta() .insert('A1') .insert('\n', { table: 'a' }) .insert('A2') .insert('\n', { table: 'a' }) .insert('A3') .insert('\n', { table: 'a' }) .insert('B1') .insert('\n', { table: 'b' }) .insert('B2') .insert('\n', { table: 'b' }) .insert('B3') .insert('\n', { table: 'b' }) .insert('C1') .insert('\n', { table: 'c' }) .insert('C2') .insert('\n', { table: 'c' }) .insert('C3') .insert('\n', { table: 'c' }); const tableHTML = `
A1 A2 A3
B1 B2 B3
C1 C2 C3
`; describe('Table', function() { it('initialize', function() { const editor = this.initialize(Editor, tableHTML); expect(editor.getDelta()).toEqual(tableDelta); expect(this.container).toEqualHTML(tableHTML); }); it('add', function() { const editor = this.initialize(Editor, ''); editor.applyDelta(new Delta([...tableDelta.ops]).delete(1)); expect(this.container).toEqualHTML(tableHTML); }); it('add format plaintext', function() { const editor = this.initialize(Editor, '

Test

'); editor.formatLine(0, 5, { table: 'a' }); expect(this.container).toEqualHTML( '
Test
', ); }); it('add format replace', function() { const editor = this.initialize(Editor, '

Test

'); editor.formatLine(0, 5, { table: 'a' }); expect(this.container).toEqualHTML( '
Test
', ); }); it('remove format plaintext', function() { const editor = this.initialize( Editor, '
Test
', ); editor.formatLine(0, 5, { table: null }); expect(this.container).toEqualHTML('

Test

'); }); it('remove format replace', function() { const editor = this.initialize( Editor, '
Test
', ); editor.formatLine(0, 5, { header: 1 }); expect(this.container).toEqualHTML('

Test

'); }); it('group rows', function() { const editor = this.initialize( Editor, `
A
B
`, ); editor.scroll.children.head.children.head.children.head.optimize(); expect(this.container).toEqualHTML(`
AB
`); }); it('split rows', function() { const editor = this.initialize( Editor, `
AB
`, ); editor.scroll.children.head.children.head.children.head.optimize(); expect(this.container).toEqualHTML(`
A
B
`); }); it('group and split rows', function() { const editor = this.initialize( Editor, `
AB1
B2
`, ); editor.scroll.children.head.children.head.children.head.optimize(); expect(this.container).toEqualHTML(`
A
B1B2
`); }); xit('group and split multiple rows', function() { const editor = this.initialize( Editor, `












`, ); editor.scroll.children.head.children.head.optimize(); expect(this.container).toEqualHTML(`












`); }); it('balance cells', function() { const editor = this.initialize( Editor, `
A1
B1 B2
C1 C2 C3
`, ); editor.scroll.children.head.balanceCells(); expect(this.container).toEqualHTML( `
A1

B1 B2
C1 C2 C3
`, ); }); it('format', function() { const editor = this.initialize(Editor, '

a

b

1

2

'); editor.formatLine(0, 4, { table: 'a' }); editor.formatLine(4, 4, { table: 'b' }); expect(this.container).toEqualHTML( `
a b
1 2
`, ); }); it('applyDelta', function() { const editor = this.initialize(Editor, '


'); editor.applyDelta( new Delta().insert('\n\n', { table: 'a' }).insert('\n\n', { table: 'b' }), ); expect(this.container).toEqualHTML( `





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


'); editor.applyDelta( new Delta() .insert('A1\nB1\nC1\n', { table: '1' }) .insert('A2\nB2\nC2\n', { table: '2' }) .insert('A3\nB3\n', { table: '3' }), ); expect(this.container).toEqualHTML( `
A1 B1 C1
A2 B2 C2
A3 B3


`, ); }); it('existing table applyDelta', function() { const editor = this.initialize( Editor, `
A1

B1
`, ); editor.applyDelta( new Delta() .retain(3) .retain(1, { table: '1' }) .insert('\n', { table: '2' }), ); expect(this.container).toEqualHTML( `
A1

B1
`, ); }); });