feat: complete catalog fleet management workflow
This commit is contained in:
@@ -0,0 +1,57 @@
|
||||
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 descriptions",
|
||||
group: "Descriptions",
|
||||
disabled: true,
|
||||
disabledReason: "Choose a metadata model first",
|
||||
},
|
||||
] as const;
|
||||
|
||||
test("keeps unavailable commands discoverable and explains why Run is disabled", async () => {
|
||||
const user = userEvent.setup();
|
||||
render(
|
||||
<FleetActionSelector
|
||||
actions={actions}
|
||||
selectedCount={1}
|
||||
onRun={vi.fn()}
|
||||
onClear={vi.fn()}
|
||||
renderContext={(action) => action === "generate" ? <span>Model selection</span> : 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(
|
||||
<FleetActionSelector
|
||||
actions={actions}
|
||||
selectedCount={2}
|
||||
onRun={onRun}
|
||||
onClear={vi.fn()}
|
||||
/>,
|
||||
);
|
||||
|
||||
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();
|
||||
await user.click(screen.getByRole("button", { name: "Run action" }));
|
||||
|
||||
expect(onRun).toHaveBeenCalledWith("sync");
|
||||
expect(picker).toHaveValue("");
|
||||
});
|
||||
Reference in New Issue
Block a user