Skip to content

Commit

Permalink
Add Playwright E2E test to trash and restore page from trash
Browse files Browse the repository at this point in the history
  • Loading branch information
juhi123 committed Dec 27, 2024
1 parent 20110f6 commit 401210d
Showing 1 changed file with 65 additions and 0 deletions.
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'
);
} );
} );

0 comments on commit 401210d

Please sign in to comment.