Skip to content

Commit

Permalink
Tests: Refactor pressKeyTimes to use for loop for simplicity
Browse files Browse the repository at this point in the history
  • Loading branch information
gziolo committed Apr 29, 2019
1 parent 20c6a3f commit aa4f816
Show file tree
Hide file tree
Showing 4 changed files with 5 additions and 27 deletions.
4 changes: 0 additions & 4 deletions packages/e2e-test-utils/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -330,10 +330,6 @@ _Parameters_
- _key_ `string`: Key to press.
- _count_ `number`: Number of times to press.

_Returns_

- `Promise`: Promise resolving when key presses complete.

<a name="pressKeyWithModifier" href="#pressKeyWithModifier">#</a> **pressKeyWithModifier**

Performs a key press with modifier (Shift, Control, Meta, Alt), where each modifier
Expand Down
1 change: 1 addition & 0 deletions packages/e2e-test-utils/src/click-block-appender.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,5 @@
*/
export async function clickBlockAppender() {
await page.click( '.block-editor-default-block-appender__content' );
await page.waitForSelector( '[data-type="core/paragraph"]' );
}
26 changes: 3 additions & 23 deletions packages/e2e-test-utils/src/press-key-times.js
Original file line number Diff line number Diff line change
@@ -1,31 +1,11 @@
/**
* External dependencies
*/
import { times } from 'lodash';

/**
* Given an array of functions, each returning a promise, performs all
* promises in sequence (waterfall) order.
*
* @param {Function[]} sequence Array of promise creators.
*
* @return {Promise} Promise resolving once all in the sequence complete.
*/
async function promiseSequence( sequence ) {
return sequence.reduce(
( current, next ) => current.then( next ),
Promise.resolve()
);
}

/**
* Presses the given keyboard key a number of times in sequence.
*
* @param {string} key Key to press.
* @param {number} count Number of times to press.
*
* @return {Promise} Promise resolving when key presses complete.
*/
export async function pressKeyTimes( key, count ) {
return promiseSequence( times( count, () => () => page.keyboard.press( key ) ) );
for ( let i = 0; i < count; i++ ) {
await page.keyboard.press( key );
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,7 @@ describe( 'Navigating the block hierarchy', () => {

// Tweak the columns count by increasing it by one.
await page.keyboard.press( 'ArrowRight' );
await page.waitForSelector( '.wp-block-columns.has-3-columns' );

// Navigate to the last column in the columns block.
await openBlockNavigator();
Expand Down

0 comments on commit aa4f816

Please sign in to comment.