From 8a2675814c565d2c5f13974632fc08b3c72bf8b3 Mon Sep 17 00:00:00 2001
From: amanape <83104063+amanape@users.noreply.github.com>
Date: Mon, 13 Jan 2025 21:27:19 +0200
Subject: [PATCH 1/3] Fetch settings if user is authenticated
---
frontend/src/hooks/query/use-settings.ts | 5 +++++
1 file changed, 5 insertions(+)
diff --git a/frontend/src/hooks/query/use-settings.ts b/frontend/src/hooks/query/use-settings.ts
index 3daa8c8780b7..f0275ae96789 100644
--- a/frontend/src/hooks/query/use-settings.ts
+++ b/frontend/src/hooks/query/use-settings.ts
@@ -4,6 +4,8 @@ import posthog from "posthog-js";
import { AxiosError } from "axios";
import { DEFAULT_SETTINGS, getLocalStorageSettings } from "#/services/settings";
import OpenHands from "#/api/open-hands";
+import { useAuth } from "#/context/auth-context";
+import { useIsAuthed } from "./use-is-authed";
const getSettingsQueryFn = async () => {
try {
@@ -36,9 +38,12 @@ const getSettingsQueryFn = async () => {
};
export const useSettings = () => {
+ const { data: isAuthed } = useIsAuthed();
+
const query = useQuery({
queryKey: ["settings"],
queryFn: getSettingsQueryFn,
+ enabled: !!isAuthed,
});
React.useEffect(() => {
From 3a10986eeac9197473f4d25924ddfdc749cd5265 Mon Sep 17 00:00:00 2001
From: amanape <83104063+amanape@users.noreply.github.com>
Date: Mon, 13 Jan 2025 21:27:56 +0200
Subject: [PATCH 2/3] Remove unused import
---
frontend/src/hooks/query/use-settings.ts | 1 -
1 file changed, 1 deletion(-)
diff --git a/frontend/src/hooks/query/use-settings.ts b/frontend/src/hooks/query/use-settings.ts
index f0275ae96789..ddf53be7444e 100644
--- a/frontend/src/hooks/query/use-settings.ts
+++ b/frontend/src/hooks/query/use-settings.ts
@@ -4,7 +4,6 @@ import posthog from "posthog-js";
import { AxiosError } from "axios";
import { DEFAULT_SETTINGS, getLocalStorageSettings } from "#/services/settings";
import OpenHands from "#/api/open-hands";
-import { useAuth } from "#/context/auth-context";
import { useIsAuthed } from "./use-is-authed";
const getSettingsQueryFn = async () => {
From 07be4416fea0e2ee722de0da96087f7c799f346a Mon Sep 17 00:00:00 2001
From: amanape <83104063+amanape@users.noreply.github.com>
Date: Mon, 13 Jan 2025 21:35:01 +0200
Subject: [PATCH 3/3] Update tests
---
.../features/sidebar/sidebar.test.tsx | 22 ++++++++++++-------
1 file changed, 14 insertions(+), 8 deletions(-)
diff --git a/frontend/__tests__/components/features/sidebar/sidebar.test.tsx b/frontend/__tests__/components/features/sidebar/sidebar.test.tsx
index 3b7a2a275ecc..ebbd30bdbef3 100644
--- a/frontend/__tests__/components/features/sidebar/sidebar.test.tsx
+++ b/frontend/__tests__/components/features/sidebar/sidebar.test.tsx
@@ -1,4 +1,4 @@
-import { screen, within } from "@testing-library/react";
+import { screen, waitFor, within } from "@testing-library/react";
import userEvent from "@testing-library/user-event";
import { afterEach, describe, expect, it, vi } from "vitest";
import { renderWithProviders } from "test-utils";
@@ -8,7 +8,7 @@ import { MULTI_CONVERSATION_UI } from "#/utils/feature-flags";
import OpenHands from "#/api/open-hands";
import { MOCK_USER_PREFERENCES } from "#/mocks/handlers";
-const renderSidebar = () => {
+describe("Sidebar", () => {
const RouterStub = createRoutesStub([
{
path: "/conversation/:conversationId",
@@ -16,10 +16,9 @@ const renderSidebar = () => {
},
]);
- renderWithProviders();
-};
+ const renderSidebar = () =>
+ renderWithProviders();
-describe("Sidebar", () => {
it.skipIf(!MULTI_CONVERSATION_UI)(
"should have the conversation panel open by default",
() => {
@@ -54,9 +53,16 @@ describe("Sidebar", () => {
vi.clearAllMocks();
});
- it("should fetch settings data on mount", () => {
- renderSidebar();
- expect(getSettingsSpy).toHaveBeenCalledOnce();
+ it("should fetch settings data on mount and if the user is authenticated", async () => {
+ const authenticateSpy = vi.spyOn(OpenHands, "authenticate");
+
+ const { rerender } = renderSidebar();
+ expect(getSettingsSpy).not.toHaveBeenCalled();
+
+ authenticateSpy.mockResolvedValueOnce(true);
+ rerender();
+
+ await waitFor(() => expect(getSettingsSpy).toHaveBeenCalledOnce());
});
it("should send all settings data when saving AI configuration", async () => {