From 584b5cfb51859fa2b5346f18c7e342d2fca37ce6 Mon Sep 17 00:00:00 2001
From: George Mamadashvili <georgemamadashvili@gmail.com>
Date: Fri, 3 Nov 2023 12:03:14 +0400
Subject: [PATCH 1/3] Migrate 'meta-attribute-block' e2e tests to Playwright

---
 .../plugins/meta-attribute-block.spec.js      | 100 ++++++++++++++++++
 1 file changed, 100 insertions(+)
 create mode 100644 test/e2e/specs/editor/plugins/meta-attribute-block.spec.js

diff --git a/test/e2e/specs/editor/plugins/meta-attribute-block.spec.js b/test/e2e/specs/editor/plugins/meta-attribute-block.spec.js
new file mode 100644
index 00000000000000..1dcfa3ad50e738
--- /dev/null
+++ b/test/e2e/specs/editor/plugins/meta-attribute-block.spec.js
@@ -0,0 +1,100 @@
+/**
+ * WordPress dependencies
+ */
+const { test, expect } = require( '@wordpress/e2e-test-utils-playwright' );
+
+const VARIATIONS = [
+	[ 'Early Registration', 'test/test-meta-attribute-block-early' ],
+	[ 'Late Registration', 'test/test-meta-attribute-block-late' ],
+];
+
+test.describe( 'Block with a meta attribute', () => {
+	test.beforeAll( async ( { requestUtils } ) => {
+		await requestUtils.activatePlugin( 'gutenberg-test-block-context' );
+	} );
+
+	test.afterAll( async ( { requestUtils } ) => {
+		await requestUtils.deactivatePlugin( 'gutenberg-test-block-context' );
+	} );
+
+	for ( const [ title, blockName ] of VARIATIONS ) {
+		test.describe( title, () => {
+			test( 'Should persist the meta attribute properly', async ( {
+				admin,
+				editor,
+				page,
+				pageUtils,
+			} ) => {
+				await admin.createNewPost();
+				await editor.insertBlock( { name: blockName } );
+				await page.keyboard.type( 'Value' );
+
+				// Regression Test: Previously the caret would wrongly reset to the end
+				// of any input for meta-sourced attributes, due to syncing behavior of
+				// meta attribute updates.
+				//
+				// See: https://github.com/WordPress/gutenberg/issues/15739
+				await pageUtils.pressKeys( 'ArrowLeft', { times: 5 } );
+				await page.keyboard.type( 'Meta ' );
+
+				await editor.saveDraft();
+				await page.reload();
+
+				const block = page.getByRole( 'document', {
+					name: `Block: Test Meta Attribute Block (${ title })`,
+				} );
+				await expect( block ).toBeVisible();
+				await expect( block.locator( '.my-meta-input' ) ).toHaveValue(
+					'Meta Value'
+				);
+			} );
+
+			test( 'Should use the same value in all the blocks', async ( {
+				admin,
+				editor,
+				page,
+			} ) => {
+				await admin.createNewPost();
+				await editor.insertBlock( { name: blockName } );
+				await editor.insertBlock( { name: blockName } );
+				await editor.insertBlock( { name: blockName } );
+				await page.keyboard.type( 'Meta Value' );
+
+				const inputs = await page.locator( '.my-meta-input' ).all();
+				for ( const input of inputs ) {
+					await expect( input ).toHaveValue( 'Meta Value' );
+				}
+			} );
+
+			test( 'Should persist the meta attribute properly in a different post type', async ( {
+				admin,
+				editor,
+				page,
+				pageUtils,
+			} ) => {
+				await admin.createNewPost( { postType: 'page' } );
+				await editor.insertBlock( { name: blockName } );
+				await page.keyboard.type( 'Value' );
+
+				// Regression Test: Previously the caret would wrongly reset to the end
+				// of any input for meta-sourced attributes, due to syncing behavior of
+				// meta attribute updates.
+				//
+				// See: https://github.com/WordPress/gutenberg/issues/15739
+				await pageUtils.pressKeys( 'ArrowLeft', { times: 5 } );
+				await page.keyboard.type( 'Meta ' );
+
+				await editor.saveDraft();
+				await page.reload();
+
+				const block = page.getByRole( 'document', {
+					name: `Block: Test Meta Attribute Block (${ title })`,
+				} );
+				await expect( block ).toBeVisible();
+				await expect( block.locator( '.my-meta-input' ) ).toHaveValue(
+					'Meta Value'
+				);
+			} );
+		} );
+	}
+} );

