-
Notifications
You must be signed in to change notification settings - Fork 4.2k
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
Migrate Toolbar roving tabindex tests to Playwright #46634
Merged
Merged
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
142 changes: 0 additions & 142 deletions
142
packages/e2e-tests/specs/editor/various/toolbar-roving-tabindex.test.js
This file was deleted.
Oops, something went wrong.
216 changes: 216 additions & 0 deletions
216
test/e2e/specs/editor/various/toolbar-roving-tabindex.spec.js
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,216 @@ | ||
/** | ||
* WordPress dependencies | ||
*/ | ||
const { test, expect } = require( '@wordpress/e2e-test-utils-playwright' ); | ||
|
||
test.use( { | ||
ToolbarRovingTabindexUtils: async ( { page, pageUtils }, use ) => { | ||
await use( new ToolbarRovingTabindexUtils( { page, pageUtils } ) ); | ||
}, | ||
} ); | ||
|
||
test.describe( 'Toolbar roving tabindex', () => { | ||
test.beforeEach( async ( { admin, editor, page } ) => { | ||
await admin.createNewPost(); | ||
await editor.insertBlock( { name: 'core/paragraph' } ); | ||
await page.keyboard.type( 'First block' ); | ||
} ); | ||
|
||
test( 'ensures paragraph block toolbar uses roving tabindex', async ( { | ||
editor, | ||
page, | ||
ToolbarRovingTabindexUtils, | ||
} ) => { | ||
await editor.insertBlock( { name: 'core/paragraph' } ); | ||
await page.keyboard.type( 'Paragraph' ); | ||
await ToolbarRovingTabindexUtils.testBlockToolbarKeyboardNavigation( | ||
'Paragraph block', | ||
'Paragraph' | ||
); | ||
await ToolbarRovingTabindexUtils.wrapCurrentBlockWithGroup( | ||
'Paragraph' | ||
); | ||
await ToolbarRovingTabindexUtils.testGroupKeyboardNavigation( | ||
'Paragraph block', | ||
'Paragraph' | ||
); | ||
} ); | ||
|
||
test( 'ensures heading block toolbar uses roving tabindex', async ( { | ||
editor, | ||
page, | ||
ToolbarRovingTabindexUtils, | ||
} ) => { | ||
await editor.insertBlock( { name: 'core/heading' } ); | ||
await page.keyboard.type( 'Heading' ); | ||
await ToolbarRovingTabindexUtils.testBlockToolbarKeyboardNavigation( | ||
'Block: Heading', | ||
'Heading' | ||
); | ||
await ToolbarRovingTabindexUtils.wrapCurrentBlockWithGroup( 'Heading' ); | ||
await ToolbarRovingTabindexUtils.testGroupKeyboardNavigation( | ||
'Block: Heading', | ||
'Heading' | ||
); | ||
} ); | ||
|
||
test( 'ensures list block toolbar uses roving tabindex', async ( { | ||
editor, | ||
page, | ||
ToolbarRovingTabindexUtils, | ||
} ) => { | ||
await editor.insertBlock( { name: 'core/list' } ); | ||
await page.keyboard.type( 'List' ); | ||
await ToolbarRovingTabindexUtils.testBlockToolbarKeyboardNavigation( | ||
'List text', | ||
'Select List' | ||
); | ||
await page.click( `role=button[name="Select List"i]` ); | ||
await ToolbarRovingTabindexUtils.wrapCurrentBlockWithGroup( 'List' ); | ||
await ToolbarRovingTabindexUtils.testGroupKeyboardNavigation( | ||
'Block: List', | ||
'List' | ||
); | ||
} ); | ||
|
||
test( 'ensures image block toolbar uses roving tabindex', async ( { | ||
editor, | ||
ToolbarRovingTabindexUtils, | ||
} ) => { | ||
await editor.insertBlock( { name: 'core/image' } ); | ||
await ToolbarRovingTabindexUtils.testBlockToolbarKeyboardNavigation( | ||
'Block: Image', | ||
'Image' | ||
); | ||
await ToolbarRovingTabindexUtils.wrapCurrentBlockWithGroup( 'Image' ); | ||
await ToolbarRovingTabindexUtils.testGroupKeyboardNavigation( | ||
'Block: Image', | ||
'Image' | ||
); | ||
} ); | ||
|
||
test( 'ensures table block toolbar uses roving tabindex', async ( { | ||
editor, | ||
page, | ||
ToolbarRovingTabindexUtils, | ||
} ) => { | ||
await editor.insertBlock( { name: 'core/table' } ); | ||
await ToolbarRovingTabindexUtils.testBlockToolbarKeyboardNavigation( | ||
'Block: Table', | ||
'Table' | ||
); | ||
// Move focus to the first toolbar item. | ||
await page.keyboard.press( 'Home' ); | ||
await ToolbarRovingTabindexUtils.expectLabelToHaveFocus( 'Table' ); | ||
await page.click( `role=button[name="Create Table"i]` ); | ||
await page.keyboard.press( 'Tab' ); | ||
await ToolbarRovingTabindexUtils.testBlockToolbarKeyboardNavigation( | ||
'Body cell text', | ||
'Table' | ||
); | ||
await ToolbarRovingTabindexUtils.wrapCurrentBlockWithGroup( 'Table' ); | ||
await ToolbarRovingTabindexUtils.testGroupKeyboardNavigation( | ||
'Block: Table', | ||
'Table' | ||
); | ||
} ); | ||
|
||
test( 'ensures custom html block toolbar uses roving tabindex', async ( { | ||
editor, | ||
ToolbarRovingTabindexUtils, | ||
} ) => { | ||
await editor.insertBlock( { name: 'core/html' } ); | ||
await ToolbarRovingTabindexUtils.testBlockToolbarKeyboardNavigation( | ||
'HTML', | ||
'Custom HTML' | ||
); | ||
await ToolbarRovingTabindexUtils.wrapCurrentBlockWithGroup( | ||
'Custom HTML' | ||
); | ||
await ToolbarRovingTabindexUtils.testGroupKeyboardNavigation( | ||
'Block: Custom HTML', | ||
'Custom HTML' | ||
); | ||
} ); | ||
|
||
test( 'ensures block toolbar remembers the last focused item', async ( { | ||
editor, | ||
page, | ||
pageUtils, | ||
ToolbarRovingTabindexUtils, | ||
} ) => { | ||
await editor.insertBlock( { name: 'core/paragraph' } ); | ||
await page.keyboard.type( 'Paragraph' ); | ||
await ToolbarRovingTabindexUtils.focusBlockToolbar(); | ||
await page.keyboard.press( 'ArrowRight' ); | ||
await ToolbarRovingTabindexUtils.expectLabelToHaveFocus( 'Move up' ); | ||
await page.keyboard.press( 'Tab' ); | ||
await pageUtils.pressKeyWithModifier( 'shift', 'Tab' ); | ||
await ToolbarRovingTabindexUtils.expectLabelToHaveFocus( 'Move up' ); | ||
} ); | ||
|
||
test( 'can reach toolbar items with arrow keys after pressing alt+F10', async ( { | ||
page, | ||
pageUtils, | ||
ToolbarRovingTabindexUtils, | ||
} ) => { | ||
await pageUtils.pressKeyWithModifier( 'alt', 'F10' ); | ||
await page.keyboard.press( 'ArrowRight' ); | ||
await page.keyboard.press( 'ArrowRight' ); | ||
await ToolbarRovingTabindexUtils.expectLabelToHaveFocus( 'Bold' ); | ||
} ); | ||
} ); | ||
|
||
class ToolbarRovingTabindexUtils { | ||
constructor( { page, pageUtils } ) { | ||
this.page = page; | ||
this.pageUtils = pageUtils; | ||
} | ||
|
||
async focusBlockToolbar() { | ||
await this.pageUtils.pressKeyWithModifier( 'alt', 'F10' ); | ||
} | ||
|
||
async testBlockToolbarKeyboardNavigation( | ||
currentBlockLabel, | ||
currentBlockTitle | ||
) { | ||
await this.focusBlockToolbar(); | ||
await this.expectLabelToHaveFocus( currentBlockTitle ); | ||
await this.page.keyboard.press( 'ArrowRight' ); | ||
await this.expectLabelToHaveFocus( 'Move up' ); | ||
await this.page.keyboard.press( 'Tab' ); | ||
await this.expectLabelToHaveFocus( currentBlockLabel ); | ||
await this.pageUtils.pressKeyWithModifier( 'shift', 'Tab' ); | ||
await this.expectLabelToHaveFocus( 'Move up' ); | ||
} | ||
|
||
async expectLabelToHaveFocus( label ) { | ||
let ariaLabel = await this.page.evaluate( () => | ||
document.activeElement.getAttribute( 'aria-label' ) | ||
); | ||
// If the labels don't match, try pressing Up Arrow to focus the block wrapper in non-content editable block. | ||
if ( ariaLabel !== label ) { | ||
await this.page.keyboard.press( 'ArrowUp' ); | ||
ariaLabel = await this.page.evaluate( () => | ||
document.activeElement.getAttribute( 'aria-label' ) | ||
); | ||
} | ||
await expect( ariaLabel ).toBe( label ); | ||
} | ||
|
||
async wrapCurrentBlockWithGroup( currentBlockTitle ) { | ||
await this.page.click( `role=button[name="${ currentBlockTitle }"i]` ); | ||
await this.page.click( `role=menuitem[name="Group"]` ); | ||
} | ||
|
||
async testGroupKeyboardNavigation( currentBlockLabel, currentBlockTitle ) { | ||
await this.expectLabelToHaveFocus( 'Block: Group' ); | ||
await this.page.keyboard.press( 'ArrowRight' ); | ||
await this.expectLabelToHaveFocus( currentBlockLabel ); | ||
await this.pageUtils.pressKeyWithModifier( 'shift', 'Tab' ); | ||
await this.expectLabelToHaveFocus( 'Select Group' ); | ||
await this.page.keyboard.press( 'ArrowRight' ); | ||
await this.expectLabelToHaveFocus( currentBlockTitle ); | ||
} | ||
} |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
I couldn't update this section to an accessible implementation. This implementation also exists in the testing of image block.