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 missing block tests to Playwright #41680

Merged
merged 2 commits into from
Aug 10, 2022
Merged
Show file tree
Hide file tree
Changes from all 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
44 changes: 0 additions & 44 deletions packages/e2e-tests/specs/editor/blocks/missing.test.js

This file was deleted.

54 changes: 54 additions & 0 deletions test/e2e/specs/editor/blocks/missing.spec.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
/**
* WordPress dependencies
*/
const { test, expect } = require( '@wordpress/e2e-test-utils-playwright' );

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

test( 'should strip potentially malicious on* attributes', async ( {
page,
} ) => {
let hasAlert = false;

page.on( 'dialog', () => {
hasAlert = true;
} );

await page.evaluate( () => {
const block = window.wp.blocks.parse(
`<!-- wp:non-existing-block-here --><img src onerror=alert(1)>`
);
window.wp.data.dispatch( 'core/block-editor' ).resetBlocks( block );
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Originally, setPostContent from e2e-test-utils was used.
However, since this utility is used infrequently, I didn't migrate this utility and rewritten to a similar process.

} );

// Give the browser time to show the alert.
await page.evaluate( () => new Promise( window.requestIdleCallback ) );

expect( hasAlert ).toBe( false );
} );

test( 'should strip potentially malicious script tags', async ( {
page,
} ) => {
let hasAlert = false;

page.on( 'dialog', () => {
hasAlert = true;
} );

await page.evaluate( () => {
const block = window.wp.blocks.parse(
`<!-- wp:non-existing-block-here --><script>alert("EVIL");</script>`
);
window.wp.data.dispatch( 'core/block-editor' ).resetBlocks( block );
} );

// Give the browser time to show the alert.
await page.evaluate( () => new Promise( window.requestIdleCallback ) );

expect( hasAlert ).toBe( false );
} );
} );