From cfd9efa6f34f46a8d69d46d9773c4d4c4db8eaf0 Mon Sep 17 00:00:00 2001 From: xuans Date: Fri, 25 Sep 2026 01:58:03 +0800 Subject: [PATCH] =?UTF-8?q?=E6=8B=86=E5=88=86=E7=A7=81=E9=92=A5=E5=BD=95?= =?UTF-8?q?=E5=85=A5=E5=BC=B9=E7=AA=97=E5=B9=B6=E4=BF=AE=E5=A4=8D=E5=BA=95?= =?UTF-8?q?=E9=83=A8=E8=A3=81=E5=88=87=E5=8F=8A=E6=82=AC=E6=B5=AE=E8=AF=B4?= =?UTF-8?q?=E6=98=8E?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../src/views/Dashboard/Dashboard.test.js | 62 +++++ frontend/src/views/Dashboard/Dashboard.vue | 211 +-------------- frontend/src/views/Dashboard/SSHKeyModal.css | 131 ++++++++++ frontend/src/views/Dashboard/SSHKeyModal.vue | 240 ++++++++++++++++++ 4 files changed, 435 insertions(+), 209 deletions(-) create mode 100644 frontend/src/views/Dashboard/SSHKeyModal.css create mode 100644 frontend/src/views/Dashboard/SSHKeyModal.vue diff --git a/frontend/src/views/Dashboard/Dashboard.test.js b/frontend/src/views/Dashboard/Dashboard.test.js index fb08034..bb198c5 100644 --- a/frontend/src/views/Dashboard/Dashboard.test.js +++ b/frontend/src/views/Dashboard/Dashboard.test.js @@ -454,3 +454,65 @@ test("changePassword.loadsScopedBaseStylesAndCompiles", async () => { assert.match(base, /\.modal-backdrop\s*\{[^}]*position:\s*fixed;/); assert.match(base, /\.field\s*\{/); }); + +test("sshKeyModal.compilesAndPreservesCredentialFields", async () => { + const { readFile } = await import("node:fs/promises"); + const { parse, compileScript, compileTemplate } = await import("@vue/compiler-sfc"); + const { renderToString } = await import("@vue/server-renderer"); + const Vue = await import("vue"); + const source = await readFile(new URL("./SSHKeyModal.vue", import.meta.url), "utf8"); + const { descriptor, errors } = parse(source); + assert.deepEqual(errors, []); + assert.ok(compileScript(descriptor, { id: "ssh-key-modal" })); + const compiled = compileTemplate({ + source: descriptor.template.content, + filename: "SSHKeyModal.vue", + id: "ssh-key-modal", + compilerOptions: { mode: "function" }, + }); + assert.deepEqual(compiled.errors, []); + assert.ok(descriptor.styles.some(style => style.scoped && style.src === "./Dashboard.css")); + assert.ok(descriptor.styles.some(style => style.scoped && style.src === "./SSHKeyModal.css")); + assert.doesNotMatch(source, / ({ + showSSHKeyForm: true, + closeSSHKeyForm: () => {}, + saveSSHKey: () => {}, + sshKeyPlatform: platform, + sshKeyFileName: "test-key", + sshKeyPrivatePath: "/test/private", + sshKeyPublicPath: "/test/public", + sshKeyCommandUsername: "deploy", + sshKeyCommandHost: "example.test", + copySSHKeyCommand: () => {}, + sshKeyCommands: { windows: "generate-windows", linux: "generate-linux" }, + sshPublicKeyCommands: { windows: "install-windows", linux: "install-linux" }, + sshKeyForm: { name: "", private_key: "", passphrase: "" }, + importSSHKeyFile: () => {}, + sshKeyPassphraseVisible: false, + sshKeyFormError: "test-validation-error", + sshKeySaving: false, + }), + }); + app.component("HelpTip", { + setup: (_, { slots }) => () => Vue.h("span", { class: "test-help-tip" }, slots.default?.()), + }); + const html = await renderToString(app); + assert.match(html, /class="modal-card ssh-key-modal"/); + assert.match(html, /type="submit"/); + assert.match(html, /type="file"/); + assert.match(html, /type="password"/); + assert.match(html, /rows="5"/); + assert.match(html, /test-validation-error/); + assert.equal((html.match(/ required/g) || []).length, 2); + assert.ok(html.includes(`generate-${platform}`)); + assert.ok(html.includes(`install-${platform}`)); + assert.ok(html.includes("deploy@example.test")); + } + const css = await readFile(new URL("./SSHKeyModal.css", import.meta.url), "utf8"); + assert.match(css, /\.ssh-key-modal\s*\{[^}]*overflow:\s*auto;/); +}); \ No newline at end of file diff --git a/frontend/src/views/Dashboard/Dashboard.vue b/frontend/src/views/Dashboard/Dashboard.vue index 86f3185..bd0a3ba 100644 --- a/frontend/src/views/Dashboard/Dashboard.vue +++ b/frontend/src/views/Dashboard/Dashboard.vue @@ -4,6 +4,7 @@ import UserManagement from "../UserManagement/UserManagement.vue"; import SettingsModal from "./SettingsModal.vue"; import DomainModal from "./DomainModal.vue"; import ServerModal from "./ServerModal.vue"; +import SSHKeyModal from "./SSHKeyModal.vue"; import { useDashboard } from "./Dashboard.js"; const dashboard = useDashboard(); @@ -474,216 +475,8 @@ const { -