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 'block context' e2e tests to Playwright #55793

Merged
merged 2 commits into from
Nov 2, 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
2 changes: 1 addition & 1 deletion packages/e2e-tests/plugins/block-context.php
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ function gutenberg_test_register_context_blocks() {
$block->context['postType'],
);

return implode( ',', $ordered_context );
return '<p>' . implode( ',', $ordered_context ) . '</p>';
},
'editor_script_handles' => array( 'gutenberg-test-block-context' ),
)
Expand Down
84 changes: 0 additions & 84 deletions packages/e2e-tests/specs/editor/plugins/block-context.test.js

This file was deleted.

78 changes: 78 additions & 0 deletions test/e2e/specs/editor/plugins/block-context.spec.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,78 @@
/**
* WordPress dependencies
*/
const { test, expect } = require( '@wordpress/e2e-test-utils-playwright' );

test.describe( 'Block context', () => {
test.beforeAll( async ( { requestUtils } ) => {
await requestUtils.activatePlugin( 'gutenberg-test-block-context' );
} );

test.beforeEach( async ( { admin } ) => {
await admin.createNewPost();
} );

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

test( 'Block context propagates to inner blocks', async ( {
editor,
page,
} ) => {
await editor.insertBlock( { name: 'gutenberg/test-context-provider' } );

const providerBlock = page.getByRole( 'document', {
name: 'Block: Test Context Provider',
} );
const consumerBlock = page.getByRole( 'document', {
name: 'Block: Test Context Consumer',
} );

await expect( consumerBlock ).toBeVisible();

// Verify initial contents of consumer.
await expect( consumerBlock ).toHaveText( 'The record ID is: 0' );

// Change the attribute value associated with the context.
await providerBlock.getByRole( 'textbox' ).fill( '123' );

await expect( consumerBlock ).toHaveText( 'The record ID is: 123' );
} );

test( 'Block context is reflected in the preview', async ( {
editor,
page,
} ) => {
const editorPage = page;

await editor.insertBlock( { name: 'gutenberg/test-context-provider' } );

// Open the preview page.
const previewPage = await editor.openPreviewPage();
const previewContent = previewPage.locator( '.entry-content p' );

await expect( previewContent ).toHaveText( /^0,\d+,post$/ );

// Return to editor to change context value to non-default.
await editorPage.bringToFront();
await editorPage
.getByRole( 'document', {
name: 'Block: Test Context Provider',
} )
.getByRole( 'textbox' )
.fill( '123' );

await editorPage
.getByRole( 'button', { name: 'Preview', expanded: false } )
.click();
await editorPage
.getByRole( 'menuitem', { name: 'Preview in new tab' } )
.click();

// Check non-default context values are populated.
await expect( previewContent ).toHaveText( /^123,\d+,post$/ );
await editorPage.bringToFront();
await previewPage.close();
} );
} );
Loading