UNPKG

@wordpress/e2e-test-utils

Version:
46 lines (42 loc) 1.6 kB
/** * 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. * @param {string} postStatus - String status of posts to trash. * * @return {Promise} Promise resolving once posts have been trashed. */ export async function trashAllPosts(postType = 'post', postStatus) { await switchUserToAdmin(); // Visit `/wp-admin/edit.php` so we can see a list of posts and delete them. const query = addQueryArgs('', { post_type: postType, post_status: postStatus }).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, "notice")]/p[contains(text(), "moved to the Trash.")]'); await switchUserToTest(); } //# sourceMappingURL=posts.js.map