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

Improve Image block e2e tests #64537

Merged
merged 1 commit into from
Aug 15, 2024
Merged
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
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
Loading