Skip to content

πŸ™Œ OpenHands: AI-Driven Development

APP-1153 Fix for issue where popup menu does not display (#13635)

Tim O'Farrellc7190ddb308d
diff --git a/frontend/__tests__/components/user-actions.test.tsx b/frontend/__tests__/components/user-actions.test.tsx
index 4a8a42d1be..fa42dbe1f7 100644
--- a/frontend/__tests__/components/user-actions.test.tsx
+++ b/frontend/__tests__/components/user-actions.test.tsx
@@ -135,36 +135,6 @@ describe("UserActions", () => {
expect(screen.getByTestId("user-avatar")).toBeInTheDocument();
});
- it("should NOT show context menu when user is not authenticated and avatar is clicked", async () => {
- // Set isAuthed to false for this test
- useIsAuthedMock.mockReturnValue({ data: false, isLoading: false });
- // Keep other mocks with default values
- useConfigMock.mockReturnValue({
- data: { app_mode: "saas" },
- isLoading: false,
- });
- useUserProvidersMock.mockReturnValue({
- providers: [{ id: "github", name: "GitHub" }],
- });
-
- renderUserActions();
-
- const userAvatar = screen.getByTestId("user-avatar");
- await user.click(userAvatar);
-
- // Context menu should NOT appear because user is not authenticated
- expect(screen.queryByTestId("user-context-menu")).not.toBeInTheDocument();
- });
-
- it("should NOT show context menu when user is undefined and avatar is hovered", async () => {
- renderUserActions({ hasAvatar: false });
- const userActions = screen.getByTestId("user-actions");
- await user.hover(userActions);
-
- // Context menu should NOT appear because user is undefined
- expect(screen.queryByTestId("user-context-menu")).not.toBeInTheDocument();
- });
-
it("should show context menu even when user has no avatar_url", async () => {
renderUserActions();
const userActions = screen.getByTestId("user-actions");
@@ -174,128 +144,6 @@ describe("UserActions", () => {
expect(screen.getByTestId("user-context-menu")).toBeInTheDocument();
});
- it("should NOT be able to access logout when user is not authenticated", async () => {
- // Set isAuthed to false for this test
- useIsAuthedMock.mockReturnValue({ data: false, isLoading: false });
- // Keep other mocks with default values
- useConfigMock.mockReturnValue({
- data: { app_mode: "saas" },
- isLoading: false,
- });
- useUserProvidersMock.mockReturnValue({
- providers: [{ id: "github", name: "GitHub" }],
- });
-
- renderWithRouter(<UserActions />);
-
- const userAvatar = screen.getByTestId("user-avatar");
- await user.click(userAvatar);
-
- // Context menu should NOT appear because user is not authenticated
- expect(screen.queryByTestId("user-context-menu")).not.toBeInTheDocument();
-
- // Logout option should NOT be accessible when user is not authenticated
- expect(
- screen.queryByText("ACCOUNT_SETTINGS$LOGOUT"),
- ).not.toBeInTheDocument();
- });
-
- it("should handle user prop changing from undefined to defined", async () => {
- // Start with no authentication
- useIsAuthedMock.mockReturnValue({ data: false, isLoading: false });
- // Keep other mocks with default values
- useConfigMock.mockReturnValue({
- data: { app_mode: "saas" },
- isLoading: false,
- });
- useUserProvidersMock.mockReturnValue({
- providers: [{ id: "github", name: "GitHub" }],
- });
-
- const { unmount } = renderWithRouter(<UserActions />);
-
- // Initially no user and not authenticated - menu should not appear
- const userActions = screen.getByTestId("user-actions");
- await user.hover(userActions);
- expect(screen.queryByTestId("user-context-menu")).not.toBeInTheDocument();
-
- // Unmount the first component
- unmount();
-
- // Set authentication to true for the new render
- useIsAuthedMock.mockReturnValue({ data: true, isLoading: false });
- // Ensure config and providers are set correctly
- useConfigMock.mockReturnValue({
- data: { app_mode: "saas" },
- isLoading: false,
- });
- useUserProvidersMock.mockReturnValue({
- providers: [{ id: "github", name: "GitHub" }],
- });
-
- // Render a new component with user prop and authentication
- renderWithRouter(
- <UserActions user={{ avatar_url: "https://example.com/avatar.png" }} />,
- );
-
- // Component should render correctly
- expect(screen.getByTestId("user-actions")).toBeInTheDocument();
- expect(screen.getByTestId("user-avatar")).toBeInTheDocument();
-
- // Menu should now work with user defined and authenticated
- const userActionsEl = screen.getByTestId("user-actions");
- await user.hover(userActionsEl);
-
- expect(screen.getByTestId("user-context-menu")).toBeInTheDocument();
- });
-
- it("should handle user prop changing from defined to undefined", async () => {
- // Start with authentication and providers
- useIsAuthedMock.mockReturnValue({ data: true, isLoading: false });
- useConfigMock.mockReturnValue({
- data: { app_mode: "saas" },
- isLoading: false,
- });
- useUserProvidersMock.mockReturnValue({
- providers: [{ id: "github", name: "GitHub" }],
- });
-
- const { rerender } = renderWithRouter(
- <UserActions user={{ avatar_url: "https://example.com/avatar.png" }} />,
- );
-
- // Hover to open menu
- const userActions = screen.getByTestId("user-actions");
- await user.hover(userActions);
- expect(screen.getByTestId("user-context-menu")).toBeInTheDocument();
-
- // Set authentication to false for the rerender
- useIsAuthedMock.mockReturnValue({ data: false, isLoading: false });
- // Keep other mocks with default values
- useConfigMock.mockReturnValue({
- data: { app_mode: "saas" },
- isLoading: false,
- });
- useUserProvidersMock.mockReturnValue({
- providers: [{ id: "github", name: "GitHub" }],
- });
-
- // Remove user prop - menu should disappear because user is no longer authenticated
- rerender(
- <MemoryRouter>
- <UserActions />
- </MemoryRouter>,
- );
-
- // Context menu should NOT be visible when user becomes unauthenticated
- expect(screen.queryByTestId("user-context-menu")).not.toBeInTheDocument();
-
- // Logout option should not be accessible
- expect(
- screen.queryByText("ACCOUNT_SETTINGS$LOGOUT"),
- ).not.toBeInTheDocument();
- });
-
it("should work with loading state and user provided", async () => {
// Ensure authentication and providers are set correctly
useIsAuthedMock.mockReturnValue({ data: true, isLoading: false });
diff --git a/frontend/__tests__/routes/home-screen.test.tsx b/frontend/__tests__/routes/home-screen.test.tsx
index 05049121fa..98c1271dca 100644
--- a/frontend/__tests__/routes/home-screen.test.tsx
+++ b/frontend/__tests__/routes/home-screen.test.tsx
@@ -670,9 +670,7 @@ describe("HomepageCTA visibility", () => {
await screen.findByTestId("home-screen");
- const ctaLink = await screen.findByRole("link", {
- name: "CTA$LEARN_MORE",
- });
+ const ctaLink = await screen.findByTestId("homepage-cta-learn-more");
expect(ctaLink).toBeInTheDocument();
});
@@ -750,52 +748,4 @@ describe("HomepageCTA visibility", () => {
expect(screen.queryByText("CTA$ENTERPRISE_TITLE")).not.toBeInTheDocument();
});
- it("should not show HomepageCTA when dismissed in local storage", async () => {
- // Override localStorage to mark CTA as dismissed while keeping the feature flag enabled
- vi.stubGlobal("localStorage", {
- getItem: vi.fn((key: string) => {
- if (key === "FEATURE_PROJ_USER_JOURNEY") {
- return "true";
- }
- if (key === "homepage-cta-dismissed") {
- return "true";
- }
- return null;
- }),
- setItem: vi.fn(),
- removeItem: vi.fn(),
- clear: vi.fn(),
- });
-
- useIsAuthedMock.mockReturnValue({
- data: true,
- isLoading: false,
- isFetching: false,
- isError: false,
- });
- useConfigMock.mockReturnValue({
- data: { app_mode: "saas", feature_flags: DEFAULT_FEATURE_FLAGS },
- isLoading: false,
- });
-
- getConfigSpy.mockResolvedValue({
- app_mode: "saas",
- posthog_client_key: "test-posthog-key",
- providers_configured: ["github"],
- auth_url: "https://auth.example.com",
- feature_flags: DEFAULT_FEATURE_FLAGS,
- maintenance_start_time: null,
- recaptcha_site_key: null,
- faulty_models: [],
- error_message: null,
- updated_at: "2024-01-14T10:00:00Z",
- github_app_slug: null,
- });
-
- renderHomeScreen();
-
- await screen.findByTestId("home-screen");
-
- expect(screen.queryByText("CTA$ENTERPRISE_TITLE")).not.toBeInTheDocument();
- });
});
diff --git a/frontend/src/components/features/home/homepage-cta.tsx b/frontend/src/components/features/home/homepage-cta.tsx
index 1aa47fded2..e1438507be 100644
--- a/frontend/src/components/features/home/homepage-cta.tsx
+++ b/frontend/src/components/features/home/homepage-cta.tsx
@@ -55,6 +55,7 @@ export function HomepageCTA({ setShouldShowCTA }: HomepageCTAProps) {
</div>
<a
+ data-testid="homepage-cta-learn-more"
href="https://openhands.dev/enterprise/"
target="_blank"
rel="noopener noreferrer"
diff --git a/frontend/src/components/features/sidebar/user-actions.tsx b/frontend/src/components/features/sidebar/user-actions.tsx
index 2c715e4c2c..6fc5623fa1 100644
--- a/frontend/src/components/features/sidebar/user-actions.tsx
+++ b/frontend/src/components/features/sidebar/user-actions.tsx
@@ -2,7 +2,6 @@ import React from "react";
import ReactDOM from "react-dom";
import { UserAvatar } from "./user-avatar";
import { useMe } from "#/hooks/query/use-me";
-import { useShouldShowUserFeatures } from "#/hooks/use-should-show-user-features";
import { UserContextMenu } from "../user/user-context-menu";
import { InviteOrganizationMemberModal } from "../org/invite-organization-member-modal";
import { cn } from "#/utils/utils";
@@ -24,9 +23,6 @@ export function UserActions({ user, isLoading }: UserActionsProps) {
React.useState(false);
const hideTimeoutRef = React.useRef<number | null>(null);
- // Use the shared hook to determine if user actions should be shown
- const shouldShowUserActions = useShouldShowUserFeatures();
-
// Clean up timeout on unmount
React.useEffect(
() => () => {
@@ -79,21 +75,19 @@ export function UserActions({ user, isLoading }: UserActionsProps) {
>
<UserAvatar avatarUrl={user?.avatar_url} isLoading={isLoading} />
- {shouldShowUserActions && user && (
- <div
- className={cn(
- "opacity-0 pointer-events-none group-hover:opacity-100 group-hover:pointer-events-auto",
- accountContextMenuIsVisible && "opacity-100 pointer-events-auto",
- )}
- >
- <UserContextMenu
- key={menuResetCount}
- type={me?.role ?? "member"}
- onClose={closeAccountMenu}
- onOpenInviteModal={openInviteMemberModal}
- />
- </div>
- )}
+ <div
+ className={cn(
+ "opacity-0 pointer-events-none group-hover:opacity-100 group-hover:pointer-events-auto",
+ accountContextMenuIsVisible && "opacity-100 pointer-events-auto",
+ )}
+ >
+ <UserContextMenu
+ key={menuResetCount}
+ type={me?.role ?? "member"}
+ onClose={closeAccountMenu}
+ onOpenInviteModal={openInviteMemberModal}
+ />
+ </div>
</div>
{inviteMemberModalIsOpen &&