| 1 |
import React from "react"; |
| 2 |
import { render, screen } from "@testing-library/react"; |
| 3 |
import { expect, test, describe } from "vitest"; |
| 4 |
// Component |
| 5 |
import SidebarLayout from "./SidebarLayout"; |
| 6 |
|
| 7 |
const sidebarChildren = [ |
| 8 |
<div key="1">Test Content</div>, |
| 9 |
<div key="2">Test Content</div>, |
| 10 |
<div key="3">Test Content</div>, |
| 11 |
]; |
| 12 |
|
| 13 |
describe("SidebarLayout Component", () => { |
| 14 |
test("should render SidebarLayout component", () => { |
| 15 |
render( |
| 16 |
<SidebarLayout itemNames={["Test Item 1", "Test Item 2"]}> |
| 17 |
{sidebarChildren} |
| 18 |
</SidebarLayout> |
| 19 |
); |
| 20 |
|
| 21 |
expect(screen.getByText("Test Item 1")).toBeInTheDocument(); |
| 22 |
expect(screen.getByText("Test Item 2")).toBeInTheDocument(); |
| 23 |
expect(screen.getAllByText("Test Content")).toHaveLength(3); |
| 24 |
}); |
| 25 |
|
| 26 |
test("should render JumpLinks with correct href and text content", () => { |
| 27 |
render( |
| 28 |
<SidebarLayout itemNames={["User Settings", "Password Policy"]}> |
| 29 |
<div>Content</div> |
| 30 |
</SidebarLayout> |
| 31 |
); |
| 32 |
|
| 33 |
const userSettingsLink = screen.getByRole("link", { |
| 34 |
name: /User Settings/i, |
| 35 |
}); |
| 36 |
expect(userSettingsLink).toHaveAttribute("href", "#user-settings"); |
| 37 |
|
| 38 |
const passwordPolicyLink = screen.getByRole("link", { |
| 39 |
name: /Password Policy/i, |
| 40 |
}); |
| 41 |
expect(passwordPolicyLink).toHaveAttribute("href", "#password-policy"); |
| 42 |
}); |
| 43 |
}); |