Skip to content

Commit

Permalink
Add tests for the BlockMover Component.
Browse files Browse the repository at this point in the history
Adds tests for the BlockMover Component.  Related to progress on #641.
The tests ensure that the callbacks render properly depending on whether
the block isFirst or isLast.
  • Loading branch information
BE-Webdesign committed Jun 10, 2017
1 parent 428957a commit aedc1ea
Show file tree
Hide file tree
Showing 2 changed files with 71 additions and 1 deletion.
2 changes: 1 addition & 1 deletion editor/block-mover/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ import './style.scss';
import { isFirstBlock, isLastBlock, getBlockIndex, getBlock } from '../selectors';
import { getBlockMoverLabel } from './mover-label';

function BlockMover( { onMoveUp, onMoveDown, isFirst, isLast, uids, blockType, firstIndex } ) {
export function BlockMover( { onMoveUp, onMoveDown, isFirst, isLast, uids, blockType, firstIndex } ) {
// We emulate a disabled state because forcefully applying the `disabled`
// attribute on the button while it has focus causes the screen to change
// to an unfocused state (body as active element) without firing blur on,
Expand Down
70 changes: 70 additions & 0 deletions editor/block-mover/test/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,70 @@
/**
* External dependencies
*/
import { expect } from 'chai';
import { shallow } from 'enzyme';

/**
* Internal dependencies
*/
import { BlockMover } from '../';

describe( 'BlockMover', () => {
describe( 'basic rendering', () => {
it( 'should render two IconButton components with the following props', () => {
const blockMover = shallow( <BlockMover /> );
expect( blockMover.hasClass( 'editor-block-mover' ) );

const moveUp = blockMover.childAt( 0 );
const moveDown = blockMover.childAt( 1 );
expect( moveUp.type().name ).to.equal( 'IconButton' );
expect( moveDown.type().name ).to.equal( 'IconButton' );
expect( moveUp.props() ).to.include( {
className: 'editor-block-mover__control',
onClick: undefined,
icon: 'arrow-up-alt2',
'aria-disabled': undefined,
} );
expect( moveDown.props() ).to.include( {
className: 'editor-block-mover__control',
onClick: undefined,
icon: 'arrow-down-alt2',
'aria-disabled': undefined,
} );
} );

it( 'should render the up arrow with a onMoveUp callback', () => {
const onMoveUp = ( event ) => event;
const blockMover = shallow( <BlockMover onMoveUp={ onMoveUp } /> );
const moveUp = blockMover.childAt( 0 );
expect( moveUp.prop( 'onClick' ) ).to.equal( onMoveUp );
} );

it( 'should render the down arrow with a onMoveDown callback', () => {
const onMoveDown = ( event ) => event;
const blockMover = shallow( <BlockMover onMoveDown={ onMoveDown } /> );
const moveDown = blockMover.childAt( 1 );
expect( moveDown.prop( 'onClick' ) ).to.equal( onMoveDown );
} );

it( 'should render with a disabled up arrown when the block isFirst', () => {
const onMoveUp = ( event ) => event;
const blockMover = shallow( <BlockMover onMoveUp={ onMoveUp } isFirst /> );
const moveUp = blockMover.childAt( 0 );
expect( moveUp.props() ).to.include( {
onClick: null,
'aria-disabled': true,
} );
} );

it( 'should render with a disabled down arrow when the block isLast', () => {
const onMoveDown = ( event ) => event;
const blockMover = shallow( <BlockMover onMoveDown={ onMoveDown } isLast /> );
const moveDown = blockMover.childAt( 1 );
expect( moveDown.props() ).to.include( {
onClick: null,
'aria-disabled': true,
} );
} );
} );
} );

0 comments on commit aedc1ea

Please sign in to comment.