@wordpress/e2e-test-utils
Version:
End-To-End (E2E) test utils for WordPress.
40 lines (36 loc) • 1.48 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", {
value: true
});
exports.trashAllComments = trashAllComments;
var _switchUserToAdmin = require("./switch-user-to-admin");
var _switchUserToTest = require("./switch-user-to-test");
var _visitAdminPage = require("./visit-admin-page");
/**
* Internal dependencies
*/
/**
* Navigates to the comments listing screen and bulk-trashes any comments which exist.
*
* @return {Promise} Promise resolving once comments have been trashed.
*/
async function trashAllComments() {
await (0, _switchUserToAdmin.switchUserToAdmin)();
// Visit `/wp-admin/edit-comments.php` so we can see a list of comments and delete them.
await (0, _visitAdminPage.visitAdminPage)('edit-comments.php');
// If this selector doesn't exist there are no comments for us to delete.
const bulkSelector = await page.$('#bulk-action-selector-top');
if (!bulkSelector) {
return;
}
// Select all comments.
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 mine/pendings/approved/spam comments 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=trash-all-comments.js.map