-
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: Add BlockList coverage (#50252)
* refactor: Add missing Group block type to core blocks list This exclusion appears to be erroneous and prevents the `setupCoreBlock` test helper from succeeding when attempting to register the Group block type. * test: Add BlockList tests In order to assert the insertion point is in the correct index location, the index must be passed to the test ID for each insertion point. * test: Restructure BlockList test descriptions Increase explicitness of test descriptions and repurpose tests for non-compact lists. * refactor: Increase uniqueness of virtualized list keys A `listKey` was required to address the following error when running tests against the `BlockList`: ``` VirtualizedList trace: Child (vertical): listKey: 8d343539-3801-4ff1-ac5b-858db2cdf662 cellKey: 8d343539-3801-4ff1-ac5b-858db2cdf662 Parent (vertical): listKey: rootList cellKey: rootList ``` * test: Expand BlockList tests Test additional block appender locations. * test: Fix typo
- Loading branch information
Showing
6 changed files
with
193 additions
and
5 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
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
169 changes: 169 additions & 0 deletions
169
packages/block-editor/src/components/block-list/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,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 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 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, | ||
}, | ||
}; |