Skip to content

Commit bc1b69d

Browse files
committed
Add e2e test coverage
1 parent 08127b7 commit bc1b69d

File tree

1 file changed

+78
-0
lines changed

1 file changed

+78
-0
lines changed

tests/e2e/command-palette.spec.ts

Lines changed: 78 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,78 @@
1+
/**
2+
* Internal dependencies
3+
*/
4+
const { test, expect } = require( './fixtures' );
5+
6+
test.describe( 'Command Palette', () => {
7+
test.beforeAll( async ( { requestUtils } ) => {
8+
await requestUtils.activatePlugin( 'secure-custom-fields' );
9+
} );
10+
11+
test.afterAll( async ( { requestUtils } ) => {
12+
await requestUtils.deactivatePlugin( 'secure-custom-fields' );
13+
} );
14+
15+
test( 'should register SCF create commands', async ( { page, admin } ) => {
16+
await admin.visitAdminPage( 'index.php' );
17+
18+
// Open the command palette via keyboard shortcut.
19+
await page.keyboard.press( 'Meta+k' );
20+
21+
const input = page.getByRole( 'combobox', {
22+
name: 'Search commands and settings',
23+
} );
24+
await expect( input ).toBeVisible();
25+
26+
// Search for a create command — these are always registered by SCF.
27+
await input.fill( 'Create New Field Group' );
28+
await expect(
29+
page.getByRole( 'option', { name: /Create New Field Group/ } )
30+
).toBeVisible();
31+
} );
32+
33+
test( 'should register SCF view commands without duplicates', async ( {
34+
page,
35+
admin,
36+
} ) => {
37+
await admin.visitAdminPage( 'index.php' );
38+
39+
await page.keyboard.press( 'Meta+k' );
40+
41+
const input = page.getByRole( 'combobox', {
42+
name: 'Search commands and settings',
43+
} );
44+
45+
// Search for a view command that exists in both WP's auto-registered
46+
// admin menu commands and SCF's view commands list.
47+
await input.fill( 'Field Groups' );
48+
49+
const options = page.getByRole( 'option', {
50+
name: /Field Groups/,
51+
} );
52+
53+
// There should be exactly one match, not two (no duplicate).
54+
await expect( options ).toHaveCount( 1 );
55+
} );
56+
57+
test( 'should navigate to field groups via command palette', async ( {
58+
page,
59+
admin,
60+
} ) => {
61+
await admin.visitAdminPage( 'index.php' );
62+
63+
await page.keyboard.press( 'Meta+k' );
64+
65+
const input = page.getByRole( 'combobox', {
66+
name: 'Search commands and settings',
67+
} );
68+
69+
await input.fill( 'Field Groups' );
70+
await page
71+
.getByRole( 'option', { name: /Field Groups/ } )
72+
.click();
73+
74+
await expect( page ).toHaveURL(
75+
/edit\.php\?post_type=acf-field-group/
76+
);
77+
} );
78+
} );

0 commit comments

Comments
 (0)