gradio/js/app/test/state_change.spec.ts
pngwn 9d2d6051ca
Change client submit API to be an AsyncIterable and support more platforms (#8451)
* fix param name

* format

* save

* changes

* changes

* fix param name

* format

* switch to async iterable interface

* switch to async iterable interface

* changes

* add changeset

* fix

* fix param name

* format

* fixes

* fix checks

* fix checks

* add changeset

* fix checks

* add changeset

* add changeset

* fix checks

* fix param name

* format

* fix types

* cleanup comments

* add changeset

* fix param name

* format

* changes

* Refactor Cancelling Logic To Use /cancel (#8370)

* Cancel refactor

* add changeset

* add changeset

* types

* Add code

* Fix types

---------

Co-authored-by: gradio-pr-bot <gradio-pr-bot@users.noreply.github.com>

* fix param name

* format

* changes

* fix

* fix param name

* format

* fix test

* fix notebooks

* fix type

---------

Co-authored-by: gradio-pr-bot <gradio-pr-bot@users.noreply.github.com>
Co-authored-by: Freddy Boulton <alfonsoboulton@gmail.com>
2024-06-06 13:16:14 +01:00

59 lines
2.4 KiB
TypeScript

import { test, expect } from "@gradio/tootils";
test("test 2d state-based render", async ({ page }) => {
await page.getByRole("button", { name: "Increment A" }).click();
await expect(
page.locator("button").filter({ hasText: "Button" })
).toHaveCount(0);
await expect(page.getByLabel("Number A")).toHaveValue("1");
await page.getByRole("button", { name: "Increment B" }).click();
await page.getByRole("button", { name: "Increment A" }).click();
await expect(page.getByLabel("Number B")).toHaveValue("1");
await expect(
page.locator("button").filter({ hasText: "Button" })
).toHaveCount(2);
await page.getByRole("button", { name: "Increment A" }).click();
await expect(page.getByLabel("Number A")).toHaveValue("2");
await page.getByRole("button", { name: "Increment B" }).click();
await expect(page.getByLabel("Number B")).toHaveValue("2");
await page.getByRole("button", { name: "Increment A" }).click();
await expect(page.getByLabel("Number A").first()).toHaveValue("4");
await expect(
page.locator("button").filter({ hasText: "Button" })
).toHaveCount(8);
});
test("test datastructure-based state changes", async ({ page }) => {
await page.getByRole("button", { name: "Count to" }).click();
await expect(page.getByLabel("Output")).toHaveValue(
`{1: 1, 2: 2, 3: 3}\n[[1, 2, 3], [1, 2, 3], [1, 2, 3]]\n{1, 2, 3}`
);
await expect(page.getByLabel("Changes")).toHaveValue("1");
await expect(page.getByLabel("Clicks")).toHaveValue("1");
await page.getByRole("button", { name: "Count to" }).click();
await expect(page.getByLabel("Changes")).toHaveValue("1");
await expect(page.getByLabel("Clicks")).toHaveValue("2");
await page.getByRole("button", { name: "Count to" }).click();
await expect(page.getByLabel("Changes")).toHaveValue("1");
await expect(page.getByLabel("Clicks")).toHaveValue("3");
await expect(page.getByLabel("Output")).toHaveValue(
`{1: 1, 2: 2, 3: 3}\n[[1, 2, 3], [1, 2, 3], [1, 2, 3]]\n{1, 2, 3}`
);
await page.getByRole("button", { name: "Zero All" }).click();
await expect(page.getByLabel("Output")).toHaveValue(
`{0: 0}\n[[0, 0, 0], [0, 0, 0], [0, 0, 0]]\n{0}`
);
await expect(page.getByLabel("Changes")).toHaveValue("2");
await expect(page.getByLabel("Clicks")).toHaveValue("4");
await page.getByRole("button", { name: "Zero All" }).click();
await expect(page.getByLabel("Changes")).toHaveValue("2");
await expect(page.getByLabel("Clicks")).toHaveValue("5");
});