-
Notifications
You must be signed in to change notification settings - Fork 22
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
7d23cfe
commit bf244b4
Showing
4 changed files
with
103 additions
and
167 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
69 changes: 22 additions & 47 deletions
69
src/components/AppLayout/Submenu /__tests__/Submenu.spec.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,65 +1,40 @@ | ||
import { render, screen } from "@testing-library/react"; | ||
import userEvent from "@testing-library/user-event"; | ||
import { Submenu } from ".."; | ||
|
||
const mockText = "Submenu test content"; | ||
|
||
describe("Submenu Component", () => { | ||
it("renders correctly with required props", () => { | ||
it("renders when isOpen is true", () => { | ||
render( | ||
<Submenu | ||
icon={<span>Icon</span>} | ||
label="Account settings" | ||
submenuContent={<button>Click me</button>} | ||
/>, | ||
<Submenu isOpen> | ||
<p>{mockText}</p> | ||
</Submenu>, | ||
); | ||
expect(screen.getByText("Account settings")).toBeInTheDocument(); | ||
expect(screen.getByText("Icon")).toBeInTheDocument(); | ||
expect(screen.getByText(mockText)).toBeInTheDocument(); | ||
}); | ||
|
||
it("toggles submenu on button click", async () => { | ||
it("does not render when isOpen is false", () => { | ||
render( | ||
<Submenu | ||
icon={<span>Icon</span>} | ||
label="Account settings" | ||
submenuContent={<span>Close</span>} | ||
/>, | ||
<Submenu isOpen={false}> | ||
<p>{mockText}</p> | ||
</Submenu>, | ||
); | ||
|
||
expect(screen.queryByText("Close")).not.toBeInTheDocument(); | ||
// Open the submenu | ||
await userEvent.click(screen.getByRole("button")); | ||
expect(screen.getByText("Close")).toBeInTheDocument(); | ||
expect(screen.queryByText(mockText)).not.toBeInTheDocument(); | ||
}); | ||
|
||
it("applies custom class names", async () => { | ||
const mockClassName = "test-class"; | ||
|
||
render( | ||
<Submenu | ||
icon={<span>Icon</span>} | ||
label="Account settings" | ||
submenuClassName={mockClassName} | ||
submenuContent={<span>Submenu Content</span>} | ||
/>, | ||
it("applies exit animation class when isOpen changes to false", () => { | ||
const { rerender, container } = render( | ||
<Submenu isOpen> | ||
<p>{mockText}</p> | ||
</Submenu>, | ||
); | ||
expect(container.firstChild).toHaveClass("submenu"); | ||
|
||
await userEvent.click(screen.getByRole("button")); | ||
expect( | ||
screen.getByRole("button", { name: "Submenu Content" }).parentNode, | ||
).toHaveClass(mockClassName); | ||
}); | ||
|
||
it("renders the submenu children properly", async () => { | ||
render( | ||
<Submenu | ||
icon={<span>Icon</span>} | ||
label="Account settings" | ||
submenuContent={<span>Submenu Content</span>} | ||
> | ||
<span>submenu children</span> | ||
rerender( | ||
<Submenu isOpen={false}> | ||
<p>{mockText}</p> | ||
</Submenu>, | ||
); | ||
|
||
await userEvent.click(screen.getByRole("button")); | ||
expect(screen.getByText("submenu children")).toBeInTheDocument(); | ||
expect(container.firstChild).toHaveClass("submenu_exit"); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters