-
Notifications
You must be signed in to change notification settings - Fork 4.3k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Migrate a11y e2e tests to Playwright (#46038)
* Migrate a11y tests. * Run a11y tests with firefox and webkit browsers. * Run the tests only with chromium for now. * Improve the tests descriptions and comments.
- Loading branch information
Showing
1 changed file
with
96 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,96 @@ | ||
/** | ||
* WordPress dependencies | ||
*/ | ||
const { test, expect } = require( '@wordpress/e2e-test-utils-playwright' ); | ||
|
||
test.describe( 'a11y', () => { | ||
test.beforeEach( async ( { admin } ) => { | ||
await admin.createNewPost(); | ||
} ); | ||
|
||
test( 'navigating through the Editor regions four times should land on the Editor top bar region', async ( { | ||
page, | ||
pageUtils, | ||
} ) => { | ||
// On a new post, initial focus is set on the Post title. | ||
await expect( | ||
page.locator( 'role=textbox[name=/Add title/i]' ) | ||
).toBeFocused(); | ||
// Navigate to the 'Editor settings' region. | ||
await pageUtils.pressKeyWithModifier( 'ctrl', '`' ); | ||
// Navigate to the 'Editor publish' region. | ||
await pageUtils.pressKeyWithModifier( 'ctrl', '`' ); | ||
// Navigate to the 'Editor footer' region. | ||
await pageUtils.pressKeyWithModifier( 'ctrl', '`' ); | ||
// Navigate to the 'Editor top bar' region. | ||
await pageUtils.pressKeyWithModifier( 'ctrl', '`' ); | ||
|
||
// This test assumes the Editor is not in Fullscreen mode. Check the | ||
// first tabbable element within the 'Editor top bar' region is the | ||
// 'Toggle block inserter' button. | ||
await page.keyboard.press( 'Tab' ); | ||
await expect( | ||
page.locator( 'role=button[name=/Toggle block inserter/i]' ) | ||
).toBeFocused(); | ||
} ); | ||
|
||
test( 'should constrain tabbing within a modal', async ( { | ||
page, | ||
pageUtils, | ||
} ) => { | ||
// Open keyboard help modal. | ||
await pageUtils.pressKeyWithModifier( 'access', 'h' ); | ||
|
||
const closeButton = page.locator( | ||
'role=dialog[name="Keyboard shortcuts"i] >> role=button[name="Close"i]' | ||
); | ||
// The close button should not be focused by default; this is a strange UX | ||
// experience. | ||
// See: https://github.com/WordPress/gutenberg/issues/9410 | ||
await expect( closeButton ).not.toBeFocused(); | ||
|
||
await page.keyboard.press( 'Tab' ); | ||
|
||
// Ensure the Close button of the modal is focused after tabbing. | ||
await expect( closeButton ).toBeFocused(); | ||
} ); | ||
|
||
test( 'should return focus to the first tabbable in a modal after blurring a tabbable', async ( { | ||
page, | ||
pageUtils, | ||
} ) => { | ||
await pageUtils.pressKeyWithModifier( 'access', 'h' ); | ||
|
||
// Click a non-focusable element after the last tabbable within the modal. | ||
const last = page | ||
.locator( 'role=dialog[name="Keyboard shortcuts"i] >> div' ) | ||
.last(); | ||
await last.click(); | ||
|
||
await page.keyboard.press( 'Tab' ); | ||
|
||
await expect( | ||
page.locator( | ||
'role=dialog[name="Keyboard shortcuts"i] >> role=button[name="Close"i]' | ||
) | ||
).toBeFocused(); | ||
} ); | ||
|
||
test( 'should return focus to the last tabbable in a modal after blurring a tabbable and tabbing in reverse direction', async ( { | ||
page, | ||
pageUtils, | ||
} ) => { | ||
await pageUtils.pressKeyWithModifier( 'access', 'h' ); | ||
|
||
// Click a non-focusable element before the first tabbable within the modal. | ||
await page.click( 'role=heading[name="Keyboard shortcuts"i]' ); | ||
|
||
await pageUtils.pressKeyWithModifier( 'shift', 'Tab' ); | ||
|
||
await expect( | ||
page.locator( | ||
'role=dialog[name="Keyboard shortcuts"i] >> role=button[name="Close"i]' | ||
) | ||
).toBeFocused(); | ||
} ); | ||
} ); |
340b51d
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Flaky tests detected in 340b51d.
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/3947767738
📝 Reported issues:
specs/editor/various/block-editor-keyboard-shortcuts.test.js