import { describe, it, expect, vi, beforeEach } from "vitest";
import { render, screen } from "@testing-library/react";
import { IssueMentionPopup } from "../IssueMentionPopup";
import type { IssueMentionItem } from "../../api";
describe("IssueMentionPopup", () => {
const defaultProps = {
visible: true,
position: { top: 100, left: 20 },
issues: [] as IssueMentionItem[],
selectedIndex: 0,
onSelect: vi.fn(),
loading: false,
};
beforeEach(() => {
vi.clearAllMocks();
});
it("renders rows and selected state", () => {
const issues: IssueMentionItem[] = [
{ number: 42, title: "Fix bug", state: "open", htmlUrl: "https://x/42", repository: "o/r" },
{ number: 7, title: "Closed item", state: "closed", htmlUrl: "https://x/7", repository: "o/r" },
];
render();
const items = screen.getAllByRole("option");
expect(items).toHaveLength(2);
expect(items[1]).toHaveClass("issue-mention-popup-item--selected");
});
it("calls onSelect on click", () => {
const issue: IssueMentionItem = {
number: 42,
title: "Fix bug",
state: "open",
htmlUrl: "https://x/42",
repository: "o/r",
};
const onSelect = vi.fn();
render();
screen.getByRole("option").click();
expect(onSelect).toHaveBeenCalledWith(issue);
});
it("renders loading and empty states", () => {
const { rerender } = render();
expect(screen.getByTestId("issue-mention-loading")).toBeInTheDocument();
rerender();
expect(screen.getByTestId("issue-mention-empty")).toBeInTheDocument();
});
});