Skip to content
This repository has been archived by the owner on Jun 26, 2020. It is now read-only.

Commit

Permalink
Changed: Move splitCell dropdown items to mergeCell dropdown.
Browse files Browse the repository at this point in the history
  • Loading branch information
jodator committed May 29, 2018
1 parent 8c312d4 commit 57c7d92
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 76 deletions.
12 changes: 2 additions & 10 deletions src/tableui.js
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down Expand Up @@ -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 );
} );
}

Expand Down
83 changes: 17 additions & 66 deletions tests/tableui.js
Original file line number Diff line number Diff line change
Expand Up @@ -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', () => {
Expand All @@ -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;
Expand All @@ -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;
} );

Expand All @@ -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' );
} );
} );
} );

0 comments on commit 57c7d92

Please sign in to comment.