/* 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 accessibility", () => {
describe("semantic HTML", () => {
it("uses proper link element for navigation", () => {
render(Test Link)
const link = screen.getByRole("link")
expect(link.tagName).toBe("A")
})
it("has accessible link text", () => {
render(View Hotels)
expect(screen.getByRole("link", { name: "View Hotels" })).toBeTruthy()
})
it("link has descriptive href attribute", () => {
render(Stockholm Hotels)
const link = screen.getByRole("link", { name: "Stockholm Hotels" })
expect(link.getAttribute("href")).toBe("/hotels/stockholm")
})
})
describe("keyboard navigation", () => {
it("link is keyboard accessible", async () => {
const user = userEvent.setup()
render(Accessible Link)
const link = screen.getByRole("link")
await user.tab()
expect(document.activeElement).toBe(link)
})
it("multiple links maintain logical focus order", async () => {
const user = userEvent.setup()
render(
First Link
Second Link
Third Link
)
const firstLink = screen.getByRole("link", { name: "First Link" })
const secondLink = screen.getByRole("link", { name: "Second Link" })
const thirdLink = screen.getByRole("link", { name: "Third Link" })
await user.tab()
expect(document.activeElement).toBe(firstLink)
await user.tab()
expect(document.activeElement).toBe(secondLink)
await user.tab()
expect(document.activeElement).toBe(thirdLink)
})
})
describe("screen reader support", () => {
it("link has accessible name from content", () => {
render(Descriptive Link Text)
const link = screen.getByRole("link")
expect(link.textContent?.trim().length).toBeGreaterThan(0)
})
it("link with icon and text has accessible name", () => {
render(
→
Next Page
)
const link = screen.getByRole("link")
expect(link.textContent).toContain("Next Page")
})
})
})