2023-06-28 03:34:52 +08:00
|
|
|
import { test, expect } from "@gradio/tootils";
|
|
|
|
import type { Response } from "@playwright/test";
|
|
|
|
|
2023-07-11 03:53:09 +08:00
|
|
|
test(".success should not run if function fails", async ({ page }) => {
|
2023-07-07 08:37:20 +08:00
|
|
|
let last_iteration;
|
2023-06-28 03:34:52 +08:00
|
|
|
const textbox = page.getByLabel("Result");
|
|
|
|
await expect(textbox).toHaveValue("");
|
|
|
|
|
2023-07-07 08:37:20 +08:00
|
|
|
page.on("websocket", (ws) => {
|
|
|
|
last_iteration = ws.waitForEvent("framereceived", {
|
|
|
|
predicate: (event) => {
|
|
|
|
return JSON.parse(event.payload as string).msg === "process_completed";
|
|
|
|
}
|
|
|
|
});
|
|
|
|
});
|
2023-06-28 03:34:52 +08:00
|
|
|
|
2023-07-07 08:37:20 +08:00
|
|
|
await page.click("text=Trigger Failure");
|
|
|
|
await last_iteration;
|
|
|
|
expect(textbox).toHaveValue("");
|
2023-07-11 03:53:09 +08:00
|
|
|
});
|
2023-06-28 03:34:52 +08:00
|
|
|
|
2023-07-11 03:53:09 +08:00
|
|
|
test(".success event runs after function successfully completes", async ({
|
|
|
|
page
|
|
|
|
}) => {
|
|
|
|
const textbox = page.getByLabel("Result");
|
2023-07-07 08:37:20 +08:00
|
|
|
await page.click("text=Trigger Success");
|
2023-07-11 03:53:09 +08:00
|
|
|
await expect(textbox).toHaveValue("Success event triggered");
|
2023-06-28 03:34:52 +08:00
|
|
|
});
|
|
|
|
|
|
|
|
test("Consecutive .success event is triggered successfully", async ({
|
|
|
|
page
|
|
|
|
}) => {
|
|
|
|
const textbox = page.getByLabel("Consecutive Event");
|
|
|
|
const first = page.getByLabel("Result");
|
|
|
|
|
2023-07-07 08:37:20 +08:00
|
|
|
await page.click("text=Trigger Consecutive Success");
|
2023-06-28 03:34:52 +08:00
|
|
|
await expect(textbox).toHaveValue("Consecutive Event Triggered");
|
|
|
|
expect(first).toHaveValue("First Event Trigered");
|
|
|
|
});
|
|
|
|
|
|
|
|
test("gr.Error makes the toast show up", async ({ page }) => {
|
2023-07-07 08:37:20 +08:00
|
|
|
let complete;
|
|
|
|
page.on("websocket", (ws) => {
|
|
|
|
complete = ws.waitForEvent("framereceived", {
|
|
|
|
predicate: (event) => {
|
|
|
|
return JSON.parse(event.payload as string).msg === "process_completed";
|
|
|
|
}
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
await page.click("text=Trigger Failure");
|
|
|
|
await complete;
|
2023-06-28 03:34:52 +08:00
|
|
|
|
2023-07-04 05:28:39 +08:00
|
|
|
const toast = page.getByTestId("toast-body");
|
|
|
|
expect(toast).toContainText("error");
|
|
|
|
const close = page.getByTestId("toast-close");
|
2023-06-28 03:34:52 +08:00
|
|
|
await close.click();
|
2023-07-04 05:28:39 +08:00
|
|
|
await expect(page.getByTestId("toast-body")).toHaveCount(0);
|
2023-06-28 03:34:52 +08:00
|
|
|
});
|
|
|
|
|
|
|
|
test("ValueError makes the toast show up when show_error=True", async ({
|
|
|
|
page
|
|
|
|
}) => {
|
2023-07-07 08:37:20 +08:00
|
|
|
let complete;
|
|
|
|
page.on("websocket", (ws) => {
|
|
|
|
complete = ws.waitForEvent("framereceived", {
|
|
|
|
predicate: (event) => {
|
|
|
|
return JSON.parse(event.payload as string).msg === "process_completed";
|
|
|
|
}
|
|
|
|
});
|
|
|
|
});
|
2023-06-28 03:34:52 +08:00
|
|
|
|
2023-07-07 08:37:20 +08:00
|
|
|
await page.click("text=Trigger Failure With ValueError");
|
|
|
|
await complete;
|
2023-06-28 03:34:52 +08:00
|
|
|
|
2023-07-07 08:37:20 +08:00
|
|
|
const toast = page.getByTestId("toast-body");
|
2023-07-04 05:28:39 +08:00
|
|
|
expect(toast).toContainText("error");
|
|
|
|
const close = page.getByTestId("toast-close");
|
2023-06-28 03:34:52 +08:00
|
|
|
await close.click();
|
2023-07-04 05:28:39 +08:00
|
|
|
await expect(page.getByTestId("toast-body")).toHaveCount(0);
|
2023-06-28 03:34:52 +08:00
|
|
|
});
|
2023-07-07 08:37:20 +08:00
|
|
|
|
|
|
|
test("gr.Info makes the toast show up", async ({ page }) => {
|
|
|
|
await page.click("text=Trigger Info");
|
|
|
|
const toast = page.getByTestId("toast-body");
|
|
|
|
|
|
|
|
expect(toast).toContainText("This is some info");
|
|
|
|
const close = page.getByTestId("toast-close");
|
|
|
|
await close.click();
|
|
|
|
await expect(page.getByTestId("toast-body")).toHaveCount(0);
|
|
|
|
});
|
|
|
|
|
|
|
|
test("gr.Warning makes the toast show up", async ({ page }) => {
|
2023-07-13 09:08:36 +08:00
|
|
|
await page.click("text=Trigger Warning");
|
2023-07-07 08:37:20 +08:00
|
|
|
|
|
|
|
const toast = page.getByTestId("toast-body");
|
|
|
|
expect(toast).toContainText("This is a warning!");
|
|
|
|
const close = page.getByTestId("toast-close");
|
|
|
|
await close.click();
|
|
|
|
await expect(page.getByTestId("toast-body")).toHaveCount(0);
|
|
|
|
});
|