|
|
@@ -18,60 +18,62 @@ import {
|
|
|
} from '../../src/converters/downcast';
|
|
|
import upcastTable from '../../src/converters/upcasttable';
|
|
|
import { formatTable, formattedModelTable, modelTable } from '../_utils/utils';
|
|
|
+import TableUtils from '../../src/tableutils';
|
|
|
|
|
|
describe( 'MergeCellCommand', () => {
|
|
|
let editor, model, command, root;
|
|
|
|
|
|
beforeEach( () => {
|
|
|
- return ModelTestEditor.create()
|
|
|
- .then( newEditor => {
|
|
|
- editor = newEditor;
|
|
|
- model = editor.model;
|
|
|
- root = model.document.getRoot( 'main' );
|
|
|
+ return ModelTestEditor.create( {
|
|
|
+ plugins: [ TableUtils ]
|
|
|
+ } ).then( newEditor => {
|
|
|
+ editor = newEditor;
|
|
|
+ model = editor.model;
|
|
|
+ root = model.document.getRoot( 'main' );
|
|
|
|
|
|
- const conversion = editor.conversion;
|
|
|
- const schema = model.schema;
|
|
|
+ const conversion = editor.conversion;
|
|
|
+ const schema = model.schema;
|
|
|
|
|
|
- schema.register( 'table', {
|
|
|
- allowWhere: '$block',
|
|
|
- allowAttributes: [ 'headingRows' ],
|
|
|
- isObject: true
|
|
|
- } );
|
|
|
+ schema.register( 'table', {
|
|
|
+ allowWhere: '$block',
|
|
|
+ allowAttributes: [ 'headingRows' ],
|
|
|
+ isObject: true
|
|
|
+ } );
|
|
|
|
|
|
- schema.register( 'tableRow', { allowIn: 'table' } );
|
|
|
+ schema.register( 'tableRow', { allowIn: 'table' } );
|
|
|
|
|
|
- schema.register( 'tableCell', {
|
|
|
- allowIn: 'tableRow',
|
|
|
- allowContentOf: '$block',
|
|
|
- allowAttributes: [ 'colspan', 'rowspan' ],
|
|
|
- isLimit: true
|
|
|
- } );
|
|
|
+ schema.register( 'tableCell', {
|
|
|
+ allowIn: 'tableRow',
|
|
|
+ allowContentOf: '$block',
|
|
|
+ allowAttributes: [ 'colspan', 'rowspan' ],
|
|
|
+ isLimit: true
|
|
|
+ } );
|
|
|
|
|
|
- model.schema.register( 'p', { inheritAllFrom: '$block' } );
|
|
|
+ model.schema.register( 'p', { inheritAllFrom: '$block' } );
|
|
|
|
|
|
- // Table conversion.
|
|
|
- conversion.for( 'upcast' ).add( upcastTable() );
|
|
|
- conversion.for( 'downcast' ).add( downcastInsertTable() );
|
|
|
+ // Table conversion.
|
|
|
+ conversion.for( 'upcast' ).add( upcastTable() );
|
|
|
+ conversion.for( 'downcast' ).add( downcastInsertTable() );
|
|
|
|
|
|
- // Insert row conversion.
|
|
|
- conversion.for( 'downcast' ).add( downcastInsertRow() );
|
|
|
+ // Insert row conversion.
|
|
|
+ conversion.for( 'downcast' ).add( downcastInsertRow() );
|
|
|
|
|
|
- // Remove row conversion.
|
|
|
- conversion.for( 'downcast' ).add( downcastRemoveRow() );
|
|
|
+ // Remove row conversion.
|
|
|
+ conversion.for( 'downcast' ).add( downcastRemoveRow() );
|
|
|
|
|
|
- // Table cell conversion.
|
|
|
- conversion.for( 'downcast' ).add( downcastInsertCell() );
|
|
|
+ // Table cell conversion.
|
|
|
+ conversion.for( 'downcast' ).add( downcastInsertCell() );
|
|
|
|
|
|
- conversion.for( 'upcast' ).add( upcastElementToElement( { model: 'tableCell', view: 'td' } ) );
|
|
|
- conversion.for( 'upcast' ).add( upcastElementToElement( { model: 'tableCell', view: 'th' } ) );
|
|
|
+ conversion.for( 'upcast' ).add( upcastElementToElement( { model: 'tableCell', view: 'td' } ) );
|
|
|
+ conversion.for( 'upcast' ).add( upcastElementToElement( { model: 'tableCell', view: 'th' } ) );
|
|
|
|
|
|
- // Table attributes conversion.
|
|
|
- conversion.attributeToAttribute( { model: 'colspan', view: 'colspan' } );
|
|
|
- conversion.attributeToAttribute( { model: 'rowspan', view: 'rowspan' } );
|
|
|
+ // Table attributes conversion.
|
|
|
+ conversion.attributeToAttribute( { model: 'colspan', view: 'colspan' } );
|
|
|
+ conversion.attributeToAttribute( { model: 'rowspan', view: 'rowspan' } );
|
|
|
|
|
|
- conversion.for( 'downcast' ).add( downcastTableHeadingColumnsChange() );
|
|
|
- conversion.for( 'downcast' ).add( downcastTableHeadingRowsChange() );
|
|
|
- } );
|
|
|
+ conversion.for( 'downcast' ).add( downcastTableHeadingColumnsChange() );
|
|
|
+ conversion.for( 'downcast' ).add( downcastTableHeadingRowsChange() );
|
|
|
+ } );
|
|
|
} );
|
|
|
|
|
|
afterEach( () => {
|
|
|
@@ -116,6 +118,24 @@ describe( 'MergeCellCommand', () => {
|
|
|
expect( command.isEnabled ).to.be.false;
|
|
|
} );
|
|
|
|
|
|
+ it( 'should be false when next cell is rowspanned', () => {
|
|
|
+ setData( model, modelTable( [
|
|
|
+ [ '00', { rowspan: 3, contents: '01' }, '02' ],
|
|
|
+ [ '10[]', '12' ],
|
|
|
+ [ '20', '22' ]
|
|
|
+ ] ) );
|
|
|
+
|
|
|
+ expect( command.isEnabled ).to.be.false;
|
|
|
+ } );
|
|
|
+
|
|
|
+ it( 'should be true when current cell is colspanned', () => {
|
|
|
+ setData( model, modelTable( [
|
|
|
+ [ { colspan: 2, contents: '00[]' }, '02' ]
|
|
|
+ ] ) );
|
|
|
+
|
|
|
+ expect( command.isEnabled ).to.be.true;
|
|
|
+ } );
|
|
|
+
|
|
|
it( 'should be false if not in a cell', () => {
|
|
|
setData( model, '<p>11[]</p>' );
|
|
|
|
|
|
@@ -216,6 +236,24 @@ describe( 'MergeCellCommand', () => {
|
|
|
expect( command.isEnabled ).to.be.false;
|
|
|
} );
|
|
|
|
|
|
+ it( 'should be false when next cell is rowspanned', () => {
|
|
|
+ setData( model, modelTable( [
|
|
|
+ [ '00', { rowspan: 3, contents: '01' }, '02' ],
|
|
|
+ [ '10', '12[]' ],
|
|
|
+ [ '20', '22' ]
|
|
|
+ ] ) );
|
|
|
+
|
|
|
+ expect( command.isEnabled ).to.be.false;
|
|
|
+ } );
|
|
|
+
|
|
|
+ it( 'should be true when mergeable cell is colspanned', () => {
|
|
|
+ setData( model, modelTable( [
|
|
|
+ [ { colspan: 2, contents: '00' }, '02[]' ]
|
|
|
+ ] ) );
|
|
|
+
|
|
|
+ expect( command.isEnabled ).to.be.true;
|
|
|
+ } );
|
|
|
+
|
|
|
it( 'should be false if not in a cell', () => {
|
|
|
setData( model, '<p>11[]</p>' );
|
|
|
|