gradio/js/app/test/blocks_chained_events.spec.ts
aliabid94 6c5427230e
Create Warning, Info modals (#4518)
* changes

* changes

* changes

* changes

* changes

* Styling for error, warning and info toasts (#4603)

* create abstract toast component for info/warning/error

* add icons

* add light mode theming

* add theme mode check and dark mode styles

* update theme_mode on update

* clean up render of toast content

* replace dynamic css vars with toast type css selectors

* tweak colours

* change error pill border colour to align with toasts

* formatting

* fix failed test

* rename icon files and clean up css

* changes

* changes

* changes

* changes

* changes

* changes

* chanegs

* changes

* changes

* changes

* changes

* changes

* changes

* changes

* changes

* changes

* changes

* changes

* changes

* changes

* changes

* changes

* changes

---------

Co-authored-by: Abubakar Abid <abubakar@huggingface.co>
Co-authored-by: Hannah <hannahblair@users.noreply.github.com>
2023-07-03 16:28:39 -05:00

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();
return data?.data?.[0] === "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("toast-body");
expect(toast).toContainText("error");
const close = page.getByTestId("toast-close");
await close.click();
await expect(page.getByTestId("toast-body")).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("toast-body");
expect(toast).toContainText("error");
const close = page.getByTestId("toast-close");
await close.click();
await expect(page.getByTestId("toast-body")).toHaveCount(0);
});