Commit 3ec26d663b5 for woocommerce

commit 3ec26d663b5f881fe18f49959b1a3a7b2d9d3c8e
Author: Pavel Dohnal <pavel.dohnal@automattic.com>
Date:   Thu Nov 26 09:13:02 2026 +0100

    Replace fixed delays with state checks in the reset E2E test (#71437)

    * Wait for the editor state instead of fixed delays in the reset E2E test

    The test slept 1 s after saving and 2 s after resetting: too short on a
    slow runner, wasted time on a fast one. It now waits for the Save button
    to be disabled after saving, and for the Actions button to be disabled
    after resetting, which happens once the template is no longer custom.

    * Wait for the editor to finish saving in the reset E2E test

    The email editor's own Save button keeps its label and is disabled while a
    save runs, so a disabled Save does not prove the save finished. Poll the
    editor store instead, as email-editor-settings-sidebar.spec.ts does.

    * Check the reset template E2E test against the server, not the editor

    The editor marks the template as reset before it deletes the custom copy,
    so the Actions button turned disabled even when the delete failed. Wait
    until the server serves the template as non-custom, then run the screen
    checks in their original order.

    * Share the wait-until-saved check between email editor E2E tests

    The reset and settings sidebar specs had the same poll on the editor
    store. Move it to waitForEditorSaved() in utils/email.ts, and update the
    changelog comment, as the reset step now checks the server.

diff --git a/plugins/woocommerce/changelog/email-editor-reset-template-e2e-waits b/plugins/woocommerce/changelog/email-editor-reset-template-e2e-waits
new file mode 100644
index 00000000000..8b7c116d04b
--- /dev/null
+++ b/plugins/woocommerce/changelog/email-editor-reset-template-e2e-waits
@@ -0,0 +1,3 @@
+Significance: patch
+Type: dev
+Comment: Replace fixed delays with state checks in the email template reset E2E test; tests only.
diff --git a/plugins/woocommerce/tests/e2e/tests/email-editor/email-editor-reset-template.spec.ts b/plugins/woocommerce/tests/e2e/tests/email-editor/email-editor-reset-template.spec.ts
index b88733a7e33..fc0eb6ad889 100644
--- a/plugins/woocommerce/tests/e2e/tests/email-editor/email-editor-reset-template.spec.ts
+++ b/plugins/woocommerce/tests/e2e/tests/email-editor/email-editor-reset-template.spec.ts
@@ -12,7 +12,7 @@ import {
 	disableEmailEditor,
 	resetWCTransactionalEmail,
 } from './helpers/enable-email-editor-feature';
-import { accessTheEmailEditor } from '../../utils/email';
+import { accessTheEmailEditor, waitForEditorSaved } from '../../utils/email';
 import { locks } from '../../fixtures/fixtures';

 /**
@@ -101,9 +101,7 @@ test.describe(
 				.getByRole( 'button', { name: 'Save', exact: true } )
 				.click();

-			// Wait for the save to complete
-			// eslint-disable-next-line playwright/no-wait-for-timeout -- wait for content to be saved
-			await page.waitForTimeout( 1000 );
+			await waitForEditorSaved( page );

 			// Verify the customization is present
 			await expect( editorFrame.getByText( uniqueText ) ).toBeVisible();
@@ -145,17 +143,24 @@ test.describe(
 				.getByRole( 'button', { name: 'Reset', exact: true } )
 				.click();

-			// Wait for the reset operation to complete
-			// eslint-disable-next-line playwright/no-wait-for-timeout -- wait for reset to complete
-			await page.waitForTimeout( 2000 );
+			// The editor marks the template as reset before the server deletes
+			// the custom copy, so wait for the server to serve the default one.
+			await expect
+				.poll( () =>
+					page.evaluate( async () => {
+						const id = window.wp.data
+							.select( 'core/editor' )
+							.getCurrentPostId();
+						const savedTemplate = await window.wp.apiFetch( {
+							path: `/wp/v2/templates/${ id }?context=edit`,
+						} );
+						return savedTemplate.source;
+					} )
+				)
+				.not.toBe( 'custom' );

 			// Verify the custom content is gone (template is reset)
-			const editorFrameAfterReset = page
-				.frameLocator( 'iframe[name="editor-canvas"]' )
-				.first();
-			await expect(
-				editorFrameAfterReset.getByText( uniqueText )
-			).toBeHidden();
+			await expect( editorFrame.getByText( uniqueText ) ).toBeHidden();

 			// Verify Save button is disabled (no changes to save)
 			await expect(
diff --git a/plugins/woocommerce/tests/e2e/tests/email-editor/email-editor-settings-sidebar.spec.ts b/plugins/woocommerce/tests/e2e/tests/email-editor/email-editor-settings-sidebar.spec.ts
index e59d86b36e9..cdd828a5960 100644
--- a/plugins/woocommerce/tests/e2e/tests/email-editor/email-editor-settings-sidebar.spec.ts
+++ b/plugins/woocommerce/tests/e2e/tests/email-editor/email-editor-settings-sidebar.spec.ts
@@ -16,6 +16,7 @@ import {
 	accessTheEmailEditor,
 	ensureEmailEditorSettingsPanelIsOpened,
 	openEmailPostInEditor,
+	waitForEditorSaved,
 } from '../../utils/email';
 import { locks } from '../../fixtures/fixtures';

@@ -71,17 +72,7 @@ test.describe(
 			await expect(
 				page.locator( '.editor-post-status__toggle' )
 			).toContainText( 'Inactive' );
-			await expect
-				.poll( () =>
-					page.evaluate( () => {
-						const editor = window.wp.data.select( 'core/editor' );
-						return (
-							! editor.isSavingPost() &&
-							! editor.isEditedPostDirty()
-						);
-					} )
-				)
-				.toBe( true );
+			await waitForEditorSaved( page );
 			await page.reload();
 			await expect(
 				page.locator( '.editor-post-status__toggle' )
diff --git a/plugins/woocommerce/tests/e2e/utils/email.ts b/plugins/woocommerce/tests/e2e/utils/email.ts
index e7b0a83ce07..857751ec145 100644
--- a/plugins/woocommerce/tests/e2e/utils/email.ts
+++ b/plugins/woocommerce/tests/e2e/utils/email.ts
@@ -162,3 +162,19 @@ export async function ensureEmailEditorSettingsPanelIsOpened( page: Page ) {
 			.click();
 	}
 }
+
+/**
+ * Waits until the editor has finished saving and nothing is left to save.
+ *
+ * @param page The Playwright page.
+ */
+export async function waitForEditorSaved( page: Page ) {
+	await expect
+		.poll( () =>
+			page.evaluate( () => {
+				const editor = window.wp.data.select( 'core/editor' );
+				return ! editor.isSavingPost() && ! editor.isEditedPostDirty();
+			} )
+		)
+		.toBe( true );
+}