浏览代码

Tests: Added unit tests for split command in case of multiple selected cells.

Marek Lewandowski 5 年之前
父节点
当前提交
7843fe41d9
共有 1 个文件被更改,包括 32 次插入1 次删除
  1. 32 1
      packages/ckeditor5-table/tests/commands/splitcellcommand.js

+ 32 - 1
packages/ckeditor5-table/tests/commands/splitcellcommand.js

@@ -8,6 +8,7 @@ import { getData, setData } from '@ckeditor/ckeditor5-engine/src/dev-utils/model
 
 import SplitCellCommand from '../../src/commands/splitcellcommand';
 import { defaultConversion, defaultSchema, modelTable } from '../_utils/utils';
+import TableSelection from '../../src/tableselection';
 import TableUtils from '../../src/tableutils';
 import { assertEqualMarkup } from '@ckeditor/ckeditor5-utils/tests/_utils/utils';
 
@@ -17,7 +18,7 @@ describe( 'SplitCellCommand', () => {
 	beforeEach( () => {
 		return ModelTestEditor
 			.create( {
-				plugins: [ TableUtils ]
+				plugins: [ TableUtils, TableSelection ]
 			} )
 			.then( newEditor => {
 				editor = newEditor;
@@ -47,6 +48,36 @@ describe( 'SplitCellCommand', () => {
 				expect( command.isEnabled ).to.be.true;
 			} );
 
+			it( 'should be true if in an entire cell is selected', () => {
+				setData( model, modelTable( [
+					[ '00', '01' ]
+				] ) );
+
+				const tableSelection = editor.plugins.get( TableSelection );
+				const modelRoot = model.document.getRoot();
+				tableSelection._setCellSelection(
+					modelRoot.getNodeByPath( [ 0, 0, 0 ] ),
+					modelRoot.getNodeByPath( [ 0, 0, 0 ] )
+				);
+
+				expect( command.isEnabled ).to.be.true;
+			} );
+
+			it( 'should be false if multiple cells are selected', () => {
+				setData( model, modelTable( [
+					[ '00', '01' ]
+				] ) );
+
+				const tableSelection = editor.plugins.get( TableSelection );
+				const modelRoot = model.document.getRoot();
+				tableSelection._setCellSelection(
+					modelRoot.getNodeByPath( [ 0, 0, 0 ] ),
+					modelRoot.getNodeByPath( [ 0, 0, 1 ] )
+				);
+
+				expect( command.isEnabled ).to.be.false;
+			} );
+
 			it( 'should be false if not in cell', () => {
 				setData( model, '<paragraph>11[]</paragraph>' );