fix(frontend): disable 'Altro' Send until non-whitespace text (no empty freetext)
Backlog T2 from the reviewer-gate-ux review: the Send button on the reserved
"Other — specify" textarea emitted control:freetext with an empty payload when
clicked on an empty/whitespace field. Guard with disabled={!text.trim()}.
Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
This commit is contained in:
@@ -21,3 +21,17 @@ test("other reveals a textarea and emits freetext with the typed text", async ()
|
||||
await userEvent.click(screen.getByRole("button", { name: /send/i }));
|
||||
expect(onControl).toHaveBeenCalledWith("freetext", "usa la tabella X");
|
||||
});
|
||||
|
||||
test("Send stays disabled until non-whitespace text is entered", async () => {
|
||||
const onControl = vi.fn();
|
||||
render(<ReservedControls reserved={["other"]} onControl={onControl} />);
|
||||
await userEvent.click(screen.getByRole("button", { name: /other — specify/i }));
|
||||
const send = screen.getByRole("button", { name: /send/i });
|
||||
expect(send).toBeDisabled();
|
||||
await userEvent.type(screen.getByRole("textbox"), " ");
|
||||
expect(send).toBeDisabled();
|
||||
await userEvent.click(send);
|
||||
expect(onControl).not.toHaveBeenCalled();
|
||||
await userEvent.type(screen.getByRole("textbox"), "ok");
|
||||
expect(send).not.toBeDisabled();
|
||||
});
|
||||
|
||||
@@ -32,7 +32,11 @@ export function ReservedControls({
|
||||
value={text}
|
||||
onChange={(e) => setText(e.target.value)}
|
||||
/>
|
||||
<button className="text-sm border rounded px-2 py-1 self-start" onClick={() => onControl("freetext", text)}>
|
||||
<button
|
||||
className="text-sm border rounded px-2 py-1 self-start disabled:opacity-50 disabled:cursor-not-allowed"
|
||||
disabled={!text.trim()}
|
||||
onClick={() => onControl("freetext", text)}
|
||||
>
|
||||
Send
|
||||
</button>
|
||||
</div>
|
||||
|
||||
Reference in New Issue
Block a user