Skip to content

Commit

Permalink
Enhance unit testing and add back implicit default
Browse files Browse the repository at this point in the history
  • Loading branch information
talldan committed Mar 8, 2022
1 parent 5367371 commit 5c94254
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 1 deletion.
2 changes: 1 addition & 1 deletion packages/edit-post/src/store/selectors.js
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ const EMPTY_ARRAY = [];
* @return {string} Editing mode.
*/
export const getEditorMode = createRegistrySelector( ( select ) => () =>
select( preferencesStore ).get( 'core/edit-post', 'editorMode' )
select( preferencesStore ).get( 'core/edit-post', 'editorMode' ) ?? 'visual'
);

/**
Expand Down
12 changes: 12 additions & 0 deletions packages/edit-post/src/store/test/actions.js
Original file line number Diff line number Diff line change
Expand Up @@ -71,13 +71,22 @@ describe( 'actions', () => {

describe( 'switchEditorMode', () => {
it( 'to visual', () => {
// Switch to text first, since the default is visual.
registry.dispatch( editPostStore ).switchEditorMode( 'text' );
expect( registry.select( editPostStore ).getEditorMode() ).toEqual(
'text'
);
registry.dispatch( editPostStore ).switchEditorMode( 'visual' );
expect( registry.select( editPostStore ).getEditorMode() ).toEqual(
'visual'
);
} );

it( 'to text', () => {
// It defaults to visual.
expect( registry.select( editPostStore ).getEditorMode() ).toEqual(
'visual'
);
// Add a selected client id and make sure it's there.
const clientId = 'clientId_1';
registry.dispatch( blockEditorStore ).selectionChange( clientId );
Expand All @@ -89,6 +98,9 @@ describe( 'actions', () => {
expect(
registry.select( blockEditorStore ).getSelectedBlockClientId()
).toBeNull();
expect( registry.select( editPostStore ).getEditorMode() ).toEqual(
'text'
);
} );
} );

Expand Down

0 comments on commit 5c94254

Please sign in to comment.