Skip to content

Commit

Permalink
Update check to see if second cover inner blocks container is clickable
Browse files Browse the repository at this point in the history
  • Loading branch information
renatho committed Oct 15, 2024
1 parent 10e1007 commit 345c7df
Showing 1 changed file with 15 additions and 33 deletions.
48 changes: 15 additions & 33 deletions test/e2e/specs/editor/blocks/cover.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -227,10 +227,9 @@ test.describe( 'Cover', () => {
await expect( overlay ).toHaveCSS( 'opacity', '0.5' );
} );

test( 'z-index of Navigation block inside a Cover block is higher than the other cover inner blocks', async ( {
test( 'other cover blocks are not over the navigation block when the menu is open', async ( {
editor,
page,
coverBlockUtils,
} ) => {
// Insert a Cover block
await editor.insertBlock( { name: 'core/cover' } );
Expand Down Expand Up @@ -282,15 +281,21 @@ test.describe( 'Cover', () => {
.getByRole( 'button', { name: 'Open menu' } )
.click();

const menuZIndex = await coverBlockUtils.calculateZIndexContext(
coverBlock.locator( '.wp-block-navigation__responsive-container' )
);

const innerBlocksZIndex = await coverBlockUtils.calculateZIndexContext(
secondCoverBlock.locator( '.wp-block-cover__inner-container' )
// Check if inner container is clickable.
const innerContainer = secondCoverBlock.locator(
'.wp-block-cover__inner-container'
);

expect( menuZIndex ).toBeGreaterThan( innerBlocksZIndex );
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( isClickable ).toBe( false );
} );
} );

Expand Down Expand Up @@ -321,27 +326,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 345c7df

Please sign in to comment.