summaryrefslogtreecommitdiffstatshomepage
path: root/tests/e2e/specs/empty-trash-restore-trashed-posts.test.js
blob: d970ca09b1c90a4f182826f4cd383c0f4d1403c4 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
/**
 * 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.' );
	} );
} );