Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
78 changes: 76 additions & 2 deletions apps/web/src/components/chat/ComposerPrimaryActions.test.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,64 @@
import { describe, expect, it } from "vite-plus/test";
import { createElement } from "react";
import { renderToStaticMarkup } from "react-dom/server";
import { describe, expect, it, vi } from "vite-plus/test";

import { formatPendingPrimaryActionLabel } from "./ComposerPrimaryActions";
vi.mock("~/hooks/useSettings", () => ({
useEnvironmentIdentificationMode: () => "none",
}));
vi.mock("../SidebarStageBackdrop", () => ({
StageBackdropButtonArt: () => null,
useSidebarStageBackdropVariant: () => null,
}));

import { ComposerPrimaryActions, formatPendingPrimaryActionLabel } from "./ComposerPrimaryActions";

function renderPendingActions(isRunning: boolean) {
return renderToStaticMarkup(
createElement(ComposerPrimaryActions, {
compact: true,
pendingAction: {
questionIndex: 0,
isLastQuestion: true,
canAdvance: true,
isResponding: false,
isComplete: true,
},
isRunning,
showPlanFollowUpPrompt: false,
promptHasText: false,
isSendBusy: false,
sendDisabledReason: null,
isConnecting: false,
isEnvironmentUnavailable: false,
isPreparingWorktree: false,
hasSendableContent: false,
onPreviousPendingQuestion: () => {},
onInterrupt: () => {},
onImplementPlanInNewThread: () => {},
}),
);
}

function renderStandaloneStop() {
return renderToStaticMarkup(
createElement(ComposerPrimaryActions, {
compact: true,
pendingAction: null,
isRunning: true,
showPlanFollowUpPrompt: false,
promptHasText: false,
isSendBusy: false,
sendDisabledReason: null,
isConnecting: false,
isEnvironmentUnavailable: false,
isPreparingWorktree: false,
hasSendableContent: false,
onPreviousPendingQuestion: () => {},
onInterrupt: () => {},
onImplementPlanInNewThread: () => {},
}),
);
}

describe("formatPendingPrimaryActionLabel", () => {
it("returns 'Submitting...' while responding", () => {
Expand Down Expand Up @@ -91,3 +149,19 @@ describe("formatPendingPrimaryActionLabel", () => {
).toBe("Submit answers");
});
});

describe("ComposerPrimaryActions", () => {
it("offers Stop generation while a running turn is waiting for user input", () => {
expect(renderPendingActions(true)).toContain('aria-label="Stop generation"');
});

it("does not offer Stop generation for a pending request without a running turn", () => {
expect(renderPendingActions(false)).not.toContain('aria-label="Stop generation"');
});

it("matches the small pending action size without changing the standalone size", () => {
expect(renderPendingActions(true)).toContain("size-8 sm:size-7");
expect(renderStandaloneStop()).toContain("size-8 sm:h-8 sm:w-8");
expect(renderStandaloneStop()).not.toContain("sm:size-7");
});
});
31 changes: 18 additions & 13 deletions apps/web/src/components/chat/ComposerPrimaryActions.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -80,10 +80,27 @@ export const ComposerPrimaryActions = memo(function ComposerPrimaryActions({
const stageBackdropVariant = useSidebarStageBackdropVariant(
environmentIdentificationMode === "artwork",
);
const renderStopGenerationButton = (insidePendingAction: boolean) => (
<button
type="button"
className={cn(
"flex cursor-pointer items-center justify-center rounded-full bg-destructive/90 text-white shadow-xs shadow-destructive/24 inset-shadow-[0_1px_--theme(--color-white/16%)] transition-all duration-150 hover:bg-destructive hover:scale-105 active:inset-shadow-[0_1px_--theme(--color-black/8%)] active:shadow-none",
insidePendingAction ? "size-8 sm:size-7" : "size-8 sm:h-8 sm:w-8",
)}
{...pointerFocusProps}
onClick={onInterrupt}
aria-label="Stop generation"
>
<svg width="12" height="12" viewBox="0 0 12 12" fill="currentColor" aria-hidden="true">
<rect x="2" y="2" width="8" height="8" rx="1.5" />
</svg>
</button>
);

if (pendingAction) {
return (
<div className={cn("flex items-center justify-end", compact ? "gap-1.5" : "gap-2")}>
{isRunning ? renderStopGenerationButton(true) : null}
{pendingAction.questionIndex > 0 ? (
compact ? (
<Button
Expand Down Expand Up @@ -133,19 +150,7 @@ export const ComposerPrimaryActions = memo(function ComposerPrimaryActions({
}

if (isRunning) {
return (
<button
type="button"
className="flex size-8 cursor-pointer items-center justify-center rounded-full bg-destructive/90 text-white shadow-xs shadow-destructive/24 inset-shadow-[0_1px_--theme(--color-white/16%)] transition-all duration-150 hover:bg-destructive hover:scale-105 active:inset-shadow-[0_1px_--theme(--color-black/8%)] active:shadow-none sm:h-8 sm:w-8"
{...pointerFocusProps}
onClick={onInterrupt}
aria-label="Stop generation"
>
<svg width="12" height="12" viewBox="0 0 12 12" fill="currentColor" aria-hidden="true">
<rect x="2" y="2" width="8" height="8" rx="1.5" />
</svg>
</button>
);
return renderStopGenerationButton(false);
}

if (showPlanFollowUpPrompt) {
Expand Down
Loading