Skip to content

Commit

Permalink
Add unit test
Browse files Browse the repository at this point in the history
  • Loading branch information
ockham committed Nov 5, 2021
1 parent 5cc2a8c commit 184d61e
Showing 1 changed file with 32 additions and 0 deletions.
32 changes: 32 additions & 0 deletions packages/core-data/src/test/actions.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ import {
receiveAutosaves,
receiveCurrentUser,
__experimentalBatch,
__experimentalResetSpecifiedEntityEdits,
} from '../actions';

jest.mock( '../batch', () => {
Expand Down Expand Up @@ -196,6 +197,37 @@ describe( 'saveEditedEntityRecord', () => {
} );
} );

describe( '__experimentalResetSpecifiedEntityEdits', () => {
it( 'triggers an EDIT_ENTITY_RECORD action to set the selected entity record edits to undefined', async () => {
const itemsToDiscard = [ 'title' ];

const select = {
getEntityRecordNonTransientEdits: () => [ { description: {} } ],
hasEditsForEntityRecord: () => true,
};

const dispatch = Object.assign( jest.fn() );

await __experimentalResetSpecifiedEntityEdits(
'root',
'site',
undefined,
itemsToDiscard
)( { dispatch, select } );

expect( dispatch ).toHaveBeenCalledTimes( 1 );
expect( dispatch ).toHaveBeenCalledWith( {
type: 'EDIT_ENTITY_RECORD',
kind: 'root',
name: 'site',
recordId: undefined,
edits: { title: undefined },
transientEdits: {},
meta: { undo: undefined },
} );
} );
} );

describe( 'saveEntityRecord', () => {
beforeEach( async () => {
apiFetch.mockReset();
Expand Down

0 comments on commit 184d61e

Please sign in to comment.