Skip to content
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

Refactor to remove usage of post related effects in packages/editor. #13716

Merged
merged 32 commits into from
Feb 28, 2019
Merged
Changes from 1 commit
Commits
Show all changes
32 commits
Select commit Hold shift + click to select a range
7e1d857
add controls for fetch, select, and dispatch
nerrad Feb 7, 2019
77a812c
move _all_ constants into the constants file for better organization
nerrad Feb 7, 2019
ae3f60b
establish file structure, begin refactoring post effects/actions
nerrad Feb 7, 2019
a673b8e
Implement trashPost action-generator
nerrad Feb 8, 2019
25c74c2
fix import jsdocs
nerrad Feb 8, 2019
54fbc38
update controls to use new createRegistryControl interface
nerrad Feb 8, 2019
455d6a8
add action generator for refreshing the current post
nerrad Feb 8, 2019
5d246e5
add tests for new code
nerrad Feb 11, 2019
0008288
fix broken tests
nerrad Feb 11, 2019
de8e6d1
don’t continue with refreshPost if there’s no current post yet
nerrad Feb 11, 2019
64216f4
remove unnecessary bail
nerrad Feb 11, 2019
f80fae4
add changelog entry
nerrad Feb 11, 2019
97b1ed5
fix lint failure for import order
nerrad Feb 12, 2019
9bce642
fix incorrect method used for autosave requests
nerrad Feb 12, 2019
36f962d
remove another wayward period.
nerrad Feb 12, 2019
d69599f
Add resolveSelect control and implement
nerrad Feb 19, 2019
4cba06a
refactor to condense code and update tests.
nerrad Feb 22, 2019
b3beb7f
update docs
nerrad Feb 22, 2019
651216d
fix doc blocks
nerrad Feb 27, 2019
a455781
fix jsdocs for param object properties
nerrad Feb 27, 2019
1a4fc0c
simplify import statement
nerrad Feb 27, 2019
49f5af6
utilize constants from constants file
nerrad Feb 27, 2019
a41039c
remove unused constants (now in block-editor)
nerrad Feb 27, 2019
2c14df4
simplify import
nerrad Feb 27, 2019
f66af80
add doc blocks for control actions
nerrad Feb 27, 2019
5568ac3
update docs
nerrad Feb 27, 2019
6d74643
make sure test is importing used constant
nerrad Feb 27, 2019
ff70f2b
fix doc block spacing issues
nerrad Feb 28, 2019
1c11a5b
Swith constant name from `MODULE_KEY` to `STORE_KEY`
nerrad Feb 28, 2019
4cc4015
remove use of generatorActions default import ans switch to dispatch …
nerrad Feb 28, 2019
0ba7d0e
doc changes
nerrad Feb 28, 2019
c17179e
Fix docs spacing
aduth Feb 28, 2019
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
simplify import statement
- this also initially experimented with just mocking `actions.savePost` for the autosave test but that didn’t work.  Needed to revert to the usage of a generatorActions default export for that.
  • Loading branch information
