From d56a7332fb47f2bf6ee4e01830486fbb5f0df513 Mon Sep 17 00:00:00 2001 From: Maud Leray Date: Wed, 11 Dec 2024 10:39:20 +0100 Subject: [PATCH] Fix e2e tests Some of these were broken by the WP upgrade to 6.7 --- tests/e2e/navigation-bar.spec.js | 8 +++----- tests/e2e/tools/lib/post.js | 6 ++++++ 2 files changed, 9 insertions(+), 5 deletions(-) diff --git a/tests/e2e/navigation-bar.spec.js b/tests/e2e/navigation-bar.spec.js index b0e0936b48..14e03ff18b 100644 --- a/tests/e2e/navigation-bar.spec.js +++ b/tests/e2e/navigation-bar.spec.js @@ -7,7 +7,7 @@ test('Test navigation bar menu', async ({page, admin, requestUtils}) => { const testPageTitle = `Navbar test ${testId}`; // Create a new page with a dummy paragraph - await requestUtils.rest({ + const newPage = await requestUtils.rest({ path: '/wp/v2/pages', method: 'POST', data: { @@ -30,14 +30,12 @@ test('Test navigation bar menu', async ({page, admin, requestUtils}) => { const pageOptions = page.locator('#add-post-type-page'); await pageOptions.getByRole('checkbox', {name: testPageTitle}).first().check(); await pageOptions.getByRole('button', {name: 'Add to Menu'}).click(); - const newMenuItem = page.locator('.menu-item-depth-0', {hasText: testPageTitle}); - await expect(newMenuItem).toBeVisible(); - const newMenuItemLink = await newMenuItem.locator('.link-to-original a').getAttribute('href'); + await page.locator('#menu-to-edit .menu-item-title').filter({hasText: testPageTitle}).waitFor(); await page.getByRole('button', {name: 'Save Menu'}).click(); await expect(page.locator('.updated.notice')).toBeVisible(); // Check in the frontend that the new menu item is correctly added await page.goto('./'); await expect(page.getByRole('link', {name: testPageTitle})).toBeVisible(); - await expect(page.getByRole('link', {name: testPageTitle})).toHaveAttribute('href', newMenuItemLink); + await expect(page.getByRole('link', {name: testPageTitle})).toHaveAttribute('href', newPage.link); }); diff --git a/tests/e2e/tools/lib/post.js b/tests/e2e/tools/lib/post.js index b2918bd5d2..807baae72a 100644 --- a/tests/e2e/tools/lib/post.js +++ b/tests/e2e/tools/lib/post.js @@ -7,6 +7,11 @@ * @return {Promise} The URL of the published post. */ async function publishPost({page, editor}) { + // We should be able to remove this check once we update Playwright to the latest version. + const closeSettingsSidebar = await page.getByRole('button', {name: 'Close Settings'}); + if (await closeSettingsSidebar.isVisible()) { + await closeSettingsSidebar.click(); + } await editor.publishPost(); const urlString = await page @@ -55,6 +60,7 @@ async function publishPostAndVisit({page, editor}) { */ async function createPostWithFeaturedImage({admin, editor}, params) { const newPost = await admin.createNewPost({...params, legacyCanvas: true}); + await editor.openDocumentSettingsSidebar(); const editorSettings = await editor.canvas.getByRole('region', {name: 'Editor settings'}); await editorSettings.getByRole('button', {name: 'Set featured image'}).click(); const imageModal = await editor.canvas.getByRole('dialog', {name: 'Featured image'});