Skip to content

Commit

Permalink
add tests
Browse files Browse the repository at this point in the history
tests
  • Loading branch information
lezama committed Aug 30, 2024
1 parent 1a975c8 commit bf99ae0
Show file tree
Hide file tree
Showing 3 changed files with 48 additions and 0 deletions.
13 changes: 13 additions & 0 deletions packages/e2e-tests/plugins/plugins-api.php
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,19 @@ function enqueue_plugins_api_plugin_scripts() {
filemtime( plugin_dir_path( __FILE__ ) . 'plugins-api/document-setting.js' ),
true
);

wp_enqueue_script(
'gutenberg-test-plugins-api-preview-menu',
plugins_url( 'plugins-api/preview-menu.js', __FILE__ ),
array(
'wp-editor',
'wp-element',
'wp-i18n',
'wp-plugins',
),
filemtime( plugin_dir_path( __FILE__ ) . 'plugins-api/preview-menu.js' ),
true
);
}

add_action( 'init', 'enqueue_plugins_api_plugin_scripts' );
14 changes: 14 additions & 0 deletions packages/e2e-tests/plugins/plugins-api/preview-menu.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
( function () {
const { __ } = wp.i18n;
const { registerPlugin } = wp.plugins;
const PluginPreviewMenuItem = wp.editor.PluginPreviewMenuItem;
const el = wp.element.createElement;

function CustomPreviewMenuItem() {
return el( PluginPreviewMenuItem, {}, __( 'Custom Preview' ) );
}

registerPlugin( 'custom-preview-menu-item', {
render: CustomPreviewMenuItem,
} );
} )();
21 changes: 21 additions & 0 deletions test/e2e/specs/editor/plugins/plugins-api.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -230,4 +230,25 @@ test.describe( 'Plugins API', () => {
).toBeVisible();
} );
} );

test.describe( 'Preview Menu Item', () => {
test( 'Should render and interact with PluginPreviewMenuItem', async ( {
page,
} ) => {
await page
.getByRole( 'region', { name: 'Editor top bar' } )
.locator( '.editor-preview-dropdown__toggle' )
.click();

const customPreviewItem = page.getByRole( 'menuitem', {
name: 'Custom Preview',
} );

await expect( customPreviewItem ).toBeVisible();

await customPreviewItem.click();

await expect( customPreviewItem ).toBeHidden();
} );
} );
} );

0 comments on commit bf99ae0

Please sign in to comment.