Skip to content

AutoGPT is the vision of accessible AI for everyone, to use and to build on. Our mission is to provide the tools, so that you can focus on what matters.

fix(frontend/copilot): remove stale 'Reset daily limit' flash, always show 'Go to billing' (#13011)

Abhimanyu Yadavaef47e1f4f66
diff --git a/autogpt_platform/frontend/src/app/(platform)/copilot/components/UsageLimits/UsageLimitReachedCard.tsx b/autogpt_platform/frontend/src/app/(platform)/copilot/components/UsageLimits/UsageLimitReachedCard.tsx
index ad0c0fe9e8..5670cccff5 100644
--- a/autogpt_platform/frontend/src/app/(platform)/copilot/components/UsageLimits/UsageLimitReachedCard.tsx
+++ b/autogpt_platform/frontend/src/app/(platform)/copilot/components/UsageLimits/UsageLimitReachedCard.tsx
@@ -4,8 +4,6 @@ import type { CoPilotUsagePublic } from "@/app/api/__generated__/models/coPilotU
import { useGetV2GetCopilotUsage } from "@/app/api/__generated__/endpoints/chat/chat";
import { Badge } from "@/components/atoms/Badge/Badge";
import { Text } from "@/components/atoms/Text/Text";
-import useCredits from "@/hooks/useCredits";
-import { Flag, useGetFlag } from "@/services/feature-flags/use-get-flag";
import { Warning } from "@phosphor-icons/react";
import Link from "next/link";
import { UsagePanelContent } from "./UsagePanelContent";
@@ -29,12 +27,6 @@ export function UsageLimitReachedCard() {
const { data: usage, isSuccess } =
useGetV2GetCopilotUsage(USAGE_QUERY_CONFIG);
- const isBillingEnabled = useGetFlag(Flag.ENABLE_PLATFORM_PAYMENT);
- const { credits, fetchCredits } = useCredits({ fetchInitialCredits: true });
- const resetCost = usage?.reset_cost;
- const hasInsufficientCredits =
- credits !== null && resetCost != null && credits < resetCost;
-
if (!isSuccess || !usage) return null;
const isDailyExhausted = !!usage.daily && usage.daily.percent_used >= 100;
const isWeeklyExhausted = !!usage.weekly && usage.weekly.percent_used >= 100;
@@ -79,9 +71,6 @@ export function UsageLimitReachedCard() {
usage={usage}
showHeader={false}
showBillingLink={false}
- hasInsufficientCredits={hasInsufficientCredits}
- isBillingEnabled={isBillingEnabled}
- onCreditChange={fetchCredits}
size="md"
/>
</div>
diff --git a/autogpt_platform/frontend/src/app/(platform)/copilot/components/UsageLimits/UsageLimits.tsx b/autogpt_platform/frontend/src/app/(platform)/copilot/components/UsageLimits/UsageLimits.tsx
index 711c36c26e..4eb13ac548 100644
--- a/autogpt_platform/frontend/src/app/(platform)/copilot/components/UsageLimits/UsageLimits.tsx
+++ b/autogpt_platform/frontend/src/app/(platform)/copilot/components/UsageLimits/UsageLimits.tsx
@@ -1,7 +1,5 @@
import type { CoPilotUsagePublic } from "@/app/api/__generated__/models/coPilotUsagePublic";
import { useGetV2GetCopilotUsage } from "@/app/api/__generated__/endpoints/chat/chat";
-import useCredits from "@/hooks/useCredits";
-import { Flag, useGetFlag } from "@/services/feature-flags/use-get-flag";
import {
Popover,
PopoverContent,
@@ -22,12 +20,6 @@ export function UsageLimits() {
},
});
- const isBillingEnabled = useGetFlag(Flag.ENABLE_PLATFORM_PAYMENT);
- const { credits, fetchCredits } = useCredits({ fetchInitialCredits: true });
- const resetCost = usage?.reset_cost;
- const hasInsufficientCredits =
- credits !== null && resetCost != null && credits < resetCost;
-
if (!isSuccess || !usage) return null;
if (!usage.daily && !usage.weekly) return null;
@@ -39,12 +31,7 @@ export function UsageLimits() {
</Button>
</PopoverTrigger>
<PopoverContent align="start" className="w-64 p-3">
- <UsagePanelContent
- usage={usage}
- hasInsufficientCredits={hasInsufficientCredits}
- isBillingEnabled={isBillingEnabled}
- onCreditChange={fetchCredits}
- />
+ <UsagePanelContent usage={usage} />
</PopoverContent>
</Popover>
);
diff --git a/autogpt_platform/frontend/src/app/(platform)/copilot/components/UsageLimits/UsagePanelContent.tsx b/autogpt_platform/frontend/src/app/(platform)/copilot/components/UsageLimits/UsagePanelContent.tsx
index 91756377ef..86fb536e75 100644
--- a/autogpt_platform/frontend/src/app/(platform)/copilot/components/UsageLimits/UsagePanelContent.tsx
+++ b/autogpt_platform/frontend/src/app/(platform)/copilot/components/UsageLimits/UsagePanelContent.tsx
@@ -3,8 +3,8 @@ import { Button } from "@/components/atoms/Button/Button";
import { Text } from "@/components/atoms/Text/Text";
import { cn } from "@/lib/utils";
import Link from "next/link";
-import { formatCents, formatResetTime } from "../usageHelpers";
-import { useResetRateLimit } from "../../hooks/useResetRateLimit";
+import { Flag, useGetFlag } from "@/services/feature-flags/use-get-flag";
+import { formatResetTime } from "../usageHelpers";
import { useWorkspaceStorage } from "./useWorkspaceStorage";
export { formatResetTime };
@@ -130,30 +130,6 @@ function StorageBar({
);
}
-function ResetButton({
- cost,
- onCreditChange,
-}: {
- cost: number;
- onCreditChange?: () => void;
-}) {
- const { resetUsage, isPending } = useResetRateLimit({ onCreditChange });
-
- return (
- <Button
- variant="primary"
- size="small"
- onClick={() => resetUsage()}
- loading={isPending}
- className="mt-1 w-full"
- >
- {isPending
- ? "Resetting..."
- : `Reset daily limit for ${formatCents(cost)}`}
- </Button>
- );
-}
-
function WorkspaceStorageSection() {
const { data: storage } = useWorkspaceStorage();
if (!storage || storage.limit_bytes <= 0) return null;
@@ -171,24 +147,17 @@ export function UsagePanelContent({
usage,
showHeader = true,
showBillingLink = true,
- hasInsufficientCredits = false,
- isBillingEnabled = false,
- onCreditChange,
size = "sm",
}: {
usage: CoPilotUsagePublic;
showHeader?: boolean;
showBillingLink?: boolean;
- hasInsufficientCredits?: boolean;
- isBillingEnabled?: boolean;
- onCreditChange?: () => void;
size?: Size;
}) {
+ const isBillingEnabled = useGetFlag(Flag.ENABLE_PLATFORM_PAYMENT);
const daily = usage.daily;
const weekly = usage.weekly;
const isDailyExhausted = !!daily && daily.percent_used >= 100;
- const isWeeklyExhausted = !!weekly && weekly.percent_used >= 100;
- const resetCost = usage.reset_cost ?? 0;
if (!daily && !weekly) {
return (
@@ -240,27 +209,18 @@ export function UsagePanelContent({
/>
)}
<WorkspaceStorageSection />
- {isDailyExhausted &&
- !isWeeklyExhausted &&
- resetCost > 0 &&
- !hasInsufficientCredits && (
- <ResetButton cost={resetCost} onCreditChange={onCreditChange} />
- )}
- {isDailyExhausted &&
- !isWeeklyExhausted &&
- hasInsufficientCredits &&
- isBillingEnabled && (
- <Button
- as="NextLink"
- href="/settings/billing"
- variant="primary"
- size="small"
- className="mt-1 w-full"
- >
- Go to billing
- </Button>
- )}
- {showBillingLink && (
+ {isDailyExhausted && isBillingEnabled && showBillingLink && (
+ <Button
+ as="NextLink"
+ href="/settings/billing"
+ variant="primary"
+ size="small"
+ className="mt-1 w-full"
+ >
+ Go to billing
+ </Button>
+ )}
+ {showBillingLink && !(isDailyExhausted && isBillingEnabled) && (
<Link href="/settings/billing" className="hover:underline">
<Text as="span" variant="small" className="text-blue-600">
Learn more about usage limits
diff --git a/autogpt_platform/frontend/src/app/(platform)/copilot/components/UsageLimits/__tests__/UsagePanelContentRender.test.tsx b/autogpt_platform/frontend/src/app/(platform)/copilot/components/UsageLimits/__tests__/UsagePanelContentRender.test.tsx
index bbb3c9f766..a1e13acc9d 100644
--- a/autogpt_platform/frontend/src/app/(platform)/copilot/components/UsageLimits/__tests__/UsagePanelContentRender.test.tsx
+++ b/autogpt_platform/frontend/src/app/(platform)/copilot/components/UsageLimits/__tests__/UsagePanelContentRender.test.tsx
@@ -1,32 +1,32 @@
-import {
- render,
- screen,
- cleanup,
- fireEvent,
-} from "@/tests/integrations/test-utils";
+import { render, screen } from "@/tests/integrations/test-utils";
import { afterEach, beforeEach, describe, expect, it, vi } from "vitest";
import { UsagePanelContent, formatBytes } from "../UsagePanelContent";
import type { CoPilotUsagePublic } from "@/app/api/__generated__/models/coPilotUsagePublic";
-const mockResetUsage = vi.fn();
-vi.mock("../../../hooks/useResetRateLimit", () => ({
- useResetRateLimit: () => ({ resetUsage: mockResetUsage, isPending: false }),
-}));
-
const mockStorageData = vi.fn();
vi.mock("../useWorkspaceStorage", () => ({
useWorkspaceStorage: () => mockStorageData(),
}));
+const mockUseGetFlag = vi.fn();
+vi.mock("@/services/feature-flags/use-get-flag", async () => {
+ const actual = await vi.importActual<
+ typeof import("@/services/feature-flags/use-get-flag")
+ >("@/services/feature-flags/use-get-flag");
+ return {
+ ...actual,
+ useGetFlag: (flag: unknown) => mockUseGetFlag(flag),
+ };
+});
+
afterEach(() => {
- cleanup();
- mockResetUsage.mockReset();
mockStorageData.mockReset();
+ mockUseGetFlag.mockReset();
});
-// Default: no storage data (most existing tests don't need it)
beforeEach(() => {
mockStorageData.mockReturnValue({ data: undefined });
+ mockUseGetFlag.mockReturnValue(true);
});
function makeUsage(
@@ -34,15 +34,9 @@ function makeUsage(
dailyPercent: number | null;
weeklyPercent: number | null;
tier: string;
- resetCost: number;
}> = {},
): CoPilotUsagePublic {
- const {
- dailyPercent = 5,
- weeklyPercent = 4,
- tier = "BASIC",
- resetCost = 100,
- } = overrides;
+ const { dailyPercent = 5, weeklyPercent = 4, tier = "BASIC" } = overrides;
const future = new Date(Date.now() + 3600 * 1000).toISOString();
return {
daily:
@@ -54,7 +48,6 @@ function makeUsage(
? null
: { percent_used: weeklyPercent, resets_at: future },
tier,
- reset_cost: resetCost,
} as CoPilotUsagePublic;
}
@@ -107,44 +100,57 @@ describe("UsagePanelContent", () => {
expect(screen.getByText("File storage")).toBeDefined();
});
- it("renders the reset button when daily limit is exhausted", () => {
+ it("never renders the legacy 'Reset daily limit' button", () => {
+ render(<UsagePanelContent usage={makeUsage({ dailyPercent: 100 })} />);
+ expect(screen.queryByText(/Reset daily limit/)).toBeNull();
+ });
+
+ it("renders 'Go to billing' when daily is exhausted and billing is enabled", () => {
+ mockUseGetFlag.mockReturnValue(true);
render(
<UsagePanelContent
- usage={makeUsage({ dailyPercent: 100, resetCost: 50 })}
+ usage={makeUsage({ dailyPercent: 100, weeklyPercent: 40 })}
/>,
);
- expect(screen.getByText(/Reset daily limit/)).toBeDefined();
+ expect(screen.getByText("Go to billing")).toBeDefined();
});
- it("does not render the reset button when weekly limit is also exhausted", () => {
+ it("hides the 'Learn more about usage limits' link when 'Go to billing' button is shown", () => {
+ mockUseGetFlag.mockReturnValue(true);
render(
<UsagePanelContent
- usage={makeUsage({
- dailyPercent: 100,
- weeklyPercent: 100,
- resetCost: 50,
- })}
+ usage={makeUsage({ dailyPercent: 100, weeklyPercent: 40 })}
/>,
);
- expect(screen.queryByText(/Reset daily limit/)).toBeNull();
+ expect(screen.getByText("Go to billing")).toBeDefined();
+ expect(screen.queryByText("Learn more about usage limits")).toBeNull();
+ });
+
+ it("does not render 'Go to billing' when showBillingLink is false", () => {
+ mockUseGetFlag.mockReturnValue(true);
+ render(
+ <UsagePanelContent
+ usage={makeUsage({ dailyPercent: 100, weeklyPercent: 40 })}
+ showBillingLink={false}
+ />,
+ );
+ expect(screen.queryByText("Go to billing")).toBeNull();
});
- it("calls resetUsage when the reset button is clicked", () => {
+ it("does not render 'Go to billing' when billing flag is disabled", () => {
+ mockUseGetFlag.mockReturnValue(false);
render(
<UsagePanelContent
- usage={makeUsage({ dailyPercent: 100, resetCost: 50 })}
+ usage={makeUsage({ dailyPercent: 100, weeklyPercent: 40 })}
/>,
);
- fireEvent.click(screen.getByText(/Reset daily limit/));
- expect(mockResetUsage).toHaveBeenCalled();
+ expect(screen.queryByText("Go to billing")).toBeNull();
});
- it("renders 'Go to billing' link when insufficient credits", () => {
+ it("still renders 'Go to billing' when both daily and weekly are exhausted", () => {
render(
<UsagePanelContent
- usage={makeUsage({ dailyPercent: 100, resetCost: 50 })}
- hasInsufficientCredits={true}
- isBillingEnabled={true}
+ usage={makeUsage({ dailyPercent: 100, weeklyPercent: 100 })}
/>,
);
expect(screen.getByText("Go to billing")).toBeDefined();
diff --git a/autogpt_platform/frontend/src/app/(platform)/copilot/hooks/useResetRateLimit.ts b/autogpt_platform/frontend/src/app/(platform)/copilot/hooks/useResetRateLimit.ts
deleted file mode 100644
index d8bf93d437..0000000000
--- a/autogpt_platform/frontend/src/app/(platform)/copilot/hooks/useResetRateLimit.ts
+++ /dev/null
@@ -1,57 +0,0 @@
-import {
- usePostV2ResetCopilotUsage,
- getGetV2GetCopilotUsageQueryKey,
-} from "@/app/api/__generated__/endpoints/chat/chat";
-import { toast } from "@/components/molecules/Toast/use-toast";
-import { ApiError } from "@/lib/autogpt-server-api";
-import { useQueryClient } from "@tanstack/react-query";
-import { useRef } from "react";
-
-export function useResetRateLimit(options?: {
- onSuccess?: () => void;
- onCreditChange?: () => void;
-}) {
- // Use refs so mutation callbacks always see the latest options,
- // avoiding stale-closure issues when the caller re-renders with
- // different callback references.
- const onSuccessRef = useRef(options?.onSuccess);
- onSuccessRef.current = options?.onSuccess;
- const onCreditChangeRef = useRef(options?.onCreditChange);
- onCreditChangeRef.current = options?.onCreditChange;
-
- const queryClient = useQueryClient();
- const { mutate: resetUsage, isPending } = usePostV2ResetCopilotUsage({
- mutation: {
- onSuccess: async () => {
- // Await the usage refetch so the UI shows updated limits before
- // closing the dialog or re-enabling the reset CTA.
- // invalidateQueries already triggers a refetch for active queries.
- await queryClient.invalidateQueries({
- queryKey: getGetV2GetCopilotUsageQueryKey(),
- });
- onCreditChangeRef.current?.();
- toast({
- title: "Rate limit reset",
- description:
- "Your daily usage limit has been reset. You can continue working.",
- });
- onSuccessRef.current?.();
- },
- onError: (error: unknown) => {
- const message =
- error instanceof ApiError
- ? (error.response?.detail ?? error.message)
- : error instanceof Error
- ? error.message
- : "Failed to reset limit.";
- toast({
- title: "Reset failed",
- description: message,
- variant: "destructive",
- });
- },
- },
- });
-
- return { resetUsage, isPending };
-}
diff --git a/autogpt_platform/frontend/src/app/(platform)/library/components/AgentBriefingPanel/BriefingTabContent.tsx b/autogpt_platform/frontend/src/app/(platform)/library/components/AgentBriefingPanel/BriefingTabContent.tsx
index f8fc8c05ee..f7fd7b043a 100644
--- a/autogpt_platform/frontend/src/app/(platform)/library/components/AgentBriefingPanel/BriefingTabContent.tsx
+++ b/autogpt_platform/frontend/src/app/(platform)/library/components/AgentBriefingPanel/BriefingTabContent.tsx
@@ -3,14 +3,9 @@
import type { CoPilotUsagePublic } from "@/app/api/__generated__/models/coPilotUsagePublic";
import type { LibraryAgent } from "@/app/api/__generated__/models/libraryAgent";
import { useGetV2GetCopilotUsage } from "@/app/api/__generated__/endpoints/chat/chat";
-import {
- formatResetTime,
- formatCents,
-} from "@/app/(platform)/copilot/components/usageHelpers";
-import { useResetRateLimit } from "@/app/(platform)/copilot/hooks/useResetRateLimit";
+import { formatResetTime } from "@/app/(platform)/copilot/components/usageHelpers";
import { Button } from "@/components/atoms/Button/Button";
import { Badge } from "@/components/atoms/Badge/Badge";
-import useCredits from "@/hooks/useCredits";
import { Flag, useGetFlag } from "@/services/feature-flags/use-get-flag";
import { useSitrepItems } from "../SitrepItem/useSitrepItems";
import { SitrepItem } from "../SitrepItem/SitrepItem";
@@ -51,14 +46,13 @@ function UsageSection() {
});
const isBillingEnabled = useGetFlag(Flag.ENABLE_PLATFORM_PAYMENT);
- const { credits, fetchCredits } = useCredits({ fetchInitialCredits: true });
- const resetCost = usage?.reset_cost;
- const hasInsufficientCredits =
- credits !== null && resetCost != null && credits < resetCost;
if (!isSuccess || !usage) return null;
if (!usage.daily && !usage.weekly) return null;
+ const isDailyExhausted = !!usage.daily && usage.daily.percent_used >= 100;
+ const showGoToBilling = isDailyExhausted && isBillingEnabled;
+
return (
<div className="py-2">
<div className="flex items-center gap-2">
@@ -71,7 +65,7 @@ function UsageSection() {
</Badge>
)}
<div className="flex-1" />
- {isBillingEnabled && (
+ {isBillingEnabled && !showGoToBilling && (
<Link
href="/settings/billing"
className="text-sm text-blue-600 hover:underline"
@@ -96,11 +90,18 @@ function UsageSection() {
/>
)}
</div>
- <UsageFooter
- usage={usage}
- hasInsufficientCredits={hasInsufficientCredits}
- onCreditChange={fetchCredits}
- />
+ {showGoToBilling && (
+ <div className="mt-4 flex items-center gap-3">
+ <Button
+ as="NextLink"
+ href="/settings/billing"
+ variant="primary"
+ size="small"
+ >
+ Go to billing
+ </Button>
+ </div>
+ )}
</div>
);
}
@@ -238,57 +239,6 @@ function AgentListSection({
);
}
-function UsageFooter({
- usage,
- hasInsufficientCredits,
- onCreditChange,
-}: {
- usage: CoPilotUsagePublic;
- hasInsufficientCredits: boolean;
- onCreditChange?: () => void;
-}) {
- const isDailyExhausted = !!usage.daily && usage.daily.percent_used >= 100;
- const isWeeklyExhausted = !!usage.weekly && usage.weekly.percent_used >= 100;
- const resetCost = usage.reset_cost ?? 0;
- const { resetUsage, isPending } = useResetRateLimit({ onCreditChange });
-
- const showReset =
- isDailyExhausted &&
- !isWeeklyExhausted &&
- resetCost > 0 &&
- !hasInsufficientCredits;
-
- const showAddCredits =
- isDailyExhausted && !isWeeklyExhausted && hasInsufficientCredits;
-
- if (!showReset && !showAddCredits) return null;
-
- return (
- <div className="mt-4 flex items-center gap-3">
- {showReset && (
- <Button
- variant="primary"
- size="small"
- onClick={() => resetUsage()}
- loading={isPending}
- >
- {isPending
- ? "Resetting..."
- : `Reset daily limit for ${formatCents(resetCost)}`}
- </Button>
- )}
- {showAddCredits && (
- <Link
- href="/settings/billing"
- className="inline-flex items-center justify-center rounded-md bg-primary px-3 py-1.5 text-sm font-medium text-primary-foreground hover:bg-primary/90"
- >
- Add credits to reset
- </Link>
- )}
- </div>
- );
-}
-
function UsageMeter({
label,
percentUsed,
diff --git a/autogpt_platform/frontend/src/app/(platform)/library/components/AgentBriefingPanel/__tests__/BriefingTabContent.test.tsx b/autogpt_platform/frontend/src/app/(platform)/library/components/AgentBriefingPanel/__tests__/BriefingTabContent.test.tsx
index f85cc3b22f..1893630daa 100644
--- a/autogpt_platform/frontend/src/app/(platform)/library/components/AgentBriefingPanel/__tests__/BriefingTabContent.test.tsx
+++ b/autogpt_platform/frontend/src/app/(platform)/library/components/AgentBriefingPanel/__tests__/BriefingTabContent.test.tsx
@@ -1,4 +1,4 @@
-import { render, screen, cleanup } from "@/tests/integrations/test-utils";
+import { render, screen } from "@/tests/integrations/test-utils";
import { afterEach, describe, expect, it, vi } from "vitest";
import { BriefingTabContent } from "../BriefingTabContent";
@@ -8,7 +8,6 @@ vi.mock("@/app/api/__generated__/endpoints/chat/chat", () => ({
query?: { select?: (r: { data: unknown }) => unknown };
}) => {
const ret = mockUseGetV2GetCopilotUsage(opts) as { data?: unknown };
- // Exercise the `select` callback so its line counts as covered.
if (ret?.data !== undefined && typeof opts?.query?.select === "function") {
opts.query.select({ data: ret.data });
}
@@ -27,37 +26,19 @@ vi.mock("@/services/feature-flags/use-get-flag", async () => {
};
});
-const mockUseCredits = vi.fn();
-vi.mock("@/hooks/useCredits", () => ({
- default: (opts: unknown) => mockUseCredits(opts),
-}));
-
-const mockResetUsage = vi.fn();
-vi.mock("@/app/(platform)/copilot/hooks/useResetRateLimit", () => ({
- useResetRateLimit: () => ({
- resetUsage: mockResetUsage,
- isPending: false,
- }),
-}));
-
afterEach(() => {
- cleanup();
mockUseGetV2GetCopilotUsage.mockReset();
mockUseGetFlag.mockReset();
- mockUseCredits.mockReset();
- mockResetUsage.mockReset();
});
function makeUsage({
dailyPercent = 5,
weeklyPercent = 4,
tier = "BASIC",
- resetCost = 500,
}: {
dailyPercent?: number | null;
weeklyPercent?: number | null;
tier?: string;
- resetCost?: number;
} = {}) {
const future = new Date(Date.now() + 3600 * 1000).toISOString();
return {
@@ -70,7 +51,6 @@ function makeUsage({
? null
: { percent_used: weeklyPercent, resets_at: future },
tier,
- reset_cost: resetCost,
};
}
@@ -81,7 +61,6 @@ describe("BriefingTabContent — UsageSection", () => {
isSuccess: false,
});
mockUseGetFlag.mockReturnValue(false);
- mockUseCredits.mockReturnValue({ credits: 1000, fetchCredits: vi.fn() });
const { container } = render(
<BriefingTabContent activeTab="all" agents={[]} />,
);
@@ -94,7 +73,6 @@ describe("BriefingTabContent — UsageSection", () => {
isSuccess: true,
});
mockUseGetFlag.mockReturnValue(false);
- mockUseCredits.mockReturnValue({ credits: 1000, fetchCredits: vi.fn() });
const { container } = render(
<BriefingTabContent activeTab="all" agents={[]} />,
);
@@ -107,7 +85,6 @@ describe("BriefingTabContent — UsageSection", () => {
isSuccess: true,
});
mockUseGetFlag.mockReturnValue(true);
- mockUseCredits.mockReturnValue({ credits: 1000, fetchCredits: vi.fn() });
render(<BriefingTabContent activeTab="all" agents={[]} />);
expect(screen.getByText("Usage limits")).toBeDefined();
@@ -119,46 +96,57 @@ describe("BriefingTabContent — UsageSection", () => {
expect(screen.getByText("Manage billing")).toBeDefined();
});
- it("shows reset button when daily limit is exhausted and user has credits", () => {
+ it("never renders the legacy 'Reset daily limit' button when daily is exhausted", () => {
mockUseGetV2GetCopilotUsage.mockReturnValue({
- data: makeUsage({ dailyPercent: 100, weeklyPercent: 40, resetCost: 500 }),
+ data: makeUsage({ dailyPercent: 100, weeklyPercent: 40 }),
isSuccess: true,
});
mockUseGetFlag.mockReturnValue(true);
- mockUseCredits.mockReturnValue({ credits: 1000, fetchCredits: vi.fn() });
render(<BriefingTabContent activeTab="all" agents={[]} />);
+ expect(screen.queryByText(/Reset daily limit/)).toBeNull();
+ });
- expect(screen.getByText(/Reset daily limit/)).toBeDefined();
+ it("shows 'Go to billing' when daily is exhausted and billing flag is on", () => {
+ mockUseGetV2GetCopilotUsage.mockReturnValue({
+ data: makeUsage({ dailyPercent: 100, weeklyPercent: 40 }),
+ isSuccess: true,
+ });
+ mockUseGetFlag.mockReturnValue(true);
+ render(<BriefingTabContent activeTab="all" agents={[]} />);
+ expect(screen.getByText("Go to billing")).toBeDefined();
});
- it("shows 'Add credits' CTA when daily exhausted but user lacks credits", () => {
+ it("hides 'Manage billing' link when 'Go to billing' button is shown", () => {
mockUseGetV2GetCopilotUsage.mockReturnValue({
- data: makeUsage({ dailyPercent: 100, weeklyPercent: 40, resetCost: 500 }),
+ data: makeUsage({ dailyPercent: 100, weeklyPercent: 40 }),
isSuccess: true,
});
mockUseGetFlag.mockReturnValue(true);
- mockUseCredits.mockReturnValue({ credits: 10, fetchCredits: vi.fn() });
render(<BriefingTabContent activeTab="all" agents={[]} />);
+ expect(screen.getByText("Go to billing")).toBeDefined();
+ expect(screen.queryByText("Manage billing")).toBeNull();
+ });
- expect(screen.getByText("Add credits to reset")).toBeDefined();
- expect(screen.queryByText(/Reset daily limit/)).toBeNull();
+ it("hides 'Go to billing' when billing flag is off", () => {
+ mockUseGetV2GetCopilotUsage.mockReturnValue({
+ data: makeUsage({ dailyPercent: 100, weeklyPercent: 40 }),
+ isSuccess: true,
+ });
+ mockUseGetFlag.mockReturnValue(false);
+ render(<BriefingTabContent activeTab="all" agents={[]} />);
+ expect(screen.queryByText("Go to billing")).toBeNull();
+ expect(screen.queryByText("Manage billing")).toBeNull();
});
- it("hides reset CTAs when the weekly limit is also exhausted", () => {
+ it("still shows 'Go to billing' when both daily and weekly are exhausted", () => {
mockUseGetV2GetCopilotUsage.mockReturnValue({
- data: makeUsage({
- dailyPercent: 100,
- weeklyPercent: 100,
- resetCost: 500,
- }),
+ data: makeUsage({ dailyPercent: 100, weeklyPercent: 100 }),
isSuccess: true,
});
mockUseGetFlag.mockReturnValue(true);
- mockUseCredits.mockReturnValue({ credits: 1000, fetchCredits: vi.fn() });
render(<BriefingTabContent activeTab="all" agents={[]} />);
-
+ expect(screen.getByText("Go to billing")).toBeDefined();
expect(screen.queryByText(/Reset daily limit/)).toBeNull();
- expect(screen.queryByText("Add credits to reset")).toBeNull();
});
it("renders <1% used when percent is >0 but rounds to 0", () => {
@@ -167,9 +155,7 @@ describe("BriefingTabContent — UsageSection", () => {
isSuccess: true,
});
mockUseGetFlag.mockReturnValue(false);
- mockUseCredits.mockReturnValue({ credits: 1000, fetchCredits: vi.fn() });
render(<BriefingTabContent activeTab="all" agents={[]} />);
-
expect(screen.getByText("<1% used")).toBeDefined();
});
@@ -179,13 +165,11 @@ describe("BriefingTabContent — UsageSection", () => {
isSuccess: false,
});
mockUseGetFlag.mockReturnValue(false);
- mockUseCredits.mockReturnValue({ credits: 1000, fetchCredits: vi.fn() });
for (const tab of ["running", "attention", "completed"] as const) {
const { unmount } = render(
<BriefingTabContent activeTab={tab} agents={[]} />,
);
- // Empty list -> EmptyMessage renders for each of the execution tabs.
expect(
screen.getByText(/No agents|No recently completed/i),
).toBeDefined();
@@ -199,7 +183,6 @@ describe("BriefingTabContent — UsageSection", () => {
isSuccess: false,
});
mockUseGetFlag.mockReturnValue(false);
- mockUseCredits.mockReturnValue({ credits: 1000, fetchCredits: vi.fn() });
for (const tab of ["listening", "scheduled", "idle"] as const) {
const { unmount } = render(