Skip to content

Commit

Permalink
Improve Image block e2e tests (#64537)
Browse files Browse the repository at this point in the history
Co-authored-by: Mamaduka <mamaduka@git.wordpress.org>
Co-authored-by: ellatrix <ellatrix@git.wordpress.org>
  • Loading branch information
3 people committed Aug 15, 2024
1 parent 294b888 commit 9fc46be
Showing 1 changed file with 44 additions and 12 deletions.
56 changes: 44 additions & 12 deletions test/e2e/specs/editor/blocks/image.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -708,13 +708,14 @@ test.describe( 'Image', () => {

await editor.clickBlockToolbarButton( 'Upload to Media Library' );

const imageBlock = editor.canvas.locator(
'role=document[name="Block: Image"i]'
await expect(
editor.canvas
.locator( 'role=document[name="Block: Image"i]' )
.locator( 'img[src^="http"]' )
).toHaveAttribute(
'src',
expect.stringMatching( /\/wp-content\/uploads\// )
);
const image = imageBlock.locator( 'img[src^="http"]' );
const src = await image.getAttribute( 'src' );

expect( src ).toMatch( /\/wp-content\/uploads\// );
} );

test( 'should upload through prepublish panel', async ( {
Expand All @@ -736,14 +737,45 @@ test.describe( 'Image', () => {
.click();

await expect( page.locator( '.components-spinner' ) ).toHaveCount( 0 );

const imageBlock = editor.canvas.locator(
'role=document[name="Block: Image"i]'
await expect(
editor.canvas
.locator( 'role=document[name="Block: Image"i]' )
.locator( 'img[src^="http"]' )
).toHaveAttribute(
'src',
expect.stringMatching( /\/wp-content\/uploads\// )
);
const image = imageBlock.locator( 'img[src^="http"]' );
const src = await image.getAttribute( 'src' );
} );

expect( src ).toMatch( /\/wp-content\/uploads\// );
test( 'uploads data url through blobs from raw handling', async ( {
editor,
page,
pageUtils,
} ) => {
const blobUrl = await page.evaluate( async () => {
const canvas = document.createElement( 'canvas' );
canvas.width = 20;
canvas.height = 20;

const ctx = canvas.getContext( '2d' );
ctx.fillStyle = 'red';
ctx.fillRect( 0, 0, 20, 20 );

return canvas.toDataURL( 'image/png' );
} );

pageUtils.setClipboardData( { html: `<img src="${ blobUrl }">` } );

await pageUtils.pressKeys( 'primary+v' );

await expect(
editor.canvas
.locator( 'role=document[name="Block: Image"i]' )
.locator( 'img[src^="http"]' )
).toHaveAttribute(
'src',
expect.stringMatching( /\/wp-content\/uploads\// )
);
} );

test( 'should have keyboard navigable link UI popover', async ( {
Expand Down

0 comments on commit 9fc46be

Please sign in to comment.