diff --git a/.eslintignore b/.eslintignore index 3d1aed71251389..a4a3d4cbd09246 100644 --- a/.eslintignore +++ b/.eslintignore @@ -2,4 +2,5 @@ build build-module coverage node_modules +test/e2e/test-plugins vendor diff --git a/.gitignore b/.gitignore index 4e10215883008d..e998f95a794de4 100644 --- a/.gitignore +++ b/.gitignore @@ -2,7 +2,6 @@ build build-module coverage -/hooks node_modules gutenberg.zip languages/gutenberg.pot diff --git a/test/e2e/specs/__snapshots__/plugins-api.test.js.snap b/test/e2e/specs/__snapshots__/plugins-api.test.js.snap new file mode 100644 index 00000000000000..e0960eee29dd7b --- /dev/null +++ b/test/e2e/specs/__snapshots__/plugins-api.test.js.snap @@ -0,0 +1,3 @@ +// Jest Snapshot v1, https://goo.gl/fbAQLP + +exports[`Using Plugins API Should open plugins sidebar using More Menu item and render content 1`] = `"
(no title)
My title plugin
(No title)
"`; diff --git a/test/e2e/specs/plugins-api.test.js b/test/e2e/specs/plugins-api.test.js new file mode 100644 index 00000000000000..b3521a57f349cd --- /dev/null +++ b/test/e2e/specs/plugins-api.test.js @@ -0,0 +1,33 @@ +/** + * Internal dependencies + */ +import '../support/bootstrap'; +import { newPost, newDesktopBrowserPage, toggleMoreMenuItem } from '../support/utils'; +import { activatePlugin, deactivatePlugin } from '../support/plugins'; + +describe( 'Using Plugins API', () => { + beforeAll( async () => { + await newDesktopBrowserPage(); + await activatePlugin( 'gutenberg-test-plugin-plugins-api' ); + await newPost(); + } ); + + afterAll( async () => { + await newDesktopBrowserPage(); + await deactivatePlugin( 'gutenberg-test-plugin-plugins-api' ); + } ); + + it( 'Should open plugins sidebar using More Menu item and render content', async () => { + await toggleMoreMenuItem( 'My title plugin' ); + + const pluginSidebarContent = await page.$eval( '.edit-post-sidebar', ( el ) => el.innerHTML ); + expect( pluginSidebarContent ).toMatchSnapshot(); + } ); + + it( 'Should close plugins sidebar using More Menu item', async () => { + await toggleMoreMenuItem( 'My title plugin' ); + + const pluginSidebar = await page.$( '.edit-post-sidebar' ); + expect( pluginSidebar ).toBeNull(); + } ); +} ); diff --git a/test/e2e/specs/templates.test.js b/test/e2e/specs/templates.test.js index 15d86445d7f243..f0cc6e4d7e5950 100644 --- a/test/e2e/specs/templates.test.js +++ b/test/e2e/specs/templates.test.js @@ -2,7 +2,7 @@ * Internal dependencies */ import '../support/bootstrap'; -import { newPost, newDesktopBrowserPage } from '../support/utils'; +import { newPost, newDesktopBrowserPage, toggleMoreMenuItem } from '../support/utils'; import { activatePlugin, deactivatePlugin } from '../support/plugins'; describe( 'Using a CPT with a predefined template', () => { @@ -19,9 +19,7 @@ describe( 'Using a CPT with a predefined template', () => { it( 'Should add a custom post types with a predefined template', async () => { //Switch to Code Editor to check HTML output - await page.click( '.edit-post-more-menu [aria-label="More"]' ); - const codeEditorButton = ( await page.$x( '//button[contains(text(), \'Code Editor\')]' ) )[ 0 ]; - await codeEditorButton.click( 'button' ); + await toggleMoreMenuItem( 'Code Editor' ); // Assert that the post already contains the template defined blocks const textEditorContent = await page.$eval( '.editor-post-text-editor', ( element ) => element.value ); diff --git a/test/e2e/support/utils.js b/test/e2e/support/utils.js index a166a7fa9e8bf6..97dd0e23ef2f02 100644 --- a/test/e2e/support/utils.js +++ b/test/e2e/support/utils.js @@ -147,3 +147,14 @@ export async function pressWithModifier( modifier, key ) { await page.keyboard.press( key ); return page.keyboard.up( modifier ); } + +/** + * Toggles More Menu item, searchers for the button with the text provided and clicks it. + * + * @param {string} buttonLabel The label to search the button for. + */ +export async function toggleMoreMenuItem( buttonLabel ) { + await page.click( '.edit-post-more-menu [aria-label="More"]' ); + const itemButton = ( await page.$x( `//button[contains(text(), \'${ buttonLabel }\')]` ) )[ 0 ]; + await itemButton.click( 'button' ); +} diff --git a/test/e2e/test-plugins/plugins-api.php b/test/e2e/test-plugins/plugins-api.php new file mode 100644 index 00000000000000..55a99872afd5ad --- /dev/null +++ b/test/e2e/test-plugins/plugins-api.php @@ -0,0 +1,22 @@ +