fix: restore server create deployment wizard

This commit is contained in:
npc0-hue
2026-07-30 21:02:17 +08:00
parent e614a17fe3
commit 2a17718158
7 changed files with 77 additions and 30 deletions
@@ -6,7 +6,7 @@ import { afterEach, describe, expect, it, vi } from "vitest";
import type { GamePluginResponse } from "../api/types";
import { defaultServerCreateForm } from "../contracts/serverManagement";
import { minimalServerCreateRequestFromForm } from "../schemas/serverManagement";
import { serverCreateRequestFromForm } from "../schemas/serverManagement";
import { ServerDeploymentWorkflow } from "./ServerDeploymentWorkflow";
const plugin: GamePluginResponse = {
@@ -48,14 +48,14 @@ afterEach(async () => {
});
describe("ServerDeploymentWorkflow", () => {
it("submits plugin type and server name as a minimal create request", async () => {
it("submits deployment mode and matching startup inputs from the create wizard", async () => {
container = document.createElement("div");
document.body.append(container);
root = createRoot(container);
const initialForm = defaultServerCreateForm([plugin], []);
let submitted: ReturnType<typeof minimalServerCreateRequestFromForm> | undefined;
let submitted: ReturnType<typeof serverCreateRequestFromForm> | undefined;
const onSubmit = vi.fn(async (form: typeof initialForm) => {
submitted = minimalServerCreateRequestFromForm(form, 17);
submitted = serverCreateRequestFromForm(form, 17);
});
await act(async () => {
@@ -74,29 +74,54 @@ describe("ServerDeploymentWorkflow", () => {
expect(container.querySelector('select[name="pluginId"]')).not.toBeNull();
expect(container.querySelector('input[name="name"]')).not.toBeNull();
for (const field of ["deploymentTargetId", "runEndpointId", "profileKey", "serverRoot", "startCommand"]) {
for (const field of ["deploymentTargetId", "runEndpointId", "profileKey", "serverRoot", "startCommand", "deploymentMode"]) {
expect(container.querySelector(`[name="${field}"]`)).toBeNull();
}
expect(container.textContent).not.toContain("运行连接设置");
expect(container.querySelector('select[name="deploymentMode"]')).toBeNull();
const nameInput = container.querySelector<HTMLInputElement>('input[name="name"]');
if (!nameInput) throw new Error("server name input not found");
await act(async () => {
setInputValue(nameInput, "Minimal Runtime Server");
setInputValue(nameInput, "Custom Runtime Server");
});
await submitWorkflow(container);
expect(container.textContent).toContain("本次只创建服务器记录");
expect(container.textContent).toContain("Minimal Runtime Server");
expect(container.textContent).toContain("选择这台服务器的创建方式");
expect(container.textContent).toContain("自定义启动方式");
await clickButtonByText(container, "自定义启动方式");
await submitWorkflow(container);
expect(container.querySelector<HTMLInputElement>('input[name="startCommand"]')).not.toBeNull();
expect(container.querySelector('[name="deploymentTargetId"]')).toBeNull();
expect(container.querySelector('[name="runEndpointId"]')).toBeNull();
expect(container.querySelector('[name="profileKey"]')).toBeNull();
const rootInput = container.querySelector<HTMLInputElement>('input[name="serverRoot"]');
const startInput = container.querySelector<HTMLInputElement>('input[name="startCommand"]');
if (!rootInput || !startInput) throw new Error("custom startup inputs not found");
await act(async () => {
setInputValue(rootInput, "/srv/custom-runtime");
setInputValue(startInput, "./start-runtime.sh");
});
await submitWorkflow(container);
expect(container.textContent).toContain("本次保存创建向导配置");
expect(container.textContent).toContain("自定义启动方式");
expect(container.textContent).toContain("将替换");
await submitWorkflow(container);
expect(onSubmit).toHaveBeenCalledTimes(1);
expect(submitted).toEqual({
id: "server-minimal-runtime-server-17",
expect(submitted).toMatchObject({
id: "server-custom-runtime-server-17",
pluginId: "game.runtime",
name: "Minimal Runtime Server",
idempotencyKey: "web:create:server-minimal-runtime-server-17:17"
name: "Custom Runtime Server",
idempotencyKey: "web:create:server-custom-runtime-server-17:17",
runEndpointId: undefined,
deployment: {
mode: "custom-command",
serverRoot: "/srv/custom-runtime",
startCommand: "./start-runtime.sh"
}
});
});
});
@@ -109,6 +134,14 @@ async function submitWorkflow(target: HTMLElement) {
});
}
async function clickButtonByText(target: HTMLElement, text: string) {
const button = Array.from(target.querySelectorAll<HTMLButtonElement>("button")).find((item) => item.textContent?.includes(text));
if (!button) throw new Error(`button not found: ${text}`);
await act(async () => {
button.dispatchEvent(new MouseEvent("click", { bubbles: true, cancelable: true }));
});
}
function setInputValue(input: HTMLInputElement, value: string) {
const setter = Object.getOwnPropertyDescriptor(HTMLInputElement.prototype, "value")?.set;
setter?.call(input, value);