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

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

describe("rendering CardProductHeader", () => {
  it("has default class card__product-header", () => {
    const { getByTestId } = render(
      <CardProductHeader data-testid="test-id">Header</CardProductHeader>,
    );
    expect(getByTestId("test-id")).toHaveClass("card__product-header");
  });

  it("renders children", () => {
    const { getByText } = render(
      <CardProductHeader>Product Header</CardProductHeader>,
    );
    expect(getByText("Product Header")).toBeInTheDocument();
  });

  it("renders image if provided", () => {
    const { getByAltText } = render(
      <CardProductHeader image={<img src="#" alt="product" />}>
        Product Header
      </CardProductHeader>,
    );
    expect(getByAltText("product")).toBeInTheDocument();
  });

  it("has additional class when className is set", () => {
    const { getByTestId } = render(
      <CardProductHeader data-testid="test-id" className="test-class" />,
    );
    expect(getByTestId("test-id")).toHaveClass("card__product-header");
    expect(getByTestId("test-id")).toHaveClass("test-class");
  });

  it('has card__product-header--space-small class when space="small"', () => {
    const { getByTestId } = render(
      <CardProductHeader data-testid="test-id" space="small" />,
    );
    expect(getByTestId("test-id")).toHaveClass(
      "card__product-header--space-small",
    );
  });

  it("does not have card__product-header--space-small class when space is not set", () => {
    const { getByTestId } = render(<CardProductHeader data-testid="test-id" />);
    expect(getByTestId("test-id")).not.toHaveClass(
      "card__product-header--space-small",
    );
  });

  it("has content wrapper with card__product-content class", () => {
    const { container } = render(
      <CardProductHeader>Product Header</CardProductHeader>,
    );
    const contentWrapper = container.querySelector(".card__product-content");
    expect(contentWrapper).toBeInTheDocument();
    expect(contentWrapper).toHaveTextContent("Product Header");
  });
});
