Skip to content

Commit

Permalink
Add Playwright e2e test for undo trashed post and delete posts perman…
Browse files Browse the repository at this point in the history
…antly from trash
  • Loading branch information
jayson31 committed Dec 11, 2024
1 parent 27c566f commit 16bd51e
Showing 1 changed file with 62 additions and 0 deletions.
62 changes: 62 additions & 0 deletions tests/e2e/specs/posts/restore-from-trash-empty-trash.test.js
Original file line number Diff line number Diff line change
@@ -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 } );

Check failure on line 11 in tests/e2e/specs/posts/restore-from-trash-empty-trash.test.js

View workflow job for this annotation

GitHub Actions / Test with SCRIPT_DEBUG disabled / Run E2E tests

[chromium] › posts/restore-from-trash-empty-trash.test.js:15:2 › Undo trashed & delete posts permanantly from Trash › Restore trash post

1) [chromium] › posts/restore-from-trash-empty-trash.test.js:15:2 › Undo trashed & delete posts permanantly from Trash › Restore trash post Error: Not logged in 9 | test.beforeEach( async ( { requestUtils, editor, admin } ) => { 10 | await requestUtils.deleteAllPosts(); > 11 | await admin.createNewPost( { postType: 'post', title: POST_TITLE } ); | ^ 12 | await editor.publishPost(); 13 | } ); 14 | at Admin.visitAdminPage (/home/runner/work/wordpress-develop/wordpress-develop/node_modules/@wordpress/e2e-test-utils-playwright/src/admin/visit-admin-page.ts:36:9) at Admin.createNewPost (/home/runner/work/wordpress-develop/wordpress-develop/node_modules/@wordpress/e2e-test-utils-playwright/src/admin/create-new-post.ts:41:2) at /home/runner/work/wordpress-develop/wordpress-develop/tests/e2e/specs/posts/restore-from-trash-empty-trash.test.js:11:3

Check failure on line 11 in tests/e2e/specs/posts/restore-from-trash-empty-trash.test.js

View workflow job for this annotation

GitHub Actions / Test with SCRIPT_DEBUG disabled / Run E2E tests

[chromium] › posts/restore-from-trash-empty-trash.test.js:15:2 › Undo trashed & delete posts permanantly from Trash › Restore trash post

1) [chromium] › posts/restore-from-trash-empty-trash.test.js:15:2 › Undo trashed & delete posts permanantly from Trash › Restore trash post Retry #2 ─────────────────────────────────────────────────────────────────────────────────────── Error: Not logged in 9 | test.beforeEach( async ( { requestUtils, editor, admin } ) => { 10 | await requestUtils.deleteAllPosts(); > 11 | await admin.createNewPost( { postType: 'post', title: POST_TITLE } ); | ^ 12 | await editor.publishPost(); 13 | } ); 14 | at Admin.visitAdminPage (/home/runner/work/wordpress-develop/wordpress-develop/node_modules/@wordpress/e2e-test-utils-playwright/src/admin/visit-admin-page.ts:36:9) at Admin.createNewPost (/home/runner/work/wordpress-develop/wordpress-develop/node_modules/@wordpress/e2e-test-utils-playwright/src/admin/create-new-post.ts:41:2) at /home/runner/work/wordpress-develop/wordpress-develop/tests/e2e/specs/posts/restore-from-trash-empty-trash.test.js:11:3

Check failure on line 11 in tests/e2e/specs/posts/restore-from-trash-empty-trash.test.js

View workflow job for this annotation

GitHub Actions / Test with SCRIPT_DEBUG enabled / Run E2E tests

[chromium] › posts/restore-from-trash-empty-trash.test.js:15:2 › Undo trashed & delete posts permanantly from Trash › Restore trash post

