-
Notifications
You must be signed in to change notification settings - Fork 4.2k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add tests for the BlockMover Component. #980
Merged
Merged
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,99 @@ | ||
/** | ||
* External dependencies | ||
*/ | ||
import { shallow } from 'enzyme'; | ||
|
||
/** | ||
* Internal dependencies | ||
*/ | ||
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 uids={ selectedUids } blockType={ blockType } firstIndex={ 0 } /> ); | ||
expect( blockMover.hasClass( 'editor-block-mover' ) ).toBe( true ); | ||
|
||
const moveUp = blockMover.childAt( 0 ); | ||
const moveDown = blockMover.childAt( 1 ); | ||
expect( moveUp.type().name ).toBe( 'IconButton' ); | ||
expect( moveDown.type().name ).toBe( 'IconButton' ); | ||
expect( moveUp.props() ).toMatchObject( { | ||
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() ).toMatchObject( { | ||
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 render the up arrow with a onMoveUp callback', () => { | ||
const onMoveUp = ( event ) => event; | ||
const blockMover = shallow( | ||
<BlockMover uids={ selectedUids } | ||
blockType={ blockType } | ||
onMoveUp={ onMoveUp } | ||
firstIndex={ 0 } /> | ||
); | ||
const moveUp = blockMover.childAt( 0 ); | ||
expect( moveUp.prop( 'onClick' ) ).toBe( onMoveUp ); | ||
} ); | ||
|
||
it( 'should render the down arrow with a onMoveDown callback', () => { | ||
const onMoveDown = ( event ) => event; | ||
const blockMover = shallow( | ||
<BlockMover uids={ selectedUids } | ||
blockType={ blockType } | ||
onMoveDown={ onMoveDown } | ||
firstIndex={ 0 } /> | ||
); | ||
const moveDown = blockMover.childAt( 1 ); | ||
expect( moveDown.prop( 'onClick' ) ).toBe( onMoveDown ); | ||
} ); | ||
|
||
it( 'should render with a disabled up arrown when the block isFirst', () => { | ||
const onMoveUp = ( event ) => event; | ||
const blockMover = shallow( | ||
<BlockMover uids={ selectedUids } | ||
blockType={ blockType } | ||
onMoveUp={ onMoveUp } | ||
isFirst | ||
firstIndex={ 0 } /> | ||
); | ||
const moveUp = blockMover.childAt( 0 ); | ||
expect( moveUp.props() ).toMatchObject( { | ||
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 uids={ selectedUids } | ||
blockType={ blockType } | ||
onMoveDown={ onMoveDown } | ||
isLast | ||
firstIndex={ 0 } /> | ||
); | ||
const moveDown = blockMover.childAt( 1 ); | ||
expect( moveDown.props() ).toMatchObject( { | ||
onClick: null, | ||
'aria-disabled': true, | ||
} ); | ||
} ); | ||
} ); | ||
} ); |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Should we do any
click
simulations with a Sinon spy?https://github.com/airbnb/enzyme/blob/master/docs/api/ShallowWrapper/simulate.md
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Probably wouldn't hurt.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
With the Mocha to Jest migration it would require using jest.fn() instead to achieve similar result.