瀏覽代碼

Add table clipboard tests and update its requires call.

Maciej Gołaszewski 5 年之前
父節點
當前提交
af0fac6466
共有 2 個文件被更改,包括 41 次插入4 次删除
  1. 5 4
      packages/ckeditor5-table/src/tableclipboard.js
  2. 36 0
      packages/ckeditor5-table/tests/tableclipboard.js

+ 5 - 4
packages/ckeditor5-table/src/tableclipboard.js

@@ -14,6 +14,7 @@ import TableWalker from './tablewalker';
 import { getColumnIndexes, getRowIndexes, isSelectionRectangular } from './utils';
 import { findAncestor } from './commands/utils';
 import { cropTableToDimensions } from './tableselection/croptable';
+import TableUtils from './tableutils';
 
 /**
  * This plugin adds support for copying/cutting/pasting fragments of tables.
@@ -33,7 +34,7 @@ export default class TableClipboard extends Plugin {
 	 * @inheritDoc
 	 */
 	static get requires() {
-		return [ TableSelection ];
+		return [ TableSelection, TableUtils ];
 	}
 
 	/**
@@ -56,7 +57,7 @@ export default class TableClipboard extends Plugin {
 	 * @param {Object} data Clipboard event data.
 	 */
 	_onCopyCut( evt, data ) {
-		const tableSelection = this.editor.plugins.get( 'TableSelection' );
+		const tableSelection = this.editor.plugins.get( TableSelection );
 
 		if ( !tableSelection.getSelectedTableCells() ) {
 			return;
@@ -94,7 +95,7 @@ export default class TableClipboard extends Plugin {
 	 * @param {module:engine/model/documentfragment~DocumentFragment|module:engine/model/item~Item} content The content to insert.
 	 */
 	_onInsertContent( evt, content ) {
-		const tableSelection = this.editor.plugins.get( 'TableSelection' );
+		const tableSelection = this.editor.plugins.get( TableSelection );
 		const selectedTableCells = tableSelection.getSelectedTableCells();
 
 		if ( !selectedTableCells ) {
@@ -118,7 +119,7 @@ export default class TableClipboard extends Plugin {
 			return;
 		}
 
-		const tableUtils = this.editor.plugins.get( 'TableUtils' );
+		const tableUtils = this.editor.plugins.get( TableUtils );
 
 		// Currently not handled. The selected table content should be trimmed to a rectangular selection.
 		// See: https://github.com/ckeditor/ckeditor5/issues/6122.

+ 36 - 0
packages/ckeditor5-table/tests/tableclipboard.js

@@ -0,0 +1,36 @@
+/**
+ * @license Copyright (c) 2003-2020, CKSource - Frederico Knabben. All rights reserved.
+ * For licensing, see LICENSE.md or https://ckeditor.com/legal/ckeditor-oss-license
+ */
+
+import VirtualTestEditor from '@ckeditor/ckeditor5-core/tests/_utils/virtualtesteditor';
+import Paragraph from '@ckeditor/ckeditor5-paragraph/src/paragraph';
+
+import TableSelection from '../src/tableselection';
+import TableUtils from '../src/tableutils';
+
+import TableClipboard from '../src/tableclipboard';
+
+describe( 'table clipboard', () => {
+	let editor;
+
+	beforeEach( async () => {
+		editor = await VirtualTestEditor.create( {
+			plugins: [ TableClipboard, Paragraph ]
+		} );
+	} );
+
+	afterEach( () => {
+		return editor.destroy();
+	} );
+
+	describe( 'TableClipboard', () => {
+		it( 'should have pluginName', () => {
+			expect( TableClipboard.pluginName ).to.equal( 'TableClipboard' );
+		} );
+
+		it( 'requires TableSelection and TableUtils ', () => {
+			expect( TableClipboard.requires ).to.deep.equal( [ TableSelection, TableUtils ] );
+		} );
+	} );
+} );