-
Notifications
You must be signed in to change notification settings - Fork 4.2k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
E2E Tests: Adding helpers to install/activate/deactivate and remove p…
…lugins (#5906)
- Loading branch information
1 parent
25a0e7a
commit 096ecec
Showing
1 changed file
with
60 additions
and
0 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
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' ); | ||
} |