|
|
@@ -3,19 +3,20 @@
|
|
|
* For licensing, see LICENSE.md or https://ckeditor.com/legal/ckeditor-oss-license
|
|
|
*/
|
|
|
|
|
|
-import ModelTestEditor from '@ckeditor/ckeditor5-core/tests/_utils/modeltesteditor';
|
|
|
+import VirtualTestEditor from '@ckeditor/ckeditor5-core/tests/_utils/virtualtesteditor';
|
|
|
import { getData, setData } from '@ckeditor/ckeditor5-engine/src/dev-utils/model';
|
|
|
+import { getData as getViewData } from '@ckeditor/ckeditor5-engine/src/dev-utils/view';
|
|
|
|
|
|
import RemoveRowCommand from '../../src/commands/removerowcommand';
|
|
|
import TableSelection from '../../src/tableselection';
|
|
|
-import { defaultConversion, defaultSchema, modelTable } from '../_utils/utils';
|
|
|
+import { defaultConversion, defaultSchema, modelTable, viewTable } from '../_utils/utils';
|
|
|
import { assertEqualMarkup } from '@ckeditor/ckeditor5-utils/tests/_utils/utils';
|
|
|
|
|
|
describe( 'RemoveRowCommand', () => {
|
|
|
let editor, model, command;
|
|
|
|
|
|
beforeEach( () => {
|
|
|
- return ModelTestEditor.create( { plugins: [ TableSelection ] } )
|
|
|
+ return VirtualTestEditor.create( { plugins: [ TableSelection ] } )
|
|
|
.then( newEditor => {
|
|
|
editor = newEditor;
|
|
|
model = editor.model;
|
|
|
@@ -215,7 +216,7 @@ describe( 'RemoveRowCommand', () => {
|
|
|
] ) );
|
|
|
} );
|
|
|
|
|
|
- it( 'should support removing multiple headings', () => {
|
|
|
+ it( 'should support removing multiple headings (removed rows in heading section)', () => {
|
|
|
setData( model, modelTable( [
|
|
|
[ '00', '01' ],
|
|
|
[ '10', '11' ],
|
|
|
@@ -238,6 +239,37 @@ describe( 'RemoveRowCommand', () => {
|
|
|
], { headingRows: 1 } ) );
|
|
|
} );
|
|
|
|
|
|
+ it( 'should support removing multiple headings (removed rows in heading and body section)', () => {
|
|
|
+ setData( model, modelTable( [
|
|
|
+ [ '00', '01' ],
|
|
|
+ [ '10', '11' ],
|
|
|
+ [ '20', '21' ],
|
|
|
+ [ '30', '31' ],
|
|
|
+ [ '40', '41' ]
|
|
|
+ ], { headingRows: 3 } ) );
|
|
|
+
|
|
|
+ const tableSelection = editor.plugins.get( TableSelection );
|
|
|
+ const modelRoot = model.document.getRoot();
|
|
|
+
|
|
|
+ tableSelection._setCellSelection(
|
|
|
+ modelRoot.getNodeByPath( [ 0, 1, 0 ] ),
|
|
|
+ modelRoot.getNodeByPath( [ 0, 3, 0 ] )
|
|
|
+ );
|
|
|
+
|
|
|
+ command.execute();
|
|
|
+
|
|
|
+ assertEqualMarkup( getData( model ), modelTable( [
|
|
|
+ [ '00', '01' ],
|
|
|
+ [ '[]40', '41' ]
|
|
|
+ ], { headingRows: 1 } ) );
|
|
|
+
|
|
|
+ // The view should also be properly downcasted.
|
|
|
+ assertEqualMarkup( getViewData( editor.editing.view, { withoutSelection: true } ), viewTable( [
|
|
|
+ [ '00', '01' ],
|
|
|
+ [ '40', '41' ]
|
|
|
+ ], { headingRows: 1 } ) );
|
|
|
+ } );
|
|
|
+
|
|
|
it( 'should support removing mixed heading and cell rows', () => {
|
|
|
setData( model, modelTable( [
|
|
|
[ '00', '01' ],
|
|
|
@@ -279,6 +311,34 @@ describe( 'RemoveRowCommand', () => {
|
|
|
[ '[]20', '01' ]
|
|
|
] ) );
|
|
|
} );
|
|
|
+
|
|
|
+ it( 'should create one undo step (1 batch)', () => {
|
|
|
+ setData( model, modelTable( [
|
|
|
+ [ '00', '01' ],
|
|
|
+ [ '10', '11' ],
|
|
|
+ [ '20', '21' ],
|
|
|
+ [ '30', '31' ]
|
|
|
+ ], { headingRows: 3 } ) );
|
|
|
+
|
|
|
+ const createdBatches = new Set();
|
|
|
+
|
|
|
+ model.on( 'applyOperation', ( evt, args ) => {
|
|
|
+ const operation = args[ 0 ];
|
|
|
+
|
|
|
+ createdBatches.add( operation.batch );
|
|
|
+ } );
|
|
|
+
|
|
|
+ const tableSelection = editor.plugins.get( TableSelection );
|
|
|
+ const modelRoot = model.document.getRoot();
|
|
|
+ tableSelection._setCellSelection(
|
|
|
+ modelRoot.getNodeByPath( [ 0, 0, 0 ] ),
|
|
|
+ modelRoot.getNodeByPath( [ 0, 1, 0 ] )
|
|
|
+ );
|
|
|
+
|
|
|
+ command.execute();
|
|
|
+
|
|
|
+ expect( createdBatches.size ).to.equal( 1 );
|
|
|
+ } );
|
|
|
} );
|
|
|
|
|
|
describe( 'with entire row selected', () => {
|