diff --git a/frontend/__tests__/components/chat/chat-interface.test.tsx b/frontend/__tests__/components/chat/chat-interface.test.tsx index 8f0ad30ce874..a5d49bb1c3d4 100644 --- a/frontend/__tests__/components/chat/chat-interface.test.tsx +++ b/frontend/__tests__/components/chat/chat-interface.test.tsx @@ -281,7 +281,7 @@ describe.skip("ChatInterface", () => { expect(within(error).getByText("Something went wrong")).toBeInTheDocument(); }); - it("should render both GitHub buttons when ghToken is available", () => { + 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" })), @@ -297,15 +297,46 @@ describe.skip("ChatInterface", () => { ]; renderChatInterface(messages); - const pushButton = screen.getByRole("button", { name: "Push to GitHub" }); + 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 GitHub"); + 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/src/components/chat-interface.tsx b/frontend/src/components/chat-interface.tsx index 15173a459bc9..7d2835731c15 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) { @@ -176,26 +177,42 @@ export function ChatInterface() {
{gitHubToken ? (
- { - handleSendMessage(value, []); - }} - /> - { - handleSendMessage(value, []); - }} - /> + {!hasPullRequest ? ( + <> + { + handleSendMessage(value, []); + }} + /> + { + handleSendMessage(value, []); + setHasPullRequest(true); + }} + /> + + ) : ( + { + handleSendMessage(value, []); + }} + /> + )}
) : (