import { QueryClient, QueryClientProvider } from "@tanstack/react-query";
import { render, screen } from "@testing-library/react";
import { beforeEach, describe, expect, it } from "vitest";
import { createI18nMock } from "../../test/i18nMock";
import AuthPage from "./AuthPage";

vi.mock("../../lib/i18n", () => createI18nMock());

function renderPage() {
  const queryClient = new QueryClient({
    defaultOptions: {
      queries: { retry: false },
      mutations: { retry: false },
    },
  });

  return render(
    <QueryClientProvider client={queryClient}>
      <AuthPage />
    </QueryClientProvider>,
  );
}

describe("AuthPage", () => {
  beforeEach(() => {
    window.localStorage.setItem("locale", "en");
  });

  it("renders localized auth guard labels in English", () => {
    renderPage();

    expect(screen.getByText("Auth Guard")).toBeInTheDocument();
    expect(screen.getByText("ReBAC permission checker")).toBeInTheDocument();
    expect(screen.getByRole("button", { name: "Check permission" })).toBeInTheDocument();
  });
});
