From 4560f070d343bfc565c49714fbd183ba93b2b995 Mon Sep 17 00:00:00 2001 From: audrasjb Date: Thu, 4 Jun 2026 14:33:15 +0200 Subject: [PATCH 1/5] E2E test changes for #64952 --- src/js/_enqueues/wp/dashboard.js | 25 ++++++++++++++++++++++--- tests/e2e/specs/dashboard.test.js | 17 +++++++++++++---- 2 files changed, 35 insertions(+), 7 deletions(-) diff --git a/src/js/_enqueues/wp/dashboard.js b/src/js/_enqueues/wp/dashboard.js index 5216611d5dc3c..aea2dc4c5da25 100644 --- a/src/js/_enqueues/wp/dashboard.js +++ b/src/js/_enqueues/wp/dashboard.js @@ -137,14 +137,33 @@ jQuery( function($) { * @return {void} */ window.quickPressLoad = function() { - var act = $('#quickpost-action'), t; + var act = $( '#quickpost-action' ), t = $( '#quick-press' ), titleInput, contentInput; // Enable the submit buttons. $( '#quick-press .submit input[type="submit"], #quick-press .submit input[type="reset"]' ).prop( 'disabled' , false ); - t = $('#quick-press').on( 'submit', function( e ) { + titleInput = t.find( '#title' ); + contentInput = t.find( '#content' ); + + function validateAtLeastOne() { + var isFilled = titleInput.val().trim() || contentInput.val().trim(), + message = isFilled ? '' : wp.i18n.__( 'Please provide at least the title or the content.' ); + titleInput[0].setCustomValidity( message ); + contentInput[0].setCustomValidity( message ); + } + + t.on( 'input', validateAtLeastOne ); + + t.on( 'submit', function( e ) { e.preventDefault(); + // Don't submit if both the title and content are empty. + validateAtLeastOne(); + if ( ! e.target.checkValidity() ) { + e.target.reportValidity(); + return; + } + // Show a spinner. $('#dashboard_quick_press #publishing-action .spinner').show(); @@ -180,7 +199,7 @@ jQuery( function($) { // Change the QuickPost action to the publish value. $('#publish').on( 'click', function() { act.val( 'post-quickpress-publish' ); } ); - $('#quick-press').on( 'click focusin', function() { + t.on( 'click focusin', function() { wpActiveEditor = 'content'; }); diff --git a/tests/e2e/specs/dashboard.test.js b/tests/e2e/specs/dashboard.test.js index 90459ac83ae6f..bb5e17ecbd40c 100644 --- a/tests/e2e/specs/dashboard.test.js +++ b/tests/e2e/specs/dashboard.test.js @@ -45,16 +45,25 @@ test.describe( 'Quick Draft', () => { ).toContainText( 'Test Draft Title' ); } ); - test( 'Allows draft to be created without Title or Content', async ( { + test( 'Allows draft to be created with content but without Title', async ( { admin, page } ) => { await admin.visitAdminPage( '/' ); - // Wait for Save Draft button to appear and click it - const saveDraftButton = page.locator( + // Wait for Quick Draft content field to appear. + const draftContentField = page.locator( '#quick-press' - ).getByRole( 'button', { name: 'Save Draft' } ); + ).getByRole( 'textbox', { name: 'Content' } ); + + await expect( draftContentField ).toBeVisible(); + + // Focus and fill in a title. + await draftContentField.fill( 'Test Draft Content' ); + + // Navigate to Save Draft button and press it. + await page.keyboard.press( 'Tab' ); + await page.keyboard.press( 'Enter' ); await expect( saveDraftButton ).toBeVisible(); await saveDraftButton.click(); From 7131d2e9c090e767b0c373015deaaddd194a9317 Mon Sep 17 00:00:00 2001 From: audrasjb Date: Thu, 4 Jun 2026 14:42:47 +0200 Subject: [PATCH 2/5] Fix an issue in the E2E test changeset --- tests/e2e/specs/dashboard.test.js | 3 --- 1 file changed, 3 deletions(-) diff --git a/tests/e2e/specs/dashboard.test.js b/tests/e2e/specs/dashboard.test.js index bb5e17ecbd40c..67dad4cabb63a 100644 --- a/tests/e2e/specs/dashboard.test.js +++ b/tests/e2e/specs/dashboard.test.js @@ -65,9 +65,6 @@ test.describe( 'Quick Draft', () => { await page.keyboard.press( 'Tab' ); await page.keyboard.press( 'Enter' ); - await expect( saveDraftButton ).toBeVisible(); - await saveDraftButton.click(); - // Check that new draft appears in Your Recent Drafts section await expect( page.locator( '.drafts .draft-title' ).first().getByRole( 'link' ) From 398b6962815e1a6bfa663e3e08aa016ca142074b Mon Sep 17 00:00:00 2001 From: audrasjb Date: Thu, 4 Jun 2026 15:19:59 +0200 Subject: [PATCH 3/5] Small text change --- tests/e2e/specs/dashboard.test.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/e2e/specs/dashboard.test.js b/tests/e2e/specs/dashboard.test.js index 67dad4cabb63a..afaf165cdc4cc 100644 --- a/tests/e2e/specs/dashboard.test.js +++ b/tests/e2e/specs/dashboard.test.js @@ -45,7 +45,7 @@ test.describe( 'Quick Draft', () => { ).toContainText( 'Test Draft Title' ); } ); - test( 'Allows draft to be created with content but without Title', async ( { + test( 'Allows draft to be created with Content but without Title', async ( { admin, page } ) => { From 654ba50a397804ae5de57bd36f13f4d22355f0ce Mon Sep 17 00:00:00 2001 From: audrasjb Date: Thu, 4 Jun 2026 15:23:49 +0200 Subject: [PATCH 4/5] Add a new E2E test for post with Title but without Content --- tests/e2e/specs/dashboard.test.js | 33 +++++++++++++++++++++++++++++++ 1 file changed, 33 insertions(+) diff --git a/tests/e2e/specs/dashboard.test.js b/tests/e2e/specs/dashboard.test.js index afaf165cdc4cc..c6b1fda8ed5be 100644 --- a/tests/e2e/specs/dashboard.test.js +++ b/tests/e2e/specs/dashboard.test.js @@ -77,4 +77,37 @@ test.describe( 'Quick Draft', () => { page.locator( '.type-post.status-draft .title' ).first() ).toContainText( 'Untitled' ); } ); + + test( 'Allows draft to be created with Title but without Content', async ( { + admin, + page + } ) => { + await admin.visitAdminPage( '/' ); + + // Wait for Quick Draft title field to appear. + const draftContentField = page.locator( + '#quick-press' + ).getByRole( 'textbox', { name: 'Title' } ); + + await expect( draftContentField ).toBeVisible(); + + // Focus and fill in a title. + await draftContentField.fill( 'Test Draft Title' ); + + // Navigate to Save Draft button and press it. + await page.keyboard.press( 'Tab' ); + await page.keyboard.press( 'Enter' ); + + // Check that new draft appears in Your Recent Drafts section + await expect( + page.locator( '.drafts .draft-title' ).first().getByRole( 'link' ) + ).toHaveText( 'Test Draft Title' ); + + // Check that new draft appears in Posts page + await admin.visitAdminPage( '/edit.php' ); + + await expect( + page.locator( '.type-post.status-draft .title' ).first() + ).toContainText( 'Test Draft Title' ); + } ); } ); From 3477de1914482dccbead47b1fdae2af40076bcd2 Mon Sep 17 00:00:00 2001 From: audrasjb Date: Thu, 4 Jun 2026 15:47:01 +0200 Subject: [PATCH 5/5] Fix an issue with the new test --- tests/e2e/specs/dashboard.test.js | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/tests/e2e/specs/dashboard.test.js b/tests/e2e/specs/dashboard.test.js index c6b1fda8ed5be..45de845533e78 100644 --- a/tests/e2e/specs/dashboard.test.js +++ b/tests/e2e/specs/dashboard.test.js @@ -85,17 +85,18 @@ test.describe( 'Quick Draft', () => { await admin.visitAdminPage( '/' ); // Wait for Quick Draft title field to appear. - const draftContentField = page.locator( + const draftTitleField = page.locator( '#quick-press' ).getByRole( 'textbox', { name: 'Title' } ); - await expect( draftContentField ).toBeVisible(); + await expect( draftTitleField ).toBeVisible(); // Focus and fill in a title. - await draftContentField.fill( 'Test Draft Title' ); + await draftTitleField.fill( 'Test Draft Title' ); // Navigate to Save Draft button and press it. await page.keyboard.press( 'Tab' ); + await page.keyboard.press( 'Tab' ); await page.keyboard.press( 'Enter' ); // Check that new draft appears in Your Recent Drafts section