2022-05-27 16:53:50 +08:00
|
|
|
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>) {
|
2023-03-08 00:36:25 +08:00
|
|
|
return page.route("**/run/predict", (route) => {
|
2022-05-27 16:53:50 +08:00
|
|
|
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"]]);
|
2023-01-27 22:39:36 +08:00
|
|
|
await page.goto("http://localhost:9876");
|
2022-05-27 16:53:50 +08:00
|
|
|
|
2022-10-13 00:30:42 +08:00
|
|
|
const textbox = await page.getByLabel("Name");
|
2022-05-27 16:53:50 +08:00
|
|
|
|
|
|
|
await textbox.fill("Frank");
|
2022-10-13 00:30:42 +08:00
|
|
|
await expect(await textbox).toHaveValue("Frank");
|
|
|
|
await expect(await page.getByLabel("Output")).toHaveValue(
|
2022-05-27 16:53:50 +08:00
|
|
|
"Welcome! This page has loaded for Frank"
|
|
|
|
);
|
|
|
|
});
|