UNPKG

@wordpress/core-data

Version:
71 lines (58 loc) 1.73 kB
/** * Internal dependencies */ import { getMethodName, rootEntitiesConfig, prePersistPostType, } from '../entities'; describe( 'getMethodName', () => { it( 'should return the right method name for an entity with the root kind', () => { const methodName = getMethodName( 'root', 'postType' ); expect( methodName ).toEqual( 'getPostType' ); } ); it( 'should use a different suffix', () => { const methodName = getMethodName( 'root', 'postType', 'set' ); expect( methodName ).toEqual( 'setPostType' ); } ); it( 'should use the given plural form', () => { const methodName = getMethodName( 'root', 'taxonomies', 'get' ); expect( methodName ).toEqual( 'getTaxonomies' ); } ); it( 'should include the kind in the method name', () => { const id = rootEntitiesConfig.length; rootEntitiesConfig[ id ] = { name: 'book', kind: 'postType' }; const methodName = getMethodName( 'postType', 'book' ); delete rootEntitiesConfig[ id ]; expect( methodName ).toEqual( 'getPostTypeBook' ); } ); } ); describe( 'prePersistPostType', () => { it( 'set the status to draft and empty the title when saving auto-draft posts', () => { let record = { status: 'auto-draft', }; const edits = {}; expect( prePersistPostType( record, edits ) ).toEqual( { status: 'draft', title: '', } ); record = { status: 'publish', }; expect( prePersistPostType( record, edits ) ).toEqual( {} ); record = { status: 'auto-draft', title: 'Auto Draft', }; expect( prePersistPostType( record, edits ) ).toEqual( { status: 'draft', title: '', } ); record = { status: 'publish', title: 'My Title', }; expect( prePersistPostType( record, edits ) ).toEqual( {} ); } ); } );