2022-03-24 18:59:09 +08:00
|
|
|
import { test, expect, Page } from "@playwright/test";
|
|
|
|
|
|
|
|
function mock_demo(page: Page, demo: string) {
|
2022-03-31 23:48:54 +08:00
|
|
|
return page.route("**/config", (route) => {
|
2022-03-24 18:59:09 +08:00
|
|
|
return route.fulfill({
|
|
|
|
headers: {
|
|
|
|
"Access-Control-Allow-Origin": "*"
|
|
|
|
},
|
|
|
|
path: `../../../demo/${demo}/config.json`
|
|
|
|
});
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
function mock_api(page: Page, body: Array<unknown>) {
|
2022-03-31 23:48:54 +08:00
|
|
|
return page.route("**/api/predict/", (route) => {
|
2022-03-24 18:59:09 +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("a component acts as both input and output", async ({ page }) => {
|
2022-08-18 03:43:26 +08:00
|
|
|
await mock_demo(page, "input_output");
|
2022-05-27 16:53:50 +08:00
|
|
|
await mock_api(page, [["tset"]]);
|
2022-03-24 18:59:09 +08:00
|
|
|
await page.goto("http://localhost:3000");
|
|
|
|
|
2022-04-14 22:12:30 +08:00
|
|
|
const textbox = await page.locator("label:has-text('Input-Output')");
|
2022-03-24 18:59:09 +08:00
|
|
|
const button = await page.locator("button");
|
|
|
|
|
2022-05-27 16:53:50 +08:00
|
|
|
await textbox.fill("test");
|
2022-03-31 23:48:54 +08:00
|
|
|
await Promise.all([button.click(), page.waitForResponse("**/api/predict/")]);
|
2022-04-14 22:12:30 +08:00
|
|
|
await expect(await page.inputValue("label:has-text('Input-Output')")).toEqual(
|
2022-05-27 16:53:50 +08:00
|
|
|
"tset"
|
2022-04-06 18:47:19 +08:00
|
|
|
);
|
2022-03-24 18:59:09 +08:00
|
|
|
});
|