From 16bd51e238e311e1ea81f1bb89cf441d02b2bce9 Mon Sep 17 00:00:00 2001 From: Jayson Rodrigues Date: Wed, 11 Dec 2024 17:30:18 +0530 Subject: [PATCH] Add Playwright e2e test for undo trashed post and delete posts permanantly from trash --- .../restore-from-trash-empty-trash.test.js | 62 +++++++++++++++++++ 1 file changed, 62 insertions(+) create mode 100644 tests/e2e/specs/posts/restore-from-trash-empty-trash.test.js diff --git a/tests/e2e/specs/posts/restore-from-trash-empty-trash.test.js b/tests/e2e/specs/posts/restore-from-trash-empty-trash.test.js new file mode 100644 index 0000000000000..16f7b4ee5f28e --- /dev/null +++ b/tests/e2e/specs/posts/restore-from-trash-empty-trash.test.js @@ -0,0 +1,62 @@ +/** + * WordPress dependencies + */ +const { test, expect } = require( '@wordpress/e2e-test-utils-playwright' ); + +test.describe( 'Undo trashed & delete posts permanantly from Trash', () => { + const POST_TITLE = 'Test Title'; + + test.beforeEach( async ( { requestUtils, editor, admin } ) => { + await requestUtils.deleteAllPosts(); + await admin.createNewPost( { postType: 'post', title: POST_TITLE } ); + await editor.publishPost(); + } ); + + test( 'Restore trash post', async ( { page, admin, editor } ) => { + await admin.visitAdminPage( '/edit.php' ); + + // Move one post to trash. + await page.hover( `[aria-label^="“${ POST_TITLE }”"]` ); + await page + .getByRole( `link`, { + name: `Move “${ POST_TITLE }” to the Trash`, + } ) + .first() + .click(); + + await expect( page.locator( '.no-items' ) ).toHaveText( + 'No posts found.' + ); + // Remove post from trash. + await page.getByRole( 'link', { name: 'Undo' } ).click(); + + await expect( page.locator( '#message p' ) ).toHaveText( + '1 post restored from the Trash.' + ); + } ); + + test( 'Empty Trash', async ( { page, admin, editor } ) => { + await admin.visitAdminPage( '/edit.php' ); + + // Move post to trash + await page.hover( `[aria-label^="“${ POST_TITLE }”"]` ); + await page + .getByRole( `link`, { + name: `Move “${ POST_TITLE }” to the Trash`, + } ) + .first() + .click(); + + await page.getByRole( 'link', { name: 'Trash' } ).click(); + + // Delete all post. + await page + .getByRole( 'button', { name: 'Empty Trash' } ) + .first() + .click(); + + await expect( page.locator( '#message' ) ).toHaveText( + /\d+ posts? permanently deleted\./ + ); + } ); +} );