Skip to content

Commit

Permalink
remove use of generatorActions default import ans switch to dispatch …
Browse files Browse the repository at this point in the history
…control for autosave
  • Loading branch information
nerrad committed Feb 28, 2019
1 parent 1c11a5b commit 4cc4015
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 19 deletions.
15 changes: 5 additions & 10 deletions packages/editor/src/store/actions.js
Original file line number Diff line number Diff line change
Expand Up @@ -472,7 +472,11 @@ export function* trashPost() {
* @param {Object?} options Extra flags to identify the autosave.
*/
export function* autosave( options ) {
yield* generatorActions.savePost( { isAutosave: true, ...options } );
yield dispatch(
STORE_KEY,
'savePost',
{ isAutosave: true, ...options }
);
}

/**
Expand Down Expand Up @@ -734,12 +738,3 @@ export const exitFormattedText = getBlockEditorAction( 'exitFormattedText' );
export const insertDefaultBlock = getBlockEditorAction( 'insertDefaultBlock' );
export const updateBlockListSettings = getBlockEditorAction( 'updateBlockListSettings' );
export const updateEditorSettings = getBlockEditorAction( 'updateEditorSettings' );

// default export of generator actions.
const generatorActions = {
savePost,
autosave,
trashPost,
refreshPost,
};
export default generatorActions;
14 changes: 5 additions & 9 deletions packages/editor/src/store/test/actions.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import { BEGIN, COMMIT, REVERT } from 'redux-optimist';
/**
* Internal dependencies
*/
import generatorActions, * as actions from '../actions';
import * as actions from '../actions';
import { select, dispatch, apiFetch, resolveSelect } from '../controls';
import {
STORE_KEY,
Expand Down Expand Up @@ -491,15 +491,11 @@ describe( 'Post generator actions', () => {
} );
} );
describe( 'autosave()', () => {
let savePostSpy;
beforeAll( () => savePostSpy = jest.spyOn( generatorActions, 'savePost' ) );
afterAll( () => savePostSpy.mockRestore() );
// autosave is mostly covered by `savePost` tests so just test the correct call
it( 'calls savePost with the correct arguments', () => {
it( 'dispatches savePost with the correct arguments', () => {
const fulfillment = actions.autosave();
fulfillment.next();
expect( savePostSpy ).toHaveBeenCalled();
expect( savePostSpy ).toHaveBeenCalledWith( { isAutosave: true } );
const { value } = fulfillment.next();
expect( value.actionName ).toBe( 'savePost' );
expect( value.args ).toEqual( [ { isAutosave: true } ] );
} );
} );
describe( 'trashPost()', () => {
Expand Down

0 comments on commit 4cc4015

Please sign in to comment.