Repository navigation
test: Add BlockList coverage #50252
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
Merged
Merged
test: Add BlockList coverage #50252
Changes from all commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
65360fa
refactor: Add missing Group block type to core blocks list
dcalhoun e960651
test: Add BlockList tests
dcalhoun 8e44adc
test: Restructure BlockList test descriptions
dcalhoun 59cbf0e
refactor: Increase uniqueness of virtualized list keys
dcalhoun 84d84bc
test: Expand BlockList tests
dcalhoun b9143a0
test: Fix typo
dcalhoun 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
This file contains hidden or 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 hidden or 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 hidden or 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
169 changes: 169 additions & 0 deletions
169
packages/block-editor/src/components/block-list/test/index.native.js
This file contains hidden or 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,169 @@ | ||
| /** | ||
| * External dependencies | ||
| */ | ||
| import { | ||
| addBlock, | ||
| getBlock, | ||
| fireEvent, | ||
| initializeEditor, | ||
| screen, | ||
| setupCoreBlocks, | ||
| triggerBlockListLayout, | ||
| within, | ||
| } from 'test/helpers'; | ||
|
|
||
| setupCoreBlocks( [ 'core/paragraph', 'core/group' ] ); | ||
|
|
||
| describe( 'BlockList', () => { | ||
| describe( 'when empty', () => { | ||
| beforeEach( async () => { | ||
| // Arrange | ||
| await initializeEditor(); | ||
| } ); | ||
|
|
||
| it( 'renders a post title', async () => { | ||
| // Assert | ||
| expect( screen.getByPlaceholderText( 'Add title' ) ).toBeTruthy(); | ||
| } ); | ||
|
|
||
| it( 'renders a block appender as a content placeholder', async () => { | ||
| // Assert | ||
| expect( | ||
| screen.getByPlaceholderText( /Start writing/ ) | ||
| ).toBeTruthy(); | ||
| } ); | ||
|
|
||
| it( 'renders an end-of-list paragraph appender', async () => { | ||
| // Assert | ||
| expect( | ||
| screen.getByLabelText( 'Add paragraph block' ) | ||
| ).toBeTruthy(); | ||
| } ); | ||
| } ); | ||
|
|
||
| describe( 'for inner blocks', () => { | ||
| it( 'renders an inner block appender', async () => { | ||
| await initializeEditor(); | ||
| await addBlock( screen, 'Group' ); | ||
| const groupBlock = await getBlock( screen, 'Group' ); | ||
| triggerBlockListLayout( groupBlock ); | ||
|
|
||
| // Assert | ||
| expect( | ||
| within( groupBlock ).getByTestId( 'appender-button' ) | ||
| ).toBeTruthy(); | ||
| } ); | ||
|
|
||
| describe( 'when a non-last block is selected', () => { | ||
| beforeEach( async () => { | ||
| // Arrange | ||
| await initializeEditor(); | ||
| await addBlock( screen, 'Group' ); | ||
| const groupBlock = await getBlock( screen, 'Group' ); | ||
| fireEvent.press( | ||
| within( groupBlock ).getByTestId( 'appender-button' ) | ||
| ); | ||
| await addBlock( screen, 'Paragraph', { isPickerOpened: true } ); | ||
| fireEvent.press( screen.getByLabelText( 'Navigate Up' ) ); | ||
| fireEvent.press( | ||
| within( groupBlock ).getByTestId( 'appender-button' ) | ||
| ); | ||
| await addBlock( screen, 'Paragraph', { isPickerOpened: true } ); | ||
| } ); | ||
|
|
||
| it( 'renders an insertion point before the block', async () => { | ||
| // Act | ||
| const paragraphBlock = await getBlock( screen, 'Paragraph', { | ||
| rowIndex: 1, | ||
| } ); | ||
| fireEvent.press( paragraphBlock ); | ||
| fireEvent( screen.getByLabelText( 'Add block' ), 'longPress' ); | ||
| fireEvent.press( screen.getByText( 'Add Block Before' ) ); | ||
|
|
||
| // Assert | ||
| expect( screen.getByText( 'ADD BLOCK HERE' ) ).toBeTruthy(); | ||
| expect( | ||
| screen.getByTestId( 'block-insertion-point-before-row-1' ) | ||
| ).toBeTruthy(); | ||
| } ); | ||
|
|
||
| it( 'renders an insertion point after the block', async () => { | ||
| // Act | ||
| const paragraphBlock = await getBlock( screen, 'Paragraph', { | ||
| rowIndex: 1, | ||
| } ); | ||
| fireEvent.press( paragraphBlock ); | ||
| fireEvent( screen.getByLabelText( 'Add block' ), 'longPress' ); | ||
| fireEvent.press( screen.getByText( 'Add Block After' ) ); | ||
|
|
||
| // Assert | ||
| expect( screen.getByText( 'ADD BLOCK HERE' ) ).toBeTruthy(); | ||
| expect( | ||
| screen.getByTestId( 'block-insertion-point-before-row-2' ) | ||
| ).toBeTruthy(); | ||
| } ); | ||
| } ); | ||
|
|
||
| describe( 'when the last block is selected', () => { | ||
| it( 'renders an insertion point before the block', async () => { | ||
| // Arrange | ||
| await initializeEditor(); | ||
| await addBlock( screen, 'Group' ); | ||
| const groupBlock = await getBlock( screen, 'Group' ); | ||
| fireEvent.press( | ||
| within( groupBlock ).getByTestId( 'appender-button' ) | ||
| ); | ||
| await addBlock( screen, 'Paragraph', { isPickerOpened: true } ); | ||
| fireEvent.press( screen.getByLabelText( 'Navigate Up' ) ); | ||
| fireEvent.press( | ||
| within( groupBlock ).getByTestId( 'appender-button' ) | ||
| ); | ||
| await addBlock( screen, 'Paragraph', { isPickerOpened: true } ); | ||
|
|
||
| // Act | ||
| const paragraphBlock = await getBlock( screen, 'Paragraph', { | ||
| rowIndex: 2, | ||
| } ); | ||
| fireEvent.press( paragraphBlock ); | ||
| fireEvent( screen.getByLabelText( 'Add block' ), 'longPress' ); | ||
| fireEvent.press( screen.getByText( 'Add Block Before' ) ); | ||
|
|
||
| // Assert | ||
| expect( screen.getByText( 'ADD BLOCK HERE' ) ).toBeTruthy(); | ||
| expect( | ||
| screen.getByTestId( 'block-insertion-point-before-row-2' ) | ||
| ).toBeTruthy(); | ||
| } ); | ||
|
|
||
| it( 'renders an insertion point after the block', async () => { | ||
| // Arrange | ||
| await initializeEditor(); | ||
| await addBlock( screen, 'Group' ); | ||
| const groupBlock = await getBlock( screen, 'Group' ); | ||
| fireEvent.press( | ||
| within( groupBlock ).getByTestId( 'appender-button' ) | ||
| ); | ||
| await addBlock( screen, 'Paragraph', { isPickerOpened: true } ); | ||
| fireEvent.press( screen.getByLabelText( 'Navigate Up' ) ); | ||
| fireEvent.press( | ||
| within( groupBlock ).getByTestId( 'appender-button' ) | ||
| ); | ||
| await addBlock( screen, 'Paragraph', { isPickerOpened: true } ); | ||
|
|
||
| // Act | ||
| const paragraphBlock = await getBlock( screen, 'Paragraph', { | ||
| rowIndex: 2, | ||
| } ); | ||
| fireEvent.press( paragraphBlock ); | ||
| fireEvent( screen.getByLabelText( 'Add block' ), 'longPress' ); | ||
| fireEvent.press( screen.getByText( 'Add Block After' ) ); | ||
|
|
||
| // Assert | ||
| expect( screen.getByText( 'ADD BLOCK HERE' ) ).toBeTruthy(); | ||
| expect( | ||
| screen.getByTestId( 'block-insertion-point-after-row-2' ) | ||
| ).toBeTruthy(); | ||
| } ); | ||
| } ); | ||
| } ); | ||
| } ); |
This file contains hidden or 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 |
|---|---|---|
|
|
@@ -88,6 +88,7 @@ export const coreBlocks = [ | |
| column, | ||
| cover, | ||
| embed, | ||
| group, | ||
| file, | ||
| html, | ||
| mediaText, | ||
|
|
||
This file contains hidden or 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 |
|---|---|---|
|
|
@@ -178,4 +178,7 @@ module.exports = { | |
| mediaAreaPadding: { | ||
| width: 12, | ||
| }, | ||
| defaultAppender: { | ||
| marginLeft: 16, | ||
| }, | ||
| }; | ||
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.
Uh oh!
There was an error while loading. Please reload this page.