Skip to content

Commit

Permalink
Remove key UP/DOWN + SHIFT tests for NumberControl and InputControl
Browse files Browse the repository at this point in the history
The reason is because we're now relying on the native HTML `input[type="number"]` incrementing/decrementing function.
Jump stepping values (holding shift to jump by a multiplier, default of 10) is now being handled by the new useJumpStep hook. This hook listens to `Shift` keyboard presses and modifies the `step` prop that is passed into the `input[type="number"]` element.
  • Loading branch information
Jon Q committed Jun 8, 2020
1 parent 68b50f5 commit 0cc791c
Show file tree
Hide file tree
Showing 2 changed files with 0 additions and 290 deletions.
205 changes: 0 additions & 205 deletions packages/components/src/number-control/test/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -151,110 +151,6 @@ describe( 'NumberControl', () => {

expect( spy ).toHaveBeenCalled();
} );

it( 'should increment by step on key UP press', () => {
act( () => {
render( <StatefulNumberControl value={ 5 } />, container );
} );

const input = getInput();

act( () => {
Simulate.keyDown( input, { keyCode: UP } );
} );

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

it( 'should increment from a negative value', () => {
act( () => {
render( <StatefulNumberControl value={ -5 } />, container );
} );

const input = getInput();

act( () => {
Simulate.keyDown( input, { keyCode: UP } );
} );

expect( input.value ).toBe( '-4' );
} );

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

const input = getInput();

act( () => {
Simulate.keyDown( input, { keyCode: UP, shiftKey: true } );
} );

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

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

const input = getInput();

act( () => {
Simulate.keyDown( input, { keyCode: UP, shiftKey: true } );
} );

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

it( 'should increment but be limited by max on shiftStep', () => {
act( () => {
render(
<StatefulNumberControl
value={ 5 }
shiftStep={ 100 }
max={ 99 }
/>,
container
);
} );

const input = getInput();

act( () => {
Simulate.keyDown( input, { keyCode: UP, shiftKey: true } );
} );

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

it( 'should not increment by shiftStep if disabled', () => {
act( () => {
render(
<StatefulNumberControl
value={ 5 }
shiftStep={ 100 }
isShiftStepEnabled={ false }
/>,
container
);
} );

const input = getInput();

act( () => {
Simulate.keyDown( input, { keyCode: UP, shiftKey: true } );
} );

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

describe( 'Key DOWN interactions', () => {
Expand All @@ -275,106 +171,5 @@ describe( 'NumberControl', () => {

expect( spy ).toHaveBeenCalled();
} );

it( 'should decrement by step on key DOWN press', () => {
act( () => {
render( <StatefulNumberControl value={ 5 } />, container );
} );

const input = getInput();

act( () => {
Simulate.keyDown( input, { keyCode: DOWN } );
} );

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

it( 'should decrement from a negative value', () => {
act( () => {
render( <StatefulNumberControl value={ -5 } />, container );
} );

const input = getInput();

act( () => {
Simulate.keyDown( input, { keyCode: DOWN } );
} );

expect( input.value ).toBe( '-6' );
} );

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

const input = getInput();

act( () => {
Simulate.keyDown( input, { keyCode: DOWN, shiftKey: true } );
} );

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

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

const input = getInput();

act( () => {
Simulate.keyDown( input, { keyCode: DOWN, shiftKey: true } );
} );

expect( input.value ).toBe( '-100' );
} );

it( 'should decrement but be limited by min on shiftStep', () => {
act( () => {
render(
<StatefulNumberControl
value={ 5 }
shiftStep={ 100 }
min={ 4 }
/>,
container
);
} );

const input = getInput();

act( () => {
Simulate.keyDown( input, { keyCode: DOWN, shiftKey: true } );
} );

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

it( 'should not decrement by shiftStep if disabled', () => {
act( () => {
render(
<StatefulNumberControl
value={ 5 }
shiftStep={ 100 }
isShiftStepEnabled={ false }
/>,
container
);
} );

const input = getInput();

act( () => {
Simulate.keyDown( input, { keyCode: DOWN, shiftKey: true } );
} );

expect( input.value ).toBe( '4' );
} );
} );
} );
85 changes: 0 additions & 85 deletions packages/components/src/unit-control/test/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,6 @@
import { render, unmountComponentAtNode } from 'react-dom';
import { act, Simulate } from 'react-dom/test-utils';

/**
* WordPress dependencies
*/
import { UP, DOWN } from '@wordpress/keycodes';

/**
* Internal dependencies
*/
Expand Down Expand Up @@ -89,86 +84,6 @@ describe( 'UnitControl', () => {

expect( state ).toBe( '62px' );
} );

it( 'should increment value on UP press', () => {
let state = 50;
const setState = ( nextState ) => ( state = nextState );

act( () => {
render(
<UnitControl value={ state } onChange={ setState } />,
container
);
} );

const input = getInput();

act( () => {
Simulate.keyDown( input, { keyCode: UP } );
} );

expect( state ).toBe( '51px' );
} );

it( 'should increment value on UP + SHIFT press, with step', () => {
let state = 50;
const setState = ( nextState ) => ( state = nextState );

act( () => {
render(
<UnitControl value={ state } onChange={ setState } />,
container
);
} );

const input = getInput();

act( () => {
Simulate.keyDown( input, { keyCode: UP, shiftKey: true } );
} );

expect( state ).toBe( '60px' );
} );

it( 'should decrement value on DOWN press', () => {
let state = 50;
const setState = ( nextState ) => ( state = nextState );

act( () => {
render(
<UnitControl value={ state } onChange={ setState } />,
container
);
} );

const input = getInput();

act( () => {
Simulate.keyDown( input, { keyCode: DOWN } );
} );

expect( state ).toBe( '49px' );
} );

it( 'should decrement value on DOWN + SHIFT press, with step', () => {
let state = 50;
const setState = ( nextState ) => ( state = nextState );

act( () => {
render(
<UnitControl value={ state } onChange={ setState } />,
container
);
} );

const input = getInput();

act( () => {
Simulate.keyDown( input, { keyCode: DOWN, shiftKey: true } );
} );

expect( state ).toBe( '40px' );
} );
} );

describe( 'Unit', () => {
Expand Down

0 comments on commit 0cc791c

Please sign in to comment.