swarm ui: the send button's off rule is a tested function
This commit is contained in:
parent
58e7cbf261
commit
2fe5759cdf
3 changed files with 18 additions and 1 deletions
|
|
@ -29,6 +29,7 @@ import {
|
||||||
enterSends,
|
enterSends,
|
||||||
matchCommands,
|
matchCommands,
|
||||||
menuQuery,
|
menuQuery,
|
||||||
|
sendDisabled,
|
||||||
textToSend,
|
textToSend,
|
||||||
moveSelection,
|
moveSelection,
|
||||||
type AgentCommand,
|
type AgentCommand,
|
||||||
|
|
@ -135,7 +136,7 @@ export function AgentInputForm({ agentName }: { agentName: string }) {
|
||||||
type="submit"
|
type="submit"
|
||||||
aria-label="send"
|
aria-label="send"
|
||||||
title="send"
|
title="send"
|
||||||
disabled={submitting || body.trim() === ""}
|
disabled={sendDisabled(body, submitting)}
|
||||||
aria-busy={submitting || undefined}
|
aria-busy={submitting || undefined}
|
||||||
>
|
>
|
||||||
{submitting ? <Spinner /> : <SendIcon />}
|
{submitting ? <Spinner /> : <SendIcon />}
|
||||||
|
|
|
||||||
|
|
@ -119,3 +119,11 @@ export function textToSend(text: string): string {
|
||||||
const trimmed = text.trim();
|
const trimmed = text.trim();
|
||||||
return menuQuery(trimmed) === null ? text : trimmed;
|
return menuQuery(trimmed) === null ? text : trimmed;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Whether the send button is off: while a send is under way, or when the box
|
||||||
|
* holds nothing but whitespace.
|
||||||
|
*/
|
||||||
|
export function sendDisabled(text: string, submitting: boolean): boolean {
|
||||||
|
return submitting || text.trim() === "";
|
||||||
|
}
|
||||||
|
|
|
||||||
|
|
@ -9,6 +9,7 @@ import {
|
||||||
matchCommands,
|
matchCommands,
|
||||||
menuQuery,
|
menuQuery,
|
||||||
moveSelection,
|
moveSelection,
|
||||||
|
sendDisabled,
|
||||||
splitName,
|
splitName,
|
||||||
textToSend,
|
textToSend,
|
||||||
} from "../src/agent/terminal/command-menu.ts";
|
} from "../src/agent/terminal/command-menu.ts";
|
||||||
|
|
@ -127,3 +128,10 @@ test("any other message goes as it is", () => {
|
||||||
assert.equal(textToSend("fix /etc/hosts"), "fix /etc/hosts");
|
assert.equal(textToSend("fix /etc/hosts"), "fix /etc/hosts");
|
||||||
assert.equal(textToSend(" "), " ");
|
assert.equal(textToSend(" "), " ");
|
||||||
});
|
});
|
||||||
|
|
||||||
|
test("send is off while sending and for a box with only whitespace", () => {
|
||||||
|
assert.equal(sendDisabled("", false), true);
|
||||||
|
assert.equal(sendDisabled(" \n ", false), true);
|
||||||
|
assert.equal(sendDisabled("hi", true), true);
|
||||||
|
assert.equal(sendDisabled("hi", false), false);
|
||||||
|
});
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue