From 63082245b2759ded80cfe313dc0eadd71c41e36e Mon Sep 17 00:00:00 2001 From: Kai Hao Date: Fri, 21 Apr 2023 13:59:33 +0800 Subject: [PATCH] Add test for dragging-and-dropping html --- test/e2e/specs/editor/blocks/image.spec.js | 60 ++++++++++++++++++++++ 1 file changed, 60 insertions(+) diff --git a/test/e2e/specs/editor/blocks/image.spec.js b/test/e2e/specs/editor/blocks/image.spec.js index cf88307bcabb18..513cdddb6aec45 100644 --- a/test/e2e/specs/editor/blocks/image.spec.js +++ b/test/e2e/specs/editor/blocks/image.spec.js @@ -624,6 +624,66 @@ test.describe( 'Image', () => { ).toBe( new URL( page.url() ).host ); }, 'should replace the original image with the second image' ).toPass(); } ); + + test( 'should allow dragging and dropping HTML to media placeholder', async ( { + page, + editor, + } ) => { + await editor.insertBlock( { name: 'core/image' } ); + const imageBlock = page.getByRole( 'document', { + name: 'Block: Image', + } ); + + const html = ` +
+ Cat +
"Cat" by tomhouslay is licensed under CC BY-NC 2.0.
+
+ `; + + await page.evaluate( ( _html ) => { + const dummy = document.createElement( 'div' ); + dummy.style.width = '10px'; + dummy.style.height = '10px'; + dummy.style.zIndex = 99999; + dummy.style.position = 'fixed'; + dummy.style.top = 0; + dummy.style.left = 0; + dummy.draggable = 'true'; + dummy.addEventListener( 'dragstart', ( event ) => { + event.dataTransfer.setData( 'text/html', _html ); + setTimeout( () => { + dummy.remove(); + }, 0 ); + } ); + document.body.appendChild( dummy ); + }, html ); + + await page.mouse.move( 0, 0 ); + await page.mouse.down(); + await imageBlock.hover(); + await page.mouse.up(); + + const host = new URL( page.url() ).host; + + await expect.poll( editor.getBlocks ).toMatchObject( [ + { + name: 'core/image', + attributes: { + link: expect.stringContaining( host ), + url: expect.stringContaining( host ), + id: expect.any( Number ), + alt: 'Cat', + caption: `"Cat" by tomhouslay is licensed under CC BY-NC 2.0.`, + }, + }, + ] ); + const url = ( await editor.getBlocks() )[ 0 ].attributes.url; + await expect( imageBlock.getByRole( 'img' ) ).toHaveAttribute( + 'src', + url + ); + } ); } ); class ImageBlockUtils {