/* eslint-disable formatjs/no-literal-string-in-jsx */ import { describe, expect, it, afterEach } from "vitest" import { render, screen, cleanup } from "@testing-library/react" import userEvent from "@testing-library/user-event" import { ChipLink } from "./ChipLink" afterEach(() => { cleanup() }) describe("ChipLink", () => { describe("rendering", () => { it("renders as a link element", () => { render(Test Link) const link = screen.getByRole("link", { name: "Test Link" }) expect(link).toBeTruthy() expect(link.tagName).toBe("A") }) it("renders children content", () => { render(Link Content) expect(screen.getByText("Link Content")).toBeTruthy() }) it("applies correct href attribute", () => { render(Go somewhere) const link = screen.getByRole("link", { name: "Go somewhere" }) expect(link.getAttribute("href")).toBe("/destination") }) it("renders with multiple children", () => { render( Icon Text ) expect(screen.getByText("Icon")).toBeTruthy() expect(screen.getByText("Text")).toBeTruthy() }) }) describe("props", () => { it("applies custom className", () => { render( Link ) const link = screen.getByRole("link", { name: "Link" }) expect(link.className).toContain("custom-class") }) it("supports target attribute", () => { render( External Link ) const link = screen.getByRole("link", { name: "External Link" }) expect(link.getAttribute("target")).toBe("_blank") }) it("supports rel attribute", () => { render( External Link ) const link = screen.getByRole("link", { name: "External Link" }) expect(link.getAttribute("rel")).toBe("noopener noreferrer") }) }) describe("keyboard navigation", () => { it("is focusable via keyboard", async () => { const user = userEvent.setup() render(Focusable Link) const link = screen.getByRole("link", { name: "Focusable Link" }) await user.tab() expect(document.activeElement).toBe(link) }) }) })