Skip to content

Commit

Permalink
Add test mocks for preferences
Browse files Browse the repository at this point in the history
  • Loading branch information
talldan committed Mar 3, 2022
1 parent 510c531 commit a1920f2
Showing 1 changed file with 14 additions and 6 deletions.
20 changes: 14 additions & 6 deletions packages/edit-site/src/store/test/selectors.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,17 +18,22 @@ import {
isNavigationOpened,
isInserterOpened,
isListViewOpened,
__unstableGetPreference,
} from '../selectors';

describe( 'selectors', () => {
const canUser = jest.fn( () => true );
const getEntityRecords = jest.fn( () => [] );
const get = jest.fn();
getCanUserCreateMedia.registry = {
select: jest.fn( () => ( { canUser } ) ),
};
getReusableBlocks.registry = {
select: jest.fn( () => ( { getEntityRecords } ) ),
};
__unstableGetPreference.registry = {
select: jest.fn( () => ( { get } ) ),
};

describe( 'getCanUserCreateMedia', () => {
it( "selects `canUser( 'create', 'media' )` from the core store", () => {
Expand Down Expand Up @@ -60,6 +65,10 @@ describe( 'selectors', () => {
it( "returns the settings when the user can't create media", () => {
canUser.mockReturnValueOnce( false );
canUser.mockReturnValueOnce( false );
get.mockImplementation( ( scope, name ) => {
if ( name === 'focusMode' ) return false;
if ( name === 'fixedToolbar' ) return false;
} );
const state = {
settings: {},
preferences: {},
Expand All @@ -77,14 +86,13 @@ describe( 'selectors', () => {
} );

it( 'returns the extended settings when the user can create media', () => {
get.mockImplementation( ( scope, name ) => {
if ( name === 'focusMode' ) return true;
if ( name === 'fixedToolbar' ) return true;
} );

const state = {
settings: { key: 'value' },
preferences: {
features: {
focusMode: true,
fixedToolbar: true,
},
},
editedPost: { type: 'wp_template_part' },
};
const setInserterOpened = () => {};
Expand Down

0 comments on commit a1920f2

Please sign in to comment.