diff --git a/packages/data/src/test/privateAPIs.js b/packages/data/src/test/privateAPIs.js index 93df00d287d60..0a0a62c915f97 100644 --- a/packages/data/src/test/privateAPIs.js +++ b/packages/data/src/test/privateAPIs.js @@ -4,6 +4,7 @@ import { createRegistry } from '../registry'; import createReduxStore from '../redux-store'; import { unlock } from '../private-apis'; +import { createRegistrySelector } from '../factory'; describe( 'Private data APIs', () => { let registry; @@ -164,6 +165,42 @@ describe( 'Private data APIs', () => { ); expect( subPrivateSelectors.getSecretDiscount() ).toEqual( 800 ); } ); + + it( 'should support registry selectors', () => { + const groceryStore = createStore(); + const otherStore = createReduxStore( 'other', { + reducer: ( state = {} ) => state, + } ); + registry.register( otherStore ); + unlock( otherStore ).registerPrivateSelectors( { + getPrice: createRegistrySelector( + ( select ) => () => select( groceryStore ).getPublicPrice() + ), + } ); + const privateSelectors = unlock( registry.select( otherStore ) ); + expect( privateSelectors.getPrice() ).toEqual( 1000 ); + } ); + + it( 'should support calling a private registry selector from a public selector', () => { + const groceryStore = createStore(); + const store = createReduxStore( 'a', { + reducer: ( state = {} ) => state, + selectors: { + getPriceWithShippingAndTax: ( state ) => + getPriceWithShipping( state ) * 1.1, + }, + } ); + registry.register( store ); + const getPriceWithShipping = createRegistrySelector( + ( select ) => () => select( groceryStore ).getPublicPrice() + 5 + ); + unlock( store ).registerPrivateSelectors( { + getPriceWithShipping, + } ); + expect( + registry.select( store ).getPriceWithShippingAndTax() + ).toEqual( 1105.5 ); + } ); } ); describe( 'private actions', () => {