Skip to content

Commit

Permalink
Navigation block e2e tests: default to a list of pages if there are n…
Browse files Browse the repository at this point in the history
…o menus (#45070)

* added first test

* check the page list block is in the list view

* removed te
sts unrelated to this PR

* make sure to use a block theme, clear posts after testing

* removed debugging change

* updated list view selector

* Use page object directly

* Remove unnecessary locator and utilise click directly

* Utilise locator chaining to improve clarity

* Await resolution to properly assert on loading state

* Attempt to await specific network evenets

* Fix timeout and refactor

* Add comment for clarity

Co-authored-by: Dave Smith <[email protected]>
Co-authored-by: Kai Hao <[email protected]>
  • Loading branch information
3 people authored Jan 9, 2023
1 parent 3a33500 commit e343afc
Showing 1 changed file with 62 additions and 0 deletions.
62 changes: 62 additions & 0 deletions test/e2e/specs/editor/blocks/navigation.spec.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
/**
* WordPress dependencies
*/
const {
test,
expect,
Editor,
} = require( '@wordpress/e2e-test-utils-playwright' );

test.use( {
editor: async ( { page }, use ) => {
await use( new Editor( { page, hasIframe: true } ) );
},
} );

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();
} );

test.afterAll( async ( { requestUtils } ) => {
await requestUtils.activateTheme( 'twentytwentyone' );
} );

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

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

const pageListBlock = editor.canvas.getByRole( 'document', {
name: 'Block: Page List',
} );

await expect( pageListBlock ).toBeVisible( {
// Wait for the Nav and Page List block API requests to resolve.
// Note: avoid waiting on network requests as these are not perceivable
// to the user.
// See: https://github.com/WordPress/gutenberg/pull/45070#issuecomment-1373712007.
timeout: 10000,
} );

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

1 comment on commit e343afc

@github-actions
Copy link

Choose a reason for hiding this comment

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

Flaky tests detected in e343afc.
Some tests passed with failed attempts. The failures may not be related to this commit but are still reported for visibility. See the documentation for more information.

🔍 Workflow run URL: https://github.com/WordPress/gutenberg/actions/runs/3873074965
📝 Reported issues:

Please sign in to comment.