Skip to content

Commit

Permalink
add unit test
Browse files Browse the repository at this point in the history
  • Loading branch information
ciampo committed Jul 20, 2022
1 parent 109cbfc commit e9e64e0
Showing 1 changed file with 30 additions and 0 deletions.
30 changes: 30 additions & 0 deletions packages/components/src/range-control/test/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -200,6 +200,36 @@ describe( 'RangeControl', () => {

expect( rangeInput?.value ).toBe( '10' );
} );

it( 'should clamp initialPosition between min and max on first render, and on reset', () => {
render(
<RangeControl
initialPosition={ 200 }
min={ 0 }
max={ 100 }
allowReset
/>
);

const numberInput = getNumberInput();
const rangeInput = getRangeInput();
const resetButton = getResetButton();

// Value should be clamped on initial load
expect( numberInput?.value ).toBe( '100' );
expect( rangeInput?.value ).toBe( '100' );

fireChangeEvent( numberInput, '50' );

expect( numberInput?.value ).toBe( '50' );
expect( rangeInput?.value ).toBe( '50' );

// Value should be clamped after resetting
fireEvent.click( resetButton as Element );

expect( numberInput?.value ).toBe( '100' );
expect( rangeInput?.value ).toBe( '100' );
} );
} );

describe( 'input field', () => {
Expand Down

0 comments on commit e9e64e0

Please sign in to comment.