完善AMESim可配置参数交互

补充气动孔口、动态管路、UD00 与弹性接触组件的离散选项、条件显示和折叠分组。

增加目录协议、非法选项和前端参数表交互回归测试,不修改现有求解公式。
This commit is contained in:
ljz committed 2026-08-04 01:27:17 +08:00
1 parent be54070855
commit df1d676131
12 files changed
+1262 -69

No files matched your search

+204
View File
@@ -50,6 +50,22 @@ async function addMecmasEncodingTestComponent(page: Page) {
await node.click();
}
async function addParameterMetadataTestComponent(
page: Page,
label: string,
type: string,
) {
const canvas = page.locator(".flow-canvas .react-flow__pane");
await page
.getByRole("button", { name: label, exact: true })
.dragTo(canvas, { targetPosition: { x: 620, y: 330 } });
const node = page.locator(
`.flow-canvas .react-flow__node[data-id="${type}_1"]`,
);
await expect(node).toBeVisible();
await node.click();
}
test("组件参数和仿真设置使用共享的三列表格", async ({ page }) => {
await page.goto("/");
await addPneumaticTestComponent(page);
@@ -310,6 +326,194 @@ test("通用离散选项按多条件控制参数行且保留隐藏值和未知
await expect(page.getByLabel("高级参数", { exact: true })).toHaveValue("42");
});
test("PNOR001 和 PNL0001 控制项前置并切换折叠组中的条件参数", async ({
page,
}) => {
await page.goto("/");
await addParameterMetadataTestComponent(
page,
"PNOR001 常系数气动孔口",
"amesim_pnor001",
);
const componentTable = page.getByRole("table", { name: "组件参数" });
const flowset = page.getByLabel("流量系数设置", { exact: true });
const flowGroup = componentTable.getByRole("button", { name: /流量系数/ });
await expect(flowset.locator("option")).toHaveText(["Cq", "Cv", "Kv"]);
await expect(flowset).toHaveValue("1");
await expect(flowGroup).toHaveAttribute("aria-expanded", "false");
await expect(page.getByLabel("流量系数 Cq", { exact: true })).toBeHidden();
await expect(page.getByLabel("孔口面积", { exact: true })).toBeHidden();
await expect(parameterRow(componentTable, "流量系数 Cv")).toHaveCount(0);
const flowsetBox = await parameterRow(
componentTable,
"流量系数设置",
).boundingBox();
const flowGroupBox = await flowGroup.boundingBox();
expect(flowsetBox).not.toBeNull();
expect(flowGroupBox).not.toBeNull();
expect(flowsetBox!.y).toBeLessThan(flowGroupBox!.y);
await flowGroup.click();
const area = page.getByLabel("孔口面积", { exact: true });
await expect(page.getByLabel("流量系数 Cq", { exact: true })).toBeVisible();
await expect(area).toBeVisible();
await area.fill("7.5e-6");
await area.press("Enter");
await expect(area).toHaveValue("7.5e-6");
await flowset.selectOption("2");
await expect(parameterRow(componentTable, "流量系数 Cq")).toHaveCount(0);
await expect(parameterRow(componentTable, "孔口面积")).toHaveCount(0);
await expect(page.getByLabel("流量系数 Cv", { exact: true })).toBeVisible();
await expect(parameterRow(componentTable, "流量系数 Kv")).toHaveCount(0);
await flowset.selectOption("1");
await expect(area).toHaveValue("7.5e-6");
await addParameterMetadataTestComponent(
page,
"PNL0001 C-R 动态管路",
"amesim_pnl0001",
);
const mode = page.getByLabel("热模型", { exact: true });
const thermalGroup = componentTable.getByRole("button", { name: /热力学/ });
await expect(mode.locator("option")).toHaveText(["多方过程", "带换热"]);
await expect(mode).toHaveValue("2");
const pnlParameterOrder = (
await componentTable.getByRole("rowheader").allTextContents()
).map((text) => text.trim());
expect(pnlParameterOrder.indexOf("热模型")).toBeLessThan(
pnlParameterOrder.indexOf("管径"),
);
await expect(thermalGroup).toHaveAttribute("aria-expanded", "false");
await thermalGroup.click();
await expect(parameterRow(componentTable, "多方指数")).toHaveCount(0);
await expect(page.getByLabel("换热系数", { exact: true })).toBeVisible();
await expect(page.getByLabel("外部温度", { exact: true })).toBeVisible();
await mode.selectOption("1");
await expect(page.getByLabel("多方指数", { exact: true })).toBeVisible();
await expect(parameterRow(componentTable, "换热系数")).toHaveCount(0);
await expect(parameterRow(componentTable, "外部温度")).toHaveCount(0);
await expect(thermalGroup).toHaveAttribute("aria-expanded", "true");
});
test("UD00 段数前置并逐段显示第 2 至第 4 段参数", async ({ page }) => {
await page.goto("/");
await addParameterMetadataTestComponent(
page,
"UD00 分段线性信号",
"amesim_ud00",
);
const componentTable = page.getByRole("table", { name: "组件参数" });
const stageCount = page.getByLabel("段数", { exact: true });
const cyclic = page.getByLabel("循环", { exact: true });
const stageGroup = componentTable.getByRole("button", { name: /分段参数/ });
await expect(stageCount.locator("option")).toHaveText([
"1",
"2",
"3",
"4",
"5",
"6",
"7",
"8",
]);
await expect(cyclic.locator("option")).toHaveText(["否", "是"]);
const parameterOrder = (
await componentTable.getByRole("rowheader").allTextContents()
).map((text) => text.trim());
expect(parameterOrder.indexOf("段数")).toBeLessThan(
parameterOrder.indexOf("启动时间"),
);
expect(parameterOrder.indexOf("循环")).toBeLessThan(
parameterOrder.indexOf("启动时间"),
);
await expect(stageGroup).toHaveAttribute("aria-expanded", "false");
await expect(page.getByLabel("第 1 段起点", { exact: true })).toBeHidden();
await stageGroup.click();
await expect(page.getByLabel("第 1 段起点", { exact: true })).toBeVisible();
const expectStageVisibility = async (stage: number, visible: boolean) => {
for (const suffix of ["起点", "终点", "时长"]) {
const row = parameterRow(componentTable, `第 ${stage} 段${suffix}`);
if (visible) {
await expect(row).toBeVisible();
} else {
await expect(row).toHaveCount(0);
}
}
};
await expectStageVisibility(2, false);
await expectStageVisibility(3, false);
await expectStageVisibility(4, false);
await stageCount.selectOption("2");
await expectStageVisibility(2, true);
await expectStageVisibility(3, false);
await expectStageVisibility(4, false);
await stageCount.selectOption("3");
await expectStageVisibility(2, true);
await expectStageVisibility(3, true);
await expectStageVisibility(4, false);
await stageCount.selectOption("4");
await expectStageVisibility(2, true);
await expectStageVisibility(3, true);
await expectStageVisibility(4, true);
await expect(stageGroup).toHaveAttribute("aria-expanded", "true");
});
test("LSTP00A 刚度模式前置并切换数值与几何刚度参数", async ({ page }) => {
await page.goto("/");
await addParameterMetadataTestComponent(
page,
"LSTP00A 弹性接触",
"amesim_lstp00a",
);
const componentTable = page.getByRole("table", { name: "组件参数" });
const stiffnessMode = page.getByLabel("刚度模式", { exact: true });
const contactOption = page.getByLabel("允许负接触力", { exact: true });
const stiffnessGroup = componentTable.getByRole("button", { name: /刚度/ });
const contactGroup = componentTable.getByRole("button", { name: /接触/ });
await expect(stiffnessMode.locator("option")).toHaveText([
"数值刚度",
"几何参数",
]);
await expect(contactOption.locator("option")).toHaveText([
"允许负接触力",
"不允许负接触力",
]);
await expect(stiffnessGroup).toHaveAttribute("aria-expanded", "false");
await expect(contactGroup).toHaveAttribute("aria-expanded", "false");
const stiffnessModeBox = await parameterRow(
componentTable,
"刚度模式",
).boundingBox();
const stiffnessGroupBox = await stiffnessGroup.boundingBox();
expect(stiffnessModeBox).not.toBeNull();
expect(stiffnessGroupBox).not.toBeNull();
expect(stiffnessModeBox!.y).toBeLessThan(stiffnessGroupBox!.y);
await stiffnessGroup.click();
await expect(page.getByLabel("接触刚度", { exact: true })).toBeVisible();
for (const label of ["有效圈数", "剪切模量", "弹簧直径", "线径"]) {
await expect(parameterRow(componentTable, label)).toHaveCount(0);
}
await stiffnessMode.selectOption("2");
await expect(parameterRow(componentTable, "接触刚度")).toHaveCount(0);
for (const label of ["有效圈数", "剪切模量", "弹簧直径", "线径"]) {
await expect(page.getByLabel(label, { exact: true })).toBeVisible();
}
await expect(stiffnessGroup).toHaveAttribute("aria-expanded", "true");
await stiffnessMode.selectOption("1");
await expect(page.getByLabel("接触刚度", { exact: true })).toBeVisible();
await expect(parameterRow(componentTable, "剪切模量")).toHaveCount(0);
});
test("MECMAS21 可配置参数前置并按条件显示可折叠参数组", async ({
page,
}) => {