-
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.
- Loading branch information
1 parent
43ab9de
commit dad3772
Showing
8 changed files
with
79 additions
and
52 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
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
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,45 @@ | ||
/** | ||
* WordPress dependencies | ||
*/ | ||
import { addQueryArgs } from '@wordpress/url'; | ||
|
||
/** | ||
* Internal dependencies | ||
*/ | ||
import { switchUserToAdmin } from './switch-user-to-admin'; | ||
import { switchUserToTest } from './switch-user-to-test'; | ||
import { visitAdminPage } from './visit-admin-page'; | ||
|
||
/** | ||
* Navigates to the post listing screen and bulk-trashes any posts which exist. | ||
* | ||
* @param {string} postType - String slug for type of post to trash. | ||
* | ||
* @return {Promise} Promise resolving once posts have been trashed. | ||
*/ | ||
export async function trashAllPosts( postType = 'post' ) { | ||
await switchUserToAdmin(); | ||
// Visit `/wp-admin/edit.php` so we can see a list of posts and delete them. | ||
const query = addQueryArgs( '', { | ||
post_type: postType, | ||
} ).slice( 1 ); | ||
await visitAdminPage( 'edit.php', query ); | ||
|
||
// If this selector doesn't exist there are no posts for us to delete. | ||
const bulkSelector = await page.$( '#bulk-action-selector-top' ); | ||
if ( ! bulkSelector ) { | ||
return; | ||
} | ||
|
||
// Select all posts. | ||
await page.waitForSelector( '[id^=cb-select-all-]' ); | ||
await page.click( '[id^=cb-select-all-]' ); | ||
// Select the "bulk actions" > "trash" option. | ||
await page.select( '#bulk-action-selector-top', 'trash' ); | ||
// Submit the form to send all draft/scheduled/published posts to the trash. | ||
await page.click( '#doaction' ); | ||
await page.waitForXPath( | ||
'//*[contains(@class, "updated notice")]/p[contains(text(), "moved to the Trash.")]' | ||
); | ||
await switchUserToTest(); | ||
} |
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
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
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
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
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