mirror of
https://github.com/gradio-app/gradio.git
synced 2024-12-15 02:11:15 +08:00
13915f9c11
* add script to create configs for test demos * no message * fixes * fixes * fix * test fix * test fix * format * fix
43 lines
1.1 KiB
TypeScript
43 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("renders the correct elements", async ({ page }) => {
|
|
await mock_demo(page, "blocks_page_load");
|
|
await mock_api(page, [["Welcome! This page has loaded for Frank"]]);
|
|
await page.goto("http://localhost:3000");
|
|
|
|
const textbox = await page.locator("label:has-text('Name')");
|
|
|
|
await textbox.fill("Frank");
|
|
await expect(await page.inputValue("label:has-text('Name')")).toEqual(
|
|
"Frank"
|
|
);
|
|
await expect(await page.inputValue("label:has-text('Output')")).toEqual(
|
|
"Welcome! This page has loaded for Frank"
|
|
);
|
|
});
|