Skip to content

Commit

Permalink
Update check to see if it's clickable
Browse files Browse the repository at this point in the history
  • Loading branch information
renatho committed Oct 15, 2024
1 parent 10e1007 commit 88944b9
Showing 1 changed file with 14 additions and 30 deletions.
44 changes: 14 additions & 30 deletions test/e2e/specs/editor/blocks/cover.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -230,7 +230,6 @@ test.describe( 'Cover', () => {
test( 'z-index of Navigation block inside a Cover block is higher than the other cover inner blocks', async ( {
editor,
page,
coverBlockUtils,
} ) => {
// Insert a Cover block
await editor.insertBlock( { name: 'core/cover' } );
Expand Down Expand Up @@ -282,15 +281,23 @@ test.describe( 'Cover', () => {
.getByRole( 'button', { name: 'Open menu' } )
.click();

const menuZIndex = await coverBlockUtils.calculateZIndexContext(
coverBlock.locator( '.wp-block-navigation__responsive-container' )
// Locate the inner container
const innerContainer = secondCoverBlock.locator(
'.wp-block-cover__inner-container'
);

const innerBlocksZIndex = await coverBlockUtils.calculateZIndexContext(
secondCoverBlock.locator( '.wp-block-cover__inner-container' )
);
let isClickable;

try {
isClickable = await innerContainer.click( {
trial: true,
timeout: 1000, // This test will always take 1 second to run.
} );
} catch ( error ) {
isClickable = false;
}

expect( menuZIndex ).toBeGreaterThan( innerBlocksZIndex );
expect( isClickable ).toBe( false );
} );
} );

Expand Down Expand Up @@ -321,27 +328,4 @@ class CoverBlockUtils {

return filename;
}

async calculateZIndexContext( element ) {
const zIndexResult = await element.evaluate( ( el ) => {
let zIndex = 0;
let currentElement = el;

while ( currentElement ) {
const computedStyle = window.getComputedStyle( currentElement );
const zIndexValue = parseInt( computedStyle.zIndex, 10 );

// If the element creates a new stacking context
if ( ! isNaN( zIndexValue ) ) {
zIndex = zIndexValue;
}

currentElement = currentElement.parentElement; // Move up the DOM tree
}

return zIndex;
} );

return zIndexResult;
}
}

0 comments on commit 88944b9

Please sign in to comment.