Skip to content

Commit

Permalink
E2E Tests: Adding helpers to install/activate/deactivate and remove p…
Browse files Browse the repository at this point in the history
…lugins (#5906)
  • Loading branch information
youknowriad authored Apr 3, 2018
1 parent 25a0e7a commit 096ecec
Showing 1 changed file with 60 additions and 0 deletions.
60 changes: 60 additions & 0 deletions test/e2e/support/plugins.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
/**
* Node dependencies
*/
import { visitAdmin } from './utils';

/**
* Install a plugin from the WP.org repository.
*
* @param {string} slug Plugin slug.
* @param {string?} searchTerm If the plugin is not findable by its slug use an alternative term to search.
*/
export async function installPlugin( slug, searchTerm ) {
await visitAdmin( 'plugin-install.php?s=' + encodeURIComponent( searchTerm || slug ) + '&tab=search&type=term' );
await page.click( '.install-now[data-slug="' + slug + '"]' );
await page.waitForSelector( '.activate-now[data-slug="' + slug + '"]' );
}

/**
* Activates an installed plugin.
*
* @param {string} slug Plugin slug.
*/
export async function activatePlugin( slug ) {
await visitAdmin( 'plugins.php' );
await page.click( 'tr[data-slug="' + slug + '"] .activate a' );
await page.waitForSelector( 'tr[data-slug="' + slug + '"] .deactivate a' );
}

/**
* Dectivates an active plugin.
*
* @param {string} slug Plugin slug.
*/
export async function deactivatePlugin( slug ) {
await visitAdmin( 'plugins.php' );
await page.click( 'tr[data-slug="' + slug + '"] .deactivate a' );
await page.waitForSelector( 'tr[data-slug="' + slug + '"] .delete a' );
}

/**
* Uninstall a plugin.
*
* @param {string} slug Plugin slug.
*/
export async function uninstallPlugin( slug ) {
await visitAdmin( 'plugins.php' );
const confirmPromise = new Promise( resolve => {
const confirmDialog = ( dialog ) => {
dialog.accept();
page.removeListener( 'dialog', confirmDialog );
resolve();
};
page.on( 'dialog', confirmDialog );
} );
await Promise.all( [
confirmPromise,
page.click( 'tr[data-slug="' + slug + '"] .delete a' ),
] );
await page.waitForSelector( 'tr[data-slug="' + slug + '"].deleted' );
}

0 comments on commit 096ecec

Please sign in to comment.