Download src/hooks/query/use-plugins.test.tsx from SaylorTwift/openhands: direct link, hf CLI and curl.
- Browser
- Download file 1.62 kB
-
https://huggingface.co/SaylorTwift/openhands/resolve/main/src/hooks/query/use-plugins.test.tsx
- Command line
-
hf download hf://SaylorTwift/openhands/src/hooks/query/use-plugins.test.tsx
-
curl -L -o use-plugins.test.tsx https://huggingface.co/SaylorTwift/openhands/resolve/main/src/hooks/query/use-plugins.test.tsx
1.62 kB
| import { QueryClient, QueryClientProvider } from "@tanstack/react-query"; | |
| import { renderHook, waitFor } from "@testing-library/react"; | |
| import type { ReactNode } from "react"; | |
| import { describe, expect, it, vi } from "vitest"; | |
| import PluginsManagementService from "#/api/plugins-management-service"; | |
| import { ActiveBackendProvider } from "#/contexts/active-backend-context"; | |
| import { usePlugins } from "./use-plugins"; | |
| import { PLUGINS_QUERY_KEYS } from "./query-keys"; | |
| function renderUsePlugins() { | |
| const queryClient = new QueryClient({ | |
| defaultOptions: { queries: { retry: false } }, | |
| }); | |
| const wrapper = ({ children }: { children: ReactNode }) => ( | |
| <QueryClientProvider client={queryClient}> | |
| <ActiveBackendProvider>{children}</ActiveBackendProvider> | |
| </QueryClientProvider> | |
| ); | |
| return { queryClient, ...renderHook(() => usePlugins(), { wrapper }) }; | |
| } | |
| describe("usePlugins", () => { | |
| it("scopes its cache entry to the active backend", async () => { | |
| vi.spyOn( | |
| PluginsManagementService, | |
| "listInstalledPlugins", | |
| ).mockResolvedValue([]); | |
| const { queryClient, result } = renderUsePlugins(); | |
| await waitFor(() => expect(result.current.isSuccess).toBe(true)); | |
| const [key] = queryClient | |
| .getQueryCache() | |
| .getAll() | |
| .map((query) => query.queryKey); | |
| // Unscoped, a second backend reads this same entry and shows the first | |
| // backend's plugins. | |
| expect(key.slice(0, PLUGINS_QUERY_KEYS.installed.length)).toEqual([ | |
| ...PLUGINS_QUERY_KEYS.installed, | |
| ]); | |
| expect(key.length).toBe(PLUGINS_QUERY_KEYS.installed.length + 2); | |
| }); | |
| }); | |