UNPKG

@wordpress/e2e-tests

Version:
62 lines (55 loc) 1.43 kB
const { registerBlockBindingsSource } = wp.blocks; const { fieldsList } = window.testingBindings || {}; const getValues = ( { bindings } ) => { const newValues = {}; for ( const [ attributeName, source ] of Object.entries( bindings ) ) { newValues[ attributeName ] = fieldsList[ source.args.key ]?.value; } return newValues; }; const setValues = ( { dispatch, context, bindings } ) => { const newMeta = {}; Object.values( bindings ).forEach( ( { args, newValue } ) => { newMeta[ args.key ] = newValue; } ); dispatch( 'core' ).editEntityRecord( 'postType', context?.postType, context?.postId, { meta: newMeta, } ); }; registerBlockBindingsSource( { name: 'testing/complete-source', getValues, setValues, canUserEditValue: () => true, getFieldsList() { return Object.entries( fieldsList || {} ).map( ( [ key, field ] ) => ( { label: field.label || key, type: field.type || 'string', args: field.args || { key }, } ) ); }, } ); registerBlockBindingsSource( { name: 'testing/can-user-edit-false', label: 'Can User Edit: False', getValues, setValues, canUserEditValue: () => false, } ); registerBlockBindingsSource( { name: 'testing/can-user-edit-undefined', label: 'Can User Edit: Undefined', getValues, setValues, } ); registerBlockBindingsSource( { name: 'testing/set-values-undefined', label: 'Set Values: Undefined', getValues, canUserEditValue: () => true, } );