/**
 * Federation Connections Page Tests
 * Tests for page structure and component integration
 */

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

// Mock the federation components
vi.mock("@/components/federation/ConnectionList", () => ({
  ConnectionList: (): React.JSX.Element => <div data-testid="connection-list">ConnectionList</div>,
}));

vi.mock("@/components/federation/InitiateConnectionDialog", () => ({
  InitiateConnectionDialog: (): React.JSX.Element => (
    <div data-testid="initiate-dialog">Dialog</div>
  ),
}));

describe("ConnectionsPage", (): void => {
  // Note: NODE_ENV is "test" during test runs, which triggers the Coming Soon view
  // This tests the production-like behavior where mock data is hidden

  it("should render the Coming Soon view in non-development environments", async (): Promise<void> => {
    // Dynamic import to ensure fresh module state
    const { default: ConnectionsPage } = await import("./page");
    render(<ConnectionsPage />);

    // In test mode (non-development), should show Coming Soon
    expect(screen.getByText("Coming Soon")).toBeInTheDocument();
    expect(screen.getByText("Federation Connections")).toBeInTheDocument();
  });

  it("should display appropriate description for federation feature", async (): Promise<void> => {
    const { default: ConnectionsPage } = await import("./page");
    render(<ConnectionsPage />);

    expect(
      screen.getByText(/connect and manage relationships with other mosaic stack instances/i)
    ).toBeInTheDocument();
  });

  it("should not render mock data in Coming Soon view", async (): Promise<void> => {
    const { default: ConnectionsPage } = await import("./page");
    render(<ConnectionsPage />);

    // Should not show the connection list or dialog in non-development mode
    expect(screen.queryByTestId("connection-list")).not.toBeInTheDocument();
    expect(screen.queryByRole("button", { name: /connect to instance/i })).not.toBeInTheDocument();
  });
});
