Skip to content

Commit

Permalink
Add Playwright e2e test for preview a page
Browse files Browse the repository at this point in the history
  • Loading branch information
jayson31 committed Dec 5, 2024
1 parent 27c566f commit a4d94d0
Showing 1 changed file with 49 additions and 0 deletions.
49 changes: 49 additions & 0 deletions tests/e2e/specs/pages/preview-page.test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
/**
* WordPress dependencies
*/
const { test, expect } = require( '@wordpress/e2e-test-utils-playwright' );

test.describe( 'Preview page', () => {
test.beforeEach( async ( { admin, editor, requestUtils } ) => {
requestUtils.deleteAllPages();

await admin.createNewPost( { postType: 'page', title: 'qa page' } );

Check failure on line 10 in tests/e2e/specs/pages/preview-page.test.js

View workflow job for this annotation

GitHub Actions / Test with SCRIPT_DEBUG disabled / Run E2E tests

[chromium] › pages/preview-page.test.js:16:2 › Preview page › Should be able to preview page in different viewport

2) [chromium] › pages/preview-page.test.js:16:2 › Preview page › Should be able to preview page in different viewport Error: Not logged in 8 | requestUtils.deleteAllPages(); 9 | > 10 | await admin.createNewPost( { postType: 'page', title: 'qa page' } ); | ^ 11 | 12 | // publish post 13 | await editor.publishPost(); 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/pages/preview-page.test.js:10:3

// publish post
await editor.publishPost();
} );

test( 'Should be able to preview page in different viewport', async ( {
page,
admin,
} ) => {
await admin.visitAdminPage( '/edit.php?post_type=page' );

await page.getByRole( 'link', { name: '“qa page” (Edit)' } ).click();

// Click Preview button
await page.getByRole( 'button', { name: 'View', exact: true } ).click();

//Check for tablet preview
await page.getByRole( 'menuitemradio', { name: 'Tablet' } ).click();
await expect( page.isVisible( '.is-tablet-preview' ) ).toBeTruthy();

//Check for Mobile preview
await page.getByRole( 'menuitemradio', { name: 'Mobile' } ).click();
await expect( page.isVisible( '.is-mobile-preview' ) ).toBeTruthy();

// Check for Desktop preview
await page.getByRole( 'menuitemradio', { name: 'Desktop' } ).click();
await expect( page.isVisible( '.is-mobile-preview' ) ).toBeTruthy();

// click on the preview in new tab link and wait for new tab to be triggered
const [ newPage ] = await Promise.all( [
page.waitForEvent( 'popup' ),
page.locator( 'text=Preview in new tab' ).click(),
] );

// wait for the new page to load and validate the URL
await newPage.waitForLoadState();
await expect( newPage ).toHaveURL( /preview=true/ );
} );
} );

0 comments on commit a4d94d0

Please sign in to comment.