Skip to content
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

Migrate code block test case to playwright #40844

Closed
Closed
Show file tree
Hide file tree
Changes from 8 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view

This file was deleted.

48 changes: 0 additions & 48 deletions packages/e2e-tests/specs/editor/blocks/code.test.js

This file was deleted.

62 changes: 62 additions & 0 deletions test/e2e/specs/editor/blocks/code.spec.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
/**
* WordPress dependencies
*/

const { test, expect } = require( '@wordpress/e2e-test-utils-playwright' );

test.describe( 'Code', () => {
test.beforeEach( async ( { admin } ) => {
await admin.createNewPost();
} );

test( 'can be created by three backticks and enter', async ( {
editor,
page,
} ) => {
await page.click( 'role=button[name="Add default block"i]' );
await page.keyboard.type( '```' );
await page.keyboard.press( 'Enter' );
await page.keyboard.type( '<?php' );

// Check the content
const content = await editor.getEditedPostContent();
expect( content ).toBe(
`<!-- wp:code -->
<pre class="wp-block-code"><code>&lt;?php</code></pre>
<!-- /wp:code -->`
);
} );

test( 'should delete block when backspace in an empty code', async ( {
editor,
page,
} ) => {
await editor.insertBlock( { name: 'core/code' } );

await page.keyboard.type( 'a' );

await page.keyboard.press( 'Backspace' );
await page.keyboard.press( 'Backspace' );

// Expect code block to be deleted.
expect( await editor.getEditedPostContent() ).toBe( '' );
} );

test( 'should paste plain text', async ( { editor, page, pageUtils } ) => {
kevin940726 marked this conversation as resolved.
Show resolved Hide resolved
await editor.insertBlock( { name: 'core/code' } );

// Test to see if HTML and white space is kept.
await pageUtils.setClipboardData( { plainText: '<img />\n\t<br>' } );

await pageUtils.pressKeyWithModifier( 'primary', 'v' );

// Check the content
const content = await editor.getEditedPostContent();
expect( content ).toBe(
`<!-- wp:code -->
<pre class="wp-block-code"><code>&lt;img />
&lt;br></code></pre>
<!-- /wp:code -->`
);
} );
} );