import { render, screen } from "@testing-library/react";
import userEvent from "@testing-library/user-event";
import { vi } from "vitest";
import { FleetActionSelector } from "./FleetActionSelector";
const actions = [
{ id: "sync", label: "Synchronize tables", group: "Synchronization", scopeLabel: "All tables in this database" },
{
id: "generate",
label: "Generate column descriptions",
group: "Descriptions",
disabled: true,
disabledReason: "Choose a metadata model first",
},
] as const;
test("disables the picker when no rows are selected", () => {
render(
,
);
expect(screen.getByRole("combobox", { name: "Batch action" })).toBeDisabled();
});
test("keeps unavailable commands discoverable and explains why Run is disabled", async () => {
const user = userEvent.setup();
render(
action === "generate" ? Model selection : null}
/>,
);
await user.selectOptions(screen.getByRole("combobox", { name: "Batch action" }), "generate");
expect(screen.getByText("Choose a metadata model first")).toBeVisible();
expect(screen.getByText("Model selection")).toBeVisible();
expect(screen.getByRole("button", { name: "Run action" })).toBeDisabled();
});
test("runs an enabled command explicitly and resets the picker", async () => {
const user = userEvent.setup();
const onRun = vi.fn().mockResolvedValue(undefined);
render(
,
);
const picker = screen.getByRole("combobox", { name: "Batch action" });
await user.selectOptions(picker, "sync");
expect(screen.getByText("All tables in this database")).toBeVisible();
expect(screen.getByText("Action scope")).toBeVisible();
expect(screen.getByRole("button", { name: "Run action" })).toHaveClass("bg-destructive");
await user.click(screen.getByRole("button", { name: "Run action" }));
expect(onRun).toHaveBeenCalledWith("sync");
expect(picker).toHaveValue("");
});