feat: unify scope settings and catalog table interactions
Deploy production / deploy (push) Successful in 54s

This commit is contained in:
yuxuanhui
2026-09-12 12:11:53 +08:00
parent 9dee2de039
commit 8981c24fda
29 changed files with 2521 additions and 796 deletions
+9 -3
View File
@@ -27,10 +27,16 @@ test("draft, immutable preview, mixed-result persistence and responsive workspac
await login(page);
await page.getByRole("button", { name: "新建回测" }).click();
await page.getByLabel("运行名称", { exact: true }).fill("浏览器回测验收");
await page.getByRole("textbox", { name: "Region", exact: true }).fill("USA");
await page.getByRole("button", { name: "同步合法设置", exact: true }).click();
await page.getByRole("button", { name: "选择组合", exact: true }).click();
await page.getByRole("combobox", { name: "Region", exact: true }).click();
await page.getByRole("option").filter({ hasText: /^USA$/ }).click();
await page.getByRole("combobox", { name: "Universe", exact: true }).click();
await page
.getByRole("textbox", { name: "Universe", exact: true })
.fill("TOP3000");
.getByRole("option")
.filter({ hasText: /^TOP3000$/ })
.click();
await page.getByRole("button", { name: "应用组合", exact: true }).click();
await page.getByLabel("回测候选").fill("rank(close)\n-rank(volume)");
await page.getByRole("button", { name: "保存草稿", exact: true }).click();
await expect(page.getByText("草稿已保存", { exact: true })).toBeVisible();
+174 -9
View File
@@ -129,16 +129,23 @@ test("在线字段跨页多选直接准备,本地只展示完整同步字段",
).toHaveAttribute("aria-selected", "true");
await page.getByRole("tab", { name: "worldquant接口", exact: true }).click();
const online = page.getByRole("tabpanel", { name: "worldquant接口" });
await online
.getByRole("button", { name: "筛选字段目录", exact: true })
.click();
await expect(
online.getByRole("button", { name: "查询", exact: true }),
page.getByRole("button", { name: "查询", exact: true }),
).toBeDisabled();
await expect(
online.getByText("请输入关键词、数据集或其他筛选条件,然后点击查询。"),
).toBeVisible();
expect(queries).toEqual([]);
await online.getByLabel("字段数据集").fill("TEST_FIN");
if (!(await page.getByRole("form", { name: "字段目录筛选条件" }).isVisible()))
await online
.getByRole("button", { name: "筛选字段目录", exact: true })
.click();
await page.getByLabel("字段数据集").fill("TEST_FIN");
expect(queries).toEqual([]);
await online.getByRole("button", { name: "查询", exact: true }).click();
await page.getByRole("button", { name: "查询", exact: true }).click();
await expect(online.getByText("TEST_FIN_001", { exact: true })).toBeVisible();
await online
.getByRole("row")
@@ -166,8 +173,11 @@ test("在线字段跨页多选直接准备,本地只展示完整同步字段",
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 local
.getByRole("button", { name: "筛选字段目录", exact: true })
.click();
await page.getByLabel("字段数据集").fill("TEST_NEWS");
await page.getByRole("button", { name: "查询", exact: true }).click();
await expect(local.getByText("共 0 个字段", { exact: true })).toBeVisible();
await page.screenshot({
path: "test-results/preparations-fields.png",
@@ -239,19 +249,174 @@ test("目录表格保持紧凑行高、截断和固定分页", async ({ page })
await page.screenshot({ path: "test-results/field-table-layout-narrow.png" });
await page.getByRole("tab", { name: "worldquant接口", exact: true }).click();
const online = page.getByRole("tabpanel", { name: "worldquant接口" });
await online.getByLabel("字段数据集").fill("TEST_FIN");
await online.getByRole("button", { name: "查询", exact: true }).click();
if (!(await page.getByRole("form", { name: "字段目录筛选条件" }).isVisible()))
await online
.getByRole("button", { name: "筛选字段目录", exact: true })
.click();
await page.getByLabel("字段数据集").fill("TEST_FIN");
await page.getByRole("button", { name: "查询", exact: true }).click();
await expect(online.getByText("TEST_FIN_001", { exact: true })).toBeVisible();
let queries = 0;
page.on("request", (req) => {
if (req.url().includes("/catalog/worldquant/fields")) queries++;
});
await online.getByRole("button", { name: "重置", exact: true }).click();
await online
.getByRole("button", { name: "筛选字段目录", exact: true })
.click();
await page.getByRole("button", { name: "重置", exact: true }).click();
await online
.getByRole("button", { name: "筛选字段目录", exact: true })
.click();
await expect(
online.getByRole("button", { name: "查询", exact: true }),
page.getByRole("button", { name: "查询", exact: true }),
).toBeDisabled();
await expect(online.getByText("TEST_FIN_001", { exact: true })).toHaveCount(
0,
);
expect(queries).toBe(0);
});
async function selectToolbarOption(page: Page, label: string, value: string) {
const control = page.getByRole("combobox", { name: label, exact: true });
await control.click();
const popup = page.locator(
`[id="${await control.getAttribute("aria-controls")}"]`,
);
await popup
.getByRole("option")
.filter({ hasText: new RegExp(`^${value}$`) })
.click();
await expect(control).toContainText(value);
await expect(popup).not.toBeVisible();
}
test("共用工具栏延迟应用筛选、保存列设置并发送服务端排序", async ({ page }) => {
await setup(page);
await sync(page, null);
await sync(page, "TEST_FIN");
await page.reload();
await expect(
page.getByRole("row").filter({ hasText: "TEST 财务报表" }),
).toBeVisible();
const requests: string[] = [];
page.on("request", (req) => {
if (
req.url().includes("/catalog/datasets?") ||
req.url().includes("/catalog/fields?") ||
req.url().includes("/data-preparations?")
)
requests.push(req.url());
});
await page.getByRole("button", { name: "筛选数据目录", exact: true }).click();
const filter = page.getByRole("form", { name: "数据目录筛选条件" });
await filter.getByLabel("搜索数据集").fill("TEST_FIN");
expect(requests.some((url) => url.includes("q=TEST_FIN"))).toBe(false);
await filter.getByRole("button", { name: "查询", exact: true }).click();
await expect
.poll(() =>
requests.some((url) => new URL(url).searchParams.get("q") === "TEST_FIN"),
)
.toBe(true);
await page.getByRole("button", { name: "显示列设置", exact: true }).click();
await page
.locator(".catalog-column-panel .semi-checkbox")
.filter({ hasText: "价值评分" })
.click();
await expect(
page.getByRole("checkbox", { name: "价值评分", exact: true }),
).not.toBeChecked();
await page.keyboard.press("Escape");
await expect(
page.getByRole("columnheader", { name: "价值评分", exact: true }),
).toHaveCount(0);
await page.reload();
await expect(
page.getByRole("row").filter({ hasText: "TEST 财务报表" }),
).toBeVisible();
await expect(
page.getByRole("columnheader", { name: "价值评分", exact: true }),
).toHaveCount(0);
await page.getByRole("button", { name: "排序设置", exact: true }).click();
await selectToolbarOption(page, "排序字段", "字段数");
await selectToolbarOption(page, "排序方向", "降序");
await expect
.poll(() =>
requests.some(
(url) =>
url.includes("sort=field_count") && url.includes("direction=desc"),
),
)
.toBe(true);
await page.screenshot({ path: "test-results/catalog-sort-popover.png" });
await page.keyboard.press("Escape");
await page
.getByRole("navigation", { name: "主导航" })
.getByRole("button", { name: "字段目录", exact: true })
.click();
const local = page.getByRole("tabpanel", { name: "本地同步" });
await expect(local.getByText("TEST_FIN_001", { exact: true })).toBeVisible();
await local.locator(".semi-page-item").filter({ hasText: /^2$/ }).click();
await expect
.poll(() =>
requests.some(
(url) => url.includes("/catalog/fields?") && url.includes("offset=25"),
),
)
.toBe(true);
await local.getByRole("button", { name: "排序设置", exact: true }).click();
await selectToolbarOption(page, "排序方向", "降序");
await expect
.poll(() =>
requests.some(
(url) =>
url.includes("/catalog/fields?") &&
url.includes("direction=desc") &&
url.includes("offset=0"),
),
)
.toBe(true);
await page.keyboard.press("Escape");
await page.getByRole("tab", { name: "worldquant接口", exact: true }).click();
await expect(
page
.getByRole("tabpanel", { name: "worldquant接口" })
.getByRole("button", { name: "排序设置", exact: true }),
).toBeDisabled();
await page
.getByRole("navigation", { name: "主导航" })
.getByRole("button", { name: "数据准备", exact: true })
.click();
await page.getByRole("button", { name: "筛选数据准备", exact: true }).click();
await page.getByLabel("搜索准备集合").fill("toolbar-preparation");
await page
.locator(".catalog-filter-panel .semi-checkbox")
.filter({ hasText: "按范围筛选" })
.click();
await page.getByRole("button", { name: "更改组合", exact: true }).click();
await selectToolbarOption(page, "Region", "USA");
await page.getByRole("button", { name: "应用组合", exact: true }).click();
await expect(
page.getByRole("form", { name: "数据准备筛选条件" }),
).toBeVisible();
expect(requests.some((url) => url.includes("q=toolbar-preparation"))).toBe(
false,
);
await page.screenshot({
path: "test-results/preparation-filter-popover.png",
});
await page.getByRole("button", { name: "查询", exact: true }).click();
await expect
.poll(() => requests.some((url) => url.includes("q=toolbar-preparation")))
.toBe(true);
await page.getByRole("button", { name: "排序设置", exact: true }).click();
await selectToolbarOption(page, "排序字段", "集合名称");
await expect
.poll(() =>
requests.some(
(url) =>
url.includes("/data-preparations?") && url.includes("sort=name"),
),
)
.toBe(true);
});
+15
View File
@@ -86,6 +86,21 @@ test("feature conversion, saved views and immutable evaluations", async ({
await expect(
page.getByRole("textbox", { name: "模板名称", exact: true }),
).toHaveValue("特征转换模板");
const settingsEditor = page.getByRole("region", {
name: "回测参数",
exact: true,
});
await settingsEditor.getByRole("button", { name: "同步合法设置" }).click();
await expect(
settingsEditor.getByRole("combobox", {
name: "Neutralization",
exact: true,
}),
).toContainText("INDUSTRY");
await expect(
settingsEditor.getByRole("button", { name: "更改组合" }),
).toHaveCount(0);
await expect(settingsEditor).toContainText("来自固定数据准备");
const templates = await (
await page.request.get(
"/api/v1/research/assets?kind=template&q=特征转换模板",
+264
View File
@@ -0,0 +1,264 @@
import { expect, test, type Page } from "@playwright/test";
import { initialSettings } from "../src/backtests/types";
import {
changeScope,
fieldOptions,
settingsErrors,
type SettingsRow,
} from "../src/settings/model";
const headers = { "X-WQ-Request": "1" };
async function login(page: Page) {
await page.goto("/#backtests");
await page.getByLabel("密码", { exact: true }).fill("browser-test-password");
await page.getByRole("button", { name: "进入工作空间" }).click();
await expect(page.getByRole("button", { name: "新建回测" })).toBeVisible();
await page.request.put("/api/v1/account/credentials", {
headers,
data: { email: "test@example.com", password: "synthetic-password" },
});
await page.request.post("/api/v1/account/connect", { headers });
await expect
.poll(
async () =>
(await (await page.request.get("/api/v1/account")).json())
.connection_status,
)
.toBe("connected");
}
async function select(page: Page, name: string, option: string) {
const control = page.getByRole("combobox", { name, exact: true });
await control.click();
const popup = page.locator(
`[id="${await control.getAttribute("aria-controls")}"]`,
);
await popup
.getByRole("option")
.filter({ hasText: new RegExp(`^${option}$`) })
.click();
await expect(control).toContainText(option);
await expect(popup).not.toBeVisible();
}
async function openEditor(page: Page) {
await page.getByRole("button", { name: "新建回测", exact: true }).click();
await page.getByRole("button", { name: "同步合法设置", exact: true }).click();
await page.getByRole("button", { name: "选择组合", exact: true }).click();
await select(page, "Region", "USA");
await select(page, "Universe", "TOP3000");
await page.getByRole("button", { name: "应用组合", exact: true }).click();
}
test("scope changes are transactional and explicit parameters reach the preview unchanged", async ({
page,
}) => {
const errors: string[] = [];
page.on("pageerror", (error) => errors.push(error.message));
await login(page);
await openEditor(page);
const picker = page.getByRole("region", { name: "组合选择", exact: true });
await expect(picker).toContainText("EQUITY / USA / TOP3000 / Delay 1");
await page.getByRole("button", { name: "更改组合", exact: true }).click();
await select(page, "Region", "CHN");
await expect(picker).toContainText("TOP2000U");
await picker.getByRole("button", { name: "取消", exact: true }).click();
await expect(picker).toContainText("EQUITY / USA / TOP3000 / Delay 1");
await page.getByRole("button", { name: "更改组合", exact: true }).click();
await expect(
page.getByRole("combobox", { name: "Region", exact: true }),
).toContainText("USA");
await select(page, "Region", "CHN");
await expect(
page.getByRole("combobox", { name: "Region", exact: true }),
).toContainText("CHN");
await page.getByRole("button", { name: "应用组合", exact: true }).click();
await expect(picker).toContainText("EQUITY / CHN / TOP2000U / Delay 1");
await select(page, "Neutralization", "NONE");
await page.getByLabel("Decay", { exact: true }).fill("12");
await page.getByText("更多参数", { exact: true }).click();
await select(page, "NaN Handling", "ON");
await select(page, "Max Position", "ON");
await select(page, "Visualization", "是");
await expect(page.getByLabel("其他参数", { exact: true })).toHaveCount(0);
await page.getByLabel("运行名称", { exact: true }).fill("组合参数一致性");
await page.getByLabel("回测候选").fill("rank(close)");
for (const width of [1440, 900, 390]) {
await page.setViewportSize({ width, height: 1000 });
const bounds = await page
.locator(".simulation-settings .settings-field:visible")
.evaluateAll((nodes) =>
nodes.map((node) => {
const r = node.getBoundingClientRect();
return { left: r.left, right: r.right, width: r.width };
}),
);
expect(
bounds.every((r) => r.left >= 0 && r.right <= width + 1 && r.width > 80),
).toBeTruthy();
await page.screenshot({
path: `../output/playwright/shared-settings-${width}.png`,
});
}
await page.setViewportSize({ width: 1440, height: 1000 });
const response = page.waitForResponse(
(r) =>
r.url().endsWith("/backtests/previews") &&
r.request().method() === "POST",
);
await page.getByRole("button", { name: "预览回测", exact: true }).click();
const preview = await (await response).json();
expect(preview.items[0].settings).toMatchObject({
region: "CHN",
universe: "TOP2000U",
neutralization: "NONE",
decay: 12,
nanHandling: "ON",
maxPosition: "ON",
visualization: true,
});
expect(errors).toEqual([]);
});
test("metadata failure retries and invalid imported settings stay visible without submission", async ({
page,
}) => {
await login(page);
await page.getByRole("button", { name: "新建回测", exact: true }).click();
await page.route("**/catalog/setting-options/refresh", (route) =>
route.fulfill({ status: 502, json: { detail: "模拟选项同步失败" } }),
);
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("**/catalog/setting-options/refresh");
await page.getByRole("button", { name: "同步合法设置", exact: true }).click();
await expect(page.getByText(/模拟选项同步失败/)).toHaveCount(0);
await page.getByText("每行一条表达式,共用参数", { exact: true }).click();
await page
.getByRole("option")
.filter({ hasText: "结构化候选 JSON,逐项完整参数" })
.click();
const text = JSON.stringify([
{
client_item_id: "old",
expression: "rank(close)",
settings: {
...initialSettings,
region: "USA",
universe: "TOP3000",
neutralization: "REMOVED_VALUE",
},
},
]);
await page.getByLabel("回测候选").fill(text);
let submits = 0;
page.on("request", (request) => {
if (
request.url().endsWith("/backtests/previews") &&
request.method() === "POST"
)
submits++;
});
await page.getByRole("button", { name: "预览回测", exact: true }).click();
await expect(page.getByText(/REMOVED_VALUE 不可用/)).toBeVisible();
await expect(page.getByLabel("回测候选")).toHaveValue(text);
expect(submits).toBe(0);
});
test("scope invalidation and platform restrictions preserve types and reject incompatible fixed inputs", () => {
const scope = {
instrument_type: "EQUITY",
region: "USA",
delay: 1,
universe: "TOP3000",
};
const options = [
{ ...scope, universes: ["TOP3000"] },
{ ...scope, region: "CHN", universes: ["TOP2000U", "TOP500"] },
];
expect(changeScope(options, scope, "region", "CHN")).toEqual({
...scope,
region: "CHN",
universe: undefined,
});
const row: SettingsRow = {
...scope,
neutralizations: ["NONE"],
fields: {
visualization: { choices: [false] },
decay: { minimum: -10, maximum: 20000 },
},
};
expect(fieldOptions(row, "decay")).toEqual({ minimum: 0, maximum: 10000 });
expect(fieldOptions(row, "visualization").choices).toEqual([false]);
expect(
fieldOptions(
{ ...row, fields: { decay: { choices: [-1, 0, 1.5, 10, 20000] } } },
"decay",
).choices,
).toEqual([0, 10]);
expect(
settingsErrors(
{
...initialSettings,
region: "USA",
universe: "TOP3000",
neutralization: "NONE",
},
[row],
[scope],
),
).toEqual([]);
const errors = settingsErrors(
{
...initialSettings,
region: "USA",
universe: "TOP3000",
decay: 0.5,
visualization: "false" as unknown as boolean,
},
[row],
[{ ...scope, region: "CHN" }],
);
expect(errors.join(" ")).toContain("相同组合");
expect(errors.join(" ")).toContain("INDUSTRY 不可用");
expect(errors.join(" ")).toContain("整数");
expect(errors.join(" ")).toContain("Visualization");
});
test("new preparation edits its scope inline and cancels without changing the collection", async ({
page,
}) => {
await login(page);
await page
.getByRole("navigation", { name: "主导航" })
.getByRole("button", { name: "数据准备", exact: true })
.click();
await page.getByRole("button", { name: "新建集合", exact: true }).click();
const dialog = page.getByRole("dialog", {
name: "新建数据准备集合",
exact: true,
});
const picker = dialog.getByRole("region", { name: "组合选择", exact: true });
await picker.getByRole("button", { name: "更改组合" }).click();
await select(page, "Region", "CHN");
await expect(dialog).toBeVisible();
await expect(page.getByRole("dialog")).toHaveCount(1);
await picker.getByRole("button", { name: "取消", exact: true }).click();
await expect(picker).toContainText("EQUITY / USA / TOP3000 / Delay 1");
await picker.getByRole("button", { name: "更改组合" }).click();
await select(page, "Region", "CHN");
await page.screenshot({
path: "../output/playwright/preparation-scope-picker.png",
});
await picker.getByRole("button", { name: "应用组合", exact: true }).click();
await expect(picker).toContainText("EQUITY / CHN / TOP2000U / Delay 1");
await dialog.getByLabel("集合名称", { exact: true }).fill("组合组件新建验收");
const response = page.waitForResponse(
(r) =>
r.url().endsWith("/data-preparations") && r.request().method() === "POST",
);
await dialog.getByRole("button", { name: "confirm", exact: true }).click();
expect((await (await response).json()).scope).toMatchObject({
region: "CHN",
universe: "TOP2000U",
delay: 1,
});
});