π OpenHands: AI-Driven Development
Fix: Display logout option even when user is not available (#10077)
Tim O'Farrella0adbd741a49
diff --git a/frontend/__tests__/components/user-actions.test.tsx b/frontend/__tests__/components/user-actions.test.tsxindex 1b6f59c2e8..4009efd738 100644--- a/frontend/__tests__/components/user-actions.test.tsx+++ b/frontend/__tests__/components/user-actions.test.tsx@@ -62,16 +62,16 @@ describe("UserActions", () => {).not.toBeInTheDocument();});- it("should NOT show context menu when user is undefined and avatar is clicked", async () => {+ it("should show context menu when user is undefined and avatar is clicked", async () => {render(<UserActions onLogout={onLogoutMock} />);const userAvatar = screen.getByTestId("user-avatar");await user.click(userAvatar);- // Context menu should NOT appear because user is undefined+ // Context menu SHOULD appear even when user is undefinedexpect(- screen.queryByTestId("account-settings-context-menu"),- ).not.toBeInTheDocument();+ screen.getByTestId("account-settings-context-menu"),+ ).toBeInTheDocument();});it("should show context menu even when user has no avatar_url", async () => {@@ -86,23 +86,35 @@ describe("UserActions", () => {).toBeInTheDocument();});- it("should NOT be able to access logout when no user is provided", async () => {+ it("should be able to access logout even when no user is provided", async () => {render(<UserActions onLogout={onLogoutMock} />);const userAvatar = screen.getByTestId("user-avatar");await user.click(userAvatar);- // Logout option should not be accessible because context menu doesn't appear+ // Logout option should be accessible even when no user is providedexpect(- screen.queryByText("ACCOUNT_SETTINGS$LOGOUT"),- ).not.toBeInTheDocument();- expect(onLogoutMock).not.toHaveBeenCalled();+ screen.getByText("ACCOUNT_SETTINGS$LOGOUT"),+ ).toBeInTheDocument();++ // Verify logout works+ const logoutOption = screen.getByText("ACCOUNT_SETTINGS$LOGOUT");+ await user.click(logoutOption);+ expect(onLogoutMock).toHaveBeenCalledOnce();});- it("should handle user prop changing from undefined to defined", () => {+ it("should handle user prop changing from undefined to defined", async () => {const { rerender } = render(<UserActions onLogout={onLogoutMock} />);- // Initially no user - context menu shouldn't work+ // Initially no user - but we can still click to show the menu+ const userAvatar = screen.getByTestId("user-avatar");+ await user.click(userAvatar);+ expect(+ screen.getByTestId("account-settings-context-menu"),+ ).toBeInTheDocument();++ // Close the menu+ await user.click(userAvatar);expect(screen.queryByTestId("account-settings-context-menu"),).not.toBeInTheDocument();@@ -118,6 +130,12 @@ describe("UserActions", () => {// Component should still render correctlyexpect(screen.getByTestId("user-actions")).toBeInTheDocument();expect(screen.getByTestId("user-avatar")).toBeInTheDocument();++ // Menu should still work with user defined+ await user.click(userAvatar);+ expect(+ screen.getByTestId("account-settings-context-menu"),+ ).toBeInTheDocument();});it("should handle user prop changing from defined to undefined", async () => {@@ -135,12 +153,18 @@ describe("UserActions", () => {screen.getByTestId("account-settings-context-menu"),).toBeInTheDocument();- // Remove user prop - menu should disappear+ // Remove user prop - menu should still be visiblererender(<UserActions onLogout={onLogoutMock} />);+ // Context menu should remain visible even when user becomes undefinedexpect(- screen.queryByTestId("account-settings-context-menu"),- ).not.toBeInTheDocument();+ screen.getByTestId("account-settings-context-menu"),+ ).toBeInTheDocument();++ // Verify logout still works+ const logoutOption = screen.getByText("ACCOUNT_SETTINGS$LOGOUT");+ await user.click(logoutOption);+ expect(onLogoutMock).toHaveBeenCalledOnce();});it("should work with loading state and user provided", async () => {diff --git a/frontend/src/components/features/sidebar/user-actions.tsx b/frontend/src/components/features/sidebar/user-actions.tsxindex edde8845ae..591337e003 100644--- a/frontend/src/components/features/sidebar/user-actions.tsx+++ b/frontend/src/components/features/sidebar/user-actions.tsx@@ -13,6 +13,7 @@ export function UserActions({ onLogout, user, isLoading }: UserActionsProps) {React.useState(false);const toggleAccountMenu = () => {+ // Always toggle the menu, even if user is undefinedsetAccountContextMenuIsVisible((prev) => !prev);};@@ -33,7 +34,7 @@ export function UserActions({ onLogout, user, isLoading }: UserActionsProps) {isLoading={isLoading}/>- {accountContextMenuIsVisible && !!user && (+ {accountContextMenuIsVisible && (<AccountSettingsContextMenuonLogout={handleLogout}onClose={closeAccountMenu}