import { describe, it, expect, vi, beforeEach } from "vitest";
import { render, screen, fireEvent } from "@testing-library/react";
import { AccountSection } from "../AccountSection";
vi.mock("react-router", () => ({
Link: ({ children, to }: { children: React.ReactNode; to: string }) => (
{children}
),
}));
const mockLinkSocial = vi.fn();
vi.mock("~/lib/auth-client", () => ({
authClient: {
linkSocial: (...args: unknown[]) => mockLinkSocial(...args),
},
}));
describe("AccountSection", () => {
beforeEach(() => {
vi.clearAllMocks();
mockLinkSocial.mockResolvedValue({});
});
it("shows Connect Discord button when Discord is not linked", () => {
render(
);
expect(screen.getByRole("button", { name: /connect discord/i })).toBeInTheDocument();
});
it("does not show Connect Discord button when Discord is already linked", () => {
render(
);
expect(screen.queryByRole("button", { name: /connect discord/i })).not.toBeInTheDocument();
});
it("calls authClient.linkSocial with discord provider on button click", () => {
render(
);
fireEvent.click(screen.getByRole("button", { name: /connect discord/i }));
expect(mockLinkSocial).toHaveBeenCalledWith({
provider: "discord",
callbackURL: "/settings?section=account",
});
});
});