Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Migrate 'meta-attribute-block' e2e tests to Playwright #55830

Merged
merged 3 commits into from
Nov 6, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view

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' );
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm wondering if typing immediately after inserting a block can potentially be flaky since we don't have a promise ensuring the block is there and focused (AFAIR there were issues with that before!). What if we returned the inserted block locator from the createBlock so that we can do a simple await expect( block ).toBeFocused()? I've drafted an implementation in #55851.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Would look more less like this:

const paragraph = await editor.insertBlock( { name: 'core/paragraph' } );
await expect( paragraph ).toBeFocused();
await page.keyboard.type( 'Howdy hoo!');

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This should be okay. The editor will automatically focus first focusable element in newly inserted block.

Copy link
Member

@WunderBart WunderBart Nov 6, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is the block insertion synchronous, though? I can see that, e.g., window.wp.data.dispatch( 'core/block-editor' ).insertBlock( x ) returns a promise but we're not really awaiting it 🤔

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Right, maybe we should await that. @kevin940726, WDYY?

I'll keep an eye on the flaky reports for this test, just in case.


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