-
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.
Writing Flow: Unset typing flag if Escape pressed (#10906)
- Loading branch information
Showing
2 changed files
with
91 additions
and
3 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
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,63 @@ | ||
/** | ||
* External dependencies | ||
*/ | ||
import { forEach } from 'lodash'; | ||
|
||
/** | ||
* Internal dependencies | ||
*/ | ||
import { newPost, pressWithModifier } from '../support/utils'; | ||
|
||
describe( 'block toolbar', () => { | ||
forEach( { | ||
unified: true, | ||
contextual: false, | ||
}, ( isUnifiedToolbar, label ) => { | ||
beforeEach( async () => { | ||
await newPost(); | ||
|
||
await page.evaluate( ( _isUnifiedToolbar ) => { | ||
const { select, dispatch } = wp.data; | ||
const isCurrentlyUnified = select( 'core/edit-post' ).isFeatureActive( 'fixedToolbar' ); | ||
if ( isCurrentlyUnified !== _isUnifiedToolbar ) { | ||
dispatch( 'core/edit-post' ).toggleFeature( 'fixedToolbar' ); | ||
} | ||
}, isUnifiedToolbar ); | ||
} ); | ||
|
||
const isInRichTextEditable = () => page.evaluate( () => ( | ||
document.activeElement.classList.contains( 'editor-rich-text__tinymce' ) | ||
) ); | ||
|
||
const isInBlockToolbar = () => page.evaluate( () => ( | ||
!! document.activeElement.closest( '.editor-block-toolbar' ) | ||
) ); | ||
|
||
describe( label, () => { | ||
it( 'navigates in and out of toolbar by keyboard (Alt+F10, Escape)', async () => { | ||
// Assumes new post focus starts in title. Create first new | ||
// block by ArrowDown. | ||
await page.keyboard.press( 'ArrowDown' ); | ||
|
||
// [TEMPORARY]: A new paragraph is not technically a block yet | ||
// until starting to type within it. | ||
await page.keyboard.type( 'Example' ); | ||
|
||
// [TEMPORARY]: With non-unified toolbar, the toolbar will not | ||
// be visible since the user has entered a "typing" mode. | ||
// Future iterations should ensure Alt+F10 works in a block | ||
// to focus the toolbar regardless of whether it is presently | ||
// visible. | ||
await page.keyboard.press( 'Escape' ); | ||
|
||
// Upward | ||
await pressWithModifier( 'Alt', 'F10' ); | ||
expect( await isInBlockToolbar() ).toBe( true ); | ||
|
||
// Downward | ||
await page.keyboard.press( 'Escape' ); | ||
expect( await isInRichTextEditable() ).toBe( true ); | ||
} ); | ||
} ); | ||
} ); | ||
} ); |