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 0a244ec
Showing 1 changed file with 16 additions and 34 deletions.
50 changes: 16 additions & 34 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 @@ -272,7 +271,7 @@ test.describe( 'Cover', () => {
} )
.click();

// Set the viewport to a small screen where the menu will become a modal and open it.
// Set the viewport to a small screen and open menu.
await page.setViewportSize( { width: 375, height: 1000 } );
const navigationBlock = editor.canvas.getByRole( 'document', {
name: 'Block: Navigation',
Expand All @@ -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 of the second cover is clickable.
const secondInnerContainer = secondCoverBlock.locator(
'.wp-block-cover__inner-container'
);

expect( menuZIndex ).toBeGreaterThan( innerBlocksZIndex );
let isClickable;
try {
isClickable = await secondInnerContainer.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 0a244ec

Please sign in to comment.