nerrad committed Feb 28, 2019
commit 1a4fc0cf1538597a643d21aef6b42fec9711502b
73 changes: 26 additions & 47 deletions packages/editor/src/store/test/actions.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,30 +6,7 @@ import { BEGIN, COMMIT, REVERT } from 'redux-optimist';
/**
* Internal dependencies
*/
import generatorActions, {
__experimentalFetchReusableBlocks as fetchReusableBlocks,
__experimentalSaveReusableBlock as saveReusableBlock,
__experimentalDeleteReusableBlock as deleteReusableBlock,
__experimentalConvertBlockToStatic as convertBlockToStatic,
__experimentalConvertBlockToReusable as convertBlockToReusable,
__experimentalRequestPostUpdateStart as requestPostUpdateStart,
__experimentalRequestPostUpdateSuccess as requestPostUpdateSuccess,
__experimentalRequestPostUpdateFailure as requestPostUpdateFailure,
__experimentalOptimisticUpdatePost as optimisticUpdatePost,
setupEditor,
resetPost,
resetAutosave,
updatePost,
lockPostSaving,
unlockPostSaving,
editPost,
savePost,
autosave,
refreshPost,
trashPost,
redo,
undo,
} from '../actions.js';
import generatorActions, * as actions from '../actions';
import { select, dispatch, apiFetch, resolveSelect } from '../controls';
import {
MODULE_KEY,
Expand Down Expand Up @@ -146,7 +123,7 @@ describe( 'Post generator actions', () => {
);
} );
const editedPostContent = 'to infinity and beyond';
const reset = ( isAutosaving ) => fulfillment = savePost(
const reset = ( isAutosaving ) => fulfillment = actions.savePost(
{ isAutosave: isAutosaving }
);
const rewind = ( isAutosaving, isNewPost ) => {
Expand Down Expand Up @@ -519,7 +496,7 @@ describe( 'Post generator actions', () => {
afterAll( () => savePostSpy.mockRestore() );
// autosave is mostly covered by `savePost` tests so just test the correct call
it( 'calls savePost with the correct arguments', () => {
const fulfillment = autosave();
const fulfillment = actions.autosave();
fulfillment.next();
expect( savePostSpy ).toHaveBeenCalled();
expect( savePostSpy ).toHaveBeenCalledWith( { isAutosave: true } );
Expand All @@ -528,7 +505,7 @@ describe( 'Post generator actions', () => {
describe( 'trashPost()', () => {
let fulfillment;
const currentPost = { id: 10, content: 'foo', status: 'publish' };
const reset = () => fulfillment = trashPost();
const reset = () => fulfillment = actions.trashPost();
const rewind = () => {
reset();
fulfillment.next();
Expand Down Expand Up @@ -608,7 +585,7 @@ describe( 'Post generator actions', () => {
describe( 'refreshPost()', () => {
let fulfillment;
const currentPost = { id: 10, content: 'foo' };
const reset = () => fulfillment = refreshPost();
const reset = () => fulfillment = actions.refreshPost();
it( 'yields expected action for selecting the currentPost', () => {
reset();
const { value } = fulfillment.next();
Expand Down Expand Up @@ -656,7 +633,7 @@ describe( 'actions', () => {
describe( 'setupEditor', () => {
it( 'should return the SETUP_EDITOR action', () => {
const post = {};
const result = setupEditor( post );
const result = actions.setupEditor( post );
expect( result ).toEqual( {
type: 'SETUP_EDITOR',
post,
Expand All @@ -667,7 +644,7 @@ describe( 'actions', () => {
describe( 'resetPost', () => {
it( 'should return the RESET_POST action', () => {
const post = {};
const result = resetPost( post );
const result = actions.resetPost( post );
expect( result ).toEqual( {
type: 'RESET_POST',
post,
Expand All @@ -678,7 +655,7 @@ describe( 'actions', () => {
describe( 'resetAutosave', () => {
it( 'should return the RESET_AUTOSAVE action', () => {
const post = {};
const result = resetAutosave( post );
const result = actions.resetAutosave( post );
expect( result ).toEqual( {
type: 'RESET_AUTOSAVE',
post,
Expand All @@ -688,7 +665,7 @@ describe( 'actions', () => {

describe( 'requestPostUpdateStart', () => {
it( 'should return the REQUEST_POST_UPDATE_START action', () => {
const result = requestPostUpdateStart();
const result = actions.__experimentalRequestPostUpdateStart();
expect( result ).toEqual( {
type: 'REQUEST_POST_UPDATE_START',
optimist: { type: BEGIN, id: POST_UPDATE_TRANSACTION_ID },
Expand All @@ -705,7 +682,7 @@ describe( 'actions', () => {
options: {},
postType: 'post',
};
const result = requestPostUpdateSuccess( {
const result = actions.__experimentalRequestPostUpdateSuccess( {
...testActionData,
isRevision: false,
} );
Expand All @@ -725,7 +702,9 @@ describe( 'actions', () => {
edits: {},
error: {},
};
const result = requestPostUpdateFailure( testActionData );
const result = actions.__experimentalRequestPostUpdateFailure(
testActionData
);
expect( result ).toEqual( {
...testActionData,
type: 'REQUEST_POST_UPDATE_FAILURE',
Expand All @@ -737,7 +716,7 @@ describe( 'actions', () => {
describe( 'updatePost', () => {
it( 'should return the UPDATE_POST action', () => {
const edits = {};
const result = updatePost( edits );
const result = actions.updatePost( edits );
expect( result ).toEqual( {
type: 'UPDATE_POST',
edits,
Expand All @@ -748,7 +727,7 @@ describe( 'actions', () => {
describe( 'editPost', () => {
it( 'should return EDIT_POST action', () => {
const edits = { format: 'sample' };
expect( editPost( edits ) ).toEqual( {
expect( actions.editPost( edits ) ).toEqual( {
type: 'EDIT_POST',
edits,
} );
Expand All @@ -758,7 +737,7 @@ describe( 'actions', () => {
describe( 'optimisticUpdatePost', () => {
it( 'should return the UPDATE_POST action with optimist property', () => {
const edits = {};
const result = optimisticUpdatePost( edits );
const result = actions.__experimentalOptimisticUpdatePost( edits );
expect( result ).toEqual( {
type: 'UPDATE_POST',
edits,
Expand All @@ -769,29 +748,29 @@ describe( 'actions', () => {

describe( 'redo', () => {
it( 'should return REDO action', () => {
expect( redo() ).toEqual( {
expect( actions.redo() ).toEqual( {
type: 'REDO',
} );
} );
} );

describe( 'undo', () => {
it( 'should return UNDO action', () => {
expect( undo() ).toEqual( {
expect( actions.undo() ).toEqual( {
type: 'UNDO',
} );
} );
} );

describe( 'fetchReusableBlocks', () => {
it( 'should return the FETCH_REUSABLE_BLOCKS action', () => {
expect( fetchReusableBlocks() ).toEqual( {
expect( actions.__experimentalFetchReusableBlocks() ).toEqual( {
type: 'FETCH_REUSABLE_BLOCKS',
} );
} );

it( 'should take an optional id argument', () => {
expect( fetchReusableBlocks( 123 ) ).toEqual( {
expect( actions.__experimentalFetchReusableBlocks( 123 ) ).toEqual( {
type: 'FETCH_REUSABLE_BLOCKS',
id: 123,
} );
Expand All @@ -800,7 +779,7 @@ describe( 'actions', () => {

describe( 'saveReusableBlock', () => {
it( 'should return the SAVE_REUSABLE_BLOCK action', () => {
expect( saveReusableBlock( 123 ) ).toEqual( {
expect( actions.__experimentalSaveReusableBlock( 123 ) ).toEqual( {
type: 'SAVE_REUSABLE_BLOCK',
id: 123,
} );
Expand All @@ -809,7 +788,7 @@ describe( 'actions', () => {

describe( 'deleteReusableBlock', () => {
it( 'should return the DELETE_REUSABLE_BLOCK action', () => {
expect( deleteReusableBlock( 123 ) ).toEqual( {
expect( actions.__experimentalDeleteReusableBlock( 123 ) ).toEqual( {
type: 'DELETE_REUSABLE_BLOCK',
id: 123,
} );
Expand All @@ -819,7 +798,7 @@ describe( 'actions', () => {
describe( 'convertBlockToStatic', () => {
it( 'should return the CONVERT_BLOCK_TO_STATIC action', () => {
const clientId = '358b59ee-bab3-4d6f-8445-e8c6971a5605';
expect( convertBlockToStatic( clientId ) ).toEqual( {
expect( actions.__experimentalConvertBlockToStatic( clientId ) ).toEqual( {
type: 'CONVERT_BLOCK_TO_STATIC',
clientId,
} );
Expand All @@ -829,7 +808,7 @@ describe( 'actions', () => {
describe( 'convertBlockToReusable', () => {
it( 'should return the CONVERT_BLOCK_TO_REUSABLE action', () => {
const clientId = '358b59ee-bab3-4d6f-8445-e8c6971a5605';
expect( convertBlockToReusable( clientId ) ).toEqual( {
expect( actions.__experimentalConvertBlockToReusable( clientId ) ).toEqual( {
type: 'CONVERT_BLOCK_TO_REUSABLE',
clientIds: [ clientId ],
} );
Expand All @@ -838,7 +817,7 @@ describe( 'actions', () => {

describe( 'lockPostSaving', () => {
it( 'should return the LOCK_POST_SAVING action', () => {
const result = lockPostSaving( 'test' );
const result = actions.lockPostSaving( 'test' );
expect( result ).toEqual( {
type: 'LOCK_POST_SAVING',
lockName: 'test',
Expand All @@ -848,7 +827,7 @@ describe( 'actions', () => {

describe( 'unlockPostSaving', () => {
it( 'should return the UNLOCK_POST_SAVING action', () => {
const result = unlockPostSaving( 'test' );
const result = actions.unlockPostSaving( 'test' );
expect( result ).toEqual( {
type: 'UNLOCK_POST_SAVING',
lockName: 'test',
Expand Down