import { cleanup, render, screen } from "@testing-library/react";
import { afterEach, describe, expect, it } from "vitest";
import { AppPreviewCard } from "./AppPreviewCard";
import type { AppArtifactPreview } from "@/lib/app-artifacts";

afterEach(cleanup);

describe("AppPreviewCard", () => {
  it("renders a generated artifact preview and routes to artifact detail", () => {
    render(<AppPreviewCard artifact={fixtureAppletPreview} />);

    expect(screen.getByText("LastMile CRM pipeline risk")).toBeTruthy();
    expect(screen.getByText("Private artifact")).toBeTruthy();
    expect(screen.getByRole("link").getAttribute("href")).toBe(
      "/artifacts/33333333-3333-4333-8333-333333333333",
    );
  });
});

const fixtureAppletPreview = {
  id: "33333333-3333-4333-8333-333333333333",
  artifactId: "artifact-33333",
  title: "LastMile CRM pipeline risk",
  kind: "applet",
  summary: "Pipeline-risk applet generated by Computer.",
  href: "/artifacts/33333333-3333-4333-8333-333333333333",
  generatedAt: "2026-05-08T16:00:00.000Z",
  favoritedAt: null,
  version: 1,
  modelId: "fixture",
  stdlibVersionAtGeneration: "0.1.0",
} satisfies AppArtifactPreview;
