Skip to content

Commit

Permalink
Migrate 'meta-attribute-block' e2e tests to Playwright (WordPress#55830)
Browse files Browse the repository at this point in the history
* Migrate 'meta-attribute-block' e2e tests to Playwright

* Remove old test files

* Fix plugin name
  • Loading branch information
Mamaduka authored Nov 6, 2023
1 parent 7d93901 commit ce3ef3e
Show file tree
Hide file tree
Showing 3 changed files with 104 additions and 109 deletions.

This file was deleted.

100 changes: 0 additions & 100 deletions packages/e2e-tests/specs/editor/plugins/meta-attribute-block.test.js

This file was deleted.

104 changes: 104 additions & 0 deletions test/e2e/specs/editor/plugins/meta-attribute-block.spec.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,104 @@
/**
* 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-meta-attribute-block'
);
} );

test.afterAll( async ( { requestUtils } ) => {
await requestUtils.deactivatePlugin(
'gutenberg-test-meta-attribute-block'
);
} );

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'
);
} );
} );
}
} );

0 comments on commit ce3ef3e

Please sign in to comment.