File size: 2,170 Bytes
6a7089a | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 | import { render, screen } from "@testing-library/react";
import userEvent from "@testing-library/user-event";
import { describe, it, expect, vi } from "vitest";
import InstanceListItem from "./InstanceListItem";
import type { Instance } from "../../generated/types";
const mockInstance: Instance = {
id: "inst_123",
profileId: "prof_456",
profileName: "test-profile",
port: "9868",
headless: false,
status: "running",
startTime: new Date().toISOString(),
attached: false,
};
describe("InstanceListItem", () => {
it("renders instance name and port", () => {
render(
<InstanceListItem
instance={mockInstance}
tabCount={5}
selected={false}
onClick={() => {}}
/>,
);
expect(screen.getByText("test-profile")).toBeInTheDocument();
expect(screen.getByText(":9868 · 5 tabs")).toBeInTheDocument();
});
it("shows running status badge", () => {
render(
<InstanceListItem
instance={mockInstance}
tabCount={0}
selected={false}
onClick={() => {}}
/>,
);
expect(screen.getByText("running")).toBeInTheDocument();
});
it("shows error status for errored instances", () => {
const errorInstance = { ...mockInstance, status: "error" };
render(
<InstanceListItem
instance={errorInstance}
tabCount={0}
selected={false}
onClick={() => {}}
/>,
);
expect(screen.getByText("error")).toBeInTheDocument();
});
it("applies selected styles when selected", () => {
render(
<InstanceListItem
instance={mockInstance}
tabCount={0}
selected={true}
onClick={() => {}}
/>,
);
const button = screen.getByRole("button");
expect(button).toHaveClass("border-primary");
});
it("calls onClick when clicked", async () => {
const handleClick = vi.fn();
render(
<InstanceListItem
instance={mockInstance}
tabCount={0}
selected={false}
onClick={handleClick}
/>,
);
await userEvent.click(screen.getByRole("button"));
expect(handleClick).toHaveBeenCalledTimes(1);
});
});
|