-
Notifications
You must be signed in to change notification settings - Fork 4.2k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
e4e3151
commit e0c2b79
Showing
4 changed files
with
163 additions
and
66 deletions.
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
67 changes: 50 additions & 17 deletions
67
packages/editor/src/components/post-last-revision/test/check.js
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 |
---|---|---|
@@ -1,41 +1,74 @@ | ||
/** | ||
* External dependencies | ||
*/ | ||
import { shallow } from 'enzyme'; | ||
import { create } from 'react-test-renderer'; | ||
|
||
/** | ||
* WordPress dependencies | ||
*/ | ||
import { createRegistry, RegistryProvider } from '@wordpress/data'; | ||
|
||
/** | ||
* Internal dependencies | ||
*/ | ||
import { PostLastRevisionCheck } from '../check'; | ||
import PostLastRevisionCheck from '../check'; | ||
|
||
function createMockRegistry( | ||
currentPostLastRevisionId, | ||
currentPostRevisionsCount | ||
) { | ||
return createRegistry( { | ||
'core/editor': { | ||
selectors: { | ||
getCurrentPostLastRevisionId: () => currentPostLastRevisionId, | ||
getCurrentPostRevisionsCount: () => currentPostRevisionsCount, | ||
getEditedPostAttribute: () => 'post', | ||
}, | ||
reducer: ( state = {} ) => state, | ||
}, | ||
core: { | ||
selectors: { | ||
getPostType: () => ( { supports: { revisions: true } } ), | ||
}, | ||
reducer: ( state = {} ) => state, | ||
}, | ||
} ); | ||
} | ||
|
||
describe( 'PostLastRevisionCheck', () => { | ||
it( 'should not render anything if the last revision ID is unknown', () => { | ||
const wrapper = shallow( | ||
<PostLastRevisionCheck revisionsCount={ 2 }> | ||
Children | ||
</PostLastRevisionCheck> | ||
const registry = createMockRegistry( undefined, 2 ); | ||
|
||
const tree = create( | ||
<RegistryProvider value={ registry }> | ||
<PostLastRevisionCheck>Children</PostLastRevisionCheck> | ||
</RegistryProvider> | ||
); | ||
|
||
expect( wrapper.type() ).toBe( null ); | ||
expect( tree.toJSON() ).toBe( null ); | ||
} ); | ||
|
||
it( 'should not render anything if there is only one revision', () => { | ||
const wrapper = shallow( | ||
<PostLastRevisionCheck lastRevisionId={ 1 } revisionsCount={ 1 }> | ||
Children | ||
</PostLastRevisionCheck> | ||
const registry = createMockRegistry( 1, 1 ); | ||
|
||
const tree = create( | ||
<RegistryProvider value={ registry }> | ||
<PostLastRevisionCheck>Children</PostLastRevisionCheck> | ||
</RegistryProvider> | ||
); | ||
|
||
expect( wrapper.type() ).toBe( null ); | ||
expect( tree.toJSON() ).toBe( null ); | ||
} ); | ||
|
||
it( 'should render if there are two revisions', () => { | ||
const wrapper = shallow( | ||
<PostLastRevisionCheck lastRevisionId={ 1 } revisionsCount={ 2 }> | ||
Children | ||
</PostLastRevisionCheck> | ||
const registry = createMockRegistry( 1, 2 ); | ||
|
||
const tree = create( | ||
<RegistryProvider value={ registry }> | ||
<PostLastRevisionCheck>Children</PostLastRevisionCheck> | ||
</RegistryProvider> | ||
); | ||
|
||
expect( wrapper.text() ).not.toBe( null ); | ||
expect( tree.toJSON() ).toBe( 'Children' ); | ||
} ); | ||
} ); |
61 changes: 47 additions & 14 deletions
61
packages/editor/src/components/post-pending-status/test/check.js
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 |
---|---|---|
@@ -1,29 +1,62 @@ | ||
/** | ||
* External dependencies | ||
*/ | ||
import { shallow } from 'enzyme'; | ||
import { create } from 'react-test-renderer'; | ||
|
||
/** | ||
* WordPress dependencies | ||
*/ | ||
import { createRegistry, RegistryProvider } from '@wordpress/data'; | ||
|
||
/** | ||
* Internal dependencies | ||
*/ | ||
import { PostPendingStatusCheck } from '../check'; | ||
import PostPendingStatusCheck from '../check'; | ||
|
||
function createMockRegistry( isCurrentPostPublished, currentPost ) { | ||
return createRegistry( { | ||
'core/editor': { | ||
selectors: { | ||
isCurrentPostPublished: () => isCurrentPostPublished, | ||
getCurrentPost: () => currentPost, | ||
}, | ||
reducer: ( state = {} ) => state, | ||
}, | ||
} ); | ||
} | ||
|
||
describe( 'PostPendingStatusCheck', () => { | ||
it( "should not render anything if the user doesn't have the right capabilities", () => { | ||
const wrapper = shallow( | ||
<PostPendingStatusCheck hasPublishAction={ false }> | ||
status | ||
</PostPendingStatusCheck> | ||
it( 'should not render anything if the post is published', () => { | ||
const registry = createMockRegistry( true, null ); | ||
const tree = create( | ||
<RegistryProvider value={ registry }> | ||
<PostPendingStatusCheck>status</PostPendingStatusCheck> | ||
</RegistryProvider> | ||
); | ||
expect( tree.toJSON() ).toBe( null ); | ||
} ); | ||
|
||
it( 'should not render anything if the post has no publish action', () => { | ||
const registry = createMockRegistry( false, { | ||
_links: {}, | ||
} ); | ||
const tree = create( | ||
<RegistryProvider value={ registry }> | ||
<PostPendingStatusCheck>status</PostPendingStatusCheck> | ||
</RegistryProvider> | ||
); | ||
expect( wrapper.type() ).toBe( null ); | ||
expect( tree.toJSON() ).toBe( null ); | ||
} ); | ||
|
||
it( 'should render if the user has the correct capability', () => { | ||
const wrapper = shallow( | ||
<PostPendingStatusCheck hasPublishAction={ true }> | ||
status | ||
</PostPendingStatusCheck> | ||
it( 'should render if the post has a publish action', () => { | ||
const registry = createMockRegistry( false, { | ||
_links: { 'wp:action-publish': 'https://' }, | ||
} ); | ||
const tree = create( | ||
<RegistryProvider value={ registry }> | ||
<PostPendingStatusCheck>status</PostPendingStatusCheck> | ||
</RegistryProvider> | ||
); | ||
expect( wrapper.type() ).not.toBe( null ); | ||
expect( tree.toJSON() ).toBe( 'status' ); | ||
} ); | ||
} ); |
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