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

test("renders leading config action separately from right icon actions", async () => {
  const user = userEvent.setup();
  const openRates = vi.fn();
  const openCreate = vi.fn();

  render(
    <HostOrgToolbar
      actions={[{ icon: <span />, label: "添加币商", onClick: openCreate, variant: "primary" }]}
      leadingActions={[{ icon: <span />, label: "工资兑换比例", onClick: openRates }]}
    />,
  );

  await user.click(screen.getByRole("button", { name: "工资兑换比例" }));
  await user.click(screen.getByRole("button", { name: "添加币商" }));

  expect(openRates).toHaveBeenCalledTimes(1);
  expect(openCreate).toHaveBeenCalledTimes(1);
});
