-
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 full coverage for REQUEST_POST_UPDATE_SUCCESS effect. #3820
Add full coverage for REQUEST_POST_UPDATE_SUCCESS effect. #3820
Conversation
editor/test/effects.js
Outdated
it( 'should dispatch meta box updates on success for dirty meta boxes.', () => { | ||
const handler = effects.REQUEST_POST_UPDATE_SUCCESS; | ||
const dispatch = jest.fn(); |
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.
We might have been able to share these variable references, since it appears the only thing we needed to do was ensure that dispatch
calls were reset between tests when asserting call count.
https://facebook.github.io/jest/docs/en/mock-function-api.html#mockfnmockclear
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.
Yeah... I thought I changed this, but I guess I never did will patch now.
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.
Somehow this broke everything.
editor/test/effects.js
Outdated
handler( { post, previousPost }, store ); | ||
|
||
expect( dispatch ).toHaveBeenCalledTimes( 2 ); | ||
expect( dispatch.mock.calls[ 0 ][ 0 ] ).toEqual( { |
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.
Minor: A bit fragile to assume the order in which the notice dispatch is called.
editor/test/effects.js
Outdated
expect( dispatch ).toHaveBeenCalledTimes( 2 ); | ||
expect( dispatch.mock.calls[ 0 ][ 0 ] ).toEqual( { | ||
notice: { | ||
content: <p><span>Post published!</span> <a href={ undefined }>View post</a></p>, // eslint-disable-line jsx-a11y/anchor-is-valid |
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.
Could we just leave off the href
prop altogether, or are you trying to be explicit here?
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.
Trying to be specific, we could use snapshots instead.
editor/test/effects.js
Outdated
content: <p> | ||
<span>Post reverted to draft.</span> | ||
{ ' ' } | ||
{ false && <a href={ post.link }>{ 'View post' }</a> } |
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.
Is this line necessary? Or again trying to be explicit?
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.
Same as above, we could use snapshots instead.
Going to refactor these to be better. |
Adds test cases to fully cover the REQUEST_POST_UPDATE_SUCCESS effect.
70e3eaf
to
e6796f9
Compare
@aduth, let me know if this looks better. |
editor/test/effects.js
Outdated
content: <p> | ||
<span>Post reverted to draft.</span> | ||
{ ' ' } | ||
{ false && <a href={ post.link }>{ 'View post' }</a> } |
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.
I think it's confusing, as it will render false
anyway. Let's remove the link part.
editor/test/effects.js
Outdated
@@ -319,6 +320,118 @@ describe( 'effects', () => { | |||
expect( dispatch ).toHaveBeenCalledTimes( 1 ); | |||
expect( dispatch ).toHaveBeenCalledWith( requestMetaBoxUpdates( [ 'normal', 'side' ] ) ); | |||
} ); | |||
|
|||
it( 'should dispatch notices when reverting a published post to a draft.', () => { |
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.
This test should be named:
should dispatch notices when publishing or scheduling a post
editor/test/effects.js
Outdated
} ) ); | ||
} ); | ||
|
||
it( 'should dispatch notices when publishing or scheduling a post.', () => { |
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.
This test should be named as the previous one is at the moment:
should dispatch notices when reverting a published post to a draft
:)
editor/test/effects.js
Outdated
@@ -281,6 +281,8 @@ describe( 'effects', () => { | |||
} ); | |||
|
|||
describe( '.REQUEST_POST_UPDATE_SUCCESS', () => { | |||
const handler = effects.REQUEST_POST_UPDATE_SUCCESS; | |||
|
|||
beforeAll( () => { | |||
selectors.getDirtyMetaBoxes = jest.spyOn( selectors, 'getDirtyMetaBoxes' ); |
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.
My IDE complains that selectors.getDirtyMetaBoxes
is a constant and shouldn't be overridden.
editor/test/effects.js
Outdated
} ) ); | ||
} ); | ||
|
||
it( 'should dispatch notices when just updating a published post again.', () => { |
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.
Just noting, that we don't use a period at the end of the test name in other places.
editor/test/effects.js
Outdated
expect( dispatch ).toHaveBeenCalledTimes( 2 ); | ||
expect( dispatch ).toHaveBeenCalledWith( expect.objectContaining( { | ||
notice: { | ||
content: <p><span>Post updated!</span>{ ' ' }<a href={ undefined }>{ 'View post' }</a></p>, // eslint-disable-line jsx-a11y/anchor-is-valid |
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.
We can omit href
if it set to undefined.
c8f3116
to
fb96084
Compare
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.
I addressed my own comments. It is ready to merge. Thanks @BE-Webdesign for adding all those tests 👍
Adds test cases to fully cover the REQUEST_POST_UPDATE_SUCCESS effect.
Checklist: