mirror of
https://github.com/gradio-app/gradio.git
synced 2024-12-21 02:19:59 +08:00
4221290d84
* first commit * Add code * Tests + code * lint * Add code * notebook * add changeset * type * Add client test * type * Add code * Chatbot type * Add code * test chatbot * fix e2e test * js tests * Consolidate Error and Tool message. Allow Messages in postprocess * Rename to messages * fix tests * notebook clean * More tests and messages * add changeset * notebook * client test * Fix issues * Chatbot docs * add changeset * Add image * Add img tag * Address comments * Add code * Revert chatinterface streaming change. Use title in metadata. Address pngwn comments * Add code * changelog highlight --------- Co-authored-by: gradio-pr-bot <gradio-pr-bot@users.noreply.github.com>
96 lines
3.1 KiB
TypeScript
96 lines
3.1 KiB
TypeScript
import { test, expect, go_to_testcase } from "@gradio/tootils";
|
|
|
|
for (const msg_format of ["tuples", "messages"]) {
|
|
test(`msg format ${msg_format} chatinterface works with streaming functions and all buttons behave as expected`, async ({
|
|
page
|
|
}) => {
|
|
if (msg_format === "messages") {
|
|
await go_to_testcase(page, "messages");
|
|
}
|
|
const submit_button = page.getByRole("button", { name: "Submit" });
|
|
const retry_button = page.getByRole("button", { name: "🔄 Retry" });
|
|
const undo_button = page.getByRole("button", { name: "↩️ Undo" });
|
|
const clear_button = page.getByRole("button", { name: "🗑️ Clear" });
|
|
const textbox = page.getByPlaceholder("Type a message...");
|
|
|
|
await textbox.fill("hello");
|
|
await submit_button.click();
|
|
|
|
await expect(textbox).toHaveValue("");
|
|
const expected_text_el_0 = page.locator(".bot p", {
|
|
hasText: "Run 1 - You typed: hello"
|
|
});
|
|
await expect(expected_text_el_0).toBeVisible();
|
|
await expect
|
|
.poll(async () => page.locator(".bot.message").count(), { timeout: 2000 })
|
|
.toBe(1);
|
|
|
|
await textbox.fill("hi");
|
|
await submit_button.click();
|
|
await expect(textbox).toHaveValue("");
|
|
const expected_text_el_1 = page.locator(".bot p", {
|
|
hasText: "Run 2 - You typed: hi"
|
|
});
|
|
await expect(expected_text_el_1).toBeVisible();
|
|
await expect
|
|
.poll(async () => page.locator(".bot.message").count(), { timeout: 2000 })
|
|
.toBe(2);
|
|
|
|
await undo_button.click();
|
|
await expect
|
|
.poll(async () => page.locator(".message.bot").count(), { timeout: 5000 })
|
|
.toBe(1);
|
|
await expect(textbox).toHaveValue("hi");
|
|
|
|
await retry_button.click();
|
|
const expected_text_el_2 = page.locator(".bot p", {
|
|
hasText: ""
|
|
});
|
|
await expect(expected_text_el_2).toBeVisible();
|
|
|
|
await expect
|
|
.poll(async () => page.locator(".message.bot").count(), { timeout: 5000 })
|
|
.toBe(1);
|
|
|
|
await textbox.fill("hi");
|
|
await submit_button.click();
|
|
await expect(textbox).toHaveValue("");
|
|
const expected_text_el_3 = page.locator(".bot p", {
|
|
hasText: "Run 4 - You typed: hi"
|
|
});
|
|
await expect(expected_text_el_3).toBeVisible();
|
|
await expect
|
|
.poll(async () => page.locator(".bot.message").count(), { timeout: 2000 })
|
|
.toBe(2);
|
|
|
|
await clear_button.click();
|
|
await expect
|
|
.poll(async () => page.locator(".bot.message").count(), { timeout: 5000 })
|
|
.toBe(0);
|
|
});
|
|
|
|
test(`msg format ${msg_format} the api recorder correctly records the api calls`, async ({
|
|
page
|
|
}) => {
|
|
if (msg_format === "messages") {
|
|
await go_to_testcase(page, "messages");
|
|
}
|
|
const textbox = page.getByPlaceholder("Type a message...");
|
|
const submit_button = page.getByRole("button", { name: "Submit" });
|
|
await textbox.fill("hi");
|
|
|
|
await page.getByRole("button", { name: "Use via API logo" }).click();
|
|
await page.locator("#start-api-recorder").click();
|
|
await submit_button.click();
|
|
await expect(textbox).toHaveValue("");
|
|
await expect(page.locator(".bot p").first()).toContainText(
|
|
/\- You typed: hi/
|
|
);
|
|
const api_recorder = await page.locator("#api-recorder");
|
|
await api_recorder.click();
|
|
await expect(page.locator("#num-recorded-api-calls")).toContainText(
|
|
"🪄 Recorded API Calls [5]"
|
|
);
|
|
});
|
|
}
|