-
Notifications
You must be signed in to change notification settings - Fork 4.7k
Navigation overlay: added basic e2e tests #75581
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| 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 } ); | ||
| }; | ||
|
|
||
| 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( '/' ); | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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?
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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(); | ||
| } ); | ||
| } ); | ||
| } ); | ||
There was a problem hiding this comment.
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 Parttab selectedDesignsidebar showing with Patterns.There was a problem hiding this comment.
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
There was a problem hiding this comment.
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