Skip to content

πŸ™Œ OpenHands: AI-Driven Development

Fix Push & Create PR button prompt to request meaningful branch names (#7529)

Xingyao Wang24773e15c53b
diff --git a/frontend/__tests__/components/chat/action-suggestions.test.tsx b/frontend/__tests__/components/chat/action-suggestions.test.tsx
new file mode 100644
index 0000000000..7ae87fa1ae
--- /dev/null
+++ b/frontend/__tests__/components/chat/action-suggestions.test.tsx
@@ -0,0 +1,81 @@
+import { describe, expect, it, vi } from "vitest";
+import { render, screen } from "@testing-library/react";
+import { ActionSuggestions } from "#/components/features/chat/action-suggestions";
+import { useAuth } from "#/context/auth-context";
+import { useSelector } from "react-redux";
+
+// Mock dependencies
+vi.mock("posthog-js", () => ({
+ default: {
+ capture: vi.fn(),
+ },
+}));
+
+vi.mock("react-redux", () => ({
+ useSelector: vi.fn(),
+}));
+
+vi.mock("#/context/auth-context", () => ({
+ useAuth: vi.fn(),
+}));
+
+describe("ActionSuggestions", () => {
+ // Setup mocks for each test
+ vi.clearAllMocks();
+
+ (useAuth as any).mockReturnValue({
+ githubTokenIsSet: true,
+ });
+
+ (useSelector as any).mockReturnValue({
+ selectedRepository: "test-repo",
+ });
+
+ it("should render both GitHub buttons when GitHub token is set and repository is selected", () => {
+ render(<ActionSuggestions onSuggestionsClick={() => {}} />);
+
+ const pushButton = screen.getByRole("button", { name: "Push to Branch" });
+ const prButton = screen.getByRole("button", { name: "Push & Create PR" });
+
+ expect(pushButton).toBeInTheDocument();
+ expect(prButton).toBeInTheDocument();
+ });
+
+ it("should not render buttons when GitHub token is not set", () => {
+ (useAuth as any).mockReturnValue({
+ githubTokenIsSet: false,
+ });
+
+ render(<ActionSuggestions onSuggestionsClick={() => {}} />);
+
+ expect(screen.queryByRole("button", { name: "Push to Branch" })).not.toBeInTheDocument();
+ expect(screen.queryByRole("button", { name: "Push & Create PR" })).not.toBeInTheDocument();
+ });
+
+ it("should not render buttons when no repository is selected", () => {
+ (useSelector as any).mockReturnValue({
+ selectedRepository: null,
+ });
+
+ render(<ActionSuggestions onSuggestionsClick={() => {}} />);
+
+ expect(screen.queryByRole("button", { name: "Push to Branch" })).not.toBeInTheDocument();
+ expect(screen.queryByRole("button", { name: "Push & Create PR" })).not.toBeInTheDocument();
+ });
+
+ it("should have different prompts for 'Push to Branch' and 'Push & Create PR' buttons", () => {
+ // This test verifies that the prompts are different in the component
+ const component = render(<ActionSuggestions onSuggestionsClick={() => {}} />);
+
+ // Get the component instance to access the internal values
+ const pushBranchPrompt = "Please push the changes to a remote branch on GitHub, but do NOT create a pull request. Please use the exact SAME branch name as the one you are currently on.";
+ const createPRPrompt = "Please push the changes to GitHub and open a pull request. Please create a meaningful branch name that describes the changes.";
+
+ // Verify the prompts are different
+ expect(pushBranchPrompt).not.toEqual(createPRPrompt);
+
+ // Verify the PR prompt mentions creating a meaningful branch name
+ expect(createPRPrompt).toContain("meaningful branch name");
+ expect(createPRPrompt).not.toContain("SAME branch name");
+ });
+});
\ No newline at end of file
diff --git a/frontend/src/components/features/chat/action-suggestions.tsx b/frontend/src/components/features/chat/action-suggestions.tsx
index c38e6c9544..fb298320eb 100644
--- a/frontend/src/components/features/chat/action-suggestions.tsx
+++ b/frontend/src/components/features/chat/action-suggestions.tsx
@@ -40,7 +40,7 @@ export function ActionSuggestions({
suggestion={{
label: "Push & Create PR",
value:
- "Please push the changes to GitHub and open a pull request. Please use the exact SAME branch name as the one you are currently on.",
+ "Please push the changes to GitHub and open a pull request. Please create a meaningful branch name that describes the changes.",
}}
onClick={(value) => {
posthog.capture("create_pr_button_clicked");