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

Migrate 'core settings' e2e tests to Playwright #57581

Merged
merged 4 commits into from
Jan 10, 2024
Merged
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
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
Loading