|
| 1 | +import { render, screen } from "@testing-library/react"; |
| 2 | +import BottomNavBar from "@/components/bottomNavbar"; |
| 3 | +import { Book, Calendar2, Home2, Money } from "iconsax-react"; |
| 4 | + |
| 5 | +// Mock the icons to verify they're rendered |
| 6 | +jest.mock("iconsax-react", () => ({ |
| 7 | + Book: jest.fn(() => <div data-testid="book-icon" />), |
| 8 | + Calendar2: jest.fn(() => <div data-testid="calendar-icon" />), |
| 9 | + Home2: jest.fn(() => <div data-testid="home-icon" />), |
| 10 | + Money: jest.fn(() => <div data-testid="money-icon" />), |
| 11 | +})); |
| 12 | + |
| 13 | +describe("BottomNavBar Component", () => { |
| 14 | + beforeEach(() => { |
| 15 | + jest.clearAllMocks(); |
| 16 | + }); |
| 17 | + |
| 18 | + it("renders without crashing", () => { |
| 19 | + render(<BottomNavBar />); |
| 20 | + expect(screen.getByRole("navigation")).toBeInTheDocument(); |
| 21 | + }); |
| 22 | + |
| 23 | + it("has correct styling classes", () => { |
| 24 | + render(<BottomNavBar />); |
| 25 | + const nav = screen.getByRole("navigation"); |
| 26 | + |
| 27 | + expect(nav).toHaveClass("fixed"); |
| 28 | + expect(nav).toHaveClass("bottom-8"); |
| 29 | + expect(nav).toHaveClass("rounded-2xl"); |
| 30 | + expect(nav).toHaveClass("bg-[var(--main)]"); |
| 31 | + }); |
| 32 | + |
| 33 | + it("renders all navigation items", () => { |
| 34 | + render(<BottomNavBar />); |
| 35 | + |
| 36 | + const listItems = screen.getAllByRole("listitem"); |
| 37 | + expect(listItems).toHaveLength(4); |
| 38 | + |
| 39 | + const buttons = screen.getAllByRole("button"); |
| 40 | + expect(buttons).toHaveLength(4); |
| 41 | + }); |
| 42 | + |
| 43 | + it("renders correct icons for each nav item", () => { |
| 44 | + render(<BottomNavBar />); |
| 45 | + |
| 46 | + expect(Home2).toHaveBeenCalled(); |
| 47 | + expect(Book).toHaveBeenCalled(); |
| 48 | + expect(Calendar2).toHaveBeenCalled(); |
| 49 | + expect(Money).toHaveBeenCalled(); |
| 50 | + |
| 51 | + // Verify icon props |
| 52 | + const homeIconProps = (Home2 as jest.Mock).mock.calls[0][0]; |
| 53 | + expect(homeIconProps.size).toBe("32"); |
| 54 | + expect(homeIconProps.color).toBe("var(--text)"); |
| 55 | + }); |
| 56 | + |
| 57 | + it("has accessible buttons", () => { |
| 58 | + render(<BottomNavBar />); |
| 59 | + |
| 60 | + const buttons = screen.getAllByRole("button"); |
| 61 | + buttons.forEach((button) => { |
| 62 | + expect(button).toHaveAttribute("type", "button"); |
| 63 | + expect(button).toHaveClass("focus:outline-none"); |
| 64 | + }); |
| 65 | + }); |
| 66 | + |
| 67 | + it("matches snapshot", () => { |
| 68 | + const { asFragment } = render(<BottomNavBar />); |
| 69 | + expect(asFragment()).toMatchSnapshot(); |
| 70 | + }); |
| 71 | +}); |
0 commit comments