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>
62 lines
1.5 KiB
TypeScript
62 lines
1.5 KiB
TypeScript
import { test, describe, assert, afterEach } from "vitest";
|
|
import { spy } from "tinyspy";
|
|
import { cleanup, fireEvent, render, get_text, wait } from "@gradio/tootils";
|
|
import event from "@testing-library/user-event";
|
|
|
|
import Textbox from "./interactive";
|
|
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("Textbox", () => {
|
|
afterEach(() => cleanup());
|
|
|
|
test("renders provided value", async () => {
|
|
const { getByDisplayValue } = await render(Textbox, {
|
|
show_label: true,
|
|
max_lines: 1,
|
|
loading_status,
|
|
lines: 1,
|
|
value: "hello world",
|
|
label: "Textbox"
|
|
});
|
|
|
|
const item: HTMLInputElement = getByDisplayValue(
|
|
"hello world"
|
|
) as HTMLInputElement;
|
|
assert.equal(item.value, "hello world");
|
|
});
|
|
|
|
test("changing the text should update the value", async () => {
|
|
const { component, getByDisplayValue, listen } = await render(Textbox, {
|
|
show_label: true,
|
|
max_lines: 10,
|
|
loading_status,
|
|
lines: 1,
|
|
value: "hi ",
|
|
label: "Textbox"
|
|
});
|
|
|
|
const item: HTMLInputElement = getByDisplayValue("hi") as HTMLInputElement;
|
|
|
|
const mock = listen("change");
|
|
|
|
item.focus();
|
|
await event.keyboard("some text");
|
|
|
|
assert.equal(item.value, "hi some text");
|
|
assert.equal(component.value, "hi some text");
|
|
assert.equal(mock.callCount, 9);
|
|
assert.equal(mock.calls[8][0].detail.data, "hi some text");
|
|
});
|
|
});
|