From a52cbc707ba50d8e0236f7b7f2e1399680c445f5 Mon Sep 17 00:00:00 2001
From: George Mamadashvili <georgemamadashvili@gmail.com>
Date: Fri, 3 Nov 2023 12:03:48 +0400
Subject: [PATCH 2/3] Remove old test files

---
 .../meta-attribute-block.test.js.snap         |   9 --
 .../plugins/meta-attribute-block.test.js      | 100 ------------------
 2 files changed, 109 deletions(-)
 delete mode 100644 packages/e2e-tests/specs/editor/plugins/__snapshots__/meta-attribute-block.test.js.snap
 delete mode 100644 packages/e2e-tests/specs/editor/plugins/meta-attribute-block.test.js

diff --git a/packages/e2e-tests/specs/editor/plugins/__snapshots__/meta-attribute-block.test.js.snap b/packages/e2e-tests/specs/editor/plugins/__snapshots__/meta-attribute-block.test.js.snap
deleted file mode 100644
index 268c8b45d059f2..00000000000000
--- a/packages/e2e-tests/specs/editor/plugins/__snapshots__/meta-attribute-block.test.js.snap
+++ /dev/null
@@ -1,9 +0,0 @@
-// Jest Snapshot v1, https://goo.gl/fbAQLP
-
-exports[`Block with a meta attribute Early Registration Should persist the meta attribute properly 1`] = `"<!-- wp:test/test-meta-attribute-block-early /-->"`;
-
-exports[`Block with a meta attribute Early Registration Should persist the meta attribute properly in a different post type 1`] = `"<!-- wp:test/test-meta-attribute-block-early /-->"`;
-
-exports[`Block with a meta attribute Late Registration Should persist the meta attribute properly 1`] = `"<!-- wp:test/test-meta-attribute-block-late /-->"`;
-
-exports[`Block with a meta attribute Late Registration Should persist the meta attribute properly in a different post type 1`] = `"<!-- wp:test/test-meta-attribute-block-late /-->"`;
diff --git a/packages/e2e-tests/specs/editor/plugins/meta-attribute-block.test.js b/packages/e2e-tests/specs/editor/plugins/meta-attribute-block.test.js
deleted file mode 100644
index a95d11b4f7dadb..00000000000000
--- a/packages/e2e-tests/specs/editor/plugins/meta-attribute-block.test.js
+++ /dev/null
@@ -1,100 +0,0 @@
-/**
- * WordPress dependencies
- */
-import {
-	activatePlugin,
-	createNewPost,
-	deactivatePlugin,
-	getEditedPostContent,
-	insertBlock,
-	saveDraft,
-	pressKeyTimes,
-} from '@wordpress/e2e-test-utils';
-
-describe( 'Block with a meta attribute', () => {
-	beforeAll( async () => {
-		await activatePlugin( 'gutenberg-test-meta-attribute-block' );
-	} );
-
-	beforeEach( async () => {
-		await createNewPost();
-	} );
-
-	afterAll( async () => {
-		await deactivatePlugin( 'gutenberg-test-meta-attribute-block' );
-	} );
-
-	describe.each( [ [ 'Early Registration' ], [ 'Late Registration' ] ] )(
-		'%s',
-		( variant ) => {
-			it( 'Should persist the meta attribute properly', async () => {
-				await insertBlock( `Test Meta Attribute Block (${ variant })` );
-				await page.keyboard.type( 'Value' );
-
-				// Regression Test: Previously the caret would wrongly reset to the end
-				// of any input for meta-sourced attributes, due to syncing behavior of
-				// meta attribute updates.
-				//
-				// See: https://github.com/WordPress/gutenberg/issues/15739
-				await pressKeyTimes( 'ArrowLeft', 5 );
-				await page.keyboard.type( 'Meta ' );
-
-				await saveDraft();
-				await page.reload();
-				await page.waitForSelector( '.edit-post-layout' );
-
-				expect( await getEditedPostContent() ).toMatchSnapshot();
-				const persistedValue = await page.evaluate(
-					() => document.querySelector( '.my-meta-input' ).value
-				);
-				expect( persistedValue ).toBe( 'Meta Value' );
-			} );
-
-			it( 'Should use the same value in all the blocks', async () => {
-				await insertBlock( `Test Meta Attribute Block (${ variant })` );
-				await insertBlock( `Test Meta Attribute Block (${ variant })` );
-				await insertBlock( `Test Meta Attribute Block (${ variant })` );
-				await page.keyboard.type( 'Meta Value' );
-
-				const inputs = await page.$$( '.my-meta-input' );
-				await Promise.all(
-					inputs.map( async ( input ) => {
-						// Clicking the input selects the block,
-						// and selecting the block enables the sync data mode
-						// as otherwise the asynchronous re-rendering of unselected blocks
-						// may cause the input to have not yet been updated for the other blocks.
-						await input.click();
-						const inputValue = await input.getProperty( 'value' );
-						expect( await inputValue.jsonValue() ).toBe(
-							'Meta Value'
-						);
-					} )
-				);
-			} );
-
-			it( 'Should persist the meta attribute properly in a different post type', async () => {
-				await createNewPost( { postType: 'page' } );
-				await insertBlock( `Test Meta Attribute Block (${ variant })` );
-				await page.keyboard.type( 'Value' );
-
-				// Regression Test: Previously the caret would wrongly reset to the end
-				// of any input for meta-sourced attributes, due to syncing behavior of
-				// meta attribute updates.
-				//
-				// See: https://github.com/WordPress/gutenberg/issues/15739
-				await pressKeyTimes( 'ArrowLeft', 5 );
-				await page.keyboard.type( 'Meta ' );
-
-				await saveDraft();
-				await page.reload();
-				await page.waitForSelector( '.edit-post-layout' );
-
-				expect( await getEditedPostContent() ).toMatchSnapshot();
-				const persistedValue = await page.evaluate(
-					() => document.querySelector( '.my-meta-input' ).value
-				);
-				expect( persistedValue ).toBe( 'Meta Value' );
-			} );
-		}
-	);
-} );

