mirror of
https://github.com/gradio-app/gradio.git
synced 2025-02-11 11:19:58 +08:00
* processing * add changeset * changes * add changeset * add changeset * changes * changes * clean * changes * add changeset * add changeset * root url * refactor * testing * testing * log * logs * fix * format * add changeset * remove * add root * format * apply to everything * annoying fix * fixes * lint * fixes * fixes * fixes * fix tests * fix js tests * format * fix python tests * clean guides * add changeset * add changeset * simplify * add changeset --------- Co-authored-by: gradio-pr-bot <gradio-pr-bot@users.noreply.github.com> Co-authored-by: pngwn <hello@pngwn.io>
86 lines
2.3 KiB
TypeScript
86 lines
2.3 KiB
TypeScript
import { test, describe, assert, afterEach, vi } from "vitest";
|
|
import { cleanup, render } from "@gradio/tootils";
|
|
import { setupi18n } from "../app/src/i18n";
|
|
|
|
import Gallery from "./Index.svelte";
|
|
import type { LoadingStatus } from "@gradio/statustracker";
|
|
|
|
const loading_status: LoadingStatus = {
|
|
eta: 0,
|
|
queue_position: 1,
|
|
queue_size: 1,
|
|
status: "complete" as LoadingStatus["status"],
|
|
scroll_to_output: false,
|
|
visible: true,
|
|
fn_index: 0,
|
|
show_progress: "full"
|
|
};
|
|
|
|
describe("Gallery", () => {
|
|
afterEach(() => {
|
|
cleanup();
|
|
vi.useRealTimers();
|
|
});
|
|
beforeEach(() => {
|
|
setupi18n();
|
|
});
|
|
test("renders the image provided", async () => {
|
|
const { getByTestId } = await render(Gallery, {
|
|
show_label: true,
|
|
label: "Gallery",
|
|
loading_status: loading_status,
|
|
preview: true,
|
|
root: "",
|
|
proxy_url: "",
|
|
value: [
|
|
{
|
|
image: {
|
|
path: "https://raw.githubusercontent.com/gradio-app/gradio/main/gradio/demo/video_component/files/a.mp4",
|
|
url: "https://raw.githubusercontent.com/gradio-app/gradio/main/gradio/demo/video_component/files/a.mp4"
|
|
},
|
|
caption: null
|
|
}
|
|
]
|
|
});
|
|
let item = getByTestId("detailed-image") as HTMLImageElement;
|
|
assert.equal(
|
|
item.src,
|
|
"https://raw.githubusercontent.com/gradio-app/gradio/main/gradio/demo/video_component/files/a.mp4"
|
|
);
|
|
});
|
|
|
|
test("triggers the change event if and only if the images change", async () => {
|
|
const { listen, component } = await render(Gallery, {
|
|
show_label: true,
|
|
label: "Gallery",
|
|
loading_status: loading_status,
|
|
preview: true,
|
|
root: "",
|
|
proxy_url: "",
|
|
value: [
|
|
{
|
|
image: {
|
|
path: "https://raw.githubusercontent.com/gradio-app/gradio/main/gradio/demo/video_component/files/a.mp4",
|
|
url: "https://raw.githubusercontent.com/gradio-app/gradio/main/gradio/demo/video_component/files/a.mp4"
|
|
},
|
|
caption: null
|
|
}
|
|
]
|
|
});
|
|
const change_event = listen("change");
|
|
|
|
await component.$set({
|
|
value: [
|
|
{
|
|
image: {
|
|
path: "https://raw.githubusercontent.com/gradio-app/gradio/main/gradio/demo/video_component/files/a.mp4",
|
|
url: "https://raw.githubusercontent.com/gradio-app/gradio/main/gradio/demo/video_component/files/a.mp4"
|
|
},
|
|
caption: null
|
|
}
|
|
]
|
|
});
|
|
assert.equal(change_event.callCount, 0);
|
|
});
|
|
});
|