8
0
Просмотр исходного кода

Changed: Move splitCell dropdown items to mergeCell dropdown.

Maciej Gołaszewski 7 лет назад
Родитель
Сommit
c4f7e396ba
2 измененных файлов с 19 добавлено и 76 удалено
  1. 2 10
      packages/ckeditor5-table/src/tableui.js
  2. 17 66
      packages/ckeditor5-table/tests/tableui.js

+ 2 - 10
packages/ckeditor5-table/src/tableui.js

@@ -18,7 +18,6 @@ import tableIcon from './../theme/icons/table.svg';
 import tableColumnIcon from './../theme/icons/table-column.svg';
 import tableRowIcon from './../theme/icons/table-row.svg';
 import tableMergeCellIcon from './../theme/icons/table-merge-cell.svg';
-import tableSplitCellIcon from './../theme/icons/table-split-cell.svg';
 
 /**
  * The table UI plugin.
@@ -92,19 +91,12 @@ export default class TableUI extends Plugin {
 				{ commandName: 'mergeCellUp', label: 'Merge cell up' },
 				{ commandName: 'mergeCellRight', label: 'Merge cell right' },
 				{ commandName: 'mergeCellDown', label: 'Merge cell down' },
-				{ commandName: 'mergeCellLeft', label: 'Merge cell left' }
-			];
-
-			return this._prepareDropdown( 'Merge cell', tableMergeCellIcon, options, locale );
-		} );
-
-		editor.ui.componentFactory.add( 'splitCell', locale => {
-			const options = [
+				{ commandName: 'mergeCellLeft', label: 'Merge cell left' },
 				{ commandName: 'splitCellVertically', label: 'Split cell vertically' },
 				{ commandName: 'splitCellHorizontally', label: 'Split cell horizontally' }
 			];
 
-			return this._prepareDropdown( 'Split cell', tableSplitCellIcon, options, locale );
+			return this._prepareDropdown( 'Merge cell', tableMergeCellIcon, options, locale );
 		} );
 	}
 

+ 17 - 66
packages/ckeditor5-table/tests/tableui.js

@@ -311,7 +311,14 @@ describe( 'TableUI', () => {
 
 			const labels = listView.items.map( ( { label } ) => label );
 
-			expect( labels ).to.deep.equal( [ 'Merge cell up', 'Merge cell right', 'Merge cell down', 'Merge cell left' ] );
+			expect( labels ).to.deep.equal( [
+				'Merge cell up',
+				'Merge cell right',
+				'Merge cell down',
+				'Merge cell left',
+				'Split cell vertically',
+				'Split cell horizontally'
+			] );
 		} );
 
 		it( 'should bind items in panel to proper commands', () => {
@@ -321,16 +328,22 @@ describe( 'TableUI', () => {
 			const mergeCellRightCommand = editor.commands.get( 'mergeCellRight' );
 			const mergeCellDownCommand = editor.commands.get( 'mergeCellDown' );
 			const mergeCellLeftCommand = editor.commands.get( 'mergeCellLeft' );
+			const splitCellVerticallyCommand = editor.commands.get( 'splitCellVertically' );
+			const splitCellHorizontallyCommand = editor.commands.get( 'splitCellHorizontally' );
 
 			mergeCellUpCommand.isEnabled = true;
 			mergeCellRightCommand.isEnabled = true;
 			mergeCellDownCommand.isEnabled = true;
 			mergeCellLeftCommand.isEnabled = true;
+			splitCellVerticallyCommand.isEnabled = true;
+			splitCellHorizontallyCommand.isEnabled = true;
 
 			expect( items.get( 0 ).isEnabled ).to.be.true;
 			expect( items.get( 1 ).isEnabled ).to.be.true;
 			expect( items.get( 2 ).isEnabled ).to.be.true;
 			expect( items.get( 3 ).isEnabled ).to.be.true;
+			expect( items.get( 4 ).isEnabled ).to.be.true;
+			expect( items.get( 5 ).isEnabled ).to.be.true;
 			expect( dropdown.buttonView.isEnabled ).to.be.true;
 
 			mergeCellUpCommand.isEnabled = false;
@@ -349,74 +362,12 @@ describe( 'TableUI', () => {
 			mergeCellLeftCommand.isEnabled = false;
 			expect( items.get( 3 ).isEnabled ).to.be.false;
 
-			expect( dropdown.buttonView.isEnabled ).to.be.false;
-		} );
-
-		it( 'should focus view after command execution', () => {
-			const focusSpy = testUtils.sinon.spy( editor.editing.view, 'focus' );
-
-			dropdown.listView.items.get( 0 ).fire( 'execute' );
-
-			sinon.assert.calledOnce( focusSpy );
-		} );
-
-		it( 'executes command when it\'s executed', () => {
-			const spy = sinon.stub( editor, 'execute' );
-
-			dropdown.listView.items.get( 0 ).fire( 'execute' );
-
-			expect( spy.calledOnce ).to.be.true;
-			expect( spy.args[ 0 ][ 0 ] ).to.equal( 'mergeCellUp' );
-		} );
-	} );
-
-	describe( 'splitCell dropdown', () => {
-		let dropdown;
-
-		beforeEach( () => {
-			dropdown = editor.ui.componentFactory.create( 'splitCell' );
-		} );
-
-		it( 'have button with proper properties set', () => {
-			expect( dropdown ).to.be.instanceOf( DropdownView );
-
-			const button = dropdown.buttonView;
-
-			expect( button.isOn ).to.be.false;
-			expect( button.tooltip ).to.be.true;
-			expect( button.label ).to.equal( 'Split cell' );
-			expect( button.icon ).to.match( /<svg / );
-		} );
-
-		it( 'should have proper items in panel', () => {
-			const listView = dropdown.listView;
-
-			const labels = listView.items.map( ( { label } ) => label );
-
-			expect( labels ).to.deep.equal( [ 'Split cell vertically', 'Split cell horizontally' ] );
-		} );
-
-		it( 'should bind items in panel to proper commands', () => {
-			const items = dropdown.listView.items;
-
-			const splitCellVerticallyCommand = editor.commands.get( 'splitCellVertically' );
-			const splitCellHorizontallyCommand = editor.commands.get( 'splitCellHorizontally' );
-
-			splitCellVerticallyCommand.isEnabled = true;
-			splitCellHorizontallyCommand.isEnabled = true;
-
-			expect( items.get( 0 ).isEnabled ).to.be.true;
-			expect( items.get( 1 ).isEnabled ).to.be.true;
-			expect( dropdown.buttonView.isEnabled ).to.be.true;
-
 			splitCellVerticallyCommand.isEnabled = false;
-
-			expect( items.get( 0 ).isEnabled ).to.be.false;
-			expect( dropdown.buttonView.isEnabled ).to.be.true;
+			expect( items.get( 4 ).isEnabled ).to.be.false;
 
 			splitCellHorizontallyCommand.isEnabled = false;
+			expect( items.get( 5 ).isEnabled ).to.be.false;
 
-			expect( items.get( 1 ).isEnabled ).to.be.false;
 			expect( dropdown.buttonView.isEnabled ).to.be.false;
 		} );
 
@@ -434,7 +385,7 @@ describe( 'TableUI', () => {
 			dropdown.listView.items.get( 0 ).fire( 'execute' );
 
 			expect( spy.calledOnce ).to.be.true;
-			expect( spy.args[ 0 ][ 0 ] ).to.equal( 'splitCellVertically' );
+			expect( spy.args[ 0 ][ 0 ] ).to.equal( 'mergeCellUp' );
 		} );
 	} );
 } );