common.js 2.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677
  1. /**
  2. * @license Copyright (c) 2003-2020, CKSource - Frederico Knabben. All rights reserved.
  3. * For licensing, see LICENSE.md or https://ckeditor.com/legal/ckeditor-oss-license
  4. */
  5. import ModelTestEditor from '@ckeditor/ckeditor5-core/tests/_utils/modeltesteditor';
  6. import Paragraph from '@ckeditor/ckeditor5-paragraph/src/paragraph';
  7. import { setData } from '@ckeditor/ckeditor5-engine/src/dev-utils/model';
  8. import TableEditing from '../../src/tableediting';
  9. import { modelTable } from '../_utils/utils';
  10. import { isHeadingColumnCell } from '../../src/utils/common';
  11. describe( 'table utils', () => {
  12. let editor, model, modelRoot, tableUtils;
  13. beforeEach( () => {
  14. return ModelTestEditor
  15. .create( {
  16. plugins: [ Paragraph, TableEditing ]
  17. } )
  18. .then( newEditor => {
  19. editor = newEditor;
  20. model = editor.model;
  21. modelRoot = model.document.getRoot();
  22. tableUtils = editor.plugins.get( 'TableUtils' );
  23. } );
  24. } );
  25. afterEach( () => {
  26. return editor.destroy();
  27. } );
  28. describe( 'common', () => {
  29. describe( 'isHeadingColumnCell()', () => {
  30. it( 'should return "true" for a heading column cell', () => {
  31. setData( model, modelTable( [
  32. [ '00', '01', '02', '03' ]
  33. ], { headingColumns: 2 } ) );
  34. const tableCell = modelRoot.getNodeByPath( [ 0, 0, 1 ] );
  35. expect( isHeadingColumnCell( tableUtils, tableCell ) ).to.be.true;
  36. } );
  37. it( 'should return "true" for a heading column cell with colspan', () => {
  38. setData( model, modelTable( [
  39. [ { colspan: 2, contents: '00' }, '01', '02', '03' ]
  40. ], { headingColumns: 2 } ) );
  41. const tableCell = modelRoot.getNodeByPath( [ 0, 0, 0 ] );
  42. expect( isHeadingColumnCell( tableUtils, tableCell ) ).to.be.true;
  43. } );
  44. it( 'should return "false" for a regular column cell', () => {
  45. setData( model, modelTable( [
  46. [ '00', '01', '02', '03' ]
  47. ], { headingColumns: 2 } ) );
  48. const tableCell = modelRoot.getNodeByPath( [ 0, 0, 2 ] );
  49. expect( isHeadingColumnCell( tableUtils, tableCell ) ).to.be.false;
  50. } );
  51. it( 'should return "false" for a regular column cell with colspan', () => {
  52. setData( model, modelTable( [
  53. [ '00', { colspan: 2, contents: '01' }, '02', '03' ]
  54. ], { headingColumns: 1 } ) );
  55. const tableCell = modelRoot.getNodeByPath( [ 0, 0, 1 ] );
  56. expect( isHeadingColumnCell( tableUtils, tableCell ) ).to.be.false;
  57. } );
  58. } );
  59. } );
  60. } );