-
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.
RNMobile: Add integration test to verify button block border radius f…
…unctionality (#33211) * Add setup for button radius test * Tweak query in test * Clean up bottons tests * Clean up buttons test further * RNMobile: Fix reusable block test assertion The test should assert the existance of a React element but because of a missing `await`, was instead asserting an unresolved Promise instead. Since the unresolved Promise is a value, `toBeDefined` was returning `true` and the test was passing. Fixing the test involves resolving the Promise using `await` so that what's asserted is an actual React element. * Update useResizeObserver mock Co-authored-by: Carlos Garcia <[email protected]>
- Loading branch information
Showing
4 changed files
with
100 additions
and
1 deletion.
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,81 @@ | ||
/** | ||
* External dependencies | ||
*/ | ||
import { | ||
fireEvent, | ||
waitFor, | ||
getEditorHtml, | ||
within, | ||
initializeEditor, | ||
} 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 ); | ||
} ); | ||
} ); | ||
|
||
describe( 'when a button is shown', () => { | ||
it( 'adjusts the border radius', async () => { | ||
const initialHtml = `<!-- wp:buttons --> | ||
<div class="wp-block-buttons"><!-- wp:button --> | ||
<div class="wp-block-button"><a class="wp-block-button__link">Hello</a></div> | ||
<!-- /wp:button --></div> | ||
<!-- /wp:buttons -->`; | ||
const { getByA11yLabel, getByTestId } = await initializeEditor( { | ||
initialHtml, | ||
} ); | ||
|
||
const buttonsBlock = await waitFor( () => | ||
getByA11yLabel( /Buttons Block\. Row 1/ ) | ||
); | ||
fireEvent.press( buttonsBlock ); | ||
|
||
// onLayout event has to be explicitly dispatched in BlockList component, | ||
// otherwise the inner blocks are not rendered. | ||
const innerBlockListWrapper = await waitFor( () => | ||
within( buttonsBlock ).getByTestId( 'block-list-wrapper' ) | ||
); | ||
fireEvent( innerBlockListWrapper, 'layout', { | ||
nativeEvent: { | ||
layout: { | ||
width: 100, | ||
}, | ||
}, | ||
} ); | ||
|
||
const buttonInnerBlock = await waitFor( () => | ||
within( buttonsBlock ).getByA11yLabel( /Button Block\. Row 1/ ) | ||
); | ||
fireEvent.press( buttonInnerBlock ); | ||
|
||
const settingsButton = await waitFor( () => | ||
getByA11yLabel( 'Open Settings' ) | ||
); | ||
fireEvent.press( settingsButton ); | ||
|
||
const radiusSlider = await waitFor( () => | ||
getByTestId( 'Slider Border Radius' ) | ||
); | ||
fireEvent( radiusSlider, 'valueChange', '25' ); | ||
|
||
const expectedHtml = `<!-- wp:buttons --> | ||
<div class="wp-block-buttons"><!-- wp:button {"style":{"border":{"radius":25}}} --> | ||
<div class="wp-block-button"><a class="wp-block-button__link" href="">Hello</a></div> | ||
<!-- /wp:button --></div> | ||
<!-- /wp:buttons -->`; | ||
expect( getEditorHtml() ).toBe( expectedHtml ); | ||
} ); | ||
} ); |
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