From 0cc791ccc70029e45ce5ea79079603faba7c033a Mon Sep 17 00:00:00 2001 From: Jon Q Date: Mon, 8 Jun 2020 12:05:47 -0400 Subject: [PATCH] Remove key UP/DOWN + SHIFT tests for NumberControl and InputControl 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. --- .../src/number-control/test/index.js | 205 ------------------ .../components/src/unit-control/test/index.js | 85 -------- 2 files changed, 290 deletions(-) diff --git a/packages/components/src/number-control/test/index.js b/packages/components/src/number-control/test/index.js index 8c006647bd2ff3..08fc54524d8d82 100644 --- a/packages/components/src/number-control/test/index.js +++ b/packages/components/src/number-control/test/index.js @@ -151,110 +151,6 @@ describe( 'NumberControl', () => { expect( spy ).toHaveBeenCalled(); } ); - - it( 'should increment by step on key UP press', () => { - act( () => { - render( , container ); - } ); - - const input = getInput(); - - act( () => { - Simulate.keyDown( input, { keyCode: UP } ); - } ); - - expect( input.value ).toBe( '6' ); - } ); - - it( 'should increment from a negative value', () => { - act( () => { - render( , 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( - , - 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( - , - 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( - , - 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( - , - container - ); - } ); - - const input = getInput(); - - act( () => { - Simulate.keyDown( input, { keyCode: UP, shiftKey: true } ); - } ); - - expect( input.value ).toBe( '6' ); - } ); } ); describe( 'Key DOWN interactions', () => { @@ -275,106 +171,5 @@ describe( 'NumberControl', () => { expect( spy ).toHaveBeenCalled(); } ); - - it( 'should decrement by step on key DOWN press', () => { - act( () => { - render( , container ); - } ); - - const input = getInput(); - - act( () => { - Simulate.keyDown( input, { keyCode: DOWN } ); - } ); - - expect( input.value ).toBe( '4' ); - } ); - - it( 'should decrement from a negative value', () => { - act( () => { - render( , 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( , 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( - , - 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( - , - 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( - , - container - ); - } ); - - const input = getInput(); - - act( () => { - Simulate.keyDown( input, { keyCode: DOWN, shiftKey: true } ); - } ); - - expect( input.value ).toBe( '4' ); - } ); } ); } ); diff --git a/packages/components/src/unit-control/test/index.js b/packages/components/src/unit-control/test/index.js index c6b0431c968474..a9d0c02bdfde6e 100644 --- a/packages/components/src/unit-control/test/index.js +++ b/packages/components/src/unit-control/test/index.js @@ -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 */ @@ -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( - , - 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( - , - 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( - , - 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( - , - container - ); - } ); - - const input = getInput(); - - act( () => { - Simulate.keyDown( input, { keyCode: DOWN, shiftKey: true } ); - } ); - - expect( state ).toBe( '40px' ); - } ); } ); describe( 'Unit', () => {