From a382219e36e906dd12fbd49ee88a9178876f4359 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Tetsuaki=20Hamano=20/=20=E6=B5=9C=E9=87=8E=20=E5=93=B2?= =?UTF-8?q?=E6=98=8E?= Date: Sun, 12 Jun 2022 13:02:56 +0000 Subject: [PATCH] Migrate missing block tests to Playwright --- .../specs/editor/blocks/missing.test.js | 44 --------------- test/e2e/specs/editor/blocks/missing.spec.js | 54 +++++++++++++++++++ 2 files changed, 54 insertions(+), 44 deletions(-) delete mode 100644 packages/e2e-tests/specs/editor/blocks/missing.test.js create mode 100644 test/e2e/specs/editor/blocks/missing.spec.js diff --git a/packages/e2e-tests/specs/editor/blocks/missing.test.js b/packages/e2e-tests/specs/editor/blocks/missing.test.js deleted file mode 100644 index 4c74cdab9c336f..00000000000000 --- a/packages/e2e-tests/specs/editor/blocks/missing.test.js +++ /dev/null @@ -1,44 +0,0 @@ -/** - * WordPress dependencies - */ -import { createNewPost, setPostContent } from '@wordpress/e2e-test-utils'; - -describe( 'missing block', () => { - beforeEach( async () => { - await createNewPost(); - } ); - - it( 'should strip potentially malicious on* attributes', async () => { - let hasAlert = false; - - page.on( 'dialog', () => { - hasAlert = true; - } ); - - await setPostContent( - `` - ); - - // Give the browser time to show the alert. - await page.evaluate( () => new Promise( window.requestIdleCallback ) ); - - expect( hasAlert ).toBe( false ); - } ); - - it( 'hould strip potentially malicious script tags', async () => { - let hasAlert = false; - - page.on( 'dialog', () => { - hasAlert = true; - } ); - - await setPostContent( - `` - ); - - // Give the browser time to show the alert. - await page.evaluate( () => new Promise( window.requestIdleCallback ) ); - - expect( hasAlert ).toBe( false ); - } ); -} ); diff --git a/test/e2e/specs/editor/blocks/missing.spec.js b/test/e2e/specs/editor/blocks/missing.spec.js new file mode 100644 index 00000000000000..69c26c3f858762 --- /dev/null +++ b/test/e2e/specs/editor/blocks/missing.spec.js @@ -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( + `` + ); + 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 ); + } ); + + 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( + `` + ); + 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 ); + } ); +} );