wordpress-develop/tests/e2e/specs/empty-trash-restore-trashed-posts.test.js
Pascal Birchler 5a838d1bb7 Build/Test Tools: Migrate Puppeteer tests to Playwright.
As per the migration plan shared last year, this migrates all browser-based tests in WordPress core to use Playwright.
This includes end-to-end, performance, and visual regression tests.

Props swissspidy, mamaduka, kevin940726, bartkalisz, desrosj, adamsilverstein.
Fixes #59517.

git-svn-id: https://develop.svn.wordpress.org/trunk@56926 602fd350-edb4-49c9-b593-d223f7449a82
2023-10-13 08:11:41 +00:00

56 lines
2.0 KiB
JavaScript

/**
* WordPress dependencies
*/
import { test, expect } from '@wordpress/e2e-test-utils-playwright';
const POST_TITLE = 'Test Title';
test.describe( 'Empty Trash', () => {
test.beforeEach( async ( { requestUtils } ) => {
await requestUtils.deleteAllPosts();
});
test('Empty Trash', async ({ admin, editor, page }) => {
await admin.createNewPost( { title: POST_TITLE } );
await editor.publishPost();
await admin.visitAdminPage( '/edit.php' );
const listTable = page.getByRole( 'table', { name: 'Table ordered by' } );
await expect( listTable ).toBeVisible();
// Move post to trash
await listTable.getByRole( 'link', { name: `${ POST_TITLE }” (Edit)` } ).hover();
await listTable.getByRole( 'link', { name: `Move “${POST_TITLE}” to the Trash` } ).click();
// Empty trash
await page.getByRole( 'link', { name: 'Trash' } ).click();
await page.getByRole( 'button', { name: 'Empty Trash' } ).first().click();
await expect( page.locator( '#message' ) ).toContainText( '1 post permanently deleted.' );
} );
test('Restore trash post', async ( { admin, editor, page }) => {
await admin.createNewPost( { title: POST_TITLE } );
await editor.publishPost();
await admin.visitAdminPage( '/edit.php' );
const listTable = page.getByRole( 'table', { name: 'Table ordered by' } );
await expect( listTable ).toBeVisible();
// Move post to trash
await listTable.getByRole( 'link', { name: `${ POST_TITLE }” (Edit)` } ).hover();
await listTable.getByRole( 'link', { name: `Move “${POST_TITLE}” to the Trash` } ).click();
await page.getByRole( 'link', { name: 'Trash' } ).click();
// Remove post from trash.
await listTable.getByRole( 'cell' ).filter( { hasText: POST_TITLE } ).hover();
await listTable.getByRole( 'link', { name: `Restore “${POST_TITLE}” from the Trash` } ).click();
// Expect for success message for restored post.
await expect( page.locator( '#message' ) ).toContainText( '1 post restored from the Trash.' );
} );
} );