Skip to content

Commit

Permalink
Migrate shortcut help e2e tests to Playwright (#53832)
Browse files Browse the repository at this point in the history
* Migrate test case

* Migrate test case

* Use Role locators

* Update to have tests pass locally

- swap pressKeyWithModifier for pressKeys
- use locator assertions
- remove some extraneous steps in latter tests
- cleanup comments

* Combine tests

* Locate platform-agnostically

* Locate more rolefully

* Assert focus return

---------

Co-authored-by: alvitazwar <55917380+alvitazwar@users.noreply.github.com>
  • Loading branch information
stokesman and alvitazwar authored Aug 30, 2023
1 parent 324e9b3 commit 6ede5e2
Show file tree
Hide file tree
Showing 2 changed files with 42 additions and 47 deletions.
47 changes: 0 additions & 47 deletions packages/e2e-tests/specs/editor/various/shortcut-help.test.js

This file was deleted.

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

test.describe( 'keyboard shortcut help modal', () => {
test.beforeEach( async ( { admin } ) => {
await admin.createNewPost();
} );

test( 'opens from the options menu, closes with its close button and returns focus', async ( {
page,
} ) => {
await page
.locator( 'role=region[name="Editor top bar"]' )
.locator( '[aria-label="Options"]' )
.click();
const menuItem = page.locator( 'role=menuitem', {
hasText: /^Keyboard shortcuts/i,
} );
const dialog = page.locator( 'role=dialog[name="Keyboard shortcuts"]' );

await menuItem.click();
await expect( dialog ).toBeVisible();

await page.locator( 'role=button[name="Close"]' ).click();
await expect( dialog ).toBeHidden();
await expect( menuItem ).toBeFocused();
} );

test( 'toggles open/closed using the keyboard shortcut (access+h)', async ( {
page,
pageUtils,
} ) => {
await pageUtils.pressKeys( 'access+h' );
const dialog = page.locator( 'role=dialog[name="Keyboard shortcuts"]' );
await expect( dialog ).toBeVisible();

await pageUtils.pressKeys( 'access+h' );
await expect( dialog ).toBeHidden();
} );
} );

1 comment on commit 6ede5e2

@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 6ede5e2.
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/6022412194
📝 Reported issues:

Please sign in to comment.