import {
  cleanup,
  render,
  screen,
} from "@testing-library/react";
import assert from "node:assert";
import {
  afterEach,
  describe,
  test,
} from "node:test";
import { Logo } from "./index";

describe("Logo", () => {
  afterEach(() => {
    cleanup();
  });

  test("renders link and image with defaults", () => {
    render(<Logo src={"/logo.svg"} />);

    const link = screen.getByRole("link");
    const img = screen.getByRole("img");

    assert.strictEqual(link.getAttribute("href"), "https://d-element.ru/");
    assert.strictEqual((img as HTMLImageElement).src.includes("/logo.svg"), true);
  });

  test("passes custom attrs to link and image", () => {
    render(
      <Logo
        src={"/logo.svg"}
        href={"https://example.com"}
        target={"_self"}
        alt={"Example logo"}
      />
    );

    const link = screen.getByRole("link");
    const img = screen.getByRole("img");

    assert.strictEqual(link.getAttribute("href"), "https://example.com");
    assert.strictEqual(link.getAttribute("target"), "_self");
    assert.strictEqual(img.getAttribute("alt"), "Example logo");
  });

  test("uses explicit aria-label and title on link", () => {
    render(
      <Logo
        src={"/logo.svg"}
        ariaLabel={"Company logo"}
        title={"Open company site"}
      />
    );

    const link = screen.getByRole("link");
    assert.strictEqual(link.getAttribute("aria-label"), "Company logo");
    assert.strictEqual(link.getAttribute("title"), "Open company site");
  });
});
