Skip to content

Commit

Permalink
Remove insert block delay from e2e tests (#22377)
Browse files Browse the repository at this point in the history
* Remove insert block delay from e2e tests

* useLayoutEffect instead of useEffect
  • Loading branch information
youknowriad committed May 15, 2020
1 parent 605cb2b commit bab1bc8
Show file tree
Hide file tree
Showing 3 changed files with 4 additions and 26 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import { isEqual } from 'lodash';
/**
* WordPress dependencies
*/
import { useRef, useEffect } from '@wordpress/element';
import { useRef, useLayoutEffect } from '@wordpress/element';
import { useSelect, useDispatch } from '@wordpress/data';
import { synchronizeBlocksWithTemplate } from '@wordpress/blocks';

Expand Down Expand Up @@ -44,7 +44,7 @@ export default function useInnerBlockTemplateSync(

// Maintain a reference to the previous value so we can do a deep equality check.
const existingTemplate = useRef( null );
useEffect( () => {
useLayoutEffect( () => {
// Only synchronize innerBlocks with template if innerBlocks are empty or
// a locking all exists directly on the block.
if ( innerBlocks.length === 0 || templateLock === 'all' ) {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
/**
* WordPress dependencies
*/
import { useEffect } from '@wordpress/element';
import { useLayoutEffect } from '@wordpress/element';
import { useSelect, useDispatch } from '@wordpress/data';
import isShallowEqual from '@wordpress/is-shallow-equal';

Expand Down Expand Up @@ -49,7 +49,7 @@ export default function useNestedSettingsUpdate(
[ clientId ]
);

useEffect( () => {
useLayoutEffect( () => {
const newSettings = {
allowedBlocks,
templateLock:
Expand Down
22 changes: 0 additions & 22 deletions packages/e2e-test-utils/src/insert-block.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@
* Internal dependencies
*/
import { searchForBlock } from './search-for-block';
import { getAllBlocks } from './get-all-blocks';

/**
* Opens the inserter, searches for the given term, then selects the first
Expand All @@ -11,30 +10,9 @@ import { getAllBlocks } from './get-all-blocks';
* @param {string} searchTerm The text to search the inserter for.
*/
export async function insertBlock( searchTerm ) {
const oldBlocks = getAllBlocks();

await searchForBlock( searchTerm );
const insertButton = (
await page.$x( `//button//span[contains(text(), '${ searchTerm }')]` )
)[ 0 ];
await insertButton.click();

const waitForBlocksToChange = ( delay = 20 ) =>
new Promise( ( resolve, reject ) => {
let elapsedTime = 0;
const pendingBlockList = setInterval( () => {
const blocks = getAllBlocks();
// Reference will change when the selector updates.
if ( blocks !== oldBlocks ) {
clearInterval( pendingBlockList );
resolve();
}
elapsedTime += delay;
if ( elapsedTime > 600 ) {
clearInterval( pendingBlockList );
reject( `Block ${ searchTerm } was never inserted.` );
}
}, delay );
} );
await waitForBlocksToChange();
}

0 comments on commit bab1bc8

Please sign in to comment.