gradio/js/app/test/chatinterface_streaming_echo.spec.ts
pngwn 1419538ea7
Refactor component directories (#5074)
* asd

* changes

* fix everything

* cleanup

* add changeset

* fix casing

* lockfile

* fix casing

* fix ci, enable linting

* fix test

* add changeset

* add changeset

* delete changeset

* fix dirs

* fix casing

* fix notebooks

* fix casing

* fix casing

* fix casing

* fix casing

* fix casing

* fix casing

* fix casing

* fix casing

---------

Co-authored-by: gradio-pr-bot <gradio-pr-bot@users.noreply.github.com>
2023-08-03 23:01:18 +01:00

61 lines
2.0 KiB
TypeScript

import { test, expect } from "@gradio/tootils";
test("chatinterface works with streaming functions and all buttons behave as expected", async ({
page
}) => {
const submit_button = await page.locator("button").nth(0);
const retry_button = await page.locator("button").nth(2);
const undo_button = await page.locator("button").nth(3);
const clear_button = await page.locator("button").nth(4);
const textbox = await page.getByTestId("textbox").nth(0);
let iterations: Promise<any>[] = [];
page.on("websocket", (ws) => {
iterations.push(
ws.waitForEvent("framereceived", {
predicate: (event) => {
return (
JSON.parse(event.payload as string).msg === "process_completed"
);
}
})
);
});
await textbox.fill("hello");
await submit_button.click();
await iterations[0];
await expect(textbox).toHaveValue("");
await expect.poll(async () => page.locator(".bot.message p").count()).toBe(1);
const bot_message_0 = await page.locator(".bot.message p").nth(0);
await expect(bot_message_0).toContainText("You typed: hello");
await textbox.fill("hi");
await submit_button.click();
await iterations[1];
await expect(textbox).toHaveValue("");
await expect.poll(async () => page.locator(".bot.message p").count()).toBe(2);
const bot_message_1 = await page.locator(".bot.message p").nth(1);
await expect(bot_message_1).toContainText("You typed: hi");
await retry_button.click();
await iterations[2];
await expect(textbox).toHaveValue("");
await expect(bot_message_1).toContainText("You typed: hi");
await undo_button.click();
await iterations[3];
await expect.poll(async () => page.locator(".bot.message p").count()).toBe(1);
await expect(textbox).toHaveValue("hi");
await textbox.fill("salaam");
await submit_button.click();
await iterations[4];
await expect(textbox).toHaveValue("");
await expect.poll(async () => page.locator(".bot.message p").count()).toBe(2);
await expect(bot_message_1).toContainText("You typed: salaam");
await clear_button.click();
await expect.poll(async () => page.locator(".bot.message p").count()).toBe(0);
});