From a6bacafaa35609be3a0aaad3420ccbd3c640487d Mon Sep 17 00:00:00 2001 From: xuans Date: Sun, 27 Sep 2026 00:25:42 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BF=AE=E5=A4=8D=E8=AF=81=E4=B9=A6=E5=AF=BC?= =?UTF-8?q?=E5=85=A5=E9=80=89=E4=B8=AD=E6=96=87=E4=BB=B6=E5=90=8E=E8=A2=AB?= =?UTF-8?q?=E5=BF=85=E5=A1=AB=E6=A0=A1=E9=AA=8C=E9=98=BB=E6=AD=A2=E6=8F=90?= =?UTF-8?q?=E4=BA=A4?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- frontend/src/views/Dashboard/Dashboard.js | 1 - .../src/views/Dashboard/Dashboard.test.js | 39 +++++++++++++++++++ 2 files changed, 39 insertions(+), 1 deletion(-) diff --git a/frontend/src/views/Dashboard/Dashboard.js b/frontend/src/views/Dashboard/Dashboard.js index 3b0a009..f56ed52 100644 --- a/frontend/src/views/Dashboard/Dashboard.js +++ b/frontend/src/views/Dashboard/Dashboard.js @@ -1009,7 +1009,6 @@ export function useDashboard() { function selectCertificateImportFile(kind, event) { importFiles.value[kind] = event.target.files?.[0] || null; - event.target.value = ""; importError.value = ""; } diff --git a/frontend/src/views/Dashboard/Dashboard.test.js b/frontend/src/views/Dashboard/Dashboard.test.js index 02cb064..4a1ba68 100644 --- a/frontend/src/views/Dashboard/Dashboard.test.js +++ b/frontend/src/views/Dashboard/Dashboard.test.js @@ -124,6 +124,45 @@ test("完整页面逐个渲染六个板块,每次只有一个内容标题", as } }); +test("certificateImport.preservesRequiredFileInputSelection", async (t) => { + const { state } = await setup(t, () => verifiedResponse()); + state.openCertificateImport({ id: "domain-import", name: "example.test" }); + for (const kind of ["certificate", "private_key", "issuer_bundle"]) { + const file = new File([kind], `${kind}.pem`); + const target = { files: [file], value: `C:\\fakepath\\${file.name}` }; + state.selectCertificateImportFile(kind, { target }); + assert.equal(target.value, `C:\\fakepath\\${file.name}`); + assert.equal(target.files[0], file); + } +}); + +test("certificateImport.submitsSelectedFilesAndResetsOnReopen", async (t) => { + const imports = []; + const { state } = await mountComposable(t, useDashboard, async (path, options) => { + if (path.endsWith("/certificate/import")) { + imports.push({ path, body: options.body }); + return Response.json({ imported: true }); + } + return Response.json({ items: [] }); + }); + state.openCertificateImport({ id: "domain-import", name: "example.test" }); + for (const kind of ["certificate", "private_key", "issuer_bundle"]) { + const file = new File([kind], `${kind}.pem`); + state.selectCertificateImportFile(kind, { target: { files: [file], value: file.name } }); + } + await state.importCertificate(); + assert.equal(imports.length, 1); + assert.equal(imports[0].path, "/api/v1/domains/domain-import/certificate/import"); + for (const kind of ["certificate", "private_key", "issuer_bundle"]) { + assert.equal(await imports[0].body.get(kind).text(), kind); + } + state.closeCertificateImport(); + state.openCertificateImport({ id: "another-domain", name: "another.test" }); + await state.importCertificate(); + assert.equal(imports.length, 1); + assert.ok(state.importError.value); +}); + async function setup(t, request) { const mounted = await mountComposable(t, useDashboard, async (path) => { if (path === "/api/v1/dns/test") return request();