gradio/js/app/test/gallery_component_events.spec.ts

50 lines
1.6 KiB
TypeScript
Raw Normal View History

import { test, expect } from "@gradio/tootils";
test("Gallery preview mode displays all images correctly.", async ({
page
}) => {
await page.getByRole("button", { name: "Run" }).click();
await page.getByLabel("Thumbnail 2 of 3").click();
await expect(
await page.getByTestId("detailed-image").getAttribute("src")
).toEqual("https://gradio-builds.s3.amazonaws.com/assets/lite-logo.png");
await expect(
await page.getByTestId("thumbnail 1").getAttribute("src")
).toEqual("https://gradio-builds.s3.amazonaws.com/assets/cheetah-003.jpg");
});
Fix the download button of the `gr.Gallery()` component to work (#6487) * Fix the download button of the `gr.Gallery()` component to work * Refactoring js/gallery/shared/Gallery.svelte * Fix `gr.Gallery()` to set `orig_name` for URLs * Fix Gallery.postprocess() * Fix `download()` to fallback to `window.open()` when CORS is not allowed * Fix `gr.Gallery` to leave as None so it will be replaced with a local cache path and restore the `<a>` tag-based download feature on the frontend * Align a variable name to its type name * Fix Gallery's tests * Fix the frontend test for gallery * Revert "Fix `gr.Gallery` to leave as None so it will be replaced with a local cache path and restore the `<a>` tag-based download feature on the frontend" This reverts commit d754980cc27ded760bfc26df4310f913c2c6944a. * Revert "Fix Gallery's tests" This reverts commit 4e2aa3fff1ef7b586839fa6c485d1a3b8738fd03. * Revert "Fix the frontend test for gallery" This reverts commit 007caa23e7b9dbab36376307137a30f277fca297. * Fix for linter * Add a test about the download button * Fix type defs on Gallery.postprocess * Improve TestGallery * add changeset * Update gradio/components/gallery.py Co-authored-by: Abubakar Abid <abubakar@huggingface.co> * Update gradio/components/gallery.py Co-authored-by: Abubakar Abid <abubakar@huggingface.co> * Revert "Update gradio/components/gallery.py" This reverts commit 4d6e12730511fe9840a5372787ad81fd83cbb44c. * Revert "Update gradio/components/gallery.py" This reverts commit f2bfad0744d20e121c8eef40a335979a7c703517. * Use `tuple` instead of `typing.Tuple` * Revert "Use `tuple` instead of `typing.Tuple`" This reverts commit 69ab93cad4f39fe38f0e0f88126be572bf12cecf. --------- Co-authored-by: gradio-pr-bot <gradio-pr-bot@users.noreply.github.com> Co-authored-by: Abubakar Abid <abubakar@huggingface.co>
2023-12-10 00:58:19 +08:00
test("Gallery select event returns the right value and the download button works correctly", async ({
page
}) => {
await page.getByRole("button", { name: "Run" }).click();
await page.getByLabel("Thumbnail 2 of 3").click();
await expect(page.getByLabel("Select Data")).toHaveValue(
"https://gradio-builds.s3.amazonaws.com/assets/lite-logo.png"
);
Fix the download button of the `gr.Gallery()` component to work (#6487) * Fix the download button of the `gr.Gallery()` component to work * Refactoring js/gallery/shared/Gallery.svelte * Fix `gr.Gallery()` to set `orig_name` for URLs * Fix Gallery.postprocess() * Fix `download()` to fallback to `window.open()` when CORS is not allowed * Fix `gr.Gallery` to leave as None so it will be replaced with a local cache path and restore the `<a>` tag-based download feature on the frontend * Align a variable name to its type name * Fix Gallery's tests * Fix the frontend test for gallery * Revert "Fix `gr.Gallery` to leave as None so it will be replaced with a local cache path and restore the `<a>` tag-based download feature on the frontend" This reverts commit d754980cc27ded760bfc26df4310f913c2c6944a. * Revert "Fix Gallery's tests" This reverts commit 4e2aa3fff1ef7b586839fa6c485d1a3b8738fd03. * Revert "Fix the frontend test for gallery" This reverts commit 007caa23e7b9dbab36376307137a30f277fca297. * Fix for linter * Add a test about the download button * Fix type defs on Gallery.postprocess * Improve TestGallery * add changeset * Update gradio/components/gallery.py Co-authored-by: Abubakar Abid <abubakar@huggingface.co> * Update gradio/components/gallery.py Co-authored-by: Abubakar Abid <abubakar@huggingface.co> * Revert "Update gradio/components/gallery.py" This reverts commit 4d6e12730511fe9840a5372787ad81fd83cbb44c. * Revert "Update gradio/components/gallery.py" This reverts commit f2bfad0744d20e121c8eef40a335979a7c703517. * Use `tuple` instead of `typing.Tuple` * Revert "Use `tuple` instead of `typing.Tuple`" This reverts commit 69ab93cad4f39fe38f0e0f88126be572bf12cecf. --------- Co-authored-by: gradio-pr-bot <gradio-pr-bot@users.noreply.github.com> Co-authored-by: Abubakar Abid <abubakar@huggingface.co>
2023-12-10 00:58:19 +08:00
const downloadPromise = page.waitForEvent("download");
await page.getByLabel("Download").click();
const download = await downloadPromise;
expect(download.suggestedFilename()).toBe("lite-logo.png");
});
test("Gallery click-to-upload, upload and change events work correctly", async ({
page
}) => {
await page
.getByRole("button", { name: "Drop Image(s) Here - or - Click to Upload" })
.first()
.click();
const uploader = await page.locator("input[type=file]").first();
await uploader.setInputFiles([
"./test/files/cheetah1.jpg",
"./test/files/cheetah1.jpg"
]);
await expect(page.getByLabel("Num Upload")).toHaveValue("1");
await page.getByLabel("Clear").first().click();
await expect(page.getByLabel("Num Change")).toHaveValue("1");
});