mirror of
https://github.com/gradio-app/gradio.git
synced 2024-11-27 01:40:20 +08:00
fe057300f0
* delegate gradio events via a custom event dispatcher * improve md perf + share code * fix df markdown * prevent model3d from rerending too frequently * tweaks * fix more event bugs with video * add changeset * optimise handle mount * does this do anything * fix * remove old dispatches * fix dropdown position * oops * fixes * fix tests * fix types * format * fix markdown code * add changeset * fix typecheck * fix typecheck * fix demos * notebooks * fix tests * changer * maybe this * fixes * add changeset * fix chatbot alignment mobile * fix chantbot * add changeset * changeset * changeset * storybook --------- Co-authored-by: gradio-pr-bot <gradio-pr-bot@users.noreply.github.com> Co-authored-by: Abubakar Abid <abubakar@huggingface.co>
69 lines
1.8 KiB
TypeScript
69 lines
1.8 KiB
TypeScript
import { test, describe, expect, vi, afterEach, assert } from "vitest";
|
|
import { spy, spyOn } from "tinyspy";
|
|
import { cleanup, render, wait_for_event } from "@gradio/tootils";
|
|
import event from "@testing-library/user-event";
|
|
import { setupi18n } from "../app/src/i18n";
|
|
import UploadButton from "./interactive";
|
|
|
|
describe("UploadButton", () => {
|
|
afterEach(() => {
|
|
cleanup();
|
|
vi.restoreAllMocks();
|
|
});
|
|
|
|
test("Uploads with blob", async () => {
|
|
vi.mock("@gradio/client", async () => {
|
|
return {
|
|
upload_files: vi.fn((f) => new Promise((res) => res({})))
|
|
};
|
|
});
|
|
|
|
const api = await import("@gradio/client");
|
|
|
|
setupi18n();
|
|
|
|
const { getByTestId } = await render(UploadButton, {
|
|
label: "file",
|
|
value: null,
|
|
root: "http://localhost:7860",
|
|
file_count: "1"
|
|
});
|
|
|
|
const item = getByTestId("file-upload-button"); // container.querySelectorAll("input")[0];
|
|
|
|
const file = new File(["hello"], "my-audio.wav", { type: "audio/wav" });
|
|
await event.upload(item, file);
|
|
|
|
expect(api.upload_files).toHaveBeenCalled();
|
|
});
|
|
|
|
test("upload sets change event", async () => {
|
|
vi.mock("@gradio/client", async () => {
|
|
return {
|
|
upload_files: vi.fn((f) => new Promise((res) => res({})))
|
|
};
|
|
});
|
|
|
|
await import("@gradio/client");
|
|
setupi18n();
|
|
const { component, getByTestId, wait_for_event } = await render(
|
|
UploadButton,
|
|
{
|
|
label: "file",
|
|
value: null,
|
|
root: "http://localhost:7860",
|
|
file_count: "1"
|
|
}
|
|
);
|
|
|
|
const item = getByTestId("file-upload-button"); //container.querySelectorAll("input")[0];
|
|
const file = new File(["hello"], "my-audio.wav", { type: "audio/wav" });
|
|
event.upload(item, file);
|
|
const mock = await wait_for_event("change");
|
|
expect(mock.callCount).toBe(1);
|
|
const [data] = component.$capture_state().value;
|
|
expect(data).toBeTruthy();
|
|
assert.equal(data.name, "my-audio.wav");
|
|
});
|
|
});
|