|
| 1 | +import { render, screen, fireEvent } from "@testing-library/react"; |
| 2 | +import ULThemeLink from "../ULThemeLink"; |
| 3 | + |
| 4 | +describe("ULThemeLink Component", () => { |
| 5 | + const defaultProps = { |
| 6 | + href: "https://example.com", |
| 7 | + children: "Example Link", |
| 8 | + className: "custom-class", |
| 9 | + }; |
| 10 | + |
| 11 | + it("renders correctly and matches snapshot", () => { |
| 12 | + const { container } = render(<ULThemeLink {...defaultProps} />); |
| 13 | + expect(container).toMatchSnapshot(); |
| 14 | + }); |
| 15 | + |
| 16 | + it("renders the correct text", () => { |
| 17 | + render(<ULThemeLink {...defaultProps} />); |
| 18 | + expect(screen.getByText("Example Link")).toBeInTheDocument(); |
| 19 | + }); |
| 20 | + |
| 21 | + it("applies additional class names", () => { |
| 22 | + render(<ULThemeLink {...defaultProps} />); |
| 23 | + const link = screen.getByRole("link"); |
| 24 | + expect(link).toHaveClass("custom-class"); |
| 25 | + }); |
| 26 | + |
| 27 | + it("renders the correct href attribute", () => { |
| 28 | + render(<ULThemeLink {...defaultProps} />); |
| 29 | + const link = screen.getByRole("link"); |
| 30 | + expect(link).toHaveAttribute("href", "https://example.com"); |
| 31 | + }); |
| 32 | + |
| 33 | + it("calls the onClick handler when clicked", () => { |
| 34 | + const mockOnClick = jest.fn(); |
| 35 | + render(<ULThemeLink {...defaultProps} onClick={mockOnClick} />); |
| 36 | + const link = screen.getByRole("link"); |
| 37 | + fireEvent.click(link); |
| 38 | + expect(mockOnClick).toHaveBeenCalledTimes(1); |
| 39 | + }); |
| 40 | + |
| 41 | + it("disables the link when the disabled prop is true", () => { |
| 42 | + render(<ULThemeLink {...defaultProps} disabled />); |
| 43 | + const link = screen.getByRole("link"); |
| 44 | + expect(link).toHaveClass("pointer-events-none cursor-not-allowed"); |
| 45 | + expect(link).toHaveAttribute("aria-disabled", "true"); |
| 46 | + }); |
| 47 | +}); |
0 commit comments