2) [chromium] › posts/restore-from-trash-empty-trash.test.js:15:2 › Undo trashed & delete posts permanantly from Trash › Restore trash post Error: Not logged in 9 | test.beforeEach( async ( { requestUtils, editor, admin } ) => { 10 | await requestUtils.deleteAllPosts(); > 11 | await admin.createNewPost( { postType: 'post', title: POST_TITLE } ); | ^ 12 | await editor.publishPost(); 13 | } ); 14 | at Admin.visitAdminPage (/home/runner/work/wordpress-develop/wordpress-develop/node_modules/@wordpress/e2e-test-utils-playwright/src/admin/visit-admin-page.ts:36:9) at Admin.createNewPost (/home/runner/work/wordpress-develop/wordpress-develop/node_modules/@wordpress/e2e-test-utils-playwright/src/admin/create-new-post.ts:41:2) at /home/runner/work/wordpress-develop/wordpress-develop/tests/e2e/specs/posts/restore-from-trash-empty-trash.test.js:11:3

Check failure on line 11 in tests/e2e/specs/posts/restore-from-trash-empty-trash.test.js

View workflow job for this annotation

GitHub Actions / Test with SCRIPT_DEBUG enabled / Run E2E tests

[chromium] › posts/restore-from-trash-empty-trash.test.js:15:2 › Undo trashed & delete posts permanantly from Trash › Restore trash post

2) [chromium] › posts/restore-from-trash-empty-trash.test.js:15:2 › Undo trashed & delete posts permanantly from Trash › Restore trash post Retry #1 ─────────────────────────────────────────────────────────────────────────────────────── Error: Not logged in 9 | test.beforeEach( async ( { requestUtils, editor, admin } ) => { 10 | await requestUtils.deleteAllPosts(); > 11 | await admin.createNewPost( { postType: 'post', title: POST_TITLE } ); | ^ 12 | await editor.publishPost(); 13 | } ); 14 | at Admin.visitAdminPage (/home/runner/work/wordpress-develop/wordpress-develop/node_modules/@wordpress/e2e-test-utils-playwright/src/admin/visit-admin-page.ts:36:9) at Admin.createNewPost (/home/runner/work/wordpress-develop/wordpress-develop/node_modules/@wordpress/e2e-test-utils-playwright/src/admin/create-new-post.ts:41:2) at /home/runner/work/wordpress-develop/wordpress-develop/tests/e2e/specs/posts/restore-from-trash-empty-trash.test.js:11:3
await editor.publishPost();

Check failure on line 12 in tests/e2e/specs/posts/restore-from-trash-empty-trash.test.js

View workflow job for this annotation

GitHub Actions / Test with SCRIPT_DEBUG disabled / Run E2E tests

[chromium] › posts/restore-from-trash-empty-trash.test.js:15:2 › Undo trashed & delete posts permanantly from Trash › Restore trash post

1) [chromium] › posts/restore-from-trash-empty-trash.test.js:15:2 › Undo trashed & delete posts permanantly from Trash › Restore trash post Retry #1 ─────────────────────────────────────────────────────────────────────────────────────── TimeoutError: locator.waitFor: Timeout 10000ms exceeded. Call log: - waiting for getByRole('button', { name: 'Dismiss this notice' }).filter({ hasText: 'published' }) to be visible 10 | await requestUtils.deleteAllPosts(); 11 | await admin.createNewPost( { postType: 'post', title: POST_TITLE } ); > 12 | await editor.publishPost(); | ^ 13 | } ); 14 | 15 | test( 'Restore trash post', async ( { page, admin, editor } ) => { at Editor.publishPost (/home/runner/work/wordpress-develop/wordpress-develop/node_modules/@wordpress/e2e-test-utils-playwright/src/editor/publish-post.ts:44:4) at /home/runner/work/wordpress-develop/wordpress-develop/tests/e2e/specs/posts/restore-from-trash-empty-trash.test.js:12:3
} );

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\./
);
} );
} );

0 comments on commit 16bd51e

Please sign in to comment.