2023-07-11 23:56:46 +08:00
|
|
|
import {
|
|
|
|
test,
|
|
|
|
describe,
|
|
|
|
assert,
|
|
|
|
afterEach,
|
|
|
|
vi,
|
|
|
|
beforeAll,
|
|
|
|
beforeEach
|
|
|
|
} from "vitest";
|
|
|
|
import { spy } from "tinyspy";
|
|
|
|
import { cleanup, render } from "@gradio/tootils";
|
2023-08-04 06:01:18 +08:00
|
|
|
import { setupi18n } from "../app/src/i18n";
|
2023-07-11 23:56:46 +08:00
|
|
|
|
2023-08-18 23:33:07 +08:00
|
|
|
import Image from "./interactive";
|
2023-08-16 02:21:41 +08:00
|
|
|
import type { LoadingStatus } from "@gradio/statustracker";
|
2023-07-11 23:56:46 +08:00
|
|
|
|
|
|
|
const loading_status = {
|
|
|
|
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" as LoadingStatus["show_progress"]
|
|
|
|
};
|
|
|
|
|
|
|
|
describe("Image", () => {
|
|
|
|
beforeAll(() => {
|
|
|
|
window.HTMLMediaElement.prototype.play = vi.fn();
|
|
|
|
window.HTMLMediaElement.prototype.pause = vi.fn();
|
|
|
|
});
|
|
|
|
beforeEach(setupi18n);
|
|
|
|
afterEach(() => cleanup());
|
|
|
|
|
|
|
|
test("image change event trigger fires when value is changed and only fires once", async () => {
|
2023-08-24 04:48:10 +08:00
|
|
|
const { component, listen } = await render(Image, {
|
2023-07-11 23:56:46 +08:00
|
|
|
show_label: true,
|
|
|
|
loading_status,
|
|
|
|
value:
|
|
|
|
"https://raw.githubusercontent.com/gradio-app/gradio/main/test/test_files/bus.png",
|
|
|
|
streaming: false,
|
|
|
|
pending: false,
|
2023-08-24 04:48:10 +08:00
|
|
|
source: "upload",
|
|
|
|
label: "Test Label",
|
|
|
|
width: 224,
|
|
|
|
height: 224,
|
|
|
|
mirror_webcam: false,
|
|
|
|
shape: [224, 224],
|
|
|
|
brush_color: "#000000",
|
|
|
|
brush_radius: 5,
|
|
|
|
mask_opacity: 0.5
|
2023-07-11 23:56:46 +08:00
|
|
|
});
|
|
|
|
|
2023-08-24 04:48:10 +08:00
|
|
|
const mock = listen("change");
|
2023-07-11 23:56:46 +08:00
|
|
|
|
|
|
|
component.value =
|
|
|
|
"https://github.com/gradio-app/gradio/blob/main/test/test_files/cheetah1.jpg";
|
|
|
|
assert.equal(mock.callCount, 1);
|
|
|
|
});
|
|
|
|
});
|