Skip to content

Commit 5d1423f

Browse files
committed
Correct the TinyMCE-initialization fix: the real bug was a wrong button-name selector.
The previous commit ported `WordPress#78631`'s TinyMCE initialization wait, on the assumption the failure was a race between the meta box's TinyMCE iframe appearing and the editor finishing initialization. Verified against real CI, that fix did not resolve the failure: it still timed out at the same `role=button[name="Code"i]` click, now after the added `waitForFunction` had already resolved successfully. The actual cause is a button-label mismatch, unrelated to any timing race. The "Code"/"Text" toggle is rendered by WordPress Core's `wp_editor()` (`wp-includes/class-wp-editor.php`), and `wp-env`'s pinned core for this branch, `WordPress/WordPress#6.7-branch`, still ships the string `_x( 'Text', 'Name for the Text editor tab (formerly HTML)' )`. Core renamed this label to "Code" only on its own `master` branch (`_x( 'Code', 'Name for the Code editor tab (formerly Text)' )`) after `6.7-branch` was cut, and never backported the wording change to the maintenance branch. Screenshots from every failed run (the original cited run and the one testing the previous, ineffective commit) confirm the rendered button reads "Text", not "Code". The underlying behavior is identical either way, so using the correct label is a like-for-like change, not a weakened assertion. The Gutenberg plugin's own trunk renamed this locator from "Text" to "Code" in `WordPress#68872`/`WordPress#68886` (Jan 2025), correctly following its own trunk's newer bundled/tested core. That rename doesn't apply on `wp/6.7`, whose `wp-env` config intentionally pins to the matching `6.7-branch` core, so this reverts the locator back to "Text" for this branch and drops the TinyMCE-`waitForFunction` addition along with it, since the original iframe-existence wait was never the actual problem: the failure was 100% reproducible, not intermittent, which is what a hard-coded wrong locator produces and a genuine race condition would not.
1 parent ae0cdd2 commit 5d1423f

1 file changed

Lines changed: 6 additions & 13 deletions

File tree

‎test/e2e/specs/editor/plugins/wp-editor-meta-box.spec.js‎

Lines changed: 6 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -24,24 +24,17 @@ test.describe( 'WP Editor Meta Boxes', () => {
2424
.locator( 'role=textbox[name="Add title"i]' )
2525
.type( 'Hello Meta' );
2626

27-
// Switch to Visual mode and wait for TinyMCE to fully initialize.
28-
// This ensures getSelection() won't return null when TinyMCE tries
29-
// to restore cursor position during subsequent mode switches.
30-
await page.locator( 'role=button[name="Visual"i]' ).click();
31-
await page.waitForFunction(
32-
() => window.tinyMCE?.get( 'test_tinymce_id' )?.initialized
33-
);
27+
// Switch tinymce to Text mode, first waiting for it to initialize
28+
// because otherwise it will flip back to Visual mode once initialized.
29+
await page.locator( '#test_tinymce_id_ifr' ).waitFor();
30+
await page.locator( 'role=button[name="Text"i]' ).click();
3431

35-
// Switch to Code mode and type into the textarea.
36-
await page.locator( 'role=button[name="Code"i]' ).click();
32+
// Type something in the tinymce Text mode textarea.
3733
const metaBoxField = page.locator( '#test_tinymce_id' );
3834
await metaBoxField.type( 'Typing in a metabox' );
3935

40-
// Switch back to Visual mode and wait for re-initialization.
36+
// Switch tinymce back to Visual mode.
4137
await page.locator( 'role=button[name="Visual"i]' ).click();
42-
await page.waitForFunction(
43-
() => window.tinyMCE?.get( 'test_tinymce_id' )?.initialized
44-
);
4538

4639
await editor.publishPost();
4740
await page.reload();

0 commit comments

Comments
 (0)