import { describe, it, expect, vi } from "vitest";
import { render, screen } from "@testing-library/react";
import { FluentProvider, webLightTheme } from "@fluentui/react-components";
import { TopCountriesBarChart } from "../TopCountriesBarChart";
vi.mock("recharts", () => ({
ResponsiveContainer: ({ children }: { children: React.ReactNode }) => (
{children}
),
BarChart: ({ children }: { children: React.ReactNode }) => (
{children}
),
Bar: () => null,
CartesianGrid: () => null,
XAxis: () => null,
YAxis: () => null,
Tooltip: () => null,
Cell: () => null,
}));
function wrap(ui: React.ReactElement) {
return render(
{ui},
);
}
describe("TopCountriesBarChart", () => {
it("shows empty state when countries is empty", () => {
wrap();
expect(screen.getByText("No bans in this time range.")).toBeInTheDocument();
expect(screen.queryByTestId("bar-chart")).not.toBeInTheDocument();
});
it("renders bar chart when country data is provided", () => {
wrap(
,
);
expect(screen.getByTestId("bar-chart")).toBeInTheDocument();
});
it("does not render more than 20 bars (TOP_N limit)", () => {
// Build 30 countries — only top 20 should appear in the chart
const countries: Record = {};
const countryNames: Record = {};
for (let i = 0; i < 30; i++) {
const code = `C${String(i).padStart(2, "0")}`;
countries[code] = 30 - i;
countryNames[code] = `Country ${String(i)}`;
}
wrap();
// Chart should render (not show empty state) with data present
expect(screen.getByTestId("bar-chart")).toBeInTheDocument();
});
});