Skip to content

Commit

Permalink
Add e2e test
Browse files Browse the repository at this point in the history
  • Loading branch information
youknowriad committed Dec 9, 2024
1 parent 8864ea3 commit 5c561f0
Showing 1 changed file with 56 additions and 0 deletions.
56 changes: 56 additions & 0 deletions test/e2e/specs/site-editor/page-list.spec.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
/**
* WordPress dependencies
*/
const { test, expect } = require( '@wordpress/e2e-test-utils-playwright' );

test.describe( 'Page List', () => {
test.beforeAll( async ( { requestUtils } ) => {
// Activate a theme with permissions to access the site editor.
await requestUtils.activateTheme( 'emptytheme' );
await requestUtils.createPage( {
title: 'Privacy Policy',
status: 'publish',
} );
await requestUtils.createPage( {
title: 'Sample Page',
status: 'publish',
} );
} );

test.afterAll( async ( { requestUtils } ) => {
// Go back to the default theme.
await Promise.all( [
requestUtils.activateTheme( 'twentytwentyone' ),
requestUtils.deleteAllPages(),
] );
} );

test.beforeEach( async ( { admin, page } ) => {
// Go to the pages page, as it has the list layout enabled by default.
await admin.visitSiteEditor();
await page.getByRole( 'button', { name: 'Pages' } ).click();
} );

test( 'Persists filter/search when switching layout', async ( {
page,
} ) => {
// Search pages
await page
.getByRole( 'searchbox', { name: 'Search' } )
.fill( 'Privacy' );

// Switch layout
await page.getByRole( 'button', { name: 'Layout' } ).click();
await page.getByRole( 'menuitemradio', { name: 'Table' } ).click();

// Confirm the table is visible
await expect( page.getByRole( 'table' ) ).toContainText(
'Privacy Policy'
);

// The search should still contain the search term
await expect(
page.getByRole( 'searchbox', { name: 'Search' } )
).toHaveValue( 'Privacy' );
} );
} );

0 comments on commit 5c561f0

Please sign in to comment.