mirror of
https://github.com/gradio-app/gradio.git
synced 2024-12-15 02:11:15 +08:00
15da39fca0
* first pass * multimodal textbox * add changeset * remove file * more changes * changes * add changeset * revert demo * doc strings fix * update demo * file icons * more updates * format * add story * remove doc line * type fixes * chat interface * new demo * image upload fix * ui changes * addressing PR comments * format * type check * more pr fixes * format * format * test fixes * test fixes * Streaming fixes + other stuff * optional keys to dict value * final fixes * notebook * format * Update guides/04_chatbots/01_creating-a-chatbot-fast.md Co-authored-by: Abubakar Abid <abubakar@huggingface.co> * Update guides/04_chatbots/01_creating-a-chatbot-fast.md Co-authored-by: Abubakar Abid <abubakar@huggingface.co> * Update guides/04_chatbots/01_creating-a-chatbot-fast.md Co-authored-by: Abubakar Abid <abubakar@huggingface.co> * merge * backend fixes * story fix * ui test fix * format * story * format * demo fix * streaming test fix * stories fix * stories fix --------- Co-authored-by: gradio-pr-bot <gradio-pr-bot@users.noreply.github.com> Co-authored-by: Abubakar Abid <abubakar@huggingface.co>
70 lines
1.8 KiB
TypeScript
70 lines
1.8 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 MultimodalTextbox 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("MultimodalTextbox", () => {
|
|
afterEach(() => cleanup());
|
|
|
|
test("renders provided value", async () => {
|
|
const { getByDisplayValue } = await render(MultimodalTextbox, {
|
|
show_label: true,
|
|
max_lines: 1,
|
|
loading_status,
|
|
lines: 1,
|
|
value: { text: "hello world", files: [] },
|
|
label: "Textbox",
|
|
interactive: false,
|
|
root: ""
|
|
});
|
|
|
|
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(
|
|
MultimodalTextbox,
|
|
{
|
|
show_label: true,
|
|
max_lines: 10,
|
|
loading_status,
|
|
lines: 1,
|
|
value: { text: "hi ", files: [] },
|
|
label: "MultimodalTextbox",
|
|
interactive: true,
|
|
root: ""
|
|
}
|
|
);
|
|
|
|
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.text, "hi some text");
|
|
assert.equal(mock.callCount, 9);
|
|
assert.equal(mock.calls[8][0].detail.data.text, "hi some text");
|
|
assert.equal(mock.calls[8][0].detail.data.files.length, 0);
|
|
});
|
|
});
|