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

const handlers = {
  onCreate: vi.fn(),
  onExport: vi.fn(),
  onOpenRoles: vi.fn()
};

test("hides protected user actions without abilities", () => {
  render(
    <UserToolbar
      abilities={{ canCreate: false, canExport: false, canViewRoles: false }}
      {...handlers}
    />
  );

  expect(screen.queryByRole("button", { name: /新增用户/ })).not.toBeInTheDocument();
  expect(screen.queryByRole("button", { name: /导出/ })).not.toBeInTheDocument();
  expect(screen.queryByRole("button", { name: /角色配置/ })).not.toBeInTheDocument();
});

test("shows user actions with matching abilities", () => {
  render(
    <UserToolbar
      abilities={{ canCreate: true, canExport: true, canViewRoles: true }}
      {...handlers}
    />
  );

  expect(screen.getByRole("button", { name: /新增用户/ })).toBeInTheDocument();
  expect(screen.getByRole("button", { name: /导出/ })).toBeInTheDocument();
  expect(screen.getByRole("button", { name: /角色配置/ })).toBeInTheDocument();
});
