test(frontend): cover ArtifactWidget view-only + multiselect allow_empty gate

This commit is contained in:
2026-06-28 12:40:09 +02:00
parent be9e761e0a
commit f933b544ff
2 changed files with 45 additions and 0 deletions
@@ -0,0 +1,21 @@
import { render, screen } from "@testing-library/react";
import { ArtifactWidget } from "./ArtifactWidget";
test("renders artifact content view-only with no response path", () => {
const onRespond = vi.fn();
render(
<ArtifactWidget
descriptor={{
id: "u1",
widget: "artifact",
artifact: { kind: "result", content: "SELECT 1" },
}}
onRespond={onRespond}
/>
);
// (a) content is rendered
expect(screen.getByText("SELECT 1")).toBeInTheDocument();
// (b) no response path: no responding button, onRespond never called
expect(screen.queryByRole("button")).not.toBeInTheDocument();
expect(onRespond).not.toHaveBeenCalled();
});
@@ -81,6 +81,30 @@ test("confirm is disabled when nothing checked and allow_empty is false", async
expect(onRespond).not.toHaveBeenCalled();
});
test("deselect-all with allow_empty false disables Conferma (empty confirm impossible)", async () => {
const onRespond = vi.fn();
render(
<MultiselectWidget
descriptor={{
id: "u1",
widget: "multiselect",
allow_empty: false,
options: [
{ id: "a", label: "Alpha", selected: true },
{ id: "b", label: "Beta", selected: true },
],
}}
onRespond={onRespond}
/>
);
const btn = screen.getByRole("button", { name: /conferma/i });
expect(btn).not.toBeDisabled();
await userEvent.click(screen.getByRole("button", { name: /deseleziona tutti/i }));
expect(btn).toBeDisabled();
await userEvent.click(btn);
expect(onRespond).not.toHaveBeenCalled();
});
test("confirm is enabled when allow_empty is false but something is checked", async () => {
const onRespond = vi.fn();
render(