Skip to content
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

UnitControl: rewrite tests in TypeScript #40697

Merged
merged 15 commits into from May 3, 2022
Merged
4 changes: 4 additions & 0 deletions packages/components/CHANGELOG.md
Expand Up @@ -2,6 +2,10 @@

## Unreleased

### Internal

- `UnitControl`: migrate unit tests to TypeScript ([#40697](https://github.com/WordPress/gutenberg/pull/40697)).

### Enhancements

- `InputControl`: Add `__next36pxDefaultSize` flag for larger default size ([#40622](https://github.com/WordPress/gutenberg/pull/40622)).
Expand Down
36 changes: 33 additions & 3 deletions packages/components/src/unit-control/stories/index.tsx
Expand Up @@ -109,10 +109,40 @@ TweakingTheNumberInput.args = {
/**
* When only one unit is available, the unit selection dropdown becomes static text.
*/
export const WithSingleUnit: ComponentStory<
export const WithSingleUnitControlled: ComponentStory<
typeof UnitControl
> = DefaultTemplate.bind( {} );
WithSingleUnit.args = {
> = ( { onChange, ...args } ) => {
// Starting value is `undefined`
const [ value, setValue ] = useState< string | undefined >( undefined );

return (
<div style={ { maxWidth: '100px' } }>
<UnitControl
{ ...args }
value={ value }
onChange={ ( v, extra ) => {
setValue( v );
onChange?.( v, extra );
} }
/>
</div>
);
};
WithSingleUnitControlled.args = {
...Default.args,
units: CSS_UNITS.slice( 0, 1 ),
};

export const WithSingleUnitUncontrolled: ComponentStory<
typeof UnitControl
> = ( args ) => {
return (
<div style={ { maxWidth: '100px' } }>
<UnitControl { ...args } />
</div>
);
};
WithSingleUnitUncontrolled.args = {
...Default.args,
units: CSS_UNITS.slice( 0, 1 ),
};
Expand Down
@@ -0,0 +1,33 @@
// Jest Snapshot v1, https://goo.gl/fbAQLP

exports[`UnitControl Basic rendering should render custom className 1`] = `
Snapshot Diff:
- First value
+ Second value

@@ -1,10 +1,10 @@
<div
class="components-unit-control-wrapper css-aa2xc3-Root e1bagdl33"
>
<div
- class="components-flex components-input-control components-number-control components-unit-control e1bagdl32 ep48uk90 em5sgkm7 css-18wzek1-View-Flex-sx-Base-sx-Items-ItemsColumn-Root-rootLabelPositionStyles-Input-ValueInput-arrowStyles-paddingStyles em57xhy0"
+ class="components-flex components-input-control components-number-control components-unit-control hello e1bagdl32 ep48uk90 em5sgkm7 css-18wzek1-View-Flex-sx-Base-sx-Items-ItemsColumn-Root-rootLabelPositionStyles-Input-ValueInput-arrowStyles-paddingStyles em57xhy0"
data-wp-c16t="true"
data-wp-component="Flex"
>
<div
class="components-flex-item em5sgkm3 css-1fmchc6-View-Item-sx-Base-LabelWrapper em57xhy0"
@@ -15,11 +15,11 @@
class="components-input-control__container css-1sy20aj-Container-containerDisabledStyles-containerMarginStyles-containerWidthStyles em5sgkm6"
>
<input
autocomplete="off"
class="components-input-control__input css-gzm6eu-Input-dragStyles-fontSizeStyles-sizeStyles em5sgkm5"
- id="inspector-input-control-1"
+ id="inspector-input-control-2"
inputmode="numeric"
max="Infinity"
min="-Infinity"
step="1"
type="number"
`;