Skip to content

Commit

Permalink
Update tests.
Browse files Browse the repository at this point in the history
Updating the tests to incorporate new changes to BlockMover.
  • Loading branch information
BE-Webdesign committed Jun 10, 2017
1 parent aedc1ea commit e53d83d
Showing 1 changed file with 52 additions and 5 deletions.
57 changes: 52 additions & 5 deletions editor/block-mover/test/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,14 @@ import { BlockMover } from '../';

describe( 'BlockMover', () => {
describe( 'basic rendering', () => {
const selectedUids = [ 'IisUID', 'IisOtherUID' ];

const blockType = {
title: 'yolo-block',
};

it( 'should render two IconButton components with the following props', () => {
const blockMover = shallow( <BlockMover /> );
const blockMover = shallow( <BlockMover uids={ selectedUids } blockType={ blockType } firstIndex={ 0 } /> );
expect( blockMover.hasClass( 'editor-block-mover' ) );

const moveUp = blockMover.childAt( 0 );
Expand All @@ -23,33 +29,68 @@ describe( 'BlockMover', () => {
className: 'editor-block-mover__control',
onClick: undefined,
icon: 'arrow-up-alt2',
label: 'Move 2 blocks from position 1 up by one place',
'aria-disabled': undefined,
} );
expect( moveDown.props() ).to.include( {
className: 'editor-block-mover__control',
onClick: undefined,
icon: 'arrow-down-alt2',
label: 'Move 2 blocks from position 1 down by one place',
'aria-disabled': undefined,
} );
} );

it( 'should set the two IconButton components\' onClick handler to be undefined', () => {
const blockMover = shallow(
<BlockMover uids={ selectedUids }
blockType={ blockType }
firstIndex={ 0 }
isFirst={ false }
isLast={ false } />
);
expect( blockMover.hasClass( 'editor-block-mover' ) );

const moveUp = blockMover.childAt( 0 );
const moveDown = blockMover.childAt( 1 );
// React will currently handle null props as undefined.
expect( moveUp.prop( 'onClick' ) ).to.be.undefined();
expect( moveDown.prop( 'onClick' ) ).to.be.undefined();
} );

it( 'should render the up arrow with a onMoveUp callback', () => {
const onMoveUp = ( event ) => event;
const blockMover = shallow( <BlockMover onMoveUp={ onMoveUp } /> );
const blockMover = shallow(
<BlockMover uids={ selectedUids }
blockType={ blockType }
onMoveUp={ onMoveUp }
firstIndex={ 0 } />
);
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 blockMover = shallow(
<BlockMover uids={ selectedUids }
blockType={ blockType }
onMoveDown={ onMoveDown }
firstIndex={ 0 } />
);
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 blockMover = shallow(
<BlockMover uids={ selectedUids }
blockType={ blockType }
onMoveUp={ onMoveUp }
isFirst
firstIndex={ 0 } />
);
const moveUp = blockMover.childAt( 0 );
expect( moveUp.props() ).to.include( {
onClick: null,
Expand All @@ -59,7 +100,13 @@ describe( 'BlockMover', () => {

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

0 comments on commit e53d83d

Please sign in to comment.