From e8ed2e948e6da09b45e88c6f9f52f4baeadd62a7 Mon Sep 17 00:00:00 2001 From: juhi123 Date: Thu, 26 Dec 2024 15:13:29 +0530 Subject: [PATCH 1/2] Add Playwright E2E test for bulk post edit --- tests/e2e/specs/posts/post-bulk-edit.test.js | 66 ++++++++++++++++++++ 1 file changed, 66 insertions(+) create mode 100644 tests/e2e/specs/posts/post-bulk-edit.test.js diff --git a/tests/e2e/specs/posts/post-bulk-edit.test.js b/tests/e2e/specs/posts/post-bulk-edit.test.js new file mode 100644 index 0000000000000..d5e41fa8040e3 --- /dev/null +++ b/tests/e2e/specs/posts/post-bulk-edit.test.js @@ -0,0 +1,66 @@ +/** + * WordPress dependencies + */ +const { test, expect } = require("@wordpress/e2e-test-utils-playwright"); + +test.describe("Bulk @wp-post Edit", () => { + + + test.beforeEach(async ({ admin, editor }) => { + // await admin.createNewPost({ title: postTitle }); + // await editor.publishPost(); + + // create Posts to use in test + const postTitles = [ + 'Test Post for bulk edit 1', + 'Test Post for bulk edit 2', + ]; + + for ( const title of postTitles ) { + await admin.createNewPost( { title: title } ); + await editor.publishPost(); + } + }); + + test.afterEach(async ({ requestUtils }) => { + await requestUtils.deleteAllPosts(); + }); + + test("Should be able to edit the posts in bulk", async ({ page, admin }) => { + // Navigate to posts page + await admin.visitAdminPage('/edit.php'); + await expect(page.locator('.wp-heading-inline')).toHaveText('Posts'); + + // click on select all checkbox + await page.locator( '#cb-select-all-1' ).click(); + + // select the edit option from the dropdown + await page.selectOption( '#bulk-action-selector-top', 'edit' ); + + // click on apply button + await page.click( 'role=button[name="Apply"i] >> nth=0' ); + + // select the draft option + await page + .getByRole( 'combobox', { name: 'Status' } ) + .selectOption( 'draft' ); + + // click on the update button + await page.getByRole( 'button', { name: 'Update' } ).click(); + + await expect( + page.locator( "div[id='message'] p" ).first() + ).toHaveText( /posts updated./ ); + + const listTable = page.getByRole( 'table', { + name: 'Table ordered by', + } ); + const posts = listTable.locator( '.page-title strong span' ); + + // Validate that the page is in draft status + await expect( posts.first() ).toHaveText( 'Draft' ); + + // // Assert success message + // await expect(page.locator("div[id='message'] p").first(), "Bulk edit success message not displayed").toHaveText(/posts updated./); + }); +}); From 926ff8d420a6c2ec6825792bb4bcddaec3164c2f Mon Sep 17 00:00:00 2001 From: juhi123 Date: Thu, 26 Dec 2024 15:15:01 +0530 Subject: [PATCH 2/2] Remove unnecessary code --- tests/e2e/specs/posts/post-bulk-edit.test.js | 49 +++++++++----------- 1 file changed, 23 insertions(+), 26 deletions(-) diff --git a/tests/e2e/specs/posts/post-bulk-edit.test.js b/tests/e2e/specs/posts/post-bulk-edit.test.js index d5e41fa8040e3..7db333609bf62 100644 --- a/tests/e2e/specs/posts/post-bulk-edit.test.js +++ b/tests/e2e/specs/posts/post-bulk-edit.test.js @@ -1,16 +1,11 @@ /** * WordPress dependencies */ -const { test, expect } = require("@wordpress/e2e-test-utils-playwright"); +const { test, expect } = require( '@wordpress/e2e-test-utils-playwright' ); -test.describe("Bulk @wp-post Edit", () => { - - - test.beforeEach(async ({ admin, editor }) => { - // await admin.createNewPost({ title: postTitle }); - // await editor.publishPost(); - - // create Posts to use in test +test.describe( 'Bulk @wp-post Edit', () => { + test.beforeEach( async ( { admin, editor } ) => { + // create Posts to use in test const postTitles = [ 'Test Post for bulk edit 1', 'Test Post for bulk edit 2', @@ -20,18 +15,23 @@ test.describe("Bulk @wp-post Edit", () => { await admin.createNewPost( { title: title } ); await editor.publishPost(); } - }); - - test.afterEach(async ({ requestUtils }) => { - await requestUtils.deleteAllPosts(); - }); - - test("Should be able to edit the posts in bulk", async ({ page, admin }) => { - // Navigate to posts page - await admin.visitAdminPage('/edit.php'); - await expect(page.locator('.wp-heading-inline')).toHaveText('Posts'); - - // click on select all checkbox + } ); + + test.afterEach( async ( { requestUtils } ) => { + await requestUtils.deleteAllPosts(); + } ); + + test( 'Should be able to edit the posts in bulk', async ( { + page, + admin, + } ) => { + // Navigate to posts page + await admin.visitAdminPage( '/edit.php' ); + await expect( page.locator( '.wp-heading-inline' ) ).toHaveText( + 'Posts' + ); + + // click on select all checkbox await page.locator( '#cb-select-all-1' ).click(); // select the edit option from the dropdown @@ -59,8 +59,5 @@ test.describe("Bulk @wp-post Edit", () => { // Validate that the page is in draft status await expect( posts.first() ).toHaveText( 'Draft' ); - - // // Assert success message - // await expect(page.locator("div[id='message'] p").first(), "Bulk edit success message not displayed").toHaveText(/posts updated./); - }); -}); + } ); +} );