Skip to content

Commit b6f62e2

Browse files
committed
Add test
1 parent 64c14d3 commit b6f62e2

1 file changed

Lines changed: 89 additions & 0 deletions

File tree

‎test/e2e/specs/editor/blocks/cover.spec.js‎

Lines changed: 89 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -226,6 +226,72 @@ test.describe( 'Cover', () => {
226226
await expect( overlay ).toHaveCSS( 'background-color', 'rgb(0, 0, 0)' );
227227
await expect( overlay ).toHaveCSS( 'opacity', '0.5' );
228228
} );
229+
230+
test( 'z-index of Navigation block inside a Cover block is higher than the other cover inner blocks', async ( {
231+
editor,
232+
page,
233+
coverBlockUtils,
234+
} ) => {
235+
// Insert a Cover block
236+
await editor.insertBlock( { name: 'core/cover' } );
237+
const coverBlock = editor.canvas.getByRole( 'document', {
238+
name: 'Block: Cover',
239+
} );
240+
241+
// Choose a color swatch to transform the placeholder block into
242+
// a functioning block.
243+
await coverBlock
244+
.getByRole( 'option', {
245+
name: 'Color: Black',
246+
} )
247+
.click();
248+
249+
// Insert a Navigation block inside the Cover block
250+
await editor.selectBlocks( coverBlock );
251+
await coverBlock.getByRole( 'button', { name: 'Add block' } ).click();
252+
await page.keyboard.type( 'Navigation' );
253+
const blockResults = page.getByRole( 'listbox', {
254+
name: 'Blocks',
255+
} );
256+
const blockResultOptions = blockResults.getByRole( 'option' );
257+
await blockResultOptions.nth( 0 ).click();
258+
259+
// Insert a second Cover block.
260+
await editor.insertBlock( { name: 'core/cover' } );
261+
const secondCoverBlock = editor.canvas
262+
.getByRole( 'document', {
263+
name: 'Block: Cover',
264+
} )
265+
.last();
266+
267+
// Choose a color swatch to transform the placeholder block into
268+
// a functioning block.
269+
await secondCoverBlock
270+
.getByRole( 'option', {
271+
name: 'Color: Black',
272+
} )
273+
.click();
274+
275+
// Set the viewport to a small screen where the menu will become a modal and open it.
276+
await page.setViewportSize( { width: 375, height: 1000 } );
277+
const navigationBlock = editor.canvas.getByRole( 'document', {
278+
name: 'Block: Navigation',
279+
} );
280+
await editor.selectBlocks( navigationBlock );
281+
await editor.canvas
282+
.getByRole( 'button', { name: 'Open menu' } )
283+
.click();
284+
285+
const menuZIndex = await coverBlockUtils.calculateZIndexContext(
286+
coverBlock.locator( '.wp-block-navigation__responsive-container' )
287+
);
288+
289+
const innerBlocksZIndex = await coverBlockUtils.calculateZIndexContext(
290+
secondCoverBlock.locator( '.wp-block-cover__inner-container' )
291+
);
292+
293+
expect( menuZIndex ).toBeGreaterThan( innerBlocksZIndex );
294+
} );
229295
} );
230296

231297
class CoverBlockUtils {
@@ -255,4 +321,27 @@ class CoverBlockUtils {
255321

256322
return filename;
257323
}
324+
325+
async calculateZIndexContext( element ) {
326+
const zIndexResult = await element.evaluate( ( el ) => {
327+
let zIndex = 0;
328+
let currentElement = el;
329+
330+
while ( currentElement ) {
331+
const computedStyle = window.getComputedStyle( currentElement );
332+
const zIndexValue = parseInt( computedStyle.zIndex, 10 );
333+
334+
// If the element creates a new stacking context
335+
if ( ! isNaN( zIndexValue ) ) {
336+
zIndex = zIndexValue;
337+
}
338+
339+
currentElement = currentElement.parentElement; // Move up the DOM tree
340+
}
341+
342+
return zIndex;
343+
} );
344+
345+
return zIndexResult;
346+
}
258347
}

0 commit comments

Comments
 (0)