From faf6aa198f460912adb4ce69909da90474ef20e0 Mon Sep 17 00:00:00 2001 From: xuans Date: Fri, 25 Sep 2026 00:46:22 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BF=AE=E5=A4=8D=E5=AE=A1=E8=AE=A1=E6=89=A7?= =?UTF-8?q?=E8=A1=8C=E4=B8=AD=E8=AF=AF=E6=8A=A5=E5=A4=B1=E8=B4=A5=E5=8F=8A?= =?UTF-8?q?=E4=BB=BB=E5=8A=A1=E7=8A=B6=E6=80=81=E9=A2=9C=E8=89=B2=E5=B9=B6?= =?UTF-8?q?=E8=A1=A5=E5=85=85=E6=B8=B2=E6=9F=93=E5=9B=9E=E5=BD=92?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- frontend/src/views/Dashboard/Dashboard.js | 4 +- .../src/views/Dashboard/Dashboard.test.js | 48 +++++++++++++++++++ frontend/src/views/Dashboard/Dashboard.vue | 5 +- 3 files changed, 54 insertions(+), 3 deletions(-) diff --git a/frontend/src/views/Dashboard/Dashboard.js b/frontend/src/views/Dashboard/Dashboard.js index 56228e5..6af2df5 100644 --- a/frontend/src/views/Dashboard/Dashboard.js +++ b/frontend/src/views/Dashboard/Dashboard.js @@ -483,9 +483,9 @@ export function useDashboard() { } function statusClass(value) { - return value === "active" + return value === "active" || value === "success" ? "success" - : value === "error" + : value === "error" || value === "failed" ? "danger" : "warning"; } diff --git a/frontend/src/views/Dashboard/Dashboard.test.js b/frontend/src/views/Dashboard/Dashboard.test.js index 6c07aaa..4d668dd 100644 --- a/frontend/src/views/Dashboard/Dashboard.test.js +++ b/frontend/src/views/Dashboard/Dashboard.test.js @@ -257,3 +257,51 @@ test("settingsReadEditSaveContract", async (t) => { assert.deepEqual(submitted.notification.recipients, ["owner@example.test"]); assert.deepEqual(submitted.notification.retry_intervals_secs, [30, 120, 600]); }); + + +test("statusClass", async (t) => { + const { state } = await setup(t, () => verifiedResponse()); + for (const status of ["active", "success"]) { + assert.equal(state.statusClass(status), "success"); + } + for (const status of ["error", "failed"]) { + assert.equal(state.statusClass(status), "danger"); + } + for (const status of ["running", "queued", "cancelled", "unknown", null]) { + assert.equal(state.statusClass(status), "warning"); + } +}); + +test("auditStatusRendering", async () => { + const { readFile } = await import("node:fs/promises"); + const { compileTemplate } = await import("@vue/compiler-sfc"); + const { renderToString } = await import("@vue/server-renderer"); + const { createSSRApp } = await import("vue"); + const source = await readFile(new URL("./Dashboard.vue", import.meta.url), "utf8"); + const start = source.indexOf('
", start) + "
".length; + const compiled = compileTemplate({ + source: source.slice(start, end), + filename: "AuditStatus.vue", + id: "audit-status-regression", + compilerOptions: { mode: "function" }, + }); + assert.deepEqual(compiled.errors, []); + const Vue = await import("vue"); + const render = new Function("Vue", compiled.code)(Vue); + for (const status of ["running", "queued", "cancelled", "unknown"]) { + const html = await renderToString(createSSRApp({ + render, + setup: () => ({ + auditLogs: [{ id: status, action: "test", status, message: "test" }], + auditActionLabel: (value) => value, + statusClass: () => "warning", + taskStatusLabels: { [status]: `label-${status}` }, + displayLabel: (labels, value) => labels[value], + }), + })); + assert.match(html, new RegExp(`label-${status}`)); + assert.doesNotMatch(html, /danger/); + } +}); diff --git a/frontend/src/views/Dashboard/Dashboard.vue b/frontend/src/views/Dashboard/Dashboard.vue index 9a8add0..b80113d 100644 --- a/frontend/src/views/Dashboard/Dashboard.vue +++ b/frontend/src/views/Dashboard/Dashboard.vue @@ -253,7 +253,10 @@ const { {{ auditActionLabel(item.action) }} {{ item.message || item.resource_type }} - {{ item.status === "success" ? "成功" : "失败" }} + {{ item.status === "success" ? "成功" : "失败" }} + + {{ displayLabel(taskStatusLabels, item.status) }} +