utils.js 1.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647
  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 { setData } from '@ckeditor/ckeditor5-engine/src/dev-utils/model';
  7. import { defaultConversion, defaultSchema, modelTable } from '../_utils/utils';
  8. import { findAncestor } from '../../src/commands/utils';
  9. describe( 'commands utils', () => {
  10. let editor, model;
  11. beforeEach( () => {
  12. return ModelTestEditor.create()
  13. .then( newEditor => {
  14. editor = newEditor;
  15. model = editor.model;
  16. defaultSchema( model.schema );
  17. defaultConversion( editor.conversion );
  18. } );
  19. } );
  20. afterEach( () => {
  21. return editor.destroy();
  22. } );
  23. describe( 'getParentTable()', () => {
  24. it( 'should return undefined if not in table', () => {
  25. setData( model, '<paragraph>foo[]</paragraph>' );
  26. expect( findAncestor( 'table', model.document.selection.focus ) ).to.be.undefined;
  27. } );
  28. it( 'should return table if position is in tableCell', () => {
  29. setData( model, modelTable( [ [ '[]' ] ] ) );
  30. const parentTable = findAncestor( 'table', model.document.selection.focus );
  31. expect( parentTable ).to.not.be.undefined;
  32. expect( parentTable.is( 'table' ) ).to.be.true;
  33. } );
  34. } );
  35. } );