148 lines
5.7 KiB
TypeScript
148 lines
5.7 KiB
TypeScript
import { expect, test } from "@playwright/test";
|
|
|
|
test("submission tabs, day selection, local correlation and reload", async ({
|
|
page,
|
|
}) => {
|
|
const errors: string[] = [];
|
|
page.on("pageerror", (error) => errors.push(error.message));
|
|
await page.goto("/#alphas");
|
|
await page.getByLabel("密码", { exact: true }).fill("browser-test-password");
|
|
await page.getByRole("button", { name: "进入工作空间" }).click();
|
|
await expect(
|
|
page.getByRole("tab", { name: "待提交", exact: true }),
|
|
).toBeVisible();
|
|
const headers = { "X-WQ-Request": "1" };
|
|
const credentials = await page.request.put("/api/v1/account/credentials", {
|
|
headers,
|
|
data: { email: "test@example.com", password: "synthetic-password" },
|
|
});
|
|
expect(credentials.ok()).toBe(true);
|
|
expect(
|
|
(await page.request.post("/api/v1/account/connect", { headers })).ok(),
|
|
).toBe(true);
|
|
await expect
|
|
.poll(
|
|
async () =>
|
|
(await (await page.request.get("/api/v1/account")).json())
|
|
.connection_status,
|
|
)
|
|
.toBe("connected");
|
|
await page.reload();
|
|
await page.getByRole("button", { name: "Alpha 管理", exact: true }).click();
|
|
await page.getByRole("tab", { name: "已提交", exact: true }).click();
|
|
await page.getByRole("button", { name: "按天同步", exact: true }).click();
|
|
await expect(page.getByRole("dialog")).toContainText("提交日期");
|
|
await page.getByRole("button", { name: "开始同步", exact: true }).click();
|
|
await expect(page.getByRole("alert")).toContainText("请选择有效的起止日期");
|
|
// Separate validation from submission; Semi ignores repeated OK clicks within 100 ms.
|
|
await page
|
|
.getByRole("dialog")
|
|
.getByRole("button", { name: "cancel", exact: true })
|
|
.click();
|
|
await page.getByRole("button", { name: "按天同步", exact: true }).click();
|
|
await page.getByLabel("同步开始日期").fill("2025-02-02");
|
|
await page.getByLabel("同步结束日期").fill("2025-02-02");
|
|
const request = page.waitForResponse(
|
|
(response) =>
|
|
response.url().endsWith("/api/v1/sync-jobs") &&
|
|
response.request().method() === "POST",
|
|
);
|
|
await page.getByRole("button", { name: "开始同步", exact: true }).click();
|
|
const job = await (await request).json();
|
|
expect(job.payload).toMatchObject({
|
|
submission: "SUBMITTED",
|
|
date_from: "2025-02-02",
|
|
date_to: "2025-02-02",
|
|
});
|
|
await expect
|
|
.poll(
|
|
async () =>
|
|
(await (await page.request.get(`/api/v1/sync-jobs/${job.id}`)).json())
|
|
.status,
|
|
)
|
|
.toBe("completed");
|
|
const complete = await (
|
|
await page.request.get(`/api/v1/sync-jobs/${job.id}`)
|
|
).json();
|
|
expect(complete.processed).toBe(103);
|
|
await expect(page.locator(".job-panel")).toContainText("2025-02-02");
|
|
await page.keyboard.press("Escape");
|
|
await page.getByRole("textbox", { name: "搜索 Alpha" }).fill("TEST0003");
|
|
await page.getByRole("button", { name: "查询", exact: true }).click();
|
|
await expect(page.locator(".alpha-link")).toHaveCount(1);
|
|
await page.getByRole("tab", { name: "待提交", exact: true }).click();
|
|
await expect(page.getByRole("textbox", { name: "搜索 Alpha" })).toHaveValue(
|
|
"",
|
|
);
|
|
await page.getByRole("button", { name: "按天同步", exact: true }).click();
|
|
await expect(page.getByRole("dialog")).toContainText("创建日期");
|
|
await page.getByLabel("同步开始日期").fill("2025-01-01");
|
|
await page.getByLabel("同步结束日期").fill("2025-01-01");
|
|
await page.getByRole("button", { name: "开始同步", exact: true }).click();
|
|
await expect
|
|
.poll(
|
|
async () =>
|
|
(
|
|
await (
|
|
await page.request.get("/api/v1/alphas?submission=UNSUBMITTED")
|
|
).json()
|
|
).total,
|
|
)
|
|
.toBe(413);
|
|
await page.keyboard.press("Escape");
|
|
await page.getByRole("textbox", { name: "搜索 Alpha" }).fill("TEST0004");
|
|
await page.getByRole("button", { name: "查询", exact: true }).click();
|
|
await page.locator(".alpha-link").click();
|
|
await page.getByRole("tab", { name: "本地自相关", exact: true }).click();
|
|
await page.getByRole("button", { name: "检测自相关", exact: true }).click();
|
|
await expect
|
|
.poll(
|
|
async () =>
|
|
(
|
|
await (
|
|
await page.request.get("/api/v1/alphas/TEST0004/self-correlation")
|
|
).json()
|
|
).result?.status,
|
|
{ timeout: 20000 },
|
|
)
|
|
.toBe("high");
|
|
await page.keyboard.press("Escape");
|
|
await expect(page.locator(".job-panel")).not.toBeVisible();
|
|
await expect(page.locator(".correlation-panel")).toContainText("相关性偏高");
|
|
await expect(page.locator(".correlation-panel")).toContainText("1.0000");
|
|
await page.screenshot({
|
|
path: "../output/playwright/local-correlation.png",
|
|
animations: "disabled",
|
|
});
|
|
await page.keyboard.press("Escape");
|
|
await page.reload();
|
|
await page.getByRole("textbox", { name: "搜索 Alpha" }).fill("TEST0004");
|
|
await page.getByRole("button", { name: "查询", exact: true }).click();
|
|
await expect(page.locator(".alpha-table:visible")).toContainText(
|
|
"相关性偏高",
|
|
);
|
|
await page.getByRole("tab", { name: "已提交", exact: true }).click();
|
|
await expect(
|
|
page.getByRole("button", { name: "全量同步已提交" }),
|
|
).toBeVisible();
|
|
for (const width of [1440, 390]) {
|
|
await page.setViewportSize({ width, height: 900 });
|
|
await expect(
|
|
page.getByRole("tab", { name: "已提交", exact: true }),
|
|
).toBeVisible();
|
|
await expect(
|
|
page.getByRole("button", { name: "按天同步", exact: true }),
|
|
).toBeVisible();
|
|
expect(
|
|
await page.evaluate(
|
|
() => document.documentElement.scrollWidth <= window.innerWidth,
|
|
),
|
|
).toBe(true);
|
|
await page.screenshot({
|
|
path: `../output/playwright/alpha-tabs-${width}.png`,
|
|
animations: "disabled",
|
|
});
|
|
}
|
|
expect(errors).toEqual([]);
|
|
});
|