Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add Playwright E2E test to trash and restore page from trash #8052

Open
wants to merge 1 commit into
base: trunk
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
65 changes: 65 additions & 0 deletions tests/e2e/specs/pages/restore-page-from-trash.test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
/**
* WordPress dependencies
*/
const { test, expect } = require( '@wordpress/e2e-test-utils-playwright' );

test.describe( 'Trash and Restore page', () => {

let pageTitle;

test.beforeEach( async ( { admin } ) => {
// Generate a unique page title for each test
pageTitle = `Test Page for Trash`;
// Ensure we start on the admin "Pages" screen
await admin.visitAdminPage( 'edit.php', 'post_type=page' );

Check failure on line 14 in tests/e2e/specs/pages/restore-page-from-trash.test.js

View workflow job for this annotation

GitHub Actions / Test with SCRIPT_DEBUG disabled / Run E2E tests

[chromium] › pages/restore-page-from-trash.test.js:21:2 › Trash and Restore page › trashes a page

2) [chromium] › pages/restore-page-from-trash.test.js:21:2 › Trash and Restore page › trashes a page Error: Not logged in 12 | pageTitle = `Test Page for Trash`; 13 | // Ensure we start on the admin "Pages" screen > 14 | await admin.visitAdminPage( 'edit.php', 'post_type=page' ); | ^ 15 | } ); 16 | 17 | test.afterAll( async ( { requestUtils } ) => { 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 /home/runner/work/wordpress-develop/wordpress-develop/tests/e2e/specs/pages/restore-page-from-trash.test.js:14:3

Check failure on line 14 in tests/e2e/specs/pages/restore-page-from-trash.test.js

View workflow job for this annotation

GitHub Actions / Test with SCRIPT_DEBUG disabled / Run E2E tests

[chromium] › pages/restore-page-from-trash.test.js:21:2 › Trash and Restore page › trashes a page

2) [chromium] › pages/restore-page-from-trash.test.js:21:2 › Trash and Restore page › trashes a page Retry #1 ─────────────────────────────────────────────────────────────────────────────────────── Error: Not logged in 12 | pageTitle = `Test Page for Trash`; 13 | // Ensure we start on the admin "Pages" screen > 14 | await admin.visitAdminPage( 'edit.php', 'post_type=page' ); | ^ 15 | } ); 16 | 17 | test.afterAll( async ( { requestUtils } ) => { 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 /home/runner/work/wordpress-develop/wordpress-develop/tests/e2e/specs/pages/restore-page-from-trash.test.js:14:3

Check failure on line 14 in tests/e2e/specs/pages/restore-page-from-trash.test.js

View workflow job for this annotation

GitHub Actions / Test with SCRIPT_DEBUG enabled / Run E2E tests

[chromium] › pages/restore-page-from-trash.test.js:21:2 › Trash and Restore page › trashes a page

2) [chromium] › pages/restore-page-from-trash.test.js:21:2 › Trash and Restore page › trashes a page Error: Not logged in 12 | pageTitle = `Test Page for Trash`; 13 | // Ensure we start on the admin "Pages" screen > 14 | await admin.visitAdminPage( 'edit.php', 'post_type=page' ); | ^ 15 | } ); 16 | 17 | test.afterAll( async ( { requestUtils } ) => { 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 /home/runner/work/wordpress-develop/wordpress-develop/tests/e2e/specs/pages/restore-page-from-trash.test.js:14:3

Check failure on line 14 in tests/e2e/specs/pages/restore-page-from-trash.test.js

View workflow job for this annotation

GitHub Actions / Test with SCRIPT_DEBUG enabled / Run E2E tests

[chromium] › pages/restore-page-from-trash.test.js:21:2 › Trash and Restore page › trashes a page

2) [chromium] › pages/restore-page-from-trash.test.js:21:2 › Trash and Restore page › trashes a page Retry #1 ─────────────────────────────────────────────────────────────────────────────────────── Error: Not logged in 12 | pageTitle = `Test Page for Trash`; 13 | // Ensure we start on the admin "Pages" screen > 14 | await admin.visitAdminPage( 'edit.php', 'post_type=page' ); | ^ 15 | } ); 16 | 17 | test.afterAll( async ( { requestUtils } ) => { 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 /home/runner/work/wordpress-develop/wordpress-develop/tests/e2e/specs/pages/restore-page-from-trash.test.js:14:3
} );

test.afterAll( async ( { requestUtils } ) => {
await requestUtils.deleteAllPages();
} );

test( 'trashes a page', async ( { page, admin, editor } ) => {
await admin.createNewPost( { postType: 'page', title: pageTitle } );

// Publish the page
await editor.publishPost();

// Verify success notice
await expect(page.locator('.components-snackbar__content')).toHaveText('Page published.View Page');

// Close the editor panel
await page.click( '[aria-label="Close panel"]' );

// Reload page to ensure the UI is updated
await page.reload();

// Move page to trash
await page.click('button.editor-post-trash[aria-disabled="false"]');

const modal = page.locator('div.components-modal__frame');
await modal.locator('button:has-text("Move to trash")').click();

// Wait for the page to navigate or reload
await page.waitForLoadState('networkidle');

// Expect successful page deletion message
await expect( page.locator( '#message p' ) ).toHaveText(
'1 page moved to the Trash. Undo'
);
} );

test( 'restores page from trash', async ( { page, admin } ) => {
// Navigate to the Trash page
const trashLink = page.locator('li.trash a:has-text("Trash")');
await trashLink.click();

// Restore trashed page
await page.locator( '.column-primary.page-title' ).first().hover();
await page.locator( '.untrash' ).first().click();

// Expect restored page success message
await expect( page.locator( '#message p' ) ).toHaveText(
'1 page restored from the Trash. Edit Page'
);
} );
} );
Loading