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

Add test to verify image appears on frontend #50472

Merged

Conversation

artemiomorales
Copy link
Contributor

What?

This PR adds a test to confirm that the image block actually outputs the expected element in the frontend published post content.

Why?

While we've done a good job of testing to make sure the image behaves as expected in the editor, this adds extra verification so we can catch if the image block ever breaks.

This will be especially important as we look to extend the image functionality with a lightbox #50373

How?

It adds to a test to the image.spec.js

Testing Instructions

Run npm run test:e2e:playwright -- image.spec.js to test the single test file locally.

Testing Instructions for Keyboard

N/A

Screenshots or screencast

@artemiomorales artemiomorales requested a review from gziolo May 9, 2023 15:18
Copy link
Member

@gziolo gziolo left a comment

Choose a reason for hiding this comment

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

Nice, this is a good start before we start covering other use cases with the lightbox enabled 😀

test/e2e/specs/editor/blocks/image.spec.js Outdated Show resolved Hide resolved
@gziolo gziolo added [Block] Image Affects the Image Block [Type] Automated Testing Testing infrastructure changes impacting the execution of end-to-end (E2E) and/or unit tests. labels May 9, 2023
@artemiomorales
Copy link
Contributor Author

@gziolo Thanks for the review! I added a check for the child img of the figure element and verified that its src attribute is correct. Note: For some reason, getByRole doesn't work when called on the figure element, so I used the locator instead.

gziolo

This comment was marked as duplicate.

Copy link
Member

@gziolo gziolo left a comment

Choose a reason for hiding this comment

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

This looks good to start with.

It’s very likely that you need to set an alt attribute on the image for the licator to be able to find it. The img without the alt is not accessible.

@gziolo gziolo marked this pull request as ready for review May 10, 2023 07:15
@gziolo gziolo requested a review from kevin940726 as a code owner May 10, 2023 07:15
@artemiomorales artemiomorales merged commit bdce28d into WordPress:trunk May 10, 2023
@github-actions github-actions bot added this to the Gutenberg 15.8 milestone May 10, 2023
Copy link
Member

@kevin940726 kevin940726 left a comment

Choose a reason for hiding this comment

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

LGTM 👍

@kevin940726
Copy link
Member

It’s very likely that you need to set an alt attribute on the image for the licator to be able to find it.

I wonder why we don't automatically set an empty alt attribute if the user doesn't specify it?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
[Block] Image Affects the Image Block [Type] Automated Testing Testing infrastructure changes impacting the execution of end-to-end (E2E) and/or unit tests.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants