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

Edit Navigation: Replace remaining store name string with constant #27281

4 changes: 4 additions & 0 deletions packages/edit-navigation/src/store/constants.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
/**
* Module Constants
*/
export const STORE_NAME = 'core/edit-navigation';
6 changes: 3 additions & 3 deletions packages/edit-navigation/src/store/controls.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import { createRegistryControl } from '@wordpress/data';
* Internal dependencies
*/
import { menuItemsQuery } from './utils';
import { STORE_NAME } from './constants';

/**
* Trigger an API Fetch request.
Expand Down Expand Up @@ -72,7 +73,7 @@ export function getMenuItemToClientIdMapping( postId ) {
export function getNavigationPostForMenu( menuId ) {
return {
type: 'SELECT',
registryName: 'core/edit-navigation',
registryName: STORE_NAME,
selectorName: 'getNavigationPostForMenu',
args: [ menuId ],
};
Expand Down Expand Up @@ -173,7 +174,6 @@ const controls = {
),
};

const getState = ( registry ) =>
registry.stores[ 'core/edit-navigation' ].store.getState();
const getState = ( registry ) => registry.stores[ STORE_NAME ].store.getState();

export default controls;
6 changes: 1 addition & 5 deletions packages/edit-navigation/src/store/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,11 +11,7 @@ import * as resolvers from './resolvers';
import * as selectors from './selectors';
import * as actions from './actions';
import controls from './controls';

/**
* Module Constants
*/
const STORE_NAME = 'core/edit-navigation';
import { STORE_NAME } from './constants';

/**
* Block editor data store configuration.
Expand Down
21 changes: 11 additions & 10 deletions packages/edit-navigation/src/store/test/controls.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ import controls, {
dispatch,
} from '../controls';
import { menuItemsQuery } from '../utils';
import { STORE_NAME } from '../constants';

// Mock it to prevent calling window.fetch in test environment
jest.mock( '@wordpress/api-fetch', () => jest.fn( ( request ) => request ) );
Expand Down Expand Up @@ -63,7 +64,7 @@ describe( 'getNavigationPostForMenu', () => {
it( 'has the correct type and payload', () => {
expect( getNavigationPostForMenu( 123 ) ).toEqual( {
type: 'SELECT',
registryName: 'core/edit-navigation',
registryName: STORE_NAME,
selectorName: 'getNavigationPostForMenu',
args: [ 123 ],
} );
Expand Down Expand Up @@ -144,7 +145,7 @@ describe( 'controls', () => {
};
const registry = {
stores: {
'core/edit-navigation': {
[ STORE_NAME ]: {
store: {
getState: jest.fn( () => state ),
},
Expand All @@ -157,7 +158,7 @@ describe( 'controls', () => {
).toEqual( [ 'action1', 'action2' ] );

expect(
registry.stores[ 'core/edit-navigation' ].store.getState
registry.stores[ STORE_NAME ].store.getState
).toHaveBeenCalledTimes( 1 );

expect(
Expand All @@ -167,7 +168,7 @@ describe( 'controls', () => {
).toEqual( [] );

expect(
registry.stores[ 'core/edit-navigation' ].store.getState
registry.stores[ STORE_NAME ].store.getState
).toHaveBeenCalledTimes( 2 );
} );

Expand All @@ -181,7 +182,7 @@ describe( 'controls', () => {
};
const registry = {
stores: {
'core/edit-navigation': {
[ STORE_NAME ]: {
store: {
getState: jest.fn( () => state ),
},
Expand All @@ -194,7 +195,7 @@ describe( 'controls', () => {
).toBe( true );

expect(
registry.stores[ 'core/edit-navigation' ].store.getState
registry.stores[ STORE_NAME ].store.getState
).toHaveBeenCalledTimes( 1 );

expect(
Expand All @@ -204,7 +205,7 @@ describe( 'controls', () => {
).toBe( false );

expect(
registry.stores[ 'core/edit-navigation' ].store.getState
registry.stores[ STORE_NAME ].store.getState
).toHaveBeenCalledTimes( 2 );
} );

Expand All @@ -218,7 +219,7 @@ describe( 'controls', () => {
};
const registry = {
stores: {
'core/edit-navigation': {
[ STORE_NAME ]: {
store: {
getState: jest.fn( () => state ),
},
Expand All @@ -235,7 +236,7 @@ describe( 'controls', () => {
} );

expect(
registry.stores[ 'core/edit-navigation' ].store.getState
registry.stores[ STORE_NAME ].store.getState
).toHaveBeenCalledTimes( 1 );

expect(
Expand All @@ -245,7 +246,7 @@ describe( 'controls', () => {
).toEqual( {} );

expect(
registry.stores[ 'core/edit-navigation' ].store.getState
registry.stores[ STORE_NAME ].store.getState
).toHaveBeenCalledTimes( 2 );
} );

Expand Down