// @vitest-environment jsdom
import { describe, it, expect, vi } from "vitest";
import { render, screen } from "@testing-library/react";
import { DetailsBackButton } from "./DetailsBackButton.js";

vi.mock("@modern-js/runtime/router", () => ({
  Link: ({
    children,
    to,
    ...props
  }: {
    children: React.ReactNode;
    to: string;
    [key: string]: unknown;
  }) => (
    <a href={to} {...props}>
      {children}
    </a>
  ),
}));

vi.mock("@/i18n/provider.js", () => ({
  useTranslation: () => ({ t: (k: string) => k }),
}));

describe("DetailsBackButton", () => {
  it("has data-testid details-back-button", () => {
    render(<DetailsBackButton locale="ru" />);
    expect(screen.getByTestId("details-back-button")).toBeTruthy();
  });

  it("links to /ru/onlineboard for locale='ru'", () => {
    render(<DetailsBackButton locale="ru" />);
    expect(screen.getByTestId("details-back-button").getAttribute("href")).toBe(
      "/ru/onlineboard",
    );
  });

  it("uses the provided locale", () => {
    render(<DetailsBackButton locale="en" />);
    expect(screen.getByTestId("details-back-button").getAttribute("href")).toBe(
      "/en/onlineboard",
    );
  });

  it("renders SHARED.BACK-BOARD label", () => {
    render(<DetailsBackButton locale="ru" />);
    expect(screen.getByText("SHARED.BACK-BOARD")).toBeTruthy();
  });
});
