import { render, screen } from "@testing-library/react"; import userEvent from "@testing-library/user-event"; import { describe, it, expect, vi } from "vitest"; import ProfileCard from "./ProfileCard"; import type { Profile, Instance } from "../../types"; const mockProfile: Profile = { id: "prof_123", name: "test-profile", created: new Date().toISOString(), lastUsed: new Date().toISOString(), diskUsage: 1024 * 1024 * 100, // 100MB sizeMB: 100, running: false, }; const mockRunningInstance: Instance = { id: "inst_123", profileId: "prof_123", profileName: "test-profile", port: "9868", headless: false, status: "running", startTime: new Date().toISOString(), attached: false, }; const mockErrorInstance: Instance = { ...mockRunningInstance, status: "error", error: "Failed to start Chrome", }; describe("ProfileCard", () => { it("renders profile name", () => { render( {}} />); expect(screen.getByText("test-profile")).toBeInTheDocument(); }); it("shows stopped badge when no instance", () => { render( {}} />); expect(screen.getByText("stopped")).toBeInTheDocument(); }); it("shows port badge when running", () => { render( {}} />, ); expect(screen.getByText(":9868")).toBeInTheDocument(); }); it("shows error badge when errored", () => { render( {}} />, ); expect(screen.getByText("error")).toBeInTheDocument(); }); it("shows error message when errored", () => { render( {}} />, ); expect(screen.getByText("Failed to start Chrome")).toBeInTheDocument(); }); it("displays size in MB", () => { render( {}} />); expect(screen.getByText("100 MB")).toBeInTheDocument(); }); it("displays dash for missing size", () => { const noSizeProfile = { ...mockProfile, sizeMB: undefined }; render( {}} />); expect(screen.getAllByText("—")).toHaveLength(2); // Size and Account both show — }); it("displays account email", () => { const profileWithEmail = { ...mockProfile, accountEmail: "test@pinchtab.com", }; render( {}} />); expect(screen.getByText("test@pinchtab.com")).toBeInTheDocument(); }); it("displays account name when no email", () => { const profileWithName = { ...mockProfile, accountName: "Test User" }; render( {}} />); expect(screen.getByText("Test User")).toBeInTheDocument(); }); it("displays useWhen text", () => { const profileWithUseWhen = { ...mockProfile, useWhen: "For testing purposes", }; render( {}} />); expect(screen.getByText("For testing purposes")).toBeInTheDocument(); }); it("shows Start button when stopped", () => { render( {}} />); expect(screen.getByRole("button", { name: "Start" })).toBeInTheDocument(); }); it("shows Stop button when running", () => { render( {}} onStop={() => {}} />, ); expect(screen.getByRole("button", { name: "Stop" })).toBeInTheDocument(); }); it("calls onLaunch when Start clicked", async () => { const handleLaunch = vi.fn(); render(); await userEvent.click(screen.getByRole("button", { name: "Start" })); expect(handleLaunch).toHaveBeenCalledTimes(1); }); it("calls onStop when Stop clicked", async () => { const handleStop = vi.fn(); render( {}} onStop={handleStop} />, ); await userEvent.click(screen.getByRole("button", { name: "Stop" })); expect(handleStop).toHaveBeenCalledTimes(1); }); it("shows Details button when onDetails provided", () => { render( {}} onDetails={() => {}} />, ); expect(screen.getByRole("button", { name: "Details" })).toBeInTheDocument(); }); it("calls onDetails when Details clicked", async () => { const handleDetails = vi.fn(); render( {}} onDetails={handleDetails} />, ); await userEvent.click(screen.getByRole("button", { name: "Details" })); expect(handleDetails).toHaveBeenCalledTimes(1); }); });