-
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.
Fix schedule and then publish flow (#11013)
* Use props instead of derived state to render the component. There was a bug that happened when: - a post was scheduled for a future date from now - then the data changed to a past date from now At this point, the post couldn't be published directly by clicking the "Publish" button. This component would show the post-publish panel with a "Post scheduled" status. * Test: check that pre-publish panel is shown * Test: check that post-publish panel is shown if post is published * Test: check that post-publish panel is shown if post is scheduled * Test: isScheduled is true, but isBeingScheduled false Although the post status is 'future', the data is before now, so we should show the pre-publish panel with the Publish button. * Fix isSaving logic * Update snapshots * Test: check that spinner is shown if post is being saved * Remove unused prop * Name spinner component so snapshot test is more semantic * Fix typo * Update snapshot
- Loading branch information
Showing
4 changed files
with
281 additions
and
42 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1,3 @@ | ||
export default () => <span className="components-spinner" />; | ||
export default function Spinner() { | ||
return <span className="components-spinner" />; | ||
} |
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
184 changes: 184 additions & 0 deletions
184
packages/editor/src/components/post-publish-panel/test/__snapshots__/index.js.snap
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,184 @@ | ||
// Jest Snapshot v1, https://goo.gl/fbAQLP | ||
|
||
exports[`PostPublishPanel should render the post-publish panel if the post is published 1`] = ` | ||
<div | ||
className="editor-post-publish-panel" | ||
> | ||
<div | ||
className="editor-post-publish-panel__header" | ||
> | ||
<div | ||
className="editor-post-publish-panel__header-published" | ||
> | ||
Published | ||
</div> | ||
<IconButton | ||
aria-expanded={true} | ||
icon="no-alt" | ||
label="Close panel" | ||
/> | ||
</div> | ||
<div | ||
className="editor-post-publish-panel__content" | ||
> | ||
<WithSelect(PostPublishPanelPostpublish) /> | ||
</div> | ||
<div | ||
className="editor-post-publish-panel__footer" | ||
> | ||
<WithInstanceId(CheckboxControl) | ||
label="Always show pre-publish checks." | ||
/> | ||
</div> | ||
</div> | ||
`; | ||
|
||
exports[`PostPublishPanel should render the post-publish panel if the post is scheduled 1`] = ` | ||
<div | ||
className="editor-post-publish-panel" | ||
> | ||
<div | ||
className="editor-post-publish-panel__header" | ||
> | ||
<div | ||
className="editor-post-publish-panel__header-published" | ||
> | ||
Scheduled | ||
</div> | ||
<IconButton | ||
aria-expanded={true} | ||
icon="no-alt" | ||
label="Close panel" | ||
/> | ||
</div> | ||
<div | ||
className="editor-post-publish-panel__content" | ||
> | ||
<WithSelect(PostPublishPanelPostpublish) /> | ||
</div> | ||
<div | ||
className="editor-post-publish-panel__footer" | ||
> | ||
<WithInstanceId(CheckboxControl) | ||
label="Always show pre-publish checks." | ||
/> | ||
</div> | ||
</div> | ||
`; | ||
|
||
exports[`PostPublishPanel should render the pre-publish panel if post status is scheduled but date is before now 1`] = ` | ||
<div | ||
className="editor-post-publish-panel" | ||
> | ||
<div | ||
className="editor-post-publish-panel__header" | ||
> | ||
<div | ||
className="editor-post-publish-panel__header-publish-button" | ||
> | ||
<WithSelect(WithDispatch(PostPublishButton)) | ||
focusOnMount={true} | ||
onSubmit={[Function]} | ||
/> | ||
<span | ||
className="editor-post-publish-panel__spacer" | ||
/> | ||
</div> | ||
<IconButton | ||
aria-expanded={true} | ||
icon="no-alt" | ||
label="Close panel" | ||
/> | ||
</div> | ||
<div | ||
className="editor-post-publish-panel__content" | ||
> | ||
<WithSelect(PostPublishPanelPrepublish) /> | ||
</div> | ||
<div | ||
className="editor-post-publish-panel__footer" | ||
> | ||
<WithInstanceId(CheckboxControl) | ||
label="Always show pre-publish checks." | ||
/> | ||
</div> | ||
</div> | ||
`; | ||
|
||
exports[`PostPublishPanel should render the pre-publish panel if the post is not saving, published or scheduled 1`] = ` | ||
<div | ||
className="editor-post-publish-panel" | ||
> | ||
<div | ||
className="editor-post-publish-panel__header" | ||
> | ||
<div | ||
className="editor-post-publish-panel__header-publish-button" | ||
> | ||
<WithSelect(WithDispatch(PostPublishButton)) | ||
focusOnMount={true} | ||
onSubmit={[Function]} | ||
/> | ||
<span | ||
className="editor-post-publish-panel__spacer" | ||
/> | ||
</div> | ||
<IconButton | ||
aria-expanded={true} | ||
icon="no-alt" | ||
label="Close panel" | ||
/> | ||
</div> | ||
<div | ||
className="editor-post-publish-panel__content" | ||
> | ||
<WithSelect(PostPublishPanelPrepublish) /> | ||
</div> | ||
<div | ||
className="editor-post-publish-panel__footer" | ||
> | ||
<WithInstanceId(CheckboxControl) | ||
label="Always show pre-publish checks." | ||
/> | ||
</div> | ||
</div> | ||
`; | ||
|
||
exports[`PostPublishPanel should render the spinner if the post is being saved 1`] = ` | ||
<div | ||
className="editor-post-publish-panel" | ||
> | ||
<div | ||
className="editor-post-publish-panel__header" | ||
> | ||
<div | ||
className="editor-post-publish-panel__header-publish-button" | ||
> | ||
<WithSelect(WithDispatch(PostPublishButton)) | ||
focusOnMount={true} | ||
onSubmit={[Function]} | ||
/> | ||
<span | ||
className="editor-post-publish-panel__spacer" | ||
/> | ||
</div> | ||
<IconButton | ||
aria-expanded={true} | ||
icon="no-alt" | ||
label="Close panel" | ||
/> | ||
</div> | ||
<div | ||
className="editor-post-publish-panel__content" | ||
> | ||
<Spinner /> | ||
</div> | ||
<div | ||
className="editor-post-publish-panel__footer" | ||
> | ||
<WithInstanceId(CheckboxControl) | ||
label="Always show pre-publish checks." | ||
/> | ||
</div> | ||
</div> | ||
`; |
61 changes: 61 additions & 0 deletions
61
packages/editor/src/components/post-publish-panel/test/index.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 |
---|---|---|
@@ -0,0 +1,61 @@ | ||
/** | ||
* External dependencies | ||
*/ | ||
import { shallow } from 'enzyme'; | ||
|
||
/** | ||
* Internal dependencies | ||
*/ | ||
import { PostPublishPanel } from '../index'; | ||
|
||
describe( 'PostPublishPanel', () => { | ||
it( 'should render the pre-publish panel if the post is not saving, published or scheduled', () => { | ||
const wrapper = shallow( | ||
<PostPublishPanel | ||
isPublished={ false } | ||
isScheduled={ false } | ||
isSaving={ false } | ||
/> | ||
); | ||
expect( wrapper ).toMatchSnapshot(); | ||
} ); | ||
|
||
it( 'should render the pre-publish panel if post status is scheduled but date is before now', () => { | ||
const wrapper = shallow( | ||
<PostPublishPanel | ||
isScheduled={ true } | ||
isBeingScheduled={ false } | ||
/> | ||
); | ||
|
||
expect( wrapper ).toMatchSnapshot(); | ||
} ); | ||
|
||
it( 'should render the spinner if the post is being saved', () => { | ||
const wrapper = shallow( | ||
<PostPublishPanel | ||
isSaving={ true } | ||
/> | ||
); | ||
expect( wrapper ).toMatchSnapshot(); | ||
} ); | ||
|
||
it( 'should render the post-publish panel if the post is published', () => { | ||
const wrapper = shallow( | ||
<PostPublishPanel | ||
isPublished={ true } | ||
/> | ||
); | ||
expect( wrapper ).toMatchSnapshot(); | ||
} ); | ||
|
||
it( 'should render the post-publish panel if the post is scheduled', () => { | ||
const wrapper = shallow( | ||
<PostPublishPanel | ||
isScheduled={ true } | ||
isBeingScheduled={ true } | ||
/> | ||
); | ||
expect( wrapper ).toMatchSnapshot(); | ||
} ); | ||
} ); |