浏览代码

Tests: Add temporary insertRow & insertColumn buttons tests.

Maciej Gołaszewski 7 年之前
父节点
当前提交
2d916616b2
共有 2 个文件被更改,包括 79 次插入4 次删除
  1. 1 1
      packages/ckeditor5-table/src/tableui.js
  2. 78 3
      packages/ckeditor5-table/tests/tableui.js

+ 1 - 1
packages/ckeditor5-table/src/tableui.js

@@ -73,7 +73,7 @@ export default class TableUI extends Plugin {
 
 			buttonView.set( {
 				icon: insertColumnIcon,
-				label: 'Insert row',
+				label: 'Insert column',
 				tooltip: true
 			} );
 

+ 78 - 3
packages/ckeditor5-table/tests/tableui.js

@@ -16,7 +16,7 @@ import TableUI from '../src/tableui';
 testUtils.createSinonSandbox();
 
 describe( 'TableUI', () => {
-	let editor, element, insertTable;
+	let editor, element;
 
 	before( () => {
 		addTranslations( 'en', {} );
@@ -37,8 +37,6 @@ describe( 'TableUI', () => {
 			} )
 			.then( newEditor => {
 				editor = newEditor;
-
-				insertTable = editor.ui.componentFactory.create( 'insertTable' );
 			} );
 	} );
 
@@ -49,6 +47,12 @@ describe( 'TableUI', () => {
 	} );
 
 	describe( 'insertTable button', () => {
+		let insertTable;
+
+		beforeEach( () => {
+			insertTable = editor.ui.componentFactory.create( 'insertTable' );
+		} );
+
 		it( 'should register insertTable buton', () => {
 			expect( insertTable ).to.be.instanceOf( ButtonView );
 			expect( insertTable.isOn ).to.be.false;
@@ -59,6 +63,7 @@ describe( 'TableUI', () => {
 		it( 'should bind to insertTable command', () => {
 			const command = editor.commands.get( 'insertTable' );
 
+			command.isEnabled = true;
 			expect( insertTable.isOn ).to.be.false;
 			expect( insertTable.isEnabled ).to.be.true;
 
@@ -75,4 +80,74 @@ describe( 'TableUI', () => {
 			sinon.assert.calledWithExactly( executeSpy, 'insertTable' );
 		} );
 	} );
+
+	describe( 'insertRow button', () => {
+		let insertRow;
+
+		beforeEach( () => {
+			insertRow = editor.ui.componentFactory.create( 'insertRow' );
+		} );
+
+		it( 'should register insertRow buton', () => {
+			expect( insertRow ).to.be.instanceOf( ButtonView );
+			expect( insertRow.isOn ).to.be.false;
+			expect( insertRow.label ).to.equal( 'Insert row' );
+			expect( insertRow.icon ).to.match( /<svg / );
+		} );
+
+		it( 'should bind to insertRow command', () => {
+			const command = editor.commands.get( 'insertRow' );
+
+			command.isEnabled = true;
+			expect( insertRow.isOn ).to.be.false;
+			expect( insertRow.isEnabled ).to.be.true;
+
+			command.isEnabled = false;
+			expect( insertRow.isEnabled ).to.be.false;
+		} );
+
+		it( 'should execute insertRow command on button execute event', () => {
+			const executeSpy = testUtils.sinon.spy( editor, 'execute' );
+
+			insertRow.fire( 'execute' );
+
+			sinon.assert.calledOnce( executeSpy );
+			sinon.assert.calledWithExactly( executeSpy, 'insertRow' );
+		} );
+	} );
+
+	describe( 'insertColumn button', () => {
+		let insertColumn;
+
+		beforeEach( () => {
+			insertColumn = editor.ui.componentFactory.create( 'insertColumn' );
+		} );
+
+		it( 'should register insertColumn buton', () => {
+			expect( insertColumn ).to.be.instanceOf( ButtonView );
+			expect( insertColumn.isOn ).to.be.false;
+			expect( insertColumn.label ).to.equal( 'Insert column' );
+			expect( insertColumn.icon ).to.match( /<svg / );
+		} );
+
+		it( 'should bind to insertColumn command', () => {
+			const command = editor.commands.get( 'insertColumn' );
+
+			command.isEnabled = true;
+			expect( insertColumn.isOn ).to.be.false;
+			expect( insertColumn.isEnabled ).to.be.true;
+
+			command.isEnabled = false;
+			expect( insertColumn.isEnabled ).to.be.false;
+		} );
+
+		it( 'should execute insertColumn command on button execute event', () => {
+			const executeSpy = testUtils.sinon.spy( editor, 'execute' );
+
+			insertColumn.fire( 'execute' );
+
+			sinon.assert.calledOnce( executeSpy );
+			sinon.assert.calledWithExactly( executeSpy, 'insertColumn' );
+		} );
+	} );
 } );