-
Notifications
You must be signed in to change notification settings - Fork 4.3k
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
Use wp:action-publish
to determine whether to display publish UI
#6724
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -2,67 +2,41 @@ | |
* External dependencies | ||
*/ | ||
import { shallow } from 'enzyme'; | ||
import { merge } from 'lodash'; | ||
|
||
/** | ||
* Internal dependencies | ||
*/ | ||
import { PostPublishButton } from '../'; | ||
|
||
describe( 'PostPublishButton', () => { | ||
const user = { | ||
data: { | ||
id: 1, | ||
post_type_capabilities: { | ||
publish_posts: true, | ||
}, | ||
}, | ||
}; | ||
|
||
const contributor = merge( {}, user, { | ||
data: { | ||
post_type_capabilities: { | ||
publish_posts: false, | ||
}, | ||
}, | ||
} ); | ||
|
||
describe( 'disabled', () => { | ||
it( 'should be disabled if current user is unknown', () => { | ||
const wrapper = shallow( | ||
<PostPublishButton user={ {} } /> | ||
); | ||
|
||
expect( wrapper.prop( 'disabled' ) ).toBe( true ); | ||
} ); | ||
|
||
it( 'should be disabled if post is currently saving', () => { | ||
const wrapper = shallow( | ||
<PostPublishButton user={ user } isSaving /> | ||
<PostPublishButton hasPublishAction={ true } isSaving /> | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
I'm not sure. My concern would be the possibility of showing incorrect UI to the end user. Could you explain your thinking? |
||
); | ||
|
||
expect( wrapper.prop( 'disabled' ) ).toBe( true ); | ||
} ); | ||
|
||
it( 'should be disabled if post is not publishable', () => { | ||
const wrapper = shallow( | ||
<PostPublishButton user={ user } isPublishable={ false } /> | ||
<PostPublishButton hasPublishAction={ true } isPublishable={ false } /> | ||
); | ||
|
||
expect( wrapper.prop( 'disabled' ) ).toBe( true ); | ||
} ); | ||
|
||
it( 'should be disabled if post is not saveable', () => { | ||
const wrapper = shallow( | ||
<PostPublishButton user={ user } isSaveable={ false } /> | ||
<PostPublishButton hasPublishAction={ true } isSaveable={ false } /> | ||
); | ||
|
||
expect( wrapper.prop( 'disabled' ) ).toBe( true ); | ||
} ); | ||
|
||
it( 'should be enabled otherwise', () => { | ||
const wrapper = shallow( | ||
<PostPublishButton user={ user } isPublishable isSaveable /> | ||
<PostPublishButton hasPublishAction={ true } isPublishable isSaveable /> | ||
); | ||
|
||
expect( wrapper.prop( 'disabled' ) ).toBe( false ); | ||
|
@@ -75,7 +49,7 @@ describe( 'PostPublishButton', () => { | |
const onSave = jest.fn(); | ||
const wrapper = shallow( | ||
<PostPublishButton | ||
user={ contributor } | ||
hasPublishAction={ false } | ||
onStatusChange={ onStatusChange } | ||
onSave={ onSave } /> | ||
); | ||
|
@@ -90,7 +64,7 @@ describe( 'PostPublishButton', () => { | |
const onSave = jest.fn(); | ||
const wrapper = shallow( | ||
<PostPublishButton | ||
user={ user } | ||
hasPublishAction={ true } | ||
onStatusChange={ onStatusChange } | ||
onSave={ onSave } | ||
isBeingScheduled /> | ||
|
@@ -106,7 +80,7 @@ describe( 'PostPublishButton', () => { | |
const onSave = jest.fn(); | ||
const wrapper = shallow( | ||
<PostPublishButton | ||
user={ user } | ||
hasPublishAction={ true } | ||
onStatusChange={ onStatusChange } | ||
onSave={ onSave } | ||
visibility="private" /> | ||
|
@@ -122,7 +96,7 @@ describe( 'PostPublishButton', () => { | |
const onSave = jest.fn(); | ||
const wrapper = shallow( | ||
<PostPublishButton | ||
user={ user } | ||
hasPublishAction={ true } | ||
onStatusChange={ onStatusChange } | ||
onSave={ onSave } /> | ||
); | ||
|
@@ -139,7 +113,7 @@ describe( 'PostPublishButton', () => { | |
const onSave = jest.fn(); | ||
const wrapper = shallow( | ||
<PostPublishButton | ||
user={ user } | ||
hasPublishAction={ true } | ||
onStatusChange={ onStatusChange } | ||
onSave={ onSave } /> | ||
); | ||
|
@@ -153,7 +127,7 @@ describe( 'PostPublishButton', () => { | |
|
||
it( 'should have save modifier class', () => { | ||
const wrapper = shallow( | ||
<PostPublishButton user={ user } isSaving /> | ||
<PostPublishButton hasPublishAction={ true } isSaving /> | ||
); | ||
|
||
expect( wrapper.hasClass( 'is-saving' ) ).toBe( true ); | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,73 +1,46 @@ | ||
/** | ||
* External dependencies | ||
*/ | ||
import { merge } from 'lodash'; | ||
|
||
/** | ||
* Internal dependencies | ||
*/ | ||
import { PublishButtonLabel } from '../label'; | ||
|
||
describe( 'PublishButtonLabel', () => { | ||
const user = { | ||
data: { | ||
id: 1, | ||
post_type_capabilities: { | ||
publish_posts: true, | ||
}, | ||
}, | ||
}; | ||
|
||
const contributor = merge( {}, user, { | ||
data: { | ||
post_type_capabilities: { | ||
publish_posts: false, | ||
}, | ||
}, | ||
} ); | ||
|
||
it( 'should show publishing if publishing in progress', () => { | ||
const label = PublishButtonLabel( { user, isPublishing: true } ); | ||
const label = PublishButtonLabel( { hasPublishAction: true, isPublishing: true } ); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The same question applies, should |
||
expect( label ).toBe( 'Publishing…' ); | ||
} ); | ||
|
||
it( 'should show updating if published and saving in progress', () => { | ||
const label = PublishButtonLabel( { user, isPublished: true, isSaving: true } ); | ||
const label = PublishButtonLabel( { hasPublishAction: true, isPublished: true, isSaving: true } ); | ||
expect( label ).toBe( 'Updating…' ); | ||
} ); | ||
|
||
it( 'should show scheduling if scheduled and saving in progress', () => { | ||
const label = PublishButtonLabel( { user, isBeingScheduled: true, isSaving: true } ); | ||
const label = PublishButtonLabel( { hasPublishAction: true, isBeingScheduled: true, isSaving: true } ); | ||
expect( label ).toBe( 'Scheduling…' ); | ||
} ); | ||
|
||
it( 'should show publish if not published and saving in progress', () => { | ||
const label = PublishButtonLabel( { user, isPublished: false, isSaving: true } ); | ||
expect( label ).toBe( 'Publish' ); | ||
} ); | ||
|
||
it( 'should show publish if user unknown', () => { | ||
const label = PublishButtonLabel( { user: {} } ); | ||
const label = PublishButtonLabel( { hasPublishAction: true, isPublished: false, isSaving: true } ); | ||
expect( label ).toBe( 'Publish' ); | ||
} ); | ||
|
||
it( 'should show submit for review for contributor', () => { | ||
const label = PublishButtonLabel( { user: contributor } ); | ||
const label = PublishButtonLabel( { hasPublishAction: false } ); | ||
expect( label ).toBe( 'Submit for Review' ); | ||
} ); | ||
|
||
it( 'should show update for already published', () => { | ||
const label = PublishButtonLabel( { user, isPublished: true } ); | ||
const label = PublishButtonLabel( { hasPublishAction: true, isPublished: true } ); | ||
expect( label ).toBe( 'Update' ); | ||
} ); | ||
|
||
it( 'should show schedule for scheduled', () => { | ||
const label = PublishButtonLabel( { user, isBeingScheduled: true } ); | ||
const label = PublishButtonLabel( { hasPublishAction: true, isBeingScheduled: true } ); | ||
expect( label ).toBe( 'Schedule' ); | ||
} ); | ||
|
||
it( 'should show publish otherwise', () => { | ||
const label = PublishButtonLabel( { user } ); | ||
const label = PublishButtonLabel( { hasPublishAction: true } ); | ||
expect( label ).toBe( 'Publish' ); | ||
} ); | ||
} ); |
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 introduce a new selector which would hide all those implementation details?
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.
See #6655