Skip to content

Commit

Permalink
Migrate 'core settings' e2e tests to Playwright (#57581)
Browse files Browse the repository at this point in the history
* Migrate 'core-settings' e2e tests to Playwright
* renamed test file
* Added role based selectors
  • Loading branch information
fai-sal authored Jan 10, 2024
1 parent d3f2c77 commit 7c21100
Showing 1 changed file with 23 additions and 13 deletions.
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
/**
* WordPress dependencies
*/
import { visitAdminPage } from '@wordpress/e2e-test-utils';
const { test, expect } = require( '@wordpress/e2e-test-utils-playwright' );

async function getOptionsValues( selector ) {
await visitAdminPage( 'options.php' );
async function getOptionsValues( selector, admin, page ) {
await admin.visitAdminPage( 'options.php' );
return page.evaluate( ( theSelector ) => {
const inputs = Array.from( document.querySelectorAll( theSelector ) );
return inputs.reduce( ( memo, input ) => {
Expand All @@ -16,22 +16,32 @@ async function getOptionsValues( selector ) {

// It might make sense to include a similar test in WP core (or move this one over).
// See discussion here: https://github.com/WordPress/gutenberg/pull/32797#issuecomment-864192088.
describe( 'Settings', () => {
test( 'Regression: updating a specific option will only change its value and will not corrupt others', async () => {
test.describe( 'Settings', () => {
test( 'Regression: updating a specific option will only change its value and will not corrupt others', async ( {
page,
admin,
} ) => {
// We won't select the option that we updated and will also remove some
// _transient options that seem to change at every update.
const optionsInputsSelector =
'form#all-options table.form-table input:not([id*="_transient"]):not([id="blogdescription"])';
const optionsBefore = await getOptionsValues( optionsInputsSelector );

await visitAdminPage( 'options-general.php' );
await page.type(
'input#blogdescription',
'Just another Gutenberg site'
const optionsBefore = await getOptionsValues(
optionsInputsSelector,
admin,
page
);
await page.click( 'input#submit' );

const optionsAfter = await getOptionsValues( optionsInputsSelector );
await admin.visitAdminPage( 'options-general.php' );
await page
.getByRole( 'textbox', { name: 'Tagline' } )
.fill( 'Just another Gutenberg site' );
await page.getByRole( 'button', { name: 'Save Changes' } ).click();

const optionsAfter = await getOptionsValues(
optionsInputsSelector,
admin,
page
);

Object.entries( optionsBefore ).forEach( ( optionBefore ) => {
const [ id ] = optionBefore;
Expand Down

0 comments on commit 7c21100

Please sign in to comment.