File size: 2,330 Bytes
0bd62e5 |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 |
import { test, describe, assert, afterEach, vi } from "vitest";
import { cleanup, render } from "@self/tootils";
import { setupi18n } from "../core/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,
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,
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);
});
});
|