Browse Source

Tests: Initial tests for heading row setter with multiple cell selection.

Marek Lewandowski 5 years ago
parent
commit
37e8e9dc86
1 changed files with 80 additions and 1 deletions
  1. 80 1
      packages/ckeditor5-table/tests/commands/setheaderrowcommand.js

+ 80 - 1
packages/ckeditor5-table/tests/commands/setheaderrowcommand.js

@@ -7,6 +7,7 @@ import ModelTestEditor from '@ckeditor/ckeditor5-core/tests/_utils/modeltestedit
 import { getData, setData } from '@ckeditor/ckeditor5-engine/src/dev-utils/model';
 import SetHeaderRowCommand from '../../src/commands/setheaderrowcommand';
 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';
 
@@ -16,7 +17,7 @@ describe( 'SetHeaderRowCommand', () => {
 	beforeEach( () => {
 		return ModelTestEditor
 			.create( {
-				plugins: [ TableUtils ]
+				plugins: [ TableUtils, TableSelection ]
 			} )
 			.then( newEditor => {
 				editor = newEditor;
@@ -42,6 +43,36 @@ describe( 'SetHeaderRowCommand', () => {
 			setData( model, '<table><tableRow><tableCell><paragraph>foo[]</paragraph></tableCell></tableRow></table>' );
 			expect( command.isEnabled ).to.be.true;
 		} );
+
+		it( 'should be true if multiple cells are selected', () => {
+			setData( model, modelTable( [
+				[ '01', '02', '03' ]
+			] ) );
+
+			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.true;
+		} );
+
+		it( 'should be true if multiple cells in a header row are selected', () => {
+			setData( model, modelTable( [
+				[ '01', '02', '03' ]
+			], { headingRows: 1 } ) );
+
+			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.true;
+		} );
 	} );
 
 	describe( 'value', () => {
@@ -80,6 +111,54 @@ describe( 'SetHeaderRowCommand', () => {
 
 			expect( command.value ).to.be.false;
 		} );
+
+		it( 'should be true if multiple header rows are selected', () => {
+			setData( model, modelTable( [
+				[ '01', '02' ],
+				[ '11', '12' ]
+			], { headingRows: 2 } ) );
+
+			const tableSelection = editor.plugins.get( TableSelection );
+			const modelRoot = model.document.getRoot();
+			tableSelection._setCellSelection(
+				modelRoot.getNodeByPath( [ 0, 0, 1 ] ),
+				modelRoot.getNodeByPath( [ 0, 1, 1 ] )
+			);
+
+			expect( command.value ).to.be.true;
+		} );
+
+		it( 'should be true if multiple header columns are selected in reversed order', () => {
+			setData( model, modelTable( [
+				[ '01', '02' ],
+				[ '11', '12' ]
+			], { headingRows: 2 } ) );
+
+			const tableSelection = editor.plugins.get( TableSelection );
+			const modelRoot = model.document.getRoot();
+			tableSelection._setCellSelection(
+				modelRoot.getNodeByPath( [ 0, 1, 1 ] ),
+				modelRoot.getNodeByPath( [ 0, 0, 1 ] )
+			);
+
+			expect( command.value ).to.be.true;
+		} );
+
+		it( 'should be false if only part of selected columns are headers', () => {
+			setData( model, modelTable( [
+				[ '01', '02' ],
+				[ '11', '12' ]
+			], { headingRows: 1 } ) );
+
+			const tableSelection = editor.plugins.get( TableSelection );
+			const modelRoot = model.document.getRoot();
+			tableSelection._setCellSelection(
+				modelRoot.getNodeByPath( [ 0, 0, 0 ] ),
+				modelRoot.getNodeByPath( [ 0, 1, 0 ] )
+			);
+
+			expect( command.value ).to.be.false;
+		} );
 	} );
 
 	describe( 'execute()', () => {