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

Navigation block e2e tests: default to a list of pages if there are no menus #45070

Merged
merged 13 commits into from
Jan 9, 2023
59 changes: 59 additions & 0 deletions test/e2e/specs/editor/blocks/navigation.spec.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
/**
* WordPress dependencies
*/
const { test, expect } = require( '@wordpress/e2e-test-utils-playwright' );

test.describe(
'As a user I want the navigation block to fallback to the best possible default',
() => {
test.beforeAll( async ( { requestUtils } ) => {
await requestUtils.activateTheme( 'emptytheme' );
} );

test.beforeEach( async ( { admin } ) => {
await admin.createNewPost();
getdave marked this conversation as resolved.
Show resolved Hide resolved
} );

test.afterAll( async ( { requestUtils } ) => {
await requestUtils.activateTheme( 'twentytwentyone' );
getdave marked this conversation as resolved.
Show resolved Hide resolved
} );

test.afterEach( async ( { requestUtils } ) => {
await requestUtils.deleteAllPosts();
} );

test( 'default to a list of pages if there are no menus', async ( {
editor,
page,
} ) => {
await editor.insertBlock( { name: 'core/navigation' } );

// Check Page List is in the list view.

// Open the list view.
await page.click( '[aria-label="Document Overview"i]' );
kevin940726 marked this conversation as resolved.
Show resolved Hide resolved

// Click the Navigation block expander, we need to use force because it has aria-hidden set to true.
await page.click(
`//a[.//span[text()='Navigation']]/span[contains(@class, 'block-editor-list-view__expander')]`,
{ force: true }
);

// Find the Page list selector inside the navigation block.
const pageListSelector = await page.locator(
`//table[contains(@aria-label,'Block navigation structure')]//a[.//span[text()='Page List']]`
);

expect( pageListSelector ).toBeTruthy();
getdave marked this conversation as resolved.
Show resolved Hide resolved

// Check the markup of the block is correct.
await editor.publishPost();
const content = await editor.getEditedPostContent();
expect( content ).toBe(
getdave marked this conversation as resolved.
Show resolved Hide resolved
`<!-- wp:navigation -->
<!-- wp:page-list /-->
<!-- /wp:navigation -->`
);
} );
}
);