import { render, screen } from "@testing-library/react";

import { HeadlineBar } from "../HeadlineBar";

describe("HeadlineBar", () => {
  it("renders title text", () => {
    render(<HeadlineBar title="ПОДХОДИТ · участок 0.82 га" />);
    expect(screen.getByText("ПОДХОДИТ · участок 0.82 га")).toBeInTheDocument();
  });

  it("renders subtitle when provided", () => {
    render(
      <HeadlineBar
        title="Заголовок"
        subtitle="Кадастровая стоимость 14.2 млн ₽"
      />,
    );
    expect(
      screen.getByText("Кадастровая стоимость 14.2 млн ₽"),
    ).toBeInTheDocument();
  });

  it("does not render subtitle section when omitted", () => {
    const { container } = render(<HeadlineBar title="Только заголовок" />);
    // The content wrapper (flex:1 column) holds the title and, when present, the
    // subtitle as a second child. With no subtitle it must hold exactly one
    // child (the title) — the subtitle separator block is not rendered.
    const contentWrapper = container.querySelector('[role="banner"] > div');
    expect(contentWrapper).not.toBeNull();
    expect(contentWrapper?.children).toHaveLength(1);
    expect(contentWrapper?.firstElementChild?.textContent).toBe(
      "Только заголовок",
    );
  });

  it("renders rightSlot content", () => {
    render(<HeadlineBar title="Title" rightSlot={<button>Export</button>} />);
    expect(screen.getByRole("button", { name: "Export" })).toBeInTheDocument();
  });
});
