Skip to content

Commit

Permalink
Autocomplete Component: add e2e tests (take two) (#42905)
Browse files Browse the repository at this point in the history
  • Loading branch information
chad1008 authored Sep 28, 2022
1 parent ea7580c commit 74b0377
Show file tree
Hide file tree
Showing 5 changed files with 498 additions and 69 deletions.
4 changes: 4 additions & 0 deletions packages/e2e-tests/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,10 @@

## Unreleased

### New features

- Added Autocomplete Component e2e test suite. [#42905](https://github.com/WordPress/gutenberg/pull/42905).

## 5.2.0 (2022-09-21)

## 5.0.0 (2022-08-24)
Expand Down
27 changes: 27 additions & 0 deletions packages/e2e-tests/plugins/test-autocompleter.php
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' );
55 changes: 55 additions & 0 deletions packages/e2e-tests/plugins/test-autocompleter/index.js
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
);
})()
69 changes: 0 additions & 69 deletions packages/e2e-tests/specs/editor/various/mentions.test.js

This file was deleted.

Loading

0 comments on commit 74b0377

Please sign in to comment.