|
|
@@ -4,20 +4,27 @@
|
|
|
*/
|
|
|
|
|
|
import ModelTestEditor from '@ckeditor/ckeditor5-core/tests/_utils/modeltesteditor';
|
|
|
+import TableUtils from '../../src/tableutils';
|
|
|
import { setData } from '@ckeditor/ckeditor5-engine/src/dev-utils/model';
|
|
|
-
|
|
|
import { defaultConversion, defaultSchema, modelTable } from '../_utils/utils';
|
|
|
-
|
|
|
-import { findAncestor } from '../../src/commands/utils';
|
|
|
+import {
|
|
|
+ findAncestor,
|
|
|
+ isHeadingColumnCell
|
|
|
+} from '../../src/commands/utils';
|
|
|
|
|
|
describe( 'commands utils', () => {
|
|
|
- let editor, model;
|
|
|
+ let editor, model, modelRoot, tableUtils;
|
|
|
|
|
|
beforeEach( () => {
|
|
|
- return ModelTestEditor.create()
|
|
|
+ return ModelTestEditor
|
|
|
+ .create( {
|
|
|
+ plugins: [ TableUtils ]
|
|
|
+ } )
|
|
|
.then( newEditor => {
|
|
|
editor = newEditor;
|
|
|
model = editor.model;
|
|
|
+ modelRoot = model.document.getRoot();
|
|
|
+ tableUtils = editor.plugins.get( TableUtils );
|
|
|
|
|
|
defaultSchema( model.schema );
|
|
|
defaultConversion( editor.conversion );
|
|
|
@@ -28,7 +35,7 @@ describe( 'commands utils', () => {
|
|
|
return editor.destroy();
|
|
|
} );
|
|
|
|
|
|
- describe( 'getParentTable()', () => {
|
|
|
+ describe( 'findAncestor()', () => {
|
|
|
it( 'should return undefined if not in table', () => {
|
|
|
setData( model, '<paragraph>foo[]</paragraph>' );
|
|
|
|
|
|
@@ -44,4 +51,46 @@ describe( 'commands utils', () => {
|
|
|
expect( parentTable.is( 'table' ) ).to.be.true;
|
|
|
} );
|
|
|
} );
|
|
|
+
|
|
|
+ describe( 'isHeadingColumnCell()', () => {
|
|
|
+ it( 'shoud return "true" for heading column cell', () => {
|
|
|
+ setData( model, modelTable( [
|
|
|
+ [ '00', '01', '02', '03' ]
|
|
|
+ ], { headingColumns: 2 } ) );
|
|
|
+
|
|
|
+ const tableCell = modelRoot.getNodeByPath( [ 0, 0, 1 ] );
|
|
|
+
|
|
|
+ expect( isHeadingColumnCell( tableUtils, tableCell ) ).to.be.true;
|
|
|
+ } );
|
|
|
+
|
|
|
+ it( 'shoud return "true" for heading column cell with colspan', () => {
|
|
|
+ setData( model, modelTable( [
|
|
|
+ [ { colspan: 2, contents: '00' }, '01', '02', '03' ]
|
|
|
+ ], { headingColumns: 2 } ) );
|
|
|
+
|
|
|
+ const tableCell = modelRoot.getNodeByPath( [ 0, 0, 0 ] );
|
|
|
+
|
|
|
+ expect( isHeadingColumnCell( tableUtils, tableCell ) ).to.be.true;
|
|
|
+ } );
|
|
|
+
|
|
|
+ it( 'shoud return "false" for regular column cell', () => {
|
|
|
+ setData( model, modelTable( [
|
|
|
+ [ '00', '01', '02', '03' ]
|
|
|
+ ], { headingColumns: 2 } ) );
|
|
|
+
|
|
|
+ const tableCell = modelRoot.getNodeByPath( [ 0, 0, 2 ] );
|
|
|
+
|
|
|
+ expect( isHeadingColumnCell( tableUtils, tableCell ) ).to.be.false;
|
|
|
+ } );
|
|
|
+
|
|
|
+ it( 'shoud return "false" for regular column cell with colspan', () => {
|
|
|
+ setData( model, modelTable( [
|
|
|
+ [ '00', { colspan: 2, contents: '01' }, '02', '03' ]
|
|
|
+ ], { headingColumns: 1 } ) );
|
|
|
+
|
|
|
+ const tableCell = modelRoot.getNodeByPath( [ 0, 0, 1 ] );
|
|
|
+
|
|
|
+ expect( isHeadingColumnCell( tableUtils, tableCell ) ).to.be.false;
|
|
|
+ } );
|
|
|
+ } );
|
|
|
} );
|