import { QueryClient, QueryClientProvider } from "@tanstack/react-query";
import { render, screen } from "@testing-library/react";
import { MemoryRouter, Route, Routes } from "react-router-dom";
import { beforeEach, describe, expect, it, vi } from "vitest";
import TenantDetailPage from "./TenantDetailPage";

vi.mock("../../../lib/adminApi", () => ({
  fetchMe: vi.fn(async () => ({ role: "super_admin" })),
  fetchTenant: vi.fn(async () => ({
    id: "hanmac-family-id",
    name: "한맥 가족",
    slug: "hanmac-family",
    parentId: null,
  })),
}));

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

  return render(
    <QueryClientProvider client={queryClient}>
      <MemoryRouter initialEntries={["/tenants/hanmac-family-id"]}>
        <Routes>
          <Route path="/tenants/:tenantId/*" element={<TenantDetailPage />}>
            <Route index element={<div>profile</div>} />
          </Route>
        </Routes>
      </MemoryRouter>
    </QueryClientProvider>,
  );
}

describe("TenantDetailPage Worksmobile navigation", () => {
  beforeEach(() => {
    vi.clearAllMocks();
  });

  it("does not render Worksmobile as a tenant detail tab", async () => {
    renderTenantDetailPage();

    await screen.findByText("프로필");

    expect(screen.queryByRole("link", { name: /Worksmobile/i })).toBeNull();
  });
});
