Skip to content

Commit

Permalink
E2E Tests: Re-enable block context testing
Browse files Browse the repository at this point in the history
With testing of availability of default post contxt
  • Loading branch information
aduth committed May 6, 2020
1 parent 9a837f3 commit 06551c4
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 15 deletions.
18 changes: 11 additions & 7 deletions packages/e2e-tests/plugins/block-context.php
Original file line number Diff line number Diff line change
Expand Up @@ -47,15 +47,19 @@ function gutenberg_test_register_context_blocks() {
register_block_type(
'gutenberg/test-context-consumer',
array(
'context' => array( 'gutenberg/recordId' ),
'context' => array(
'gutenberg/recordId',
'postId',
'postType',
),
'render_callback' => function( $attributes, $content, $block ) {
$record_id = $block->context['gutenberg/recordId'];

if ( ! is_int( $record_id ) ) {
throw new Exception( 'Expected numeric recordId' );
}
$ordered_context = array(
$block->context['gutenberg/recordId'],
$block->context['postId'],
$block->context['postType'],
);

return 'The record ID is: ' . filter_var( $record_id, FILTER_VALIDATE_INT );
return implode( ',', $ordered_context );
},
)
);
Expand Down
11 changes: 3 additions & 8 deletions packages/e2e-tests/specs/editor/plugins/block-context.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -70,12 +70,7 @@ describe( 'Block context', () => {
expect( innerBlockText ).toBe( 'The record ID is: 123' );
} );

// Disable reason: Block context PHP implementation is temporarily reverted.
// This will be unskipped once the implementation is restored. Skipping was
// the most direct option for revert given time constraints.

/* eslint-disable-next-line jest/no-disabled-tests */
test.skip( 'Block context is reflected in the preview', async () => {
test( 'Block context is reflected in the preview', async () => {
await insertBlock( 'Test Context Provider' );
const editorPage = page;
const previewPage = await openPreviewPage( editorPage );
Expand All @@ -85,7 +80,7 @@ describe( 'Block context', () => {
'.entry-content',
( contentWrapper ) => contentWrapper.textContent.trim()
);
expect( content ).toBe( 'The record ID is: 0' );
expect( content ).toMatch( /^0,\d+,post$/ );

// Return to editor to change context value to non-default.
await editorPage.bringToFront();
Expand All @@ -104,7 +99,7 @@ describe( 'Block context', () => {
'.entry-content',
( contentWrapper ) => contentWrapper.textContent.trim()
);
expect( content ).toBe( 'The record ID is: 123' );
expect( content ).toMatch( /^123,\d+,post$/ );

// Clean up
await editorPage.bringToFront();
Expand Down

0 comments on commit 06551c4

Please sign in to comment.