refactor: unify data preparations and research input snapshots
Deploy production / deploy (push) Successful in 53s

This commit is contained in:
yuxuanhui
2026-09-12 01:24:02 +08:00
parent 849f86fef7
commit 394438e753
82 changed files with 4146 additions and 2076 deletions
+105 -248
View File
@@ -1,14 +1,12 @@
import { test, expect, type Page } from "@playwright/test";
import { choosePreparation } from "./preparation-helpers";
const headers = { "X-WQ-Request": "1" };
const scope = {
instrument_type: "EQUITY",
region: "USA",
universe: "TOP3000",
delay: 1,
};
const query = new URLSearchParams(
Object.entries(scope).map(([k, v]) => [k, String(v)]),
).toString();
const headers = { "X-WQ-Request": "1" };
async function setup(page: Page) {
await page.goto("/#datasets");
await page.getByLabel("密码", { exact: true }).fill("browser-test-password");
@@ -20,273 +18,132 @@ async function setup(page: Page) {
headers,
data: { email: "test@example.com", password: "synthetic-only" },
});
const connect = await (
const job = await (
await page.request.post("/api/v1/account/connect", { headers })
).json();
await expect
.poll(
async () =>
(
await (
await page.request.get(`/api/v1/sync-jobs/${connect.id}`)
).json()
).status,
(await (await page.request.get(`/api/v1/sync-jobs/${job.id}`)).json())
.status,
)
.toBe("completed");
await page.getByRole("button", { name: "同步目录", exact: true }).click();
await page.reload();
}
async function sync(page: Page, dataset_id: string | null) {
const job = await (
await page.request.post("/api/v1/catalog/sync-jobs", {
headers,
data: { scope, dataset_id },
})
).json();
await expect
.poll(
async () =>
(await (await page.request.get(`/api/v1/sync-jobs/${job.id}`)).json())
.status,
)
.toBe("completed");
}
test("数据集完整同步、使用、集合编辑与研究选择", async ({ page }) => {
const errors: string[] = [];
page.on("pageerror", (e) => errors.push(e.message));
await setup(page);
await sync(page, null);
await page.reload();
const row = page.getByRole("row").filter({ hasText: "TEST 财务报表" });
await expect(
row.getByRole("button", { name: "使用", exact: true }),
).toBeDisabled();
await row.getByRole("button", { name: "同步", exact: true }).click();
await expect
.poll(
async () =>
(
await (
await page.request.get(`/api/v1/catalog/datasets?${query}`)
await page.request.get(
"/api/v1/catalog/datasets/TEST_FIN?region=USA&universe=TOP3000&delay=1",
)
).json()
).total,
).complete_count,
)
.toBe(3);
.toBe(123);
await page.keyboard.press("Escape");
await expect(
page.getByRole("button", { name: "TEST 财务报表", exact: true }),
).toBeVisible();
}
async function openFields(page: Page) {
await page
.getByRole("row")
.filter({ hasText: "TEST 财务报表" })
.getByRole("button", { name: "查看字段", exact: true })
.click();
const sync = page
.getByRole("dialog", { name: "数据字段", exact: true })
.getByRole("button", { name: "同步全部字段", exact: true });
if (await sync.isVisible()) {
await sync.click();
await expect
.poll(
async () =>
(
await (
await page.request.get(
`/api/v1/catalog/datasets/TEST_FIN/fields?${query}`,
)
).json()
).complete_count,
)
.toBe(123);
await page.keyboard.press("Escape");
}
}
test("目录筛选、双层详情、完整输入、排除、备注与刷新", async ({ page }) => {
const errors: string[] = [];
page.on("pageerror", (e) => errors.push(e.message));
await page.setViewportSize({ width: 1440, height: 1000 });
await setup(page);
await page.getByLabel("分类", { exact: true }).click();
await page.getByRole("option", { name: /基本面/ }).click();
await page.getByLabel("子分类", { exact: true }).click();
await page.getByRole("option", { name: /财务报表/ }).click();
await openFields(page);
const fields = page.getByRole("dialog", { name: "数据字段", exact: true });
await expect(fields).toBeVisible();
await expect(fields).toContainText("全部 123 个字段");
expect((await fields.boundingBox())!.width).toBeCloseTo(864, 0);
await page.getByLabel("搜索字段").fill("字段 12");
await expect(fields.getByRole("button", { name: /TEST 字段/ })).toHaveCount(
3,
);
await page
.getByRole("button", { name: "TEST 字段 122", exact: true })
.click();
const detail = page.getByRole("dialog", { name: "字段详情", exact: true });
await expect(detail).toContainText("FUTURE_TYPE");
expect((await detail.boundingBox())!.width).toBeCloseTo(864, 0);
await page.getByLabel("研究备注", { exact: true }).fill("保留字段研究假设");
await page.getByRole("button", { name: "保存备注", exact: true }).click();
await expect(page.getByText("研究备注已保存")).toBeVisible();
await page.keyboard.press("Escape");
await expect(detail).not.toBeVisible();
await expect(page.getByLabel("搜索字段")).toHaveValue("字段 12");
await expect(
page.getByRole("button", { name: "TEST 字段 122", exact: true }),
).toBeFocused();
await page
.getByRole("button", { name: "用于 Alpha 模板", exact: true })
.click();
await page.getByRole("button", { name: "保存输入草稿", exact: true }).click();
await expect(
page.getByRole("heading", { name: "输入草稿已保存" }),
).toBeVisible();
expect(
(
await (await page.request.get(`/api/v1/catalog/inputs?${query}`)).json()
)[0].field_ids,
).toHaveLength(123);
await page.keyboard.press("Escape");
await page
.getByRole("checkbox", { name: "选择TEST 字段 122", exact: true })
.press("Space");
await page.getByRole("button", { name: "覆盖率排序" }).click();
await expect(fields).toContainText("122 / 123 个字段");
await page
.getByRole("button", { name: "用于 Alpha 模板", exact: true })
.click();
await page.getByRole("button", { name: "保存输入草稿", exact: true }).click();
await expect(
page.getByRole("heading", { name: "输入草稿已保存" }),
).toBeVisible();
const subset = (
await (await page.request.get(`/api/v1/catalog/inputs?${query}`)).json()
)[0];
expect(subset.field_ids).toHaveLength(122);
expect(subset.field_ids).not.toContain("TEST_FIN_122");
await page.keyboard.press("Escape");
await page.getByRole("button", { name: "恢复全选" }).click();
await page
.getByRole("checkbox", { name: "选择本数据集全部字段" })
.press("Space");
await expect(
page.getByRole("button", { name: "用于 Alpha 模板", exact: true }),
).toBeDisabled();
await page.getByRole("button", { name: "恢复全选" }).click();
await page
.getByRole("button", { name: "TEST 字段 122", exact: true })
.click();
await expect(page.getByLabel("研究备注", { exact: true })).toHaveValue(
"保留字段研究假设",
);
await page.screenshot({ path: "../output/playwright/dataset-desktop.png" });
await page.keyboard.press("Escape");
await page.keyboard.press("Escape");
await expect(page.getByLabel("分类", { exact: true })).toContainText(
"基本面",
);
await page.reload();
await row.getByRole("button", { name: "查看", exact: true }).click();
const detail = page.getByRole("dialog", {
name: "TEST 财务报表",
exact: true,
});
await expect(detail).toContainText("TEST_FIN_001");
await detail.getByLabel("研究备注").fill("验证备注");
await detail.getByRole("button", { name: "保存备注", exact: true }).click();
await page.keyboard.press("Escape");
await row.getByRole("button", { name: "使用", exact: true }).click();
await page.getByRole("link", { name: "打开数据准备" }).click();
const prep = page.getByRole("dialog", { name: "数据准备详情", exact: true });
await expect(prep).toContainText("123 字段 / 1 数据集");
await prep.getByLabel("集合名称", { exact: true }).fill("浏览器准备集合");
await prep.getByRole("button", { name: "保存名称和备注" }).click();
await expect(prep).toContainText("v2");
await prep
.getByRole("row")
.filter({ hasText: "TEST_FIN_000" })
.locator("span.semi-checkbox")
.click();
await prep.getByRole("button", { name: "移除所选字段" }).click();
await expect(prep).toContainText("122 字段");
await page.keyboard.press("Escape");
await page
.getByRole("navigation", { name: "主导航" })
.getByRole("button", { name: "特征工程", exact: true })
.click();
await page.getByRole("button", { name: "新建特征方案", exact: true }).click();
await choosePreparation(page, "浏览器准备集合", "选择特征数据准备");
await expect(
page.getByRole("button", { name: "已保存输入 (2)" }),
page.locator("p").filter({ hasText: /浏览器准备集合 ·.*122 字段/ }),
).toBeVisible();
expect(errors).toEqual([]);
});
test("窄屏抽屉、键盘隔离和研究范围切换", async ({ page }) => {
await page.setViewportSize({ width: 390, height: 844 });
test("在线字段跨页多选直接准备,本地只展示完整同步字段", async ({ page }) => {
await setup(page);
await openFields(page);
const fields = page.getByRole("dialog", { name: "数据字段", exact: true });
await expect(fields).toBeVisible();
expect((await fields.boundingBox())!.width).toBeCloseTo(234, 0);
await page
.getByRole("button", { name: "TEST 字段 000", exact: true })
.getByRole("navigation", { name: "主导航" })
.getByRole("button", { name: "字段目录", exact: true })
.click();
await expect(
page.getByRole("dialog", { name: "字段详情", exact: true }),
).toBeVisible();
await page.keyboard.press("Escape");
await expect(fields).toBeVisible();
expect(
await page.evaluate(
() => document.documentElement.scrollWidth <= innerWidth,
),
).toBe(true);
await page.screenshot({ path: "../output/playwright/dataset-mobile.png" });
await page.keyboard.press("Escape");
await page.getByLabel("Region", { exact: true }).click();
await page.getByRole("option", { name: /CHN/ }).click();
await expect(page.getByLabel("Universe", { exact: true })).toContainText(
"TOP2000",
);
await expect(
page.getByRole("button", { name: "用于 Alpha 模板", exact: true }),
).toBeDisabled();
});
test("非首页排除、聊天暂存详情、遮罩逐层关闭和多尺寸", async ({ page }) => {
const errors: string[] = [];
page.on("pageerror", (e) => errors.push(e.message));
await page.setViewportSize({ width: 1280, height: 900 });
await setup(page);
await openFields(page);
const fields = page.getByRole("dialog", { name: "数据字段", exact: true });
await fields.getByRole("button", { name: "Next", exact: true }).click();
await expect(
page.getByRole("button", { name: "TEST 字段 025", exact: true }),
).toBeVisible();
await page
.getByRole("checkbox", { name: "选择TEST 字段 025", exact: true })
.press("Space");
await page.getByLabel("搜索字段").fill("字段 12");
await expect(fields).toContainText("122 / 123 个字段");
await page.getByLabel("字段类型", { exact: true }).click();
await page.getByRole("option", { name: /VECTOR/ }).click();
await expect(
page.getByRole("button", { name: "TEST 字段 120", exact: true }),
).toBeVisible();
await page
.getByRole("button", { name: "TEST 字段 120", exact: true })
const online = page.getByRole("tabpanel", { name: "worldquant接口" });
await expect(online.getByText("TEST_FIN_001", { exact: true })).toBeVisible();
await online
.getByRole("row")
.filter({ hasText: "TEST_FIN_001" })
.locator("span.semi-checkbox")
.click();
await page.getByLabel("研究备注", { exact: true }).fill("未保存草稿需要恢复");
await page
.getByRole("dialog", { name: "字段详情", exact: true })
.getByRole("button", { name: "AI 助手", exact: true })
await online.locator(".semi-page-item").filter({ hasText: /^2$/ }).click();
await online
.getByRole("row")
.filter({ hasText: "TEST_FIN_025" })
.locator("span.semi-checkbox")
.click();
await expect(fields).not.toBeVisible();
await page.keyboard.press("Escape");
await expect(page.getByLabel("研究备注", { exact: true })).toHaveValue(
"未保存草稿需要恢复",
);
for (const width of [850, 390, 1920]) {
await page.setViewportSize({ width, height: 900 });
await expect(
page.getByRole("button", { name: "关闭详情", exact: true }),
).toBeVisible();
expect(
await page.evaluate(
() => document.documentElement.scrollWidth <= innerWidth,
),
).toBe(true);
}
await page.setViewportSize({ width: 1440, height: 900 });
await page.mouse.click(10, 400);
await expect(
page.getByRole("dialog", { name: "字段详情", exact: true }),
).not.toBeVisible();
await expect(fields).toBeVisible();
await expect(fields).toContainText("122 / 123 个字段");
await page.mouse.click(10, 400);
await expect(fields).not.toBeVisible();
expect(errors).toEqual([]);
});
test("平台选项失败可重试,地区联动限制 Delay 和 Universe", async ({ page }) => {
await setup(page);
await page.getByLabel("Delay", { exact: true }).click();
await page.getByRole("option", { name: /Delay 0/ }).click();
await page.getByLabel("Region", { exact: true }).click();
await page.getByRole("option", { name: /IND/ }).click();
await expect(page.getByLabel("Universe", { exact: true })).toContainText(
"TOP500",
);
await expect(page.getByLabel("Delay", { exact: true })).toContainText(
"Delay 1",
);
await page.getByLabel("Delay", { exact: true }).click();
await expect(page.getByRole("option", { name: /Delay 0/ })).toHaveCount(0);
await page.keyboard.press("Escape");
await page.route("**/api/v1/catalog/scopes", (route) =>
route.fulfill({
status: 502,
contentType: "application/json",
body: JSON.stringify({ detail: "测试平台选项不可用" }),
}),
);
await page.getByRole("button", { name: "Alpha 管理", exact: true }).click();
await page.getByRole("button", { name: "数据目录", exact: true }).click();
await expect(page.getByText("测试平台选项不可用")).toBeVisible();
await expect(
page.getByRole("button", { name: "同步目录", exact: true }),
).toBeDisabled();
await page.unroute("**/api/v1/catalog/scopes");
await page.getByRole("button", { name: "重试获取选项" }).click();
await expect(
page.getByRole("button", { name: "同步目录", exact: true }),
).toBeEnabled();
await expect(online.getByText(/已选 2 个字段/)).toBeVisible();
await online
.getByRole("button", { name: "加入数据准备", exact: true })
.click();
const add = page.getByRole("dialog", { name: "加入数据准备", exact: true });
await add.getByLabel("新集合名称").fill("在线选取集合");
await add.getByRole("button", { name: "新建集合并加入" }).click();
await expect(add).not.toBeVisible();
const collections = await (
await page.request.get("/api/v1/data-preparations?q=在线选取集合")
).json();
expect(collections.items[0].field_count).toBe(2);
await page.getByRole("tab", { name: "本地同步", exact: true }).click();
const local = page.getByRole("tabpanel", { name: "本地同步" });
// Other browser tests share this isolated server, so verify the unsynced dataset explicitly.
await local.getByLabel("字段数据集").fill("TEST_NEWS");
await local.getByRole("button", { name: "查询", exact: true }).click();
await expect(local.getByText("共 0 个字段", { exact: true })).toBeVisible();
await page.screenshot({
path: "test-results/preparations-fields.png",
fullPage: true,
});
});