/**
 * Tests require: jest + @testing-library/react + @testing-library/jest-dom
 * npm i -D jest jest-environment-jsdom @testing-library/react @testing-library/jest-dom ts-jest
 */
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="Только заголовок" />);
    // subtitle div has marginTop style — not present when subtitle is undefined
    const subtitleDivs = container.querySelectorAll("div > div > div");
    expect(subtitleDivs).toHaveLength(0);
  });

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