Skip to content

Commit

Permalink
Add basic Navigation block coverage
Browse files Browse the repository at this point in the history
  • Loading branch information
ockham committed Feb 13, 2025
1 parent e707a7c commit 04aec39
Show file tree
Hide file tree
Showing 2 changed files with 49 additions and 0 deletions.
4 changes: 4 additions & 0 deletions packages/e2e-tests/plugins/block-hooks.php
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,10 @@ function gutenberg_test_insert_hooked_blocks( $hooked_blocks, $position, $anchor
$hooked_blocks[] = 'core/paragraph';
}

if ( 'core/navigation' === $anchor_block && 'first_child' === $position ) {
$hooked_blocks[] = 'core/home-link';
}

return $hooked_blocks;
}
add_filter( 'hooked_block_types', 'gutenberg_test_insert_hooked_blocks', 10, 4 );
Expand Down
45 changes: 45 additions & 0 deletions test/e2e/specs/editor/plugins/block-hooks.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -163,4 +163,49 @@ test.describe( 'Block Hooks API', () => {
} );
} );
} );

test.describe( `Hooked blocks in Navigation Menu`, () => {
let postObject, containerPost;
test.beforeAll( async ( { requestUtils } ) => {
postObject = await requestUtils.createNavigationMenu( {
title: 'Navigation Menu',
status: 'publish',
content: '<!-- wp:page-list /-->',
} );

await requestUtils.activatePlugin( 'gutenberg-test-block-hooks' );

// We need a container post to hold our block instance.
containerPost = await requestUtils.createPost( {
title: `Block Hooks in Navigation Menu`,
status: 'publish',
content: `<!-- wp:navigation {"ref":${ postObject.id }} /-->`,
meta: {
// Prevent Block Hooks from injecting blocks into the container
// post content so they won't distract from the ones injected
// into the block instance.
_wp_ignored_hooked_blocks: '["core/paragraph"]',
},
} );
} );

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

await requestUtils.deleteAllPosts();
await requestUtils.deleteAllBlocks();
} );

test( `should insert hooked blocks into Navigation Menu on frontend`, async ( {
page,
} ) => {
await page.goto( `/?p=${ containerPost.id }` );
await expect(
page.locator( '.wp-block-navigation__container > *' )
).toHaveClass( [
'wp-block-navigation-item wp-block-home-link',
'wp-block-page-list',
] );
} );
} );
} );

0 comments on commit 04aec39

Please sign in to comment.