Skip to content

Commit

Permalink
Fix and add tests
Browse files Browse the repository at this point in the history
  • Loading branch information
oandregal committed Sep 14, 2018
1 parent 3b66f1a commit 3548cd0
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 1 deletion.
5 changes: 4 additions & 1 deletion packages/editor/src/store/selectors.js
Original file line number Diff line number Diff line change
Expand Up @@ -1894,5 +1894,8 @@ export function canUserUseUnfilteredHTML( state ) {
* @return {boolean} Whether the pre-publish panel should be shown or not.
*/
export function isPublishSidebarEnabled( state ) {
return state.preferences.isPublishSidebarEnabled || PREFERENCES_DEFAULTS.isPublishSidebarEnabled;
if ( state.preferences.hasOwnProperty( 'isPublishSidebarEnabled' ) ) {
return state.preferences.isPublishSidebarEnabled;
}
return PREFERENCES_DEFAULTS.isPublishSidebarEnabled;
}
29 changes: 29 additions & 0 deletions packages/editor/src/store/test/selectors.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ import { moment } from '@wordpress/date';
* Internal dependencies
*/
import * as selectors from '../selectors';
import { PREFERENCES_DEFAULTS } from '../defaults';

const {
canUserUseUnfilteredHTML,
Expand Down Expand Up @@ -82,6 +83,7 @@ const {
getReusableBlocks,
getStateBeforeOptimisticTransaction,
isPublishingPost,
isPublishSidebarEnabled,
canInsertBlockType,
getInserterItems,
isValidTemplate,
Expand Down Expand Up @@ -3387,6 +3389,33 @@ describe( 'selectors', () => {
} );
} );

describe( 'isPublishSidebarEnabled', () => {
it( 'should return the value on state if it is thruthy', () => {
const state = {
preferences: {
isPublishSidebarEnabled: true,
},
};
expect( isPublishSidebarEnabled( state ) ).toBe( state.preferences.isPublishSidebarEnabled );
} );

it( 'should return the value on state if it is falsy', () => {
const state = {
preferences: {
isPublishSidebarEnabled: false,
},
};
expect( isPublishSidebarEnabled( state ) ).toBe( state.preferences.isPublishSidebarEnabled );
} );

it( 'should return the default value if there is no isPublishSidebarEnabled key on state', () => {
const state = {
preferences: { },
};
expect( isPublishSidebarEnabled( state ) ).toBe( PREFERENCES_DEFAULTS.isPublishSidebarEnabled );
} );
} );

describe( 'isFetchingReusableBlock', () => {
it( 'should return false when the block is not being fetched', () => {
const state = {
Expand Down

0 comments on commit 3548cd0

Please sign in to comment.