mirror of
https://github.com/gradio-app/gradio.git
synced 2025-01-24 10:54:04 +08:00
29c916c9a6
* Add success e2e test * add demo notebook * Fix * Fix test * Make modifications * Dont use timeouts * Format * Success e2e test fix (#4698) * try this * tweak * tweak * tweak * cleanup * cleanup --------- Co-authored-by: pngwn <hello@pngwn.io>
76 lines
2.1 KiB
TypeScript
76 lines
2.1 KiB
TypeScript
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;
|
|
|
|
const data = (await url.json()).data[0];
|
|
return data === "Consecutive Event Triggered";
|
|
}
|
|
|
|
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);
|
|
});
|