Skip to content

Gallery Unit Tests#13213

Merged
freddyaboulton merged 8 commits intomainfrom
13080-gallery-unit-tests
Apr 9, 2026
Merged

Gallery Unit Tests#13213
freddyaboulton merged 8 commits intomainfrom
13080-gallery-unit-tests

Conversation

@freddyaboulton
Copy link
Copy Markdown
Collaborator

@freddyaboulton freddyaboulton commented Apr 7, 2026

Description

Closes: #13080
Closes: #13217

Fixed two issues as well:

  • on_custom_button_click got renamed to custom_button_click
  • The API for the data passed between Gallery.svelte and Index.svelte changed and so Index.svelte was out of date

AI Disclosure

We encourage the use of AI tooling in creating PRs, but the any non-trivial use of AI needs be disclosed. E.g. if you used Claude to write a first draft, you should mention that. Trivial tab-completion doesn't need to be disclosed. You should self-review all PRs, especially if they were generated with AI.

  • I used AI to implement the tests following our pattern
  • I did not use AI

🎯 PRs Should Target Issues

Before your create a PR, please check to see if there is an existing issue for this change. If not, please create an issue before you create this PR, unless the fix is very small.

Not adhering to this guideline will result in the PR being closed.

Testing and Formatting Your Code

  1. PRs will only be merged if tests pass on CI. We recommend at least running the backend tests locally, please set up your Gradio environment locally and run the backed tests: bash scripts/run_backend_tests.sh

  2. Please run these bash scripts to automatically format your code: bash scripts/format_backend.sh, and (if you made any changes to non-Python files) bash scripts/format_frontend.sh

@gradio-pr-bot
Copy link
Copy Markdown
Collaborator

gradio-pr-bot commented Apr 7, 2026

🪼 branch checks and previews

Name Status URL
Spaces ready! Spaces preview
Storybook ready! Storybook preview
🦄 Changes detected! Details

Install Gradio from this PR

pip install https://huggingface.co/buckets/gradio/pypi-previews/resolve/3dea27aadd6c94c137583392ec9407fc4590c952/gradio-6.11.0-py3-none-any.whl

Install Gradio Python Client from this PR

pip install "gradio-client @ git+https://github.com/gradio-app/gradio@3dea27aadd6c94c137583392ec9407fc4590c952#subdirectory=client/python"

Install Gradio JS Client from this PR

npm install https://gradio-npm-previews.s3.amazonaws.com/3dea27aadd6c94c137583392ec9407fc4590c952/gradio-client-2.1.0.tgz

@gradio-pr-bot
Copy link
Copy Markdown
Collaborator

gradio-pr-bot commented Apr 7, 2026

🦄 change detected

This Pull Request includes changes to the following packages.

Package Version
@gradio/gallery patch
gradio patch

  • Gallery Unit Tests

✅ Changeset approved by @freddyaboulton

  • Maintainers can remove approval by unchecking this checkbox.

Something isn't right?

  • Maintainers can change the version label to modify the version bump.
  • If the bot has failed to detect any changes, or if this pull request needs to update multiple packages to different versions or requires a more comprehensive changelog entry, maintainers can update the changelog file directly.

@freddyaboulton freddyaboulton changed the title 13080 gallery unit tests Gallery Unit Tests Apr 7, 2026
@freddyaboulton freddyaboulton added the v: patch A change that requires a patch release label Apr 7, 2026
@freddyaboulton freddyaboulton marked this pull request as ready for review April 7, 2026 21:26
Copy link
Copy Markdown
Member

@pngwn pngwn left a comment

Choose a reason for hiding this comment

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

Look great @freddyaboulton. But we are doing a lot of truthy checks on elements. I'd rather we asserted on exactly what we expect. Are they visible, hidden, not rendered etc.

There are more appropriate expect methods for that:

  • toBeInTheDocument() / not.toBeInTheDocument()
  • toBeInTheViewport() / not.toBeInTheViewport()
  • toBeVisible() / not.toBeVisible()

I think i'll need to modify the skill a bit.

});

// Gallery uses {#if show_label} — label is completely removed, not just hidden
expect(queryByText("My Gallery")).toBeNull();
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

I think not.toBeInTheDocument() works for this case, unless i've just made it up.

Comment on lines +123 to +126
expect(getByRole("button", { name: "Thumbnail 1 of 3" })).toBeTruthy();
expect(getByRole("button", { name: "Thumbnail 2 of 3" })).toBeTruthy();
expect(getByRole("button", { name: "Thumbnail 3 of 3" })).toBeTruthy();
});
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

toBeVisible()

Comment on lines +134 to +135
expect(getByRole("button", { name: "Thumbnail 1 of 2" })).toBeTruthy();
expect(getByRole("button", { name: "Thumbnail 2 of 2" })).toBeTruthy();
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

toBeVisible()

show_label: true,
label: "Gallery",
loading_status: loading_status,
// ─── Props: selected_index ───────────────────────────────────────────
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Can we get rid of these redundant comments pls, they are just duplicating the describe block.

@freddyaboulton
Copy link
Copy Markdown
Collaborator Author

On it @pngwn ! Thank you

@freddyaboulton
Copy link
Copy Markdown
Collaborator Author

I think I've addressed all the comments @pngwn !

Copy link
Copy Markdown
Member

@pngwn pngwn left a comment

Choose a reason for hiding this comment

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

Looks great. Thanks @freddyaboulton!

@freddyaboulton
Copy link
Copy Markdown
Collaborator Author

Thanks for the review @pngwn !

@freddyaboulton freddyaboulton merged commit 457f130 into main Apr 9, 2026
24 of 25 checks passed
@freddyaboulton freddyaboulton deleted the 13080-gallery-unit-tests branch April 9, 2026 14:07
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

v: patch A change that requires a patch release

Projects

None yet

Development

Successfully merging this pull request may close these issues.

gallery: refactor unit tests

3 participants