The fastest, litest AI Gateway. Rust core with Python SDK. Call 100+ LLM APIs in OpenAI (or native) format with cost tracking, guardrails, load balancing, and logging [Bedrock, Azure, OpenAI, Anthropic, OpenAI, VertexAI, vLLM, Nvidia NIM]
Python ai-gatewayanthropicazure-openaibedrockgatewaylangchainlitellmllmllm-gatewayllmopsmcp-gatewayopenaiopenai-proxyrustrust-aivertex-ai
test(ui): update organization_view tests for useOrganization hook
Ryan Crabbe18afe6ab6401
diff --git a/ui/litellm-dashboard/src/components/organization/organization_view.test.tsx b/ui/litellm-dashboard/src/components/organization/organization_view.test.tsxindex a54c7e1fbaa..8325bea0fce 100644--- a/ui/litellm-dashboard/src/components/organization/organization_view.test.tsx+++ b/ui/litellm-dashboard/src/components/organization/organization_view.test.tsx@@ -1,14 +1,15 @@import React from "react";-import { render, screen, waitFor } from "@testing-library/react";+import { screen, waitFor } from "@testing-library/react";import userEvent from "@testing-library/user-event";-import { vi, test, expect } from "vitest";+import { vi, test, expect, beforeEach } from "vitest";+import { renderWithProviders } from "../../../tests/test-utils";import OrganizationInfoView from "./organization_view";+import { useOrganization } from "@/app/(dashboard)/hooks/organizations/useOrganizations";-// Mock networking calls used by the component+// Mock networking calls used by the component's mutation handlersvi.mock("../networking", () => {return {__esModule: true,- organizationInfoCall: vi.fn(),organizationMemberAddCall: vi.fn(),organizationMemberUpdateCall: vi.fn(),organizationMemberDeleteCall: vi.fn(),@@ -16,6 +17,20 @@ vi.mock("../networking", () => {};});+// Mock the React Query hook the component now reads org data from. The component+// also imports organizationKeys (used inside mutation handlers for invalidation),+// so provide a stub shape here too.+vi.mock("@/app/(dashboard)/hooks/organizations/useOrganizations", () => ({+ useOrganization: vi.fn(),+ organizationKeys: {+ all: ["organizations"],+ list: () => ["organizations", "list", { params: {} }],+ detail: (id: string) => ["organizations", "detail", id],+ },+}));++const mockUseOrganization = vi.mocked(useOrganization);+// Mock noisy/heavy child components to keep this test focused on rendervi.mock("../object_permissions_view", () => ({__esModule: true,@@ -81,11 +96,14 @@ const mockOrg = {metadata: null,};+beforeEach(() => {+ mockUseOrganization.mockReset();+});+test("renders organization view after loading data", async () => {- const { organizationInfoCall } = await import("../networking");- (organizationInfoCall as unknown as ReturnType<typeof vi.fn>).mockResolvedValueOnce(mockOrg);+ mockUseOrganization.mockReturnValue({ data: mockOrg, isLoading: false } as any);- const { findAllByText } = render(+ const { findAllByText } = renderWithProviders(<OrganizationInfoVieworganizationId="org_123"onClose={() => {}}@@ -103,11 +121,10 @@ test("renders organization view after loading data", async () => {});test("should display empty state when organization has no members", async () => {- const { organizationInfoCall } = await import("../networking");- (organizationInfoCall as unknown as ReturnType<typeof vi.fn>).mockResolvedValueOnce(mockOrg);+ mockUseOrganization.mockReturnValue({ data: mockOrg, isLoading: false } as any);const user = userEvent.setup();- render(+ renderWithProviders(<OrganizationInfoVieworganizationId="org_123"onClose={() => {}}@@ -131,14 +148,13 @@ test("should display empty state when organization has no members", async () =>});test("should display team aliases when teams are available", async () => {- const { organizationInfoCall } = await import("../networking");const orgWithTeams = {...mockOrg,teams: [{ team_id: "team_123" }, { team_id: "team_456" }],};- (organizationInfoCall as unknown as ReturnType<typeof vi.fn>).mockResolvedValueOnce(orgWithTeams);+ mockUseOrganization.mockReturnValue({ data: orgWithTeams, isLoading: false } as any);- render(+ renderWithProviders(<OrganizationInfoVieworganizationId="org_123"onClose={() => {}}@@ -157,7 +173,6 @@ test("should display team aliases when teams are available", async () => {});test("should display team ID as fallback when alias is not found", async () => {- const { organizationInfoCall } = await import("../networking");mockUseTeams.mockReturnValueOnce({data: [{@@ -171,9 +186,9 @@ test("should display team ID as fallback when alias is not found", async () => {...mockOrg,teams: [{ team_id: "team_999" }],};- (organizationInfoCall as unknown as ReturnType<typeof vi.fn>).mockResolvedValueOnce(orgWithUnknownTeam);+ mockUseOrganization.mockReturnValue({ data: orgWithUnknownTeam, isLoading: false } as any);- render(+ renderWithProviders(<OrganizationInfoVieworganizationId="org_123"onClose={() => {}}