fix(webui): restore full-project typechecking

This commit is contained in:
chengyongru authored and chengyongru committed 2026-10-20 14:47:38 +08:00
1 parent f869212e7d
commit a1bca7dc50
56 files changed
+622 -583

No files matched your search

+14 -12
View File
@@ -4,7 +4,8 @@ import QRCode from "qrcode";
import type { NanobotFeatureInfo } from "@/lib/types";
import { WeixinConnectFlow } from "../../../nanobot/channels/weixin/webui/WeixinConnectFlow";
import { WeixinConnectFlowView } from "../../../nanobot/channels/weixin/webui/WeixinConnectFlowView";
import { WeixinConnectFlowView, type WeixinConnectFlowViewProps } from "../../../nanobot/channels/weixin/webui/WeixinConnectFlowView";
import type { WeixinVerificationPayload } from "../../../nanobot/channels/weixin/webui/presentation";
const { requestMutation, useClientMock } = vi.hoisted(() => ({
requestMutation: vi.fn(), useClientMock: vi.fn(),
@@ -12,9 +13,10 @@ const { requestMutation, useClientMock } = vi.hoisted(() => ({
vi.mock("@/providers/ClientProvider", () => ({ useClient: useClientMock }));
const challenge = {
session_id: "weixin-verification", status: "pending" as const,
qr_url: "https://example.com/weixin", challenge: "verify_code" as const,
};
session_id: "weixin-verification", status: "pending",
qr_url: "https://example.com/weixin", challenge: "verify_code",
} satisfies WeixinVerificationPayload;
const rejectedChallenge = { ...challenge, verification_failed: true } satisfies WeixinVerificationPayload;
const feature: NanobotFeatureInfo = {
name: "weixin", display_name: "WeChat", type: "channel", webui: "webui/index.tsx",
enabled: false, configured: false, installed: true, ready: true, status: "not_enabled",
@@ -24,13 +26,13 @@ const feature: NanobotFeatureInfo = {
beforeEach(() => {
requestMutation.mockReset();
useClientMock.mockReset().mockReturnValue({ client: { requestMutation } });
vi.spyOn(QRCode, "toDataURL").mockResolvedValue("data:image/png;base64,preview");
vi.spyOn(QRCode, "toDataURL").mockImplementation(async () => "data:image/png;base64,preview");
});
afterEach(() => { cleanup(); vi.useRealTimers(); vi.restoreAllMocks(); });
describe("WeChat verification views", () => {
it("renders without a runtime client and retains the verification draft after a rejected code", async () => {
const onPoll = vi.fn().mockResolvedValue({ ...challenge, verification_failed: true });
const onPoll = vi.fn<WeixinConnectFlowViewProps["onPoll"]>().mockResolvedValue(rejectedChallenge);
const props = {
connect: challenge, busy: false, error: null, minimalPending: true,
onStart: vi.fn(), onCancel: vi.fn(), onPoll,
@@ -38,13 +40,13 @@ describe("WeChat verification views", () => {
const view = render(<WeixinConnectFlowView {...props} />);
const code = screen.getByRole("textbox", { name: "Code" });
fireEvent.change(code, { target: { value: " 987654 " } });
fireEvent.click(screen.getByRole("button", { name: "Verify", exact: true }));
fireEvent.click(screen.getByRole("button", { name: "Verify" }));
await waitFor(() => expect(onPoll).toHaveBeenCalledWith({ verify_code: "987654" }));
view.rerender(<WeixinConnectFlowView {...props} connect={{ ...challenge, verification_failed: true }} busy />);
view.rerender(<WeixinConnectFlowView {...props} connect={rejectedChallenge} busy />);
expect(code).toHaveValue(" 987654 ");
expect(code).toHaveAttribute("aria-invalid", "true");
expect(code).toHaveAttribute("aria-describedby", screen.getByRole("alert").id);
expect(screen.getByRole("button", { name: "Verify", exact: true })).toBeDisabled();
expect(screen.getByRole("button", { name: "Verify" })).toBeDisabled();
expect(useClientMock).not.toHaveBeenCalled();
expect(requestMutation).not.toHaveBeenCalled();
});
@@ -59,9 +61,9 @@ describe("WeChat verification views", () => {
expect(requestMutation).toHaveBeenCalledTimes(1);
expect(requestMutation).toHaveBeenCalledWith("settings.channel.connect.start", { channel: "weixin" }, 150_000);
requestMutation.mockResolvedValueOnce({ ...challenge, verification_failed: true });
requestMutation.mockResolvedValueOnce(rejectedChallenge);
fireEvent.change(code, { target: { value: "123456" } });
await act(async () => { fireEvent.click(screen.getByRole("button", { name: "Verify", exact: true })); });
await act(async () => { fireEvent.click(screen.getByRole("button", { name: "Verify" })); });
expect(requestMutation).toHaveBeenLastCalledWith("settings.channel.connect.poll", {
channel: "weixin", session_id: "weixin-verification", verify_code: "123456",
}, 150_000);
@@ -70,7 +72,7 @@ describe("WeChat verification views", () => {
const features = { features: [{ ...feature, configured: true }], enabled_count: 0 };
requestMutation.mockResolvedValueOnce({ ...challenge, status: "succeeded", nanobot_features: features });
await act(async () => { fireEvent.click(screen.getByRole("button", { name: "Verify", exact: true })); });
await act(async () => { fireEvent.click(screen.getByRole("button", { name: "Verify" })); });
expect(onFeaturesUpdate).toHaveBeenCalledWith(features);
expect(screen.getByText("WeChat is connected.")).toBeVisible();
expect(screen.queryByRole("textbox", { name: "Code" })).not.toBeInTheDocument();