import { render, screen } from "@testing-library/react";
import userEvent from "@testing-library/user-event";
import { expect, test, vi } from "vitest";
import { UserTable } from "./UserTable.jsx";

const baseUser = {
  account: "alice",
  id: 1,
  lastLogin: "2026-05-01 10:00",
  mfa: "已开启",
  name: "Alice",
  role: "管理员",
  status: "active",
  team: "平台"
};

test("opens user profile from user identity", async () => {
  const onOpenProfile = vi.fn();
  const user = userEvent.setup();

  render(
    <UserTable
      canEdit
      canResetPassword
      canStatus
      onEdit={vi.fn()}
      onOpenProfile={onOpenProfile}
      onResetPassword={vi.fn()}
      onToggleDisabled={vi.fn()}
      onToggleLocked={vi.fn()}
      selectedIds={[]}
      setSelectedIds={vi.fn()}
      users={[baseUser]}
    />
  );

  await user.click(screen.getByRole("button", { name: "查看 Alice 信息" }));

  expect(onOpenProfile).toHaveBeenCalledWith(baseUser);
});
