import { render, screen, within } from "@testing-library/react";
import { describe, expect, it } from "vitest";

import { SellerTrustCard } from "../seller-trust-card";

describe("SellerTrustCard", () => {
  it("renders verified seller rating details and store link", () => {
    render(
      <SellerTrustCard
        storeId="store-1"
        storeName="ReNew Fashion"
        city="Brooklyn"
        state="NY"
        isVerified
        averageRating={4.8}
        reviewCount={37}
        ratingBreakdown={{
          item_as_described: 4.9,
          shipping_speed: 4.7,
          communication: 4.8,
          packaging: 4.8,
        }}
      />,
    );

    const region = screen.getByRole("region", { name: "ReNew Fashion" });

    expect(within(region).getByText("Verified")).toBeInTheDocument();
    expect(within(region).getByText("Brooklyn, NY")).toBeInTheDocument();
    expect(within(region).getByTestId("rating-badge")).toBeInTheDocument();
    expect(within(region).getByText("4.9")).toBeInTheDocument();
    expect(within(region).getByText("Shipping speed")).toBeInTheDocument();
    expect(within(region).getByRole("link", { name: "View Store" })).toHaveAttribute(
      "href",
      "/stores/store-1",
    );
  });

  it("renders a neutral no-review state", () => {
    render(
      <SellerTrustCard
        storeId="store-1"
        storeName="ReNew Fashion"
        averageRating={null}
        reviewCount={0}
      />,
    );

    expect(screen.getByText("No reviews yet")).toBeInTheDocument();
    expect(screen.queryByText("Verified")).toBeNull();
    expect(screen.queryByText("As described")).toBeNull();
  });
});
