mirror of
https://github.com/farion1231/cc-switch.git
synced 2026-07-24 12:44:18 +08:00
fix(codex-oauth): scope account quota to auth center
This commit is contained in:
@@ -28,6 +28,8 @@ import CodexOauthAccountQuota from "@/components/CodexOauthAccountQuota";
|
||||
|
||||
interface CodexOAuthSectionProps {
|
||||
className?: string;
|
||||
/** 是否展示每个账号的订阅额度 */
|
||||
showAccountQuota?: boolean;
|
||||
/** 当前选中的 ChatGPT 账号 ID */
|
||||
selectedAccountId?: string | null;
|
||||
/** 账号选择回调 */
|
||||
@@ -46,6 +48,7 @@ interface CodexOAuthSectionProps {
|
||||
*/
|
||||
export const CodexOAuthSection: React.FC<CodexOAuthSectionProps> = ({
|
||||
className,
|
||||
showAccountQuota = false,
|
||||
selectedAccountId,
|
||||
onAccountSelect,
|
||||
fastModeEnabled = false,
|
||||
@@ -222,7 +225,9 @@ export const CodexOAuthSection: React.FC<CodexOAuthSectionProps> = ({
|
||||
</Button>
|
||||
</div>
|
||||
</div>
|
||||
<CodexOauthAccountQuota accountId={account.id} />
|
||||
{showAccountQuota && (
|
||||
<CodexOauthAccountQuota accountId={account.id} />
|
||||
)}
|
||||
</div>
|
||||
))}
|
||||
</div>
|
||||
|
||||
@@ -67,7 +67,7 @@ export function AuthCenterPanel() {
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<CodexOAuthSection />
|
||||
<CodexOAuthSection showAccountQuota />
|
||||
</section>
|
||||
</div>
|
||||
);
|
||||
|
||||
@@ -0,0 +1,70 @@
|
||||
import { render, screen } from "@testing-library/react";
|
||||
import { beforeEach, describe, expect, it, vi } from "vitest";
|
||||
import { CodexOAuthSection } from "@/components/providers/forms/CodexOAuthSection";
|
||||
import { AuthCenterPanel } from "@/components/settings/AuthCenterPanel";
|
||||
|
||||
const mocks = vi.hoisted(() => ({
|
||||
useCodexOauth: vi.fn(),
|
||||
renderAccountQuota: vi.fn(),
|
||||
}));
|
||||
|
||||
vi.mock("@/components/providers/forms/hooks/useCodexOauth", () => ({
|
||||
useCodexOauth: mocks.useCodexOauth,
|
||||
}));
|
||||
|
||||
vi.mock("@/components/CodexOauthAccountQuota", () => ({
|
||||
default: ({ accountId }: { accountId: string }) => {
|
||||
mocks.renderAccountQuota(accountId);
|
||||
return <div data-testid="account-quota">{accountId}</div>;
|
||||
},
|
||||
}));
|
||||
|
||||
vi.mock("@/components/providers/forms/CopilotAuthSection", () => ({
|
||||
CopilotAuthSection: () => <div />,
|
||||
}));
|
||||
|
||||
describe("CodexOAuthSection", () => {
|
||||
beforeEach(() => {
|
||||
mocks.useCodexOauth.mockReturnValue({
|
||||
accounts: [
|
||||
{
|
||||
id: "account-1",
|
||||
provider: "codex_oauth",
|
||||
login: "user@example.com",
|
||||
avatar_url: null,
|
||||
authenticated_at: 0,
|
||||
is_default: true,
|
||||
github_domain: "",
|
||||
},
|
||||
],
|
||||
defaultAccountId: "account-1",
|
||||
hasAnyAccount: true,
|
||||
pollingState: "idle",
|
||||
deviceCode: null,
|
||||
error: null,
|
||||
isPolling: false,
|
||||
isAddingAccount: false,
|
||||
isRemovingAccount: false,
|
||||
isSettingDefaultAccount: false,
|
||||
addAccount: vi.fn(),
|
||||
removeAccount: vi.fn(),
|
||||
setDefaultAccount: vi.fn(),
|
||||
cancelAuth: vi.fn(),
|
||||
logout: vi.fn(),
|
||||
});
|
||||
});
|
||||
|
||||
it("does not render account quota by default", () => {
|
||||
render(<CodexOAuthSection />);
|
||||
|
||||
expect(mocks.renderAccountQuota).not.toHaveBeenCalled();
|
||||
expect(screen.queryByTestId("account-quota")).not.toBeInTheDocument();
|
||||
});
|
||||
|
||||
it("renders account quota in Auth Center", () => {
|
||||
render(<AuthCenterPanel />);
|
||||
|
||||
expect(mocks.renderAccountQuota).toHaveBeenCalledWith("account-1");
|
||||
expect(screen.getByTestId("account-quota")).toHaveTextContent("account-1");
|
||||
});
|
||||
});
|
||||
Reference in New Issue
Block a user