From 79efbefa819fb2baa2f28cfc5a8fb0aa445184aa Mon Sep 17 00:00:00 2001
From: George Mamadashvili <georgemamadashvili@gmail.com>
Date: Fri, 3 Nov 2023 13:13:38 +0400
Subject: [PATCH 3/3] Fix plugin name

---
 .../e2e/specs/editor/plugins/meta-attribute-block.spec.js | 8 ++++++--
 1 file changed, 6 insertions(+), 2 deletions(-)

diff --git a/test/e2e/specs/editor/plugins/meta-attribute-block.spec.js b/test/e2e/specs/editor/plugins/meta-attribute-block.spec.js
index 1dcfa3ad50e738..f11d59b39dc6d8 100644
--- a/test/e2e/specs/editor/plugins/meta-attribute-block.spec.js
+++ b/test/e2e/specs/editor/plugins/meta-attribute-block.spec.js
@@ -10,11 +10,15 @@ const VARIATIONS = [
 
 test.describe( 'Block with a meta attribute', () => {
 	test.beforeAll( async ( { requestUtils } ) => {
-		await requestUtils.activatePlugin( 'gutenberg-test-block-context' );
+		await requestUtils.activatePlugin(
+			'gutenberg-test-meta-attribute-block'
+		);
 	} );
 
 	test.afterAll( async ( { requestUtils } ) => {
-		await requestUtils.deactivatePlugin( 'gutenberg-test-block-context' );
+		await requestUtils.deactivatePlugin(
+			'gutenberg-test-meta-attribute-block'
+		);
 	} );
 
 	for ( const [ title, blockName ] of VARIATIONS ) {