import { describe, expect, it, vi } from "vitest";
import { render, screen } from "@testing-library/react";
import userEvent from "@testing-library/user-event";
import { RowActions } from "./row-actions";
// unify-admin-listing-toolbar: a row shows its main action and puts every other action in a ⋯ menu.
describe("RowActions", () => {
it("shows the main action and a More actions menu holding the rest", async () => {
const onReset = vi.fn();
const user = userEvent.setup();
render(
,
);
expect(screen.getByRole("button", { name: "Edit" })).toBeInTheDocument();
expect(screen.queryByRole("menuitem", { name: "Send password reset" })).toBeNull();
await user.click(screen.getByRole("button", { name: "More actions for admin2" }));
await user.click(await screen.findByRole("menuitem", { name: "Send password reset" }));
expect(onReset).toHaveBeenCalledOnce();
});
it("colours a destructive item and keeps disabled items unselectable", async () => {
const onDisabled = vi.fn();
const user = userEvent.setup();
render(
,
);
await user.click(screen.getByRole("button", { name: "More actions for Hero 1" }));
expect(await screen.findByRole("menuitem", { name: "Deactivate" })).toHaveAttribute("data-variant", "destructive");
const archive = screen.getByRole("menuitem", { name: "Archive" });
expect(archive).toHaveAttribute("data-disabled");
await user.click(archive);
expect(onDisabled).not.toHaveBeenCalled();
});
it("draws no menu when there are no items", () => {
render();
expect(screen.queryByRole("button", { name: /More actions/ })).toBeNull();
expect(screen.getByRole("button", { name: "Edit" })).toBeInTheDocument();
});
});