UNPKG

@wordpress/e2e-test-utils

Version:
52 lines (47 loc) 1.78 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.trashAllPosts = trashAllPosts; var _url = require("@wordpress/url"); var _switchUserToAdmin = require("./switch-user-to-admin"); var _switchUserToTest = require("./switch-user-to-test"); var _visitAdminPage = require("./visit-admin-page"); /** * WordPress dependencies */ /** * Internal dependencies */ /** * 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. */ async function trashAllPosts(postType = 'post', postStatus) { await (0, _switchUserToAdmin.switchUserToAdmin)(); // Visit `/wp-admin/edit.php` so we can see a list of posts and delete them. const query = (0, _url.addQueryArgs)('', { post_type: postType, post_status: postStatus }).slice(1); await (0, _visitAdminPage.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 (0, _switchUserToTest.switchUserToTest)(); } //# sourceMappingURL=posts.js.map