-
Notifications
You must be signed in to change notification settings - Fork 4.3k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Autocomplete Component: add e2e tests (take two) (#42905)
- Loading branch information
Showing
5 changed files
with
498 additions
and
69 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,27 @@ | ||
<?php | ||
/** | ||
* Plugin Name: Gutenberg Test Autocompleter | ||
* Plugin URI: https://github.com/WordPress/gutenberg | ||
* Author: Gutenberg Team | ||
* | ||
* @package gutenberg-test-autocompleter | ||
*/ | ||
|
||
/** | ||
* Registers a custom script for the plugin. | ||
*/ | ||
function enqueue_test_autocompleter_plugin_script() { | ||
wp_enqueue_script( | ||
'gutenberg-test-autocompleter', | ||
plugins_url( 'test-autocompleter/index.js', __FILE__ ), | ||
array( | ||
'wp-hooks', | ||
'wp-element', | ||
'wp-block-editor', | ||
), | ||
filemtime( plugin_dir_path( __FILE__ ) . 'test-autocompleter/index.js' ), | ||
false | ||
); | ||
} | ||
|
||
add_action( 'init', 'enqueue_test_autocompleter_plugin_script' ); |
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 @@ | ||
(function () { | ||
const fruits = { | ||
name: 'fruit', | ||
// The prefix that triggers this completer | ||
triggerPrefix: '~', | ||
// The option data | ||
options: [ | ||
{ visual: '🍎', name: 'Apple', id: 1 }, | ||
{ visual: '🍊', name: 'Orange', id: 2 }, | ||
{ visual: '🍇', name: 'Grapes', id: 3 }, | ||
{ visual: '🥭', name: 'Mango', id: 4 }, | ||
{ visual: '🍓', name: 'Strawberry', id: 5 }, | ||
{ visual: '🫐', name: 'Blueberry', id: 6 }, | ||
{ visual: '🍒', name: 'Cherry', id: 7 }, | ||
], | ||
// Returns a label for an option like "🍊 Orange" | ||
getOptionLabel: ( option ) => `${ option.visual } ${ option.name }`, | ||
// Declares that options should be matched by their name | ||
getOptionKeywords: ( option ) => [ option.name ], | ||
// Declares that the Grapes option is disabled | ||
isOptionDisabled: ( option ) => option.name === 'Grapes', | ||
// Declares completions should be inserted as abbreviations | ||
getOptionCompletion: ( option ) => ( | ||
option.visual | ||
), | ||
}; | ||
|
||
function duplicateUserMentions( completers ) { | ||
const [ users ] = completers.filter( | ||
( completer ) => completer.name === 'users' | ||
); | ||
return { | ||
...users, | ||
name: 'users-copy', | ||
triggerPrefix: '+', | ||
getOptionCompletion: ( user ) => `+${ user.slug }`, | ||
}; | ||
} | ||
|
||
function appendTestCompleters( completers, blockName ) { | ||
const copiedUsers = duplicateUserMentions( completers ); | ||
return blockName === 'core/paragraph' | ||
? [ ...completers, fruits, copiedUsers ] | ||
: completers; | ||
} | ||
|
||
// Adding the filter with a priority of 11 | ||
// to ensure it fires after the default user mentions are added. | ||
wp.hooks.addFilter( | ||
'editor.Autocomplete.completers', | ||
'editor/autocompleters/test', | ||
appendTestCompleters, | ||
11 | ||
); | ||
})() |
This file was deleted.
Oops, something went wrong.
Oops, something went wrong.