Skip to content

Commit 6d1a3e8

Browse files
committed
Tests: Cover classic menu creation and deletion in the browser.
Exercise menu creation, custom link insertion, theme location assignment, and deletion through the classic menu screen. Verify that the assigned menu appears in front-end navigation and that deletion removes the menu. Developed in: #12669 Props csmcneill. See #54892, #52895. git-svn-id: https://develop.svn.wordpress.org/trunk@65063 602fd350-edb4-49c9-b593-d223f7449a82
1 parent 71c7321 commit 6d1a3e8

1 file changed

Lines changed: 125 additions & 0 deletions

File tree

Lines changed: 125 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,125 @@
1+
/**
2+
* WordPress dependencies
3+
*/
4+
import { test, expect } from '@wordpress/e2e-test-utils-playwright';
5+
6+
/**
7+
* The classic menus admin screen (nav-menus.php). Relies on Twenty
8+
* Twenty-One being the active theme, which registers the "Primary menu"
9+
* and "Secondary menu" locations.
10+
*/
11+
test.describe( 'Classic Menus', () => {
12+
test.beforeEach( async ( { requestUtils } ) => {
13+
await requestUtils.deleteAllMenus();
14+
} );
15+
16+
test( 'creates a menu, adds a custom link, and assigns it to a location', async ( {
17+
admin,
18+
page,
19+
requestUtils,
20+
} ) => {
21+
await admin.visitAdminPage( '/nav-menus.php' );
22+
23+
// With no menus, the screen opens directly on the create form.
24+
const menuNameField = page.getByRole( 'textbox', {
25+
name: 'Menu Name',
26+
} );
27+
await menuNameField.fill( 'E2E Menu' );
28+
await page
29+
.getByRole( 'button', { name: 'Create Menu' } )
30+
.first()
31+
.click();
32+
33+
// The screen reloads into the edit state for the new menu.
34+
await expect(
35+
page.getByRole( 'textbox', { name: 'Menu Name' } )
36+
).toHaveValue( 'E2E Menu' );
37+
38+
// Add a custom link from the accordion.
39+
await page.getByRole( 'button', { name: 'Custom Links' } ).click();
40+
await page
41+
.getByRole( 'textbox', { name: 'URL' } )
42+
.fill( 'https://wordpress.org/' );
43+
await page
44+
.getByRole( 'textbox', { name: 'Link Text' } )
45+
.fill( 'E2E Custom Link' );
46+
// Each accordion panel has its own submit; scope to Custom Links.
47+
await page
48+
.locator( '#customlinkdiv' )
49+
.getByRole( 'button', { name: 'Add to Menu' } )
50+
.click();
51+
52+
// The item lands in the menu structure.
53+
await expect(
54+
page
55+
.locator( '#menu-to-edit' )
56+
.getByText( 'E2E Custom Link', { exact: true } )
57+
).toBeVisible();
58+
59+
// Assign the menu to the theme's primary location and save.
60+
await page.getByRole( 'checkbox', { name: 'Primary menu' } ).check();
61+
62+
// Activate via keyboard: the sticky footer bar can shift on focus
63+
// and swallow the first pointer click at certain window heights.
64+
// See https://core.trac.wordpress.org/ticket/65684.
65+
await page.getByRole( 'button', { name: 'Save Menu' } ).first().focus();
66+
await page.keyboard.press( 'Enter' );
67+
68+
// The location assignment persists.
69+
await expect
70+
.poll(
71+
async () => {
72+
const menus = await requestUtils.rest( {
73+
path: '/wp/v2/menus',
74+
params: { context: 'edit' },
75+
} );
76+
return menus.find( ( menu ) => menu.name === 'E2E Menu' )
77+
?.locations;
78+
},
79+
{
80+
message:
81+
'the menu should be assigned to the primary location',
82+
}
83+
)
84+
.toContain( 'primary' );
85+
86+
// The menu renders in the site navigation on the front end.
87+
await page.goto( '/' );
88+
await expect(
89+
page
90+
.getByRole( 'navigation' )
91+
.getByRole( 'link', { name: 'E2E Custom Link' } )
92+
).toBeVisible();
93+
} );
94+
95+
test( 'deletes a menu', async ( { admin, page, requestUtils } ) => {
96+
await requestUtils.createClassicMenu( 'Doomed Menu' );
97+
98+
await admin.visitAdminPage( '/nav-menus.php' );
99+
100+
// Deleting asks for confirmation.
101+
page.on( 'dialog', ( dialog ) => dialog.accept() );
102+
103+
// Activate via keyboard: the sticky footer bar can shift on focus
104+
// and swallow the first pointer click at certain window heights.
105+
// See https://core.trac.wordpress.org/ticket/65684.
106+
await page.getByRole( 'link', { name: 'Delete Menu' } ).focus();
107+
await page.keyboard.press( 'Enter' );
108+
109+
// With the only menu gone, the screen returns to the create form.
110+
await expect(
111+
page.getByRole( 'textbox', { name: 'Menu Name' } )
112+
).toHaveValue( '' );
113+
await expect
114+
.poll(
115+
async () => {
116+
const menus = await requestUtils.rest( {
117+
path: '/wp/v2/menus',
118+
} );
119+
return menus.length;
120+
},
121+
{ message: 'no menus should remain' }
122+
)
123+
.toBe( 0 );
124+
} );
125+
} );

0 commit comments

Comments
 (0)