2023-06-28 03:34:52 +08:00
|
|
|
import { test, expect } from "@gradio/tootils";
|
|
|
|
import type { Response } from "@playwright/test";
|
|
|
|
|
|
|
|
test(".success event runs after function successfully completes. .success should not run if function fails", async ({
|
|
|
|
page
|
|
|
|
}) => {
|
|
|
|
const textbox = page.getByLabel("Result");
|
|
|
|
await expect(textbox).toHaveValue("");
|
|
|
|
|
|
|
|
await Promise.all([
|
|
|
|
page.waitForResponse("**/run/predict"),
|
|
|
|
page.click("text=Trigger Failure")
|
|
|
|
]);
|
|
|
|
expect(textbox).toHaveValue("");
|
|
|
|
|
|
|
|
await Promise.all([
|
|
|
|
page.click("text=Trigger Success"),
|
|
|
|
page.waitForResponse("**/run/predict")
|
|
|
|
]);
|
|
|
|
|
|
|
|
expect(textbox).toHaveValue("Success event triggered");
|
|
|
|
});
|
|
|
|
|
|
|
|
test("Consecutive .success event is triggered successfully", async ({
|
|
|
|
page
|
|
|
|
}) => {
|
|
|
|
const textbox = page.getByLabel("Consecutive Event");
|
|
|
|
const first = page.getByLabel("Result");
|
|
|
|
|
|
|
|
async function predicate(url: Response) {
|
|
|
|
const is_json =
|
|
|
|
(await url.headerValue("content-type")) === "application/json";
|
|
|
|
if (!is_json) return false;
|
|
|
|
|
2023-06-29 05:40:53 +08:00
|
|
|
const data = await url.json();
|
|
|
|
return data?.data?.[0] === "Consecutive Event Triggered";
|
2023-06-28 03:34:52 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
await Promise.all([
|
|
|
|
page.waitForResponse(predicate),
|
|
|
|
page.click("text=Trigger Consecutive Success")
|
|
|
|
]);
|
|
|
|
|
|
|
|
await expect(textbox).toHaveValue("Consecutive Event Triggered");
|
|
|
|
expect(first).toHaveValue("First Event Trigered");
|
|
|
|
});
|
|
|
|
|
|
|
|
test("gr.Error makes the toast show up", async ({ page }) => {
|
|
|
|
await Promise.all([
|
|
|
|
page.waitForResponse("**/run/predict"),
|
|
|
|
page.click("text=Trigger Failure")
|
|
|
|
]);
|
|
|
|
|
|
|
|
const toast = page.getByTestId("error-toast");
|
|
|
|
expect(toast).toContainText("Something went wrong");
|
|
|
|
const close = page.getByTestId("error-close");
|
|
|
|
await close.click();
|
|
|
|
await expect(page.getByTestId("error-toast")).toHaveCount(0);
|
|
|
|
});
|
|
|
|
|
|
|
|
test("ValueError makes the toast show up when show_error=True", async ({
|
|
|
|
page
|
|
|
|
}) => {
|
|
|
|
await Promise.all([
|
|
|
|
page.waitForResponse("**/run/predict"),
|
|
|
|
page.click("text=Trigger Failure With ValueError")
|
|
|
|
]);
|
|
|
|
|
|
|
|
const toast = page.getByTestId("error-toast");
|
|
|
|
|
|
|
|
expect(toast).toContainText("Something went wrong");
|
|
|
|
const close = page.getByTestId("error-close");
|
|
|
|
await close.click();
|
|
|
|
await expect(page.getByTestId("error-toast")).toHaveCount(0);
|
|
|
|
});
|