import { describe, it, expect } from "vitest";
import { render, screen } from "@testing-library/react";
import { BookingErrorPage } from "../pages/BookingError.tsx";
import { BUSINESS_CONTACT_INFO } from "../lib/contact.ts";

describe("BookingErrorPage", () => {
  it("renders the error heading", () => {
    render(<BookingErrorPage />);
    expect(screen.getByRole("heading", { name: /Link Invalid or Expired/i })).toBeInTheDocument();
  });

  it("renders the error body text", () => {
    render(<BookingErrorPage />);
    expect(screen.getByText(/This confirmation link is invalid/i)).toBeInTheDocument();
  });

  it("has a Start a new booking link pointing to /admin/book", () => {
    render(<BookingErrorPage />);
    const link = screen.getByRole("link", { name: /Start a new booking/i });
    expect(link).toHaveAttribute("href", "/admin/book");
  });

  it("has a Back to Portal link pointing to /", () => {
    render(<BookingErrorPage />);
    const link = screen.getByRole("link", { name: /Back to Portal/i });
    expect(link).toHaveAttribute("href", "/");
  });

  it("displays business contact phone", () => {
    render(<BookingErrorPage />);
    expect(screen.getByText(new RegExp(BUSINESS_CONTACT_INFO.phone.replace(/[()]/g, "\\$&")))).toBeInTheDocument();
  });

  it("displays business contact email", () => {
    render(<BookingErrorPage />);
    expect(screen.getByText(new RegExp(BUSINESS_CONTACT_INFO.email))).toBeInTheDocument();
  });
});
