Skip to content

Commit

Permalink
Merge pull request #3821 from WordPress/add/test/editor/effects/reque…
Browse files Browse the repository at this point in the history
…st-post-update-failure

Add test cases for REQUEST_POST_UPDATE_FAILURE effect
  • Loading branch information
gziolo committed Mar 8, 2018
2 parents 107b0a7 + 9fcb64e commit f56fb20
Showing 1 changed file with 59 additions and 2 deletions.
61 changes: 59 additions & 2 deletions editor/store/test/effects.js
Expand Up @@ -31,12 +31,13 @@ import {
convertBlockToReusable,
selectBlock,
removeBlock,
} from '../../store/actions';
createErrorNotice,
} from '../actions';
import reducer from '../reducer';
import effects, {
removeProvisionalBlock,
} from '../effects';
import * as selectors from '../../store/selectors';
import * as selectors from '../selectors';

// Make all generated UUIDs the same for testing
jest.mock( 'uuid/v4', () => {
Expand Down Expand Up @@ -438,6 +439,62 @@ describe( 'effects', () => {
} );
} );

describe( '.REQUEST_POST_UPDATE_FAILURE', () => {
it( 'should dispatch a notice on failure when publishing a draft fails.', () => {
const handler = effects.REQUEST_POST_UPDATE_FAILURE;
const dispatch = jest.fn();
const store = { getState: () => {}, dispatch };

const action = {
post: {
id: 1,
title: {
raw: 'A History of Pork',
},
content: {
raw: '',
},
status: 'draft',
},
edits: {
status: 'publish',
},
};

handler( action, store );

expect( dispatch ).toHaveBeenCalledTimes( 1 );
expect( dispatch ).toHaveBeenCalledWith( createErrorNotice( 'Publishing failed', { id: 'SAVE_POST_NOTICE_ID' } ) );
} );

it( 'should dispatch a notice on failure when trying to update a draft.', () => {
const handler = effects.REQUEST_POST_UPDATE_FAILURE;
const dispatch = jest.fn();
const store = { getState: () => {}, dispatch };

const action = {
post: {
id: 1,
title: {
raw: 'A History of Pork',
},
content: {
raw: '',
},
status: 'draft',
},
edits: {
status: 'draft',
},
};

handler( action, store );

expect( dispatch ).toHaveBeenCalledTimes( 1 );
expect( dispatch ).toHaveBeenCalledWith( createErrorNotice( 'Updating failed', { id: 'SAVE_POST_NOTICE_ID' } ) );
} );
} );

describe( '.SETUP_EDITOR', () => {
const handler = effects.SETUP_EDITOR;

Expand Down

0 comments on commit f56fb20

Please sign in to comment.