-
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.
Test block insertion after blurring post title field
Relates to #32831. Adds tests asserting that block inserter inserts new blocks in the correct position after blurring the post title field.
- Loading branch information
Showing
1 changed file
with
93 additions
and
0 deletions.
There are no files selected for viewing
93 changes: 93 additions & 0 deletions
93
packages/edit-post/src/components/visual-editor/test/index.native.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,93 @@ | ||
/** | ||
* External dependencies | ||
*/ | ||
import { initializeEditor, fireEvent } from 'test/helpers'; | ||
|
||
/** | ||
* WordPress dependencies | ||
*/ | ||
import { getBlockTypes, unregisterBlockType } from '@wordpress/blocks'; | ||
import { registerCoreBlocks } from '@wordpress/block-library'; | ||
|
||
beforeAll( () => { | ||
// Register all core blocks | ||
registerCoreBlocks(); | ||
} ); | ||
|
||
afterAll( () => { | ||
// Clean up registered blocks | ||
getBlockTypes().forEach( ( block ) => { | ||
unregisterBlockType( block.name ); | ||
} ); | ||
} ); | ||
|
||
const initialHtml = ` | ||
<!-- wp:paragraph --> | ||
<p>First example paragraph.</p> | ||
<!-- /wp:paragraph --> | ||
<!-- wp:paragraph --> | ||
<p>Second example paragraph.</p> | ||
<!-- /wp:paragraph --> | ||
`; | ||
|
||
describe( 'when title is focused', () => { | ||
it( 'new blocks are inserted after the title', async () => { | ||
const screen = await initializeEditor( { | ||
initialHtml, | ||
} ); | ||
|
||
// Focus first block | ||
fireEvent.press( screen.getByA11yLabel( /Paragraph Block. Row 1/ ) ); | ||
|
||
// Focus title | ||
fireEvent( | ||
screen.getAllByA11yLabel( 'Post title. test' )[ 0 ], | ||
'select' | ||
); | ||
|
||
// Add new Heading block | ||
fireEvent.press( screen.getByA11yLabel( 'Add block' ) ); | ||
fireEvent.press( screen.getByText( 'Heading' ) ); | ||
|
||
expect( screen.getByA11yLabel( /Heading Block. Row 1/ ) ).toBeDefined(); | ||
expect( | ||
screen.getByA11yLabel( /Paragraph Block. Row 2/ ) | ||
).toBeDefined(); | ||
expect( | ||
screen.getByA11yLabel( /Paragraph Block. Row 3/ ) | ||
).toBeDefined(); | ||
} ); | ||
} ); | ||
|
||
describe( 'when title is no longer focused', () => { | ||
it( 'new blocks are inserted after the currently focused block', async () => { | ||
const screen = await initializeEditor( { | ||
initialHtml, | ||
} ); | ||
|
||
// Focus first block | ||
fireEvent.press( screen.getByA11yLabel( /Paragraph Block. Row 1/ ) ); | ||
|
||
// Focus title | ||
fireEvent( | ||
screen.getAllByA11yLabel( 'Post title. test' )[ 0 ], | ||
'select' | ||
); | ||
|
||
// Focus last block | ||
fireEvent.press( screen.getByA11yLabel( /Paragraph Block. Row 2/ ) ); | ||
|
||
// Add new Heading block | ||
fireEvent.press( screen.getByA11yLabel( 'Add block' ) ); | ||
fireEvent.press( screen.getByText( 'Heading' ) ); | ||
|
||
expect( | ||
screen.getByA11yLabel( /Paragraph Block. Row 1/ ) | ||
).toBeDefined(); | ||
expect( | ||
screen.getByA11yLabel( /Paragraph Block. Row 2/ ) | ||
).toBeDefined(); | ||
expect( screen.getByA11yLabel( /Heading Block. Row 3/ ) ).toBeDefined(); | ||
} ); | ||
} ); |