测试:隔离无效规则场景并只等待本轮错误提示

This commit is contained in:
cieanyau committed 2026-11-06 01:47:21 +08:00
1 parent 695bc9192f
commit c1c8bf2696
1 file changed
+26 -21
+26 -21
View File
@@ -129,26 +129,31 @@ test(
}), }),
); );
test( // 每种拒绝输入使用全新的浏览器上下文;上一轮的错误提示不能冒充本轮已处理完成。
"security group batches reject unknown enums without submitting partial rules", for (const [name, input] of [
{ timeout: 25000 }, ["unknown direction", "ot tcp 22 0.0.0.0/0 misspelled-direction"],
(t) => ["unknown protocol", "in tcq 22 0.0.0.0/0 misspelled-protocol"],
scenario(t, { loginMode: "password-only" }, async (page) => { [
const writes = await securityGroupBoundary(page); "a valid rule followed by an unknown direction",
await login(page, "/security/groups/group?id=1"); "out tcp 443 0.0.0.0/0 valid-first\not tcp 22 0.0.0.0/0 invalid-second",
const dialog = await openBatchEditor(page); ],
const invalidInputs = [ ]) {
"ot tcp 22 0.0.0.0/0 misspelled-direction", test(
"in tcq 22 0.0.0.0/0 misspelled-protocol", `security group batches reject ${name} without partial writes`,
"out tcp 443 0.0.0.0/0 valid-first\not tcp 22 0.0.0.0/0 invalid-second", { timeout: 25000 },
]; (t) =>
for (const input of invalidInputs) { scenario(t, { loginMode: "password-only" }, async (page) => {
const writes = await securityGroupBoundary(page);
await login(page, "/security/groups/group?id=1");
const dialog = await openBatchEditor(page);
// 弹窗本来就有 info 级使用说明;只有错误级别的可见提示才表示本次校验失败。
const errorAlert = dialog.locator('[role="alert"].p-message-error');
assert.equal(await errorAlert.count(), 0);
await dialog.locator("textarea").fill(input); await dialog.locator("textarea").fill(input);
await dialog.getByRole("button", { name: "添加", exact: true }).click(); await dialog.getByRole("button", { name: "添加", exact: true }).click();
// 等到可观察的拒绝或错误下发,不用休眠长度推断“没有发请求”。 // 等到可观察的拒绝或错误下发,不用休眠长度推断“没有发请求”。
await eventually( await eventually(
async () => async () => writes.length > 0 || (await errorAlert.isVisible()),
writes.length > 0 || (await dialog.getByRole("alert").count()) > 0,
Boolean, Boolean,
"Invalid rules must produce a form error or expose an unexpected write", "Invalid rules must produce a form error or expose an unexpected write",
); );
@@ -158,11 +163,11 @@ test(
"Unknown enums must never reach the API", "Unknown enums must never reach the API",
); );
assert.equal(await dialog.isVisible(), true); assert.equal(await dialog.isVisible(), true);
assert.ok((await dialog.getByRole("alert").count()) > 0); assert.equal(await errorAlert.isVisible(), true);
} return { rejectedInput: name, submittedBatches: 0 };
return { rejectedInputs: invalidInputs.length, submittedBatches: 0 }; }),
}), );
); }
test( test(
"legacy ticket menu query navigation resets drafts and writes only the selected ticket", "legacy ticket menu query navigation resets drafts and writes only the selected ticket",