Skip to content
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
42 changes: 42 additions & 0 deletions packages/e2e-tests/specs/misc/settings.test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
/**
* WordPress dependencies
*/
import { visitAdminPage } from '@wordpress/e2e-test-utils';

async function getOptionsValues( selector ) {
await visitAdminPage( 'options.php' );
return page.evaluate( ( theSelector ) => {
const inputs = Array.from( document.querySelectorAll( theSelector ) );
return inputs.reduce( ( memo, input ) => {
memo[ input.id ] = input.value;
return memo;
}, {} );
}, 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 () => {
// 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'
);
await page.click( 'input#submit' );

const optionsAfter = await getOptionsValues( optionsInputsSelector );

Object.entries( optionsBefore ).forEach( ( optionBefore ) => {
const [ id ] = optionBefore;
const optionAfter = [ id, optionsAfter[ id ] ];
expect( optionAfter ).toStrictEqual( optionBefore );
} );
} );
} );