Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
211 changes: 211 additions & 0 deletions test/e2e/specs/site-editor/navigation-overlay-template-part.spec.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,211 @@
/**
* WordPress dependencies
*/
const { test, expect } = require( '@wordpress/e2e-test-utils-playwright' );

const createNavigationOverlay = async ( {
admin,
editor,
page,
requestUtils,
menuContent = `
<!-- wp:navigation-link {"label":"Link 1","type":"custom","url":"http://www.wordpress.org/"} /-->
`,
} ) => {
await requestUtils.createNavigationMenu( {
title: 'Test Menu',
content: menuContent,
} );

await admin.visitSiteEditor( {
postId: 'emptytheme//header',
postType: 'wp_template_part',
canvas: 'edit',
} );

await editor.insertBlock( {
name: 'core/navigation',
attributes: { overlayMenu: 'always' },
} );

const navigationBlock = editor.canvas
.locator( '[data-type="core/navigation"]' )
.last();
await editor.selectBlocks( navigationBlock );

await editor.openDocumentSettingsSidebar();

const settingsTab = page.getByRole( 'tab', {
name: 'Settings',
} );
await settingsTab.click();

const createOverlayButton = page.getByRole( 'button', {
name: 'Create overlay',
exact: true,
} );
await createOverlayButton.click();

await expect(
page.locator( 'h1' ).filter( { hasText: 'Navigation Overlay' } )
).toBeVisible( { timeout: 10000 } );
};
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

For me our smoke test for Overlay Editing could end here with a simple tests for

  • Template Part tab selected
  • Design sidebar showing with Patterns.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

the pattern one is coming on #75618 because it requires the fix for that

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm not sure what you mean about the template part tab one


test.describe( 'Navigation Overlay Template Part', () => {
test.beforeAll( async ( { requestUtils } ) => {
await requestUtils.activateTheme( 'emptytheme' );
} );

test.afterAll( async ( { requestUtils } ) => {
await requestUtils.activateTheme( 'twentytwentyone' );
} );

test.afterEach( async ( { requestUtils } ) => {
await requestUtils.deleteAllTemplates( 'wp_template' );
await requestUtils.deleteAllTemplates( 'wp_template_part' );
await requestUtils.deleteAllPages();
await requestUtils.deleteAllMenus();
} );

test.describe( 'Creation', () => {
test( 'As a user I want to be able to create a navigation overlay for a specific navigation block', async ( {
admin,
editor,
page,
pageUtils,
requestUtils,
} ) => {
await createNavigationOverlay( {
admin,
editor,
page,
requestUtils,
menuContent: `
<!-- wp:navigation-link {"label":"Item 1","type":"custom","url":"http://www.wordpress.org/"} /-->
<!-- wp:navigation-link {"label":"Item 2","type":"custom","url":"http://www.wordpress.org/"} /-->
`,
} );

await page
.getByRole( 'button', { name: 'Back', exact: true } )
.click();

await editor.saveSiteEditorEntities();

await page.goto( '/' );
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I like that these tests are also validating front end rendering.

As a safety could we add multiple overlay close blocks and close using each of them in turn to provide small coverage for that as well?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Added that on 53ce362


const overlayMenuItem = page.getByRole( 'link', {
name: 'Item 1',
} );
const openMenuButton = page.getByRole( 'button', {
name: 'Open menu',
} );

await expect( overlayMenuItem ).toBeHidden();
await openMenuButton.click();
await expect( overlayMenuItem ).toBeVisible();

await pageUtils.pressKeys( 'Escape' );
await expect( overlayMenuItem ).toBeHidden();
await expect( openMenuButton ).toBeFocused();
} );
} );

test.describe( 'Customization', () => {
test.beforeEach( async ( { admin, editor, page, requestUtils } ) => {
await createNavigationOverlay( {
admin,
editor,
page,
requestUtils,
} );
} );

test( 'As a user I want to be able to customize the navigation overlay with styled content', async ( {
editor,
page,
} ) => {
await editor.insertBlock(
{
name: 'core/heading',
attributes: {
content: 'Custom Overlay Heading',
style: {
color: {
text: '#ff0000',
background: '#0000ff',
},
},
},
},
{ index: 0 }
);

await page
.getByRole( 'region', { name: 'Editor top bar' } )
.getByRole( 'button', { name: 'Back', exact: true } )
.click();

await editor.saveSiteEditorEntities();

await page.goto( '/' );

const openMenuButton = page.getByRole( 'button', {
name: 'Open menu',
} );
await openMenuButton.click();

const customHeading = page.getByRole( 'heading', {
name: 'Custom Overlay Heading',
} );
await expect( customHeading ).toBeVisible();

await expect( customHeading ).toHaveCSS(
'color',
'rgb(255, 0, 0)'
);
await expect( customHeading ).toHaveCSS(
'background-color',
'rgb(0, 0, 255)'
);
} );

test( 'As a user I want to be able to add multiple close buttons so that users can close the overlay from different positions', async ( {
editor,
page,
} ) => {
await editor.insertBlock(
{
name: 'core/navigation-overlay-close',
},
{ index: 0 }
);

await page
.getByRole( 'region', { name: 'Editor top bar' } )
.getByRole( 'button', { name: 'Back', exact: true } )
.click();

await editor.saveSiteEditorEntities();

await page.goto( '/' );

const openMenuButton = page.getByRole( 'button', {
name: 'Open menu',
} );
await openMenuButton.click();

const closeButtons = page.getByRole( 'button', {
name: 'Close',
} );
await expect( closeButtons ).toHaveCount( 2 );

await closeButtons.first().click();
await expect( openMenuButton ).toBeVisible();

await openMenuButton.click();
await closeButtons.last().click();
await expect( openMenuButton ).toBeVisible();
} );
} );
} );
Loading