From 70f280fd93cf486686f5b77db1249dc4ae8d69e0 Mon Sep 17 00:00:00 2001 From: Pascal Birchler Date: Fri, 8 Nov 2024 15:19:13 +0100 Subject: [PATCH] Bail early if no checkboxes selected --- packages/e2e-test-utils/src/trashAllPosts.js | 15 +++++++++++++-- 1 file changed, 13 insertions(+), 2 deletions(-) diff --git a/packages/e2e-test-utils/src/trashAllPosts.js b/packages/e2e-test-utils/src/trashAllPosts.js index b22a369c47f1..3ee6fbae51db 100644 --- a/packages/e2e-test-utils/src/trashAllPosts.js +++ b/packages/e2e-test-utils/src/trashAllPosts.js @@ -41,10 +41,21 @@ async function trashAllPosts(postType = 'post') { // 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 Promise.all([page.waitForNavigation(), page.click('#doaction')]); + + // Bail early if there were no items selected, + // e.g. if there were no posts or if they were all locked. + // See https://core.trac.wordpress.org/ticket/45006. + const hasSelectedCheckboxes = await page.evaluate( + () => document.querySelectorAll('input[name="post[]"]:checked').length > 0 + ); + + if (hasSelectedCheckboxes) { + // Submit the form to send all draft/scheduled/published posts to the trash. + await Promise.all([page.waitForNavigation(), page.click('#doaction')]); + } } await setCurrentUser(currentUser.username, currentUser.password);