Skip to content

Commit

Permalink
Add NumberControl tests for step="any"
Browse files Browse the repository at this point in the history
  • Loading branch information
stokesman committed Oct 5, 2021
1 parent 12a6dd1 commit a041308
Showing 1 changed file with 40 additions and 0 deletions.
40 changes: 40 additions & 0 deletions packages/components/src/number-control/test/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -170,6 +170,16 @@ describe( 'NumberControl', () => {
expect( input.value ).toBe( '-4' );
} );

it( 'should increment while preserving the decimal value when `step` is “any”', () => {
render( <StatefulNumberControl value={ 866.5309 } step="any" /> );

const input = getInput();
input.focus();
fireKeyDown( { keyCode: UP } );

expect( input.value ).toBe( '867.5309' );
} );

it( 'should increment by shiftStep on key UP + shift press', () => {
render( <StatefulNumberControl value={ 5 } shiftStep={ 10 } /> );

Expand All @@ -180,6 +190,16 @@ describe( 'NumberControl', () => {
expect( input.value ).toBe( '20' );
} );

it( 'should increment by shiftStep while preserving the decimal value when `step` is “any”', () => {
render( <StatefulNumberControl value={ 857.5309 } step="any" /> );

const input = getInput();
input.focus();
fireKeyDown( { keyCode: UP, shiftKey: true } );

expect( input.value ).toBe( '867.5309' );
} );

it( 'should increment by custom shiftStep on key UP + shift press', () => {
render( <StatefulNumberControl value={ 5 } shiftStep={ 100 } /> );

Expand Down Expand Up @@ -254,6 +274,16 @@ describe( 'NumberControl', () => {
expect( input.value ).toBe( '-6' );
} );

it( 'should decrement while preserving the decimal value when `step` is “any”', () => {
render( <StatefulNumberControl value={ 868.5309 } step="any" /> );

const input = getInput();
input.focus();
fireKeyDown( { keyCode: DOWN } );

expect( input.value ).toBe( '867.5309' );
} );

it( 'should decrement by shiftStep on key DOWN + shift press', () => {
render( <StatefulNumberControl value={ 5 } /> );

Expand All @@ -264,6 +294,16 @@ describe( 'NumberControl', () => {
expect( input.value ).toBe( '0' );
} );

it( 'should decrement by shiftStep while preserving the decimal value when `step` is “any”', () => {
render( <StatefulNumberControl value={ 877.5309 } step="any" /> );

const input = getInput();
input.focus();
fireKeyDown( { keyCode: DOWN, shiftKey: true } );

expect( input.value ).toBe( '867.5309' );
} );

it( 'should decrement by custom shiftStep on key DOWN + shift press', () => {
render( <StatefulNumberControl value={ 5 } shiftStep={ 100 } /> );

Expand Down

0 comments on commit a041308

Please sign in to comment.