gaza/src/features/connections/components.test.tsx
Ubuntu a74cfa990f 实现 Teamserver 连接中心与安全诊断
Co-authored-by: multica-agent <github@multica.ai>
2026-08-03 19:25:30 +00:00

24 lines
1.4 KiB
TypeScript
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

import { fireEvent, render, screen, waitFor } from "@testing-library/react";
import { describe, expect, it } from "vitest";
import { ConnectionCenter, ConnectionEditor } from "./components";
import { MemoryMockConnectionAdapter } from "./mockAdapter";
describe("连接中心组件", () => {
it("表单拒绝无效配置,秘密字段使用 password 类型", () => {
render(<ConnectionEditor onSave={() => undefined} onCancel={() => undefined} />);
expect(screen.getByLabelText("认证秘密")).toHaveAttribute("type", "password");
fireEvent.click(screen.getByRole("button", { name: "保存到内存" }));
expect(screen.getByRole("alert")).toHaveTextContent("配置错误");
});
it("通过 mock adapter 完成创建并明确未建立网络连接", async () => {
render(<ConnectionCenter adapter={new MemoryMockConnectionAdapter()} />);
fireEvent.click(await screen.findByRole("button", { name: " 新建连接" }));
fireEvent.change(screen.getByLabelText("名称"), { target: { value: "Atlas" } });
fireEvent.change(screen.getByLabelText("地址"), { target: { value: "https://atlas.example" } });
fireEvent.click(screen.getByRole("button", { name: "保存到内存" }));
await waitFor(() => expect(screen.getByText("Atlas")).toBeInTheDocument());
expect(screen.getByText(/尚未建立网络连接/)).toBeInTheDocument();
});
});