Skip to content

Commit 2aff6da

Browse files
authored
e2e: Add basic tests for settings page (#105)
* e2e: Add basic tests for settings page * Remove `skip` * Try to fix e2e test
1 parent c3208a1 commit 2aff6da

File tree

1 file changed

+77
-54
lines changed

1 file changed

+77
-54
lines changed

test/e2e/test.spec.js

Lines changed: 77 additions & 54 deletions
Original file line numberDiff line numberDiff line change
@@ -3,63 +3,64 @@
33
*/
44
import { test, expect } from '@wordpress/e2e-test-utils-playwright';
55

6-
test.describe( 'Editor', () => {
7-
test( 'input by Emmet should be expanded on the classic editor', async ( {
8-
admin,
9-
page,
10-
requestUtils,
11-
} ) => {
12-
await admin.visitAdminPage( '' );
13-
const wpPointerCloseButton = page.locator( '#wp-pointer-0 a.close' );
14-
const isVisible = await wpPointerCloseButton.isVisible();
15-
if ( isVisible ) {
16-
await wpPointerCloseButton.click();
17-
}
18-
await requestUtils.activatePlugin( 'classic-editor' );
19-
await admin.visitAdminPage( 'post-new.php' );
20-
await page.click( '#content-tmce' );
21-
await page.click( '#content-html' );
22-
await page.click( '#monaco-editor-container .monaco-editor' );
23-
await page.keyboard.type( 'p.selector' );
24-
await page.keyboard.down( 'Tab' );
25-
await page.click( '#publish' );
26-
await page.click( '#content-tmce' );
27-
await page.click( '#content-html' );
28-
const textarea = await page.locator( '#wp-content-editor-container textarea.wp-editor-area' );
29-
expect( textarea ).toHaveText( '<p class="selector"></p>' );
30-
await requestUtils.deactivatePlugin( 'classic-editor' );
31-
} );
6+
test.describe( 'Custom HTML Block Extension', () => {
7+
test.describe( 'Editor', () => {
8+
test( 'input by Emmet should be expanded on the classic editor', async ( {
9+
admin,
10+
page,
11+
requestUtils,
12+
} ) => {
13+
await admin.visitAdminPage( '' );
14+
const wpPointerCloseButton = page.locator( '#wp-pointer-0 a.close' );
15+
const isVisible = await wpPointerCloseButton.isVisible();
16+
if ( isVisible ) {
17+
await wpPointerCloseButton.click();
18+
}
19+
await requestUtils.activatePlugin( 'classic-editor' );
20+
await admin.visitAdminPage( 'post-new.php' );
21+
await page.click( '#content-tmce' );
22+
await page.click( '#content-html' );
23+
await page.click( '#monaco-editor-container .monaco-editor' );
24+
await page.keyboard.type( 'p.selector' );
25+
await page.keyboard.down( 'Tab' );
26+
await page.click( '#publish' );
27+
await page.click( '#content-tmce' );
28+
await page.click( '#content-html' );
29+
const textarea = await page.locator( '#wp-content-editor-container textarea.wp-editor-area' );
30+
expect( textarea ).toHaveText( '<p class="selector"></p>' );
31+
await requestUtils.deactivatePlugin( 'classic-editor' );
32+
} );
3233

33-
test( 'input by Emmet should be expanded on the theme editor', async ( {
34-
admin,
35-
page,
36-
pageUtils,
37-
} ) => {
38-
await admin.visitAdminPage( 'theme-editor.php' );
39-
await page.click( '#monaco-editor-container .monaco-editor' );
40-
await pageUtils.pressKeys( 'primary+a' );
41-
await page.keyboard.press( 'Delete' );
42-
await page.keyboard.type( '.selector{fz100', { delay: 50 } );
43-
await page.keyboard.press( 'Tab' );
44-
await page.click( '#submit' );
45-
const textarea = await page.locator( '#newcontent' );
46-
expect( textarea ).toHaveText( '.selector{font-size: 100px;}' );
47-
} );
34+
test( 'input by Emmet should be expanded on the theme editor', async ( {
35+
admin,
36+
page,
37+
pageUtils,
38+
} ) => {
39+
await admin.visitAdminPage( 'theme-editor.php' );
40+
await page.click( '#monaco-editor-container .monaco-editor' );
41+
await pageUtils.pressKeys( 'primary+a' );
42+
await page.keyboard.press( 'Delete' );
43+
await page.keyboard.type( '.selector{fz100', { delay: 50 } );
44+
await page.keyboard.press( 'Tab' );
45+
await page.click( '#submit' );
46+
const textarea = await page.locator( '#newcontent' );
47+
expect( textarea ).toHaveText( '.selector{font-size: 100px;}' );
48+
} );
4849

49-
test( 'input by Emmet should be expanded on the block editor', async ( {
50-
admin,
51-
page,
52-
editor,
53-
} ) => {
54-
await admin.createNewPost();
55-
await editor.insertBlock( { name: 'core/html' } );
56-
await editor.canvas.locator( '[data-type="core/html"] .monaco-editor' ).click();
57-
await page.keyboard.type( 'ul.list>li.item*5' );
58-
await page.keyboard.down( 'Tab' );
59-
const postContent = await editor.getEditedPostContent();
60-
const replacedPostContent = postContent.replace( /\r\n/g, '\n' );
50+
test( 'input by Emmet should be expanded on the block editor', async ( {
51+
admin,
52+
page,
53+
editor,
54+
} ) => {
55+
await admin.createNewPost();
56+
await editor.insertBlock( { name: 'core/html' } );
57+
await editor.canvas.locator( '[data-type="core/html"] .monaco-editor' ).click();
58+
await page.keyboard.type( 'ul.list>li.item*5' );
59+
await page.keyboard.down( 'Tab' );
60+
const postContent = await editor.getEditedPostContent();
61+
const replacedPostContent = postContent.replace( /\r\n/g, '\n' );
6162

62-
expect( replacedPostContent ).toBe( `<!-- wp:html -->
63+
expect( replacedPostContent ).toBe( `<!-- wp:html -->
6364
<ul class="list">
6465
<li class="item"></li>
6566
<li class="item"></li>
@@ -68,5 +69,27 @@ test.describe( 'Editor', () => {
6869
<li class="item"></li>
6970
</ul>
7071
<!-- /wp:html -->` );
72+
} );
73+
} );
74+
75+
test.describe( 'Settings page', () => {
76+
test( 'should be rendered', async ( { admin, page } ) => {
77+
await admin.visitAdminPage( 'options-general.php?page=custom-html-block-extension' );
78+
// Hide welcome guide.
79+
const welcomeGuide = page.locator( 'role=dialog[name="About Custom HTML Block Extension"i]' );
80+
const isVisible = await welcomeGuide.isVisible();
81+
if ( isVisible ) {
82+
await welcomeGuide.getByRole( 'button', { name: 'Close' } ).click();
83+
}
84+
85+
// Editsor config tab
86+
await expect( page.getByRole( 'button', { name: 'Save settings' } ) ).toBeVisible();
87+
// Tools tab
88+
await page.getByRole( 'tab', { name: 'Tools' } ).click();
89+
await expect( page.getByRole( 'button', { name: 'Export', exact: true } ) ).toBeVisible();
90+
// Options tab
91+
await page.getByRole( 'tab', { name: 'Options' } ).click();
92+
await expect( page.getByRole( 'button', { name: 'Save Options' } ) ).toBeVisible();
93+
} );
7194
} );
7295
} );

0 commit comments

Comments
 (0)