diff --git a/frontend/__tests__/components/chat/chat-interface.test.tsx b/frontend/__tests__/components/chat/chat-interface.test.tsx index d5969550d9..a5d49bb1c3 100644 --- a/frontend/__tests__/components/chat/chat-interface.test.tsx +++ b/frontend/__tests__/components/chat/chat-interface.test.tsx @@ -281,6 +281,62 @@ describe.skip("ChatInterface", () => { expect(within(error).getByText("Something went wrong")).toBeInTheDocument(); }); + it("should render both GitHub buttons initially when ghToken is available", () => { + vi.mock("@remix-run/react", async (importActual) => ({ + ...(await importActual()), + useRouteLoaderData: vi.fn(() => ({ ghToken: "test-token" })), + })); + + const messages: Message[] = [ + { + sender: "assistant", + content: "Hello", + imageUrls: [], + timestamp: new Date().toISOString(), + }, + ]; + renderChatInterface(messages); + + const pushButton = screen.getByRole("button", { name: "Push to Branch" }); + const prButton = screen.getByRole("button", { name: "Push & Create PR" }); + + expect(pushButton).toBeInTheDocument(); + expect(prButton).toBeInTheDocument(); + expect(pushButton).toHaveTextContent("Push to Branch"); + expect(prButton).toHaveTextContent("Push & Create PR"); + }); + + it("should render only 'Push changes to PR' button after PR is created", async () => { + vi.mock("@remix-run/react", async (importActual) => ({ + ...(await importActual()), + useRouteLoaderData: vi.fn(() => ({ ghToken: "test-token" })), + })); + + const messages: Message[] = [ + { + sender: "assistant", + content: "Hello", + imageUrls: [], + timestamp: new Date().toISOString(), + }, + ]; + const { rerender } = renderChatInterface(messages); + const user = userEvent.setup(); + + // Click the "Push & Create PR" button + const prButton = screen.getByRole("button", { name: "Push & Create PR" }); + await user.click(prButton); + + // Re-render to trigger state update + rerender(); + + // Verify only one button is shown + const pushToPrButton = screen.getByRole("button", { name: "Push changes to PR" }); + expect(pushToPrButton).toBeInTheDocument(); + expect(screen.queryByRole("button", { name: "Push to Branch" })).not.toBeInTheDocument(); + expect(screen.queryByRole("button", { name: "Push & Create PR" })).not.toBeInTheDocument(); + }); + it("should render feedback actions if there are more than 3 messages", () => { const messages: Message[] = [ { diff --git a/frontend/public/config.json b/frontend/public/config.json index 94900dcbaf..7dbb7e1d96 100644 --- a/frontend/public/config.json +++ b/frontend/public/config.json @@ -2,4 +2,4 @@ "APP_MODE": "oss", "GITHUB_CLIENT_ID": "", "POSTHOG_CLIENT_KEY": "phc_3ESMmY9SgqEAGBB6sMGK5ayYHkeUuknH2vP6FmWH9RA" -} \ No newline at end of file +} diff --git a/frontend/src/components/chat-interface.tsx b/frontend/src/components/chat-interface.tsx index 0cad013e7c..5e2a7d161e 100644 --- a/frontend/src/components/chat-interface.tsx +++ b/frontend/src/components/chat-interface.tsx @@ -52,6 +52,7 @@ export function ChatInterface() { const [feedbackModalIsOpen, setFeedbackModalIsOpen] = React.useState(false); const [messageToSend, setMessageToSend] = React.useState(null); const [isDownloading, setIsDownloading] = React.useState(false); + const [hasPullRequest, setHasPullRequest] = React.useState(false); React.useEffect(() => { if (status === WsClientProviderStatus.ACTIVE) { @@ -175,16 +176,44 @@ export function ChatInterface() { curAgentState === AgentState.FINISHED) && (
{gitHubToken ? ( - { - handleSendMessage(value, []); - }} - /> +
+ {!hasPullRequest ? ( + <> + { + handleSendMessage(value, []); + }} + /> + { + handleSendMessage(value, []); + setHasPullRequest(true); + }} + /> + + ) : ( + { + handleSendMessage(value, []); + }} + /> + )} +
) : ( +