gradio/ui/packages/app/test/input-output.spec.ts
Abubakar Abid e0a64e5b55
added interactive parameter to components (#992)
* added interactive parameter to components

* respect interactive prop

* fixed input tests

* fixed output tests

* fixed test_components.py

* fixed test blocks

* fixed test utils

* fixed formatting

* update test configs

* fix textbox static output

* static audio output

* static video output

* cleanup

* static inmage output

* Static Timeseries

* cleanup outptus fopr markdown _ html

* ensure dataframe can load in static mode

* tweaks

Co-authored-by: pngwn <hello@pngwn.io>
2022-04-14 15:12:30 +01:00

44 lines
1.1 KiB
TypeScript

import { test, expect, Page } from "@playwright/test";
function mock_demo(page: Page, demo: string) {
return page.route("**/config", (route) => {
return route.fulfill({
headers: {
"Access-Control-Allow-Origin": "*"
},
path: `../../../demo/${demo}/config.json`
});
});
}
function mock_api(page: Page, body: Array<unknown>) {
return page.route("**/api/predict/", (route) => {
const id = JSON.parse(route.request().postData()!).fn_index;
return route.fulfill({
headers: {
"Access-Control-Allow-Origin": "*"
},
body: JSON.stringify({
data: body[id]
})
});
});
}
test("a component acts as both input and output", async ({ page }) => {
await mock_demo(page, "input-output");
await mock_api(page, [["world hello"]]);
await page.goto("http://localhost:3000");
const textbox = await page.locator("label:has-text('Input-Output')");
const button = await page.locator("button");
await textbox.fill("hello world");
await Promise.all([button.click(), page.waitForResponse("**/api/predict/")]);
await expect(await page.inputValue("label:has-text('Input-Output')")).toEqual(
"world hello"
);
});