forked from WordPress/gutenberg
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Block Bindings: Refactor e2e tests (WordPress#65526)
* WIP: Add script to block bindings tests * Add first version of block bindings test theme * Register movie CPT * Create structure for tests * Remove current specs * Share data between server and client * Add `getValues` tests * Move checks for paragraph locking * Wrap tests that should lock editing * Add setValues e2e tests * Add tests for `getFieldsList` * Add tests for rich text workflows * Add remaining use cases * Use one complete source * Add tests for CPT template * Fix label test * Add attributes panel tests * Add dropdown post meta tests * Add post meta tests for custom templates * Add e2e tests in movie post * Add template for posts * Rename specs * Fix post-meta tests * Check post meta in the frontend * Update theme definition * Populate `setValues` * Check image title locking Co-authored-by: SantosGuillamot <santosguillamot@git.wordpress.org> Co-authored-by: cbravobernal <cbravobernal@git.wordpress.org>
- Loading branch information
Showing
12 changed files
with
1,979 additions
and
2,472 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,55 @@ | ||
const { unlock } = | ||
wp.privateApis.__dangerousOptInToUnstableAPIsOnlyForCoreModules( | ||
'I acknowledge private features are not for use in themes or plugins and doing so will break in the next version of WordPress.', | ||
'@wordpress/blocks' | ||
); | ||
|
||
const { registerBlockBindingsSource } = unlock( wp.blocks.privateApis ); | ||
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 = ( { registry, bindings } ) => { | ||
Object.values( bindings ).forEach( ( { args, newValue } ) => { | ||
// Example of what could be done. | ||
registry.dispatch( 'core' ).editEntityRecord( 'postType', 'post', 1, { | ||
meta: { [ args?.key ]: newValue }, | ||
} ); | ||
} ); | ||
}; | ||
|
||
registerBlockBindingsSource( { | ||
name: 'testing/complete-source', | ||
label: 'Complete Source', | ||
getValues, | ||
setValues, | ||
canUserEditValue: () => true, | ||
getFieldsList: () => fieldsList, | ||
} ); | ||
|
||
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, | ||
} ); |
Oops, something went wrong.