test(ui): assert Usage page passes organizations from useOrganizations

Covers org list and undefined -> [] for UsagePageView props; addresses Greptile P2 on #26778.

Made-with: Cursor
This commit is contained in:
Milan 2026-04-29 16:27:38 +03:00
parent 7313fad9e4
commit 4356daf1f2
No known key found for this signature in database

View file

@ -0,0 +1,65 @@
import { describe, it, expect, vi, beforeEach } from "vitest";
import { renderWithProviders } from "../../../../tests/test-utils";
import UsagePage from "./page";
import UsagePageView from "@/components/UsagePage/components/UsagePageView";
import { useOrganizations } from "@/app/(dashboard)/hooks/organizations/useOrganizations";
const { mockUseOrganizations, mockUseAuthorized, mockUseTeams } = vi.hoisted(() => ({
mockUseOrganizations: vi.fn(),
mockUseAuthorized: vi.fn(),
mockUseTeams: vi.fn(),
}));
vi.mock("@/app/(dashboard)/hooks/organizations/useOrganizations", () => ({
useOrganizations: mockUseOrganizations,
}));
vi.mock("@/app/(dashboard)/hooks/useAuthorized", () => ({
default: mockUseAuthorized,
}));
vi.mock("@/app/(dashboard)/hooks/useTeams", () => ({
default: mockUseTeams,
}));
vi.mock("@/components/UsagePage/components/UsagePageView", () => ({
default: vi.fn(() => <div data-testid="usage-page-view-stub" />),
}));
describe("Usage dashboard page", () => {
beforeEach(() => {
vi.clearAllMocks();
mockUseAuthorized.mockReturnValue({
accessToken: "token",
userRole: "org_admin",
userId: "user-1",
premiumUser: false,
});
mockUseTeams.mockReturnValue({ teams: [{ team_id: "team-1" }] });
mockUseOrganizations.mockReturnValue({ data: undefined, isLoading: false });
});
it("calls useOrganizations and passes fetched organizations to UsagePageView", () => {
const organizations = [{ organization_id: "org-1", organization_alias: "Acme" }];
mockUseOrganizations.mockReturnValue({ data: organizations, isLoading: false });
renderWithProviders(<UsagePage />);
expect(useOrganizations).toHaveBeenCalled();
expect(vi.mocked(UsagePageView).mock.calls[0][0]).toEqual({
teams: [{ team_id: "team-1" }],
organizations,
});
});
it("passes empty organizations array when useOrganizations returns no data", () => {
mockUseOrganizations.mockReturnValue({ data: undefined, isLoading: false });
renderWithProviders(<UsagePage />);
expect(vi.mocked(UsagePageView).mock.calls[0][0]).toEqual({
teams: [{ team_id: "team-1" }],
organizations: [],
});
});
});