Skip to content

Never stop coding. Free MIT AI gateway: one endpoint, 375 providers (150+ free), 1,400+ models Kimi, Claude, GPT, Gemini, GLM, DeepSeek, MiniMax. Works with Claude Code, Codex, Cursor, OpenCode, Cline & Copilot. Quota-aware auto-fallback, RTK+Caveman compression saves 15-95% tokens, MCP/A2A, Desktop/PWA. Built by 900+ contributors

1.5 KB
Raw Blame
import React from "react";
import { renderToStaticMarkup } from "react-dom/server";
import { describe, expect, it, vi } from "vitest";

vi.mock("next-intl", () => ({
  useLocale: () => "en",
  useTranslations: () => (key: string) => key,
}));

import QuotaCardExpanded from "../../../src/app/(dashboard)/dashboard/usage/components/ProviderLimits/parts/QuotaCardExpanded";

const credits = { hasCredits: true, unlimited: false, overageLimitReached: false, balance: null };

function renderCredits(paidCredits = credits) {
  return renderToStaticMarkup(
    <QuotaCardExpanded
      providerId="codex"
      quotas={[{ name: "session", used: 100, total: 100, remainingPercentage: 0 }]}
      paidCredits={paidCredits}
      loading={false}
      error={null}
      hasStaleData={false}
      canEditCutoff={true}
      hasCutoffOverrides={false}
      onRefresh={() => {}}
      onOpenCutoff={() => {}}
      onOpenCost={() => {}}
    />
  );
}

describe("Codex paid credit display", () => {
  it("shows availability separately from an exhausted subscription without inventing a balance", () => {
    const html = renderCredits();
    expect(html).toContain("codexPaidCreditsLabel");
    expect(html).toContain("codexPaidCreditsAvailable");
    expect(html).toContain("0%");
  });

  it("shows the spending limit instead of claiming credits remain usable", () => {
    const html = renderCredits({ ...credits, overageLimitReached: true });
    expect(html).toContain("codexPaidCreditsUnavailable");
    expect(html).not.toContain("codexPaidCreditsAvailable");
  });
});