-
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
Add full coverage for REQUEST_POST_UPDATE_SUCCESS effect. #3820
Changes from 2 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 |
---|---|---|
|
@@ -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' ); | ||
window.history.replaceState = jest.spyOn( window.history, 'replaceState' ); | ||
|
@@ -296,11 +298,10 @@ describe( 'effects', () => { | |
window.history.replaceState.mockRestore(); | ||
} ); | ||
|
||
const handler = effects.REQUEST_POST_UPDATE_SUCCESS; | ||
const dispatch = jest.fn(); | ||
const store = { getState: () => {}, dispatch }; | ||
|
||
it( 'should dispatch meta box updates on success for dirty meta boxes.', () => { | ||
const dispatch = jest.fn(); | ||
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. We might have been able to share these variable references, since it appears the only thing we needed to do was ensure that 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 commentThe 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 commentThe reason will be displayed to describe this comment to others. Learn more. Somehow this broke everything. |
||
const store = { getState: () => {}, dispatch }; | ||
|
||
selectors.getDirtyMetaBoxes.mockReturnValue( [ 'normal', 'side' ] ); | ||
|
||
const post = { | ||
|
@@ -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 commentThe reason will be displayed to describe this comment to others. Learn more. This test should be named:
|
||
const dispatch = jest.fn(); | ||
const store = { getState: () => {}, dispatch }; | ||
|
||
selectors.getDirtyMetaBoxes.mockReturnValue( [ 'normal', 'side' ] ); | ||
|
||
const post = { | ||
id: 1, | ||
title: { | ||
raw: 'A History of Pork', | ||
}, | ||
content: { | ||
raw: '', | ||
}, | ||
status: 'publish', | ||
}; | ||
|
||
const previousPost = { | ||
...post, | ||
status: 'draft', | ||
}; | ||
|
||
handler( { post, previousPost }, store ); | ||
|
||
expect( dispatch ).toHaveBeenCalledTimes( 2 ); | ||
expect( dispatch ).toHaveBeenCalledWith( expect.objectContaining( { | ||
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 commentThe reason will be displayed to describe this comment to others. Learn more. Could we just leave off the 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. Trying to be specific, we could use snapshots instead. |
||
id: 'SAVE_POST_NOTICE_ID', | ||
isDismissible: true, | ||
status: 'success', | ||
}, | ||
type: 'CREATE_NOTICE', | ||
} ) ); | ||
} ); | ||
|
||
it( 'should dispatch notices when publishing or scheduling a post.', () => { | ||
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. This test should be named as the previous one is at the moment:
:) |
||
const dispatch = jest.fn(); | ||
const store = { getState: () => {}, dispatch }; | ||
|
||
selectors.getDirtyMetaBoxes.mockReturnValue( [ 'normal', 'side' ] ); | ||
|
||
const post = { | ||
id: 1, | ||
title: { | ||
raw: 'A History of Pork', | ||
}, | ||
content: { | ||
raw: '', | ||
}, | ||
status: 'draft', | ||
}; | ||
|
||
const previousPost = { | ||
...post, | ||
status: 'publish', | ||
}; | ||
|
||
handler( { post, previousPost }, store ); | ||
|
||
expect( dispatch ).toHaveBeenCalledTimes( 2 ); | ||
expect( dispatch ).toHaveBeenCalledWith( expect.objectContaining( { | ||
notice: { | ||
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 commentThe reason will be displayed to describe this comment to others. Learn more. I think it's confusing, as it will render |
||
</p>, | ||
id: 'SAVE_POST_NOTICE_ID', | ||
isDismissible: true, | ||
status: 'success', | ||
}, | ||
type: 'CREATE_NOTICE', | ||
} ) ); | ||
} ); | ||
|
||
it( 'should dispatch notices when just updating a published post again.', () => { | ||
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. Just noting, that we don't use a period at the end of the test name in other places. |
||
const dispatch = jest.fn(); | ||
const store = { getState: () => {}, dispatch }; | ||
|
||
selectors.getDirtyMetaBoxes.mockReturnValue( [ 'normal', 'side' ] ); | ||
|
||
const post = { | ||
id: 1, | ||
title: { | ||
raw: 'A History of Pork', | ||
}, | ||
content: { | ||
raw: '', | ||
}, | ||
status: 'publish', | ||
}; | ||
|
||
const previousPost = { | ||
...post, | ||
status: 'publish', | ||
}; | ||
|
||
handler( { post, previousPost }, store ); | ||
|
||
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 commentThe reason will be displayed to describe this comment to others. Learn more. We can omit |
||
id: 'SAVE_POST_NOTICE_ID', | ||
isDismissible: true, | ||
status: 'success', | ||
}, | ||
type: 'CREATE_NOTICE', | ||
} ) ); | ||
} ); | ||
} ); | ||
|
||
describe( '.SETUP_EDITOR', () => { | ||
|
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.