Skip to content
Merged
Show file tree
Hide file tree
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
3 changes: 1 addition & 2 deletions packages/fields/src/actions/reorder-page.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -35,8 +35,7 @@ interface Action< Item > {
function isItemValid( item: BasePost ): boolean {
return (
typeof item.menu_order === 'number' &&
Number.isInteger( item.menu_order ) &&
item.menu_order > 0
Number.isInteger( item.menu_order )
);
}

Expand Down
72 changes: 72 additions & 0 deletions test/e2e/specs/site-editor/pages.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -321,4 +321,76 @@ test.describe( 'Pages', () => {
.getByText( 'Change template' )
).toBeDisabled();
} );

// Regression test for https://github.com/WordPress/gutenberg/issues/73820
test( 'should allow setting page order to zero and negative values', async ( {
admin,
page,
requestUtils,
} ) => {
// Create a published page for testing
await requestUtils.createPage( {
title: 'Order Test Page',
status: 'publish',
} );

await admin.visitSiteEditor();
await page.getByRole( 'button', { name: 'Pages' } ).click();

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

// Open actions menu for the test page
let row = page.getByRole( 'row', { name: /Order Test Page/ } );
await row.getByRole( 'button', { name: 'Actions' } ).click();

// Click on Order action
await page.getByRole( 'menuitem', { name: 'Order' } ).click();

// Get the order input and save button
let orderInput = page.getByRole( 'spinbutton', { name: 'Order' } );
const saveButton = page.getByRole( 'button', { name: 'Save' } );

// Test that 0 is valid
await orderInput.fill( '0' );
await expect( saveButton ).toBeEnabled();

// Test that negative values are valid
await orderInput.fill( '-1' );
await expect( saveButton ).toBeEnabled();

await orderInput.fill( '-100' );
await expect( saveButton ).toBeEnabled();

// Test that positive values are still valid
await orderInput.fill( '5' );
await expect( saveButton ).toBeEnabled();

// Save with a negative value to verify it persists
await orderInput.fill( '-5' );
await saveButton.click();

// Verify success notice
await expect(
page.locator(
'role=button[name="Dismiss this notice"i] >> text="Order updated."'
)
).toBeVisible();

// Reload the page to verify the value persisted
await admin.visitSiteEditor();
await page.getByRole( 'button', { name: 'Pages' } ).click();
await page.getByRole( 'button', { name: 'Layout' } ).click();
await page.getByRole( 'menuitemradio', { name: 'Table' } ).click();

// Open Order action again for the same page
row = page.getByRole( 'row', { name: /Order Test Page/ } );
await row.getByRole( 'button', { name: 'Actions' } ).click();
await page.getByRole( 'menuitem', { name: 'Order' } ).click();

// Verify the negative value was persisted
orderInput = page.getByRole( 'spinbutton', { name: 'Order' } );
await expect( orderInput ).toHaveValue( '-5' );
} );
} );
Loading