import { render, screen } from "@testing-library/react";
import { describe, expect, it, vi } from "vitest";
import { AdminActivityPanel } from "./AdminActivityPanel";

vi.mock("@modules/auth", () => ({
  useIsSuperuser: () => true
}));

vi.mock("@tanstack/react-query", () => ({
  useQuery: ({ queryKey }: { queryKey: string[] }) => {
    if (queryKey[0] === "admin-activity-feed") {
      return {
        isLoading: false,
        data: { events: [{ action: "admin.user.patch", timestamp: "2026-07-14T10:00:00Z" }] }
      };
    }
    return { data: { lines: ["line-1"] } };
  }
}));

vi.mock("../api/adminApi", () => ({
  getAdminActivityFeed: vi.fn(),
  getAdminServerLog: vi.fn()
}));

describe("AdminActivityPanel", () => {
  it("renders feed and server log for superuser", () => {
    render(<AdminActivityPanel />);
    expect(screen.getByRole("heading", { name: "Activity" })).toBeInTheDocument();
    expect(screen.getByText("admin.user.patch")).toBeInTheDocument();
    expect(screen.getByText("line-1")).toBeInTheDocument();
  });
});
