-
Notifications
You must be signed in to change notification settings - Fork 4.2k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[RNMobile] Fix/button radius update more units (#33434)
* Fix: Button button value to be stored as a value + unit * Update the test to include the px values. * Fix toFixed to work more as expected. This resulted in somecase the up or down clicks with proper incoments. * Remove decimalNum propertly from unit control This unit now gets calculated from the step value. * Update Button Component to now accept any unit. * fix toFixed to return a number instead of a string * Update with comments for more clarity for getDecimal * Only calculate decimalNum once. * Make the stepper cell return integers instead of floats for nicer numbers * Normalize floats to always include leading zero * Make the code not repeat itself * Display nicer numbers when the numbers are integers from 1.00 to 1 * Adjust the intergration test so it passes again * minor
- Loading branch information
Showing
12 changed files
with
221 additions
and
29 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,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 {"style":{"border":{"radius":"5%"}}} --> | ||
<div class="wp-block-button"><a class="wp-block-button__link" style="border-radius:5%" >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="" style="border-radius:25%">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
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
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
Oops, something went wrong.