Skip to content

Commit 9eb04df

Browse files
authored
Migrate preformatted block tests to Playwright (#41128)
* Add preformatted block tests * await page.click( 'role=button[name="Add default block"i]' ); * Update preformatted.spec.js
1 parent f8313d6 commit 9eb04df

6 files changed

+73
-86
lines changed

packages/e2e-tests/specs/editor/blocks/__snapshots__/preformatted.test.js.snap

-24
This file was deleted.

packages/e2e-tests/specs/editor/blocks/preformatted.test.js

-62
This file was deleted.
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
<!-- wp:html -->
2+
<pre>1
3+
2</pre>
4+
<!-- /wp:html -->
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
<!-- wp:preformatted -->
2+
<pre class="wp-block-preformatted">0
3+
1
4+
2</pre>
5+
<!-- /wp:preformatted -->
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
<!-- wp:preformatted -->
2+
<pre class="wp-block-preformatted">1
3+
2
4+
3</pre>
5+
<!-- /wp:preformatted -->
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,59 @@
1+
/**
2+
* WordPress dependencies
3+
*/
4+
const { test, expect } = require( '@wordpress/e2e-test-utils-playwright' );
5+
6+
test.describe( 'Preformatted', () => {
7+
test.beforeEach( async ( { admin } ) => {
8+
await admin.createNewPost();
9+
} );
10+
11+
test( 'should preserve character newlines', async ( { editor, page } ) => {
12+
await editor.insertBlock( { name: 'core/html' } );
13+
await page.keyboard.type( '<pre>1' );
14+
await page.keyboard.press( 'Enter' );
15+
await page.keyboard.type( '2</pre>' );
16+
17+
expect( await editor.getEditedPostContent() ).toMatchSnapshot();
18+
19+
await editor.clickBlockOptionsMenuItem( 'Convert to Blocks' );
20+
// Once it's edited, it should be saved as BR tags.
21+
await page.keyboard.type( '0' );
22+
await page.keyboard.press( 'Enter' );
23+
await editor.clickBlockOptionsMenuItem( 'Edit as HTML' );
24+
25+
expect( await editor.getEditedPostContent() ).toMatchSnapshot();
26+
} );
27+
28+
test( 'should preserve white space when merging', async ( {
29+
editor,
30+
page,
31+
} ) => {
32+
await editor.insertBlock( { name: 'core/preformatted' } );
33+
await page.keyboard.type( '1' );
34+
await page.keyboard.press( 'Enter' );
35+
await page.keyboard.type( '2' );
36+
await page.keyboard.press( 'Enter' );
37+
await editor.insertBlock( { name: 'core/paragraph' } );
38+
await page.keyboard.type( '3' );
39+
await page.keyboard.press( 'ArrowLeft' );
40+
await page.keyboard.press( 'Backspace' );
41+
42+
expect( await editor.getEditedPostContent() ).toMatchSnapshot();
43+
} );
44+
45+
test( 'should delete block when backspace in an empty preformatted', async ( {
46+
editor,
47+
page,
48+
} ) => {
49+
await editor.insertBlock( { name: 'core/preformatted' } );
50+
51+
await page.keyboard.type( 'a' );
52+
53+
await page.keyboard.press( 'Backspace' );
54+
await page.keyboard.press( 'Backspace' );
55+
56+
// Expect preformatted block to be deleted.
57+
expect( await editor.getEditedPostContent() ).toBe( '' );
58+
} );
59+
} );

0 commit comments

Comments
 (0)