fix: clarify memory selection semantics
This commit is contained in:
@@ -36,6 +36,8 @@ export interface WidgetDescriptor {
|
||||
options?: WidgetOption[];
|
||||
reserved?: string[];
|
||||
allow_empty?: boolean;
|
||||
selection_label?: string;
|
||||
confirm_label?: string;
|
||||
artifact?: { kind: string; content?: string; [k: string]: unknown };
|
||||
level?: "info" | "warning" | "error";
|
||||
text?: string;
|
||||
|
||||
@@ -22,6 +22,30 @@ test("confirms the checked ids including initially selected", async () => {
|
||||
expect(onRespond).toHaveBeenCalledWith({ id: "u1", kind: "multiselect", choices: ["t1", "t2"] });
|
||||
});
|
||||
|
||||
test("uses memory-specific selection copy without changing selected ids", async () => {
|
||||
const onRespond = vi.fn();
|
||||
render(
|
||||
<MultiselectWidget
|
||||
descriptor={{
|
||||
id: "u-memory",
|
||||
widget: "multiselect",
|
||||
selection_label: "memory da applicare",
|
||||
confirm_label: "Applica le memory selezionate",
|
||||
options: [
|
||||
{ id: "recommended", label: "Memory raccomandata", selected: true },
|
||||
{ id: "optional", label: "Memory opzionale", selected: false },
|
||||
],
|
||||
}}
|
||||
onRespond={onRespond}
|
||||
/>
|
||||
);
|
||||
|
||||
expect(screen.getByRole("checkbox", { name: /memory raccomandata/i })).toBeChecked();
|
||||
expect(screen.getByText("1 / 2 memory da applicare")).toBeInTheDocument();
|
||||
await userEvent.click(screen.getByRole("button", { name: "Applica le memory selezionate" }));
|
||||
expect(onRespond).toHaveBeenCalledWith({ id: "u-memory", kind: "multiselect", choices: ["recommended"] });
|
||||
});
|
||||
|
||||
test("select-all checks all options", async () => {
|
||||
const onRespond = vi.fn();
|
||||
render(
|
||||
|
||||
@@ -39,7 +39,7 @@ export function MultiselectWidget({ descriptor, onRespond }: WidgetProps) {
|
||||
{allChecked ? "Deselect all" : "Select all"}
|
||||
</button>
|
||||
<span className="text-xs tabular-nums text-muted-foreground">
|
||||
{checked.size} / {options.length} selected
|
||||
{checked.size} / {options.length} {descriptor.selection_label ?? "selected"}
|
||||
</span>
|
||||
</div>
|
||||
<div className="flex flex-col gap-1 pt-2">
|
||||
@@ -67,7 +67,7 @@ export function MultiselectWidget({ descriptor, onRespond }: WidgetProps) {
|
||||
disabled={isDisabled}
|
||||
onClick={() => onRespond({ id: descriptor.id, kind: "multiselect", choices: Array.from(checked) })}
|
||||
>
|
||||
Confirm
|
||||
{descriptor.confirm_label ?? "Confirm"}
|
||||
</button>
|
||||
</div>
|
||||
<ReservedControls
|
||||
|
||||
Reference in New Issue
Block a user