Skip to content

Commit

Permalink
Add more reset unit tests for RangeControl
Browse files Browse the repository at this point in the history
  • Loading branch information
stokesman committed Apr 28, 2022
1 parent 89affab commit 06d16fd
Showing 1 changed file with 22 additions and 5 deletions.
27 changes: 22 additions & 5 deletions packages/components/src/range-control/test/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -288,14 +288,31 @@ describe( 'RangeControl', () => {
} );

describe( 'reset', () => {
it( 'should reset to a custom fallback value, defined by a parent component', () => {
it.concurrent.each( [
[
'initialPosition if it is defined',
{ initialPosition: 21 },
[ '21', undefined ],
],
[
'resetFallbackValue if it is defined',
{ resetFallbackValue: 34 },
[ '34', 34 ],
],
[
'resetFallbackValue if both it and initialPosition are defined',
{ initialPosition: 21, resetFallbackValue: 34 },
[ '34', 34 ],
],
] )( 'should reset to %s', ( ...all ) => {
const [ , propsForReset, [ expectedValue, expectedChange ] ] = all;
const spy = jest.fn();
const { container } = render(
<RangeControl
initialPosition={ 10 }
allowReset={ true }
onChange={ spy }
resetFallbackValue={ 33 }
{ ...propsForReset }
/>
);

Expand All @@ -305,9 +322,9 @@ describe( 'RangeControl', () => {

fireEvent.click( resetButton );

expect( rangeInput.value ).toBe( '33' );
expect( numberInput.value ).toBe( '33' );
expect( spy ).toHaveBeenCalledWith( 33 );
expect( rangeInput.value ).toBe( expectedValue );
expect( numberInput.value ).toBe( expectedValue );
expect( spy ).toHaveBeenCalledWith( expectedChange );
} );

it.concurrent.each( [ RangeControl, ControlledRangeControl ] )(
Expand Down

0 comments on commit 06d16fd

Please sign in to comment.