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.

test(frontend/copilot): cover the spend card's $0 chat ceiling (#14962)

Reinier van der Leer47a0eccd73d7
diff --git a/autogpt_platform/frontend/src/app/(platform)/copilot/components/ApprovalQueue/__tests__/fixtures.ts b/autogpt_platform/frontend/src/app/(platform)/copilot/components/ApprovalQueue/__tests__/fixtures.ts
index b23e94fe97..1a260d4ff7 100644
--- a/autogpt_platform/frontend/src/app/(platform)/copilot/components/ApprovalQueue/__tests__/fixtures.ts
+++ b/autogpt_platform/frontend/src/app/(platform)/copilot/components/ApprovalQueue/__tests__/fixtures.ts
@@ -1,5 +1,6 @@
import { http, HttpResponse } from "msw";
import type { PendingHumanReviewModel } from "@/app/api/__generated__/models/pendingHumanReviewModel";
+import type { ApprovalSpend } from "../helpers";
import referenceCardsJson from "./referenceCards.json";
import realCardsJson from "./realCards.json";
@@ -292,7 +293,11 @@ export function realCardSchemaHandler(cards: RealCard[]) {
});
}
// A paid read over the task's spend ceiling; money in microdollars.
-export function spendCard(id = "spend", chatRules: string[] = []) {
+export function spendCard(
+ id = "spend",
+ chatRules: string[] = [],
+ spend: Partial<ApprovalSpend> = {},
+) {
return heldReview({
id,
tool: "run_capability",
@@ -317,6 +322,7 @@ export function spendCard(id = "spend", chatRules: string[] = []) {
spent: 2_410_000,
ceiling: 2_000_000,
unit: 1_000_000,
+ ...spend,
},
},
});
diff --git a/autogpt_platform/frontend/src/app/(platform)/copilot/components/ApprovalQueue/__tests__/spendCard.test.tsx b/autogpt_platform/frontend/src/app/(platform)/copilot/components/ApprovalQueue/__tests__/spendCard.test.tsx
index 15422d1db6..147b83567d 100644
--- a/autogpt_platform/frontend/src/app/(platform)/copilot/components/ApprovalQueue/__tests__/spendCard.test.tsx
+++ b/autogpt_platform/frontend/src/app/(platform)/copilot/components/ApprovalQueue/__tests__/spendCard.test.tsx
@@ -40,6 +40,17 @@ test("a spend card shows this step's cost, the chat's spend against its ceiling,
expect(screen.queryByText(/costs about/)).toBeNull();
});
+test("a chat with a $0 ceiling shows a full bar, not an empty one", async () => {
+ renderQueue([spendCard("zero", [], { spent: 0, ceiling: 0 })]);
+
+ expect(await screen.findByText("$0.00 of $0.00")).toBeDefined();
+ expect(
+ screen
+ .getByRole("progressbar", { name: "Spent of this chat's ceiling" })
+ .getAttribute("aria-valuenow"),
+ ).toBe("100");
+});
+
test("a spend card offers no rule even when one is listed, and is never approved as a set", async () => {
renderQueue([spendCard("a", ["allow", "judge"]), spendCard("b")]);