Skip to content

πŸ™Œ OpenHands: AI-Driven Development

fix(frontend): Failing tests (#10369)

sp.wacka6a4246e303d
diff --git a/frontend/__tests__/routes/settings-with-payment.test.tsx b/frontend/__tests__/routes/settings-with-payment.test.tsx
index 2f7ad6a31c..08a6020aed 100644
--- a/frontend/__tests__/routes/settings-with-payment.test.tsx
+++ b/frontend/__tests__/routes/settings-with-payment.test.tsx
@@ -1,6 +1,6 @@
import { screen, within } from "@testing-library/react";
import userEvent from "@testing-library/user-event";
-import { afterEach, describe, expect, it, vi } from "vitest";
+import { afterEach, beforeEach, describe, expect, it, vi } from "vitest";
import { createRoutesStub } from "react-router";
import { renderWithProviders } from "test-utils";
import OpenHands from "#/api/open-hands";
@@ -36,6 +36,8 @@ vi.mock("react-i18next", async () => {
"SETTINGS$NAV_API_KEYS": "API Keys",
"SETTINGS$NAV_LLM": "LLM",
"SETTINGS$NAV_USER": "User",
+ "SETTINGS$NAV_SECRETS": "Secrets",
+ "SETTINGS$NAV_MCP": "MCP",
"SETTINGS$TITLE": "Settings"
};
return translations[key] || key;
@@ -47,8 +49,33 @@ vi.mock("react-i18next", async () => {
};
});
+// Mock useConfig hook
+const { mockUseConfig } = vi.hoisted(() => ({
+ mockUseConfig: vi.fn(),
+}));
+vi.mock("#/hooks/query/use-config", () => ({
+ useConfig: mockUseConfig,
+}));
+
describe("Settings Billing", () => {
- const getConfigSpy = vi.spyOn(OpenHands, "getConfig");
+ beforeEach(() => {
+ // Set default config to OSS mode
+ mockUseConfig.mockReturnValue({
+ data: {
+ APP_MODE: "oss",
+ GITHUB_CLIENT_ID: "123",
+ POSTHOG_CLIENT_KEY: "456",
+ FEATURE_FLAGS: {
+ ENABLE_BILLING: false,
+ HIDE_LLM_SETTINGS: false,
+ ENABLE_JIRA: false,
+ ENABLE_JIRA_DC: false,
+ ENABLE_LINEAR: false,
+ },
+ },
+ isLoading: false,
+ });
+ });
const RoutesStub = createRoutesStub([
{
@@ -79,19 +106,7 @@ describe("Settings Billing", () => {
});
it("should not render the credits tab if OSS mode", async () => {
- getConfigSpy.mockResolvedValue({
- APP_MODE: "oss",
- GITHUB_CLIENT_ID: "123",
- POSTHOG_CLIENT_KEY: "456",
- FEATURE_FLAGS: {
- ENABLE_BILLING: false,
- HIDE_LLM_SETTINGS: false,
- ENABLE_JIRA: false,
- ENABLE_JIRA_DC: false,
- ENABLE_LINEAR: false,
- },
- });
-
+ // OSS mode is set by default in beforeEach
renderSettingsScreen();
const navbar = await screen.findByTestId("settings-navbar");
@@ -100,17 +115,20 @@ describe("Settings Billing", () => {
});
it("should render the credits tab if SaaS mode and billing is enabled", async () => {
- getConfigSpy.mockResolvedValue({
- APP_MODE: "saas",
- GITHUB_CLIENT_ID: "123",
- POSTHOG_CLIENT_KEY: "456",
- FEATURE_FLAGS: {
- ENABLE_BILLING: true,
- HIDE_LLM_SETTINGS: false,
- ENABLE_JIRA: false,
- ENABLE_JIRA_DC: false,
- ENABLE_LINEAR: false,
+ mockUseConfig.mockReturnValue({
+ data: {
+ APP_MODE: "saas",
+ GITHUB_CLIENT_ID: "123",
+ POSTHOG_CLIENT_KEY: "456",
+ FEATURE_FLAGS: {
+ ENABLE_BILLING: true,
+ HIDE_LLM_SETTINGS: false,
+ ENABLE_JIRA: false,
+ ENABLE_JIRA_DC: false,
+ ENABLE_LINEAR: false,
+ },
},
+ isLoading: false,
});
renderSettingsScreen();
@@ -121,17 +139,20 @@ describe("Settings Billing", () => {
it("should render the billing settings if clicking the credits item", async () => {
const user = userEvent.setup();
- getConfigSpy.mockResolvedValue({
- APP_MODE: "saas",
- GITHUB_CLIENT_ID: "123",
- POSTHOG_CLIENT_KEY: "456",
- FEATURE_FLAGS: {
- ENABLE_BILLING: true,
- HIDE_LLM_SETTINGS: false,
- ENABLE_JIRA: false,
- ENABLE_JIRA_DC: false,
- ENABLE_LINEAR: false,
+ mockUseConfig.mockReturnValue({
+ data: {
+ APP_MODE: "saas",
+ GITHUB_CLIENT_ID: "123",
+ POSTHOG_CLIENT_KEY: "456",
+ FEATURE_FLAGS: {
+ ENABLE_BILLING: true,
+ HIDE_LLM_SETTINGS: false,
+ ENABLE_JIRA: false,
+ ENABLE_JIRA_DC: false,
+ ENABLE_LINEAR: false,
+ },
},
+ isLoading: false,
});
renderSettingsScreen();
diff --git a/frontend/__tests__/routes/settings.test.tsx b/frontend/__tests__/routes/settings.test.tsx
index ccb7d8a8b4..7a24728016 100644
--- a/frontend/__tests__/routes/settings.test.tsx
+++ b/frontend/__tests__/routes/settings.test.tsx
@@ -19,6 +19,9 @@ vi.mock("react-i18next", async () => {
SETTINGS$NAV_CREDITS: "Credits",
SETTINGS$NAV_API_KEYS: "API Keys",
SETTINGS$NAV_LLM: "LLM",
+ SETTINGS$NAV_SECRETS: "Secrets",
+ SETTINGS$NAV_MCP: "MCP",
+ SETTINGS$NAV_USER: "User",
SETTINGS$TITLE: "Settings",
};
return translations[key] || key;
@@ -119,22 +122,21 @@ describe("Settings Screen", () => {
});
it("should render the saas navbar", async () => {
- const getConfigSpy = vi.spyOn(OpenHands, "getConfig");
- // @ts-expect-error - only return app mode
- getConfigSpy.mockResolvedValue({
- APP_MODE: "saas",
- });
+ const saasConfig = { APP_MODE: "saas" };
+
+ // Clear any existing query data and set the config
+ mockQueryClient.clear();
+ mockQueryClient.setQueryData(["config"], saasConfig);
+
const sectionsToInclude = [
+ "user",
"integrations",
"application",
"credits", // The nav item shows "credits" text but routes to /billing
"secrets",
"api keys",
];
- const sectionsToExclude = ["llm"];
-
- // Clear any existing query data
- mockQueryClient.clear();
+ const sectionsToExclude = ["llm", "mcp"];
renderSettingsScreen();
@@ -151,8 +153,6 @@ describe("Settings Screen", () => {
});
expect(sectionElement).not.toBeInTheDocument();
});
-
- getConfigSpy.mockRestore();
});
it("should not be able to access saas-only routes in oss mode", async () => {
diff --git a/frontend/src/mocks/handlers.ts b/frontend/src/mocks/handlers.ts
index 7b685c8007..f815bdf26b 100644
--- a/frontend/src/mocks/handlers.ts
+++ b/frontend/src/mocks/handlers.ts
@@ -25,7 +25,7 @@ export const MOCK_DEFAULT_USER_SETTINGS: ApiSettings | PostApiSettings = {
security_analyzer: DEFAULT_SETTINGS.SECURITY_ANALYZER,
remote_runtime_resource_factor:
DEFAULT_SETTINGS.REMOTE_RUNTIME_RESOURCE_FACTOR,
- provider_tokens_set: { github: null, gitlab: null, bitbucket: null },
+ provider_tokens_set: {},
enable_default_condenser: DEFAULT_SETTINGS.ENABLE_DEFAULT_CONDENSER,
enable_sound_notifications: DEFAULT_SETTINGS.ENABLE_SOUND_NOTIFICATIONS,
enable_proactive_conversation_starters: