|
@@ -12,7 +12,7 @@ import { downcastInsertTable } from '../../src/converters/downcast';
|
|
|
import upcastTable from '../../src/converters/upcasttable';
|
|
import upcastTable from '../../src/converters/upcasttable';
|
|
|
import { formatTable, formattedModelTable, modelTable } from '../_utils/utils';
|
|
import { formatTable, formattedModelTable, modelTable } from '../_utils/utils';
|
|
|
|
|
|
|
|
-describe.only( 'MergeCellCommand', () => {
|
|
|
|
|
|
|
+describe( 'MergeCellCommand', () => {
|
|
|
let editor, model, command, root;
|
|
let editor, model, command, root;
|
|
|
|
|
|
|
|
beforeEach( () => {
|
|
beforeEach( () => {
|
|
@@ -268,4 +268,114 @@ describe.only( 'MergeCellCommand', () => {
|
|
|
} );
|
|
} );
|
|
|
} );
|
|
} );
|
|
|
} );
|
|
} );
|
|
|
|
|
+
|
|
|
|
|
+ describe( 'direction=down', () => {
|
|
|
|
|
+ beforeEach( () => {
|
|
|
|
|
+ command = new MergeCellCommand( editor, { direction: 'down' } );
|
|
|
|
|
+ } );
|
|
|
|
|
+
|
|
|
|
|
+ describe( 'isEnabled', () => {
|
|
|
|
|
+ it( 'should be true if in cell that has mergeable cell in next row', () => {
|
|
|
|
|
+ setData( model, modelTable( [
|
|
|
|
|
+ [ '00', '01[]' ],
|
|
|
|
|
+ [ '10', '11' ]
|
|
|
|
|
+ ] ) );
|
|
|
|
|
+
|
|
|
|
|
+ expect( command.isEnabled ).to.be.true;
|
|
|
|
|
+ } );
|
|
|
|
|
+
|
|
|
|
|
+ it( 'should be false if in last row', () => {
|
|
|
|
|
+ setData( model, modelTable( [
|
|
|
|
|
+ [ '00', '01' ],
|
|
|
|
|
+ [ '10[]', '11' ]
|
|
|
|
|
+ ] ) );
|
|
|
|
|
+
|
|
|
|
|
+ expect( command.isEnabled ).to.be.false;
|
|
|
|
|
+ } );
|
|
|
|
|
+
|
|
|
|
|
+ it( 'should be true if in a cell that has mergeable cell with the same colspan', () => {
|
|
|
|
|
+ setData( model, modelTable( [
|
|
|
|
|
+ [ { colspan: 2, contents: '00[]' }, '02' ],
|
|
|
|
|
+ [ { colspan: 2, contents: '01' }, '12' ]
|
|
|
|
|
+ ] ) );
|
|
|
|
|
+
|
|
|
|
|
+ expect( command.isEnabled ).to.be.true;
|
|
|
|
|
+ } );
|
|
|
|
|
+
|
|
|
|
|
+ it( 'should be false if in a cell that potential mergeable cell has different colspan', () => {
|
|
|
|
|
+ setData( model, modelTable( [
|
|
|
|
|
+ [ { colspan: 2, contents: '00[]' }, '02' ],
|
|
|
|
|
+ [ { colspan: 3, contents: '01' } ]
|
|
|
|
|
+ ] ) );
|
|
|
|
|
+
|
|
|
|
|
+ expect( command.isEnabled ).to.be.false;
|
|
|
|
|
+ } );
|
|
|
|
|
+
|
|
|
|
|
+ it( 'should be false if not in a cell', () => {
|
|
|
|
|
+ setData( model, '<p>11[]</p>' );
|
|
|
|
|
+
|
|
|
|
|
+ expect( command.isEnabled ).to.be.false;
|
|
|
|
|
+ } );
|
|
|
|
|
+ } );
|
|
|
|
|
+
|
|
|
|
|
+ describe( 'value', () => {
|
|
|
|
|
+ it( 'should be set to mergeable cell', () => {
|
|
|
|
|
+ setData( model, modelTable( [
|
|
|
|
|
+ [ '00', '01[]' ],
|
|
|
|
|
+ [ '10', '11' ]
|
|
|
|
|
+ ] ) );
|
|
|
|
|
+
|
|
|
|
|
+ expect( command.value ).to.equal( root.getNodeByPath( [ 0, 1, 1 ] ) );
|
|
|
|
|
+ } );
|
|
|
|
|
+
|
|
|
|
|
+ it( 'should be undefined if in last row', () => {
|
|
|
|
|
+ setData( model, modelTable( [
|
|
|
|
|
+ [ '00', '01' ],
|
|
|
|
|
+ [ '10[]', '11' ]
|
|
|
|
|
+ ] ) );
|
|
|
|
|
+
|
|
|
|
|
+ expect( command.value ).to.be.undefined;
|
|
|
|
|
+ } );
|
|
|
|
|
+
|
|
|
|
|
+ it( 'should be set to mergeable cell with the same rowspan', () => {
|
|
|
|
|
+ setData( model, modelTable( [
|
|
|
|
|
+ [ { colspan: 2, contents: '00[]' }, '02' ],
|
|
|
|
|
+ [ { colspan: 2, contents: '01' }, '12' ]
|
|
|
|
|
+ ] ) );
|
|
|
|
|
+
|
|
|
|
|
+ expect( command.value ).to.equal( root.getNodeByPath( [ 0, 1, 0 ] ) );
|
|
|
|
|
+ } );
|
|
|
|
|
+
|
|
|
|
|
+ it( 'should be undefined if in a cell that potential mergeable cell has different rowspan', () => {
|
|
|
|
|
+ setData( model, modelTable( [
|
|
|
|
|
+ [ { colspan: 2, contents: '00[]' }, '02' ],
|
|
|
|
|
+ [ { colspan: 3, contents: '01' } ]
|
|
|
|
|
+ ] ) );
|
|
|
|
|
+
|
|
|
|
|
+ expect( command.value ).to.be.undefined;
|
|
|
|
|
+ } );
|
|
|
|
|
+
|
|
|
|
|
+ it( 'should be undefined if not in a cell', () => {
|
|
|
|
|
+ setData( model, '<p>11[]</p>' );
|
|
|
|
|
+
|
|
|
|
|
+ expect( command.value ).to.be.undefined;
|
|
|
|
|
+ } );
|
|
|
|
|
+ } );
|
|
|
|
|
+
|
|
|
|
|
+ describe( 'execute()', () => {
|
|
|
|
|
+ it( 'should merge table cells ', () => {
|
|
|
|
|
+ setData( model, modelTable( [
|
|
|
|
|
+ [ '00', '01[]' ],
|
|
|
|
|
+ [ '10', '11' ]
|
|
|
|
|
+ ] ) );
|
|
|
|
|
+
|
|
|
|
|
+ command.execute();
|
|
|
|
|
+
|
|
|
|
|
+ expect( formatTable( getData( model ) ) ).to.equal( formattedModelTable( [
|
|
|
|
|
+ [ '00', { rowspan: 2, contents: '0111[]' } ],
|
|
|
|
|
+ [ '10' ]
|
|
|
|
|
+ ] ) );
|
|
|
|
|
+ } );
|
|
|
|
|
+ } );
|
|
|
|
|
+ } );
|
|
|
} );
|
|
} );
|