Skip to content

Commit

Permalink
Add Menu test
Browse files Browse the repository at this point in the history
  • Loading branch information
evadecker committed Dec 17, 2024
1 parent c816841 commit e02227c
Showing 1 changed file with 33 additions and 0 deletions.
33 changes: 33 additions & 0 deletions src/components/common/Menu/Menu.test.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
import { render, screen } from "@testing-library/react";
import userEvent from "@testing-library/user-event";
import { describe, expect, it } from "vitest";
import { Button } from "../Button";
import { DialogTrigger } from "../Dialog";
import { Menu, MenuItem } from "./Menu";

describe("Menu", () => {
it("renders Menu with accessible title", async () => {
render(
<DialogTrigger>
<Button>Open Menu</Button>
<Menu>
<MenuItem id="item1">Item 1</MenuItem>
<MenuItem id="item2">Item 2</MenuItem>
</Menu>
</DialogTrigger>,
);

const button = screen.getByRole("button", { name: "Open Menu" });
userEvent.click(button);

// Renders the menu
const menu = await screen.findByRole("menu");
expect(menu).toBeInTheDocument();

// Renders the accessible title
const title = await screen.findByRole("dialog", {
name: "Select an option",
});
expect(title).toBeInTheDocument();
});
});

0 comments on commit e02227c

Please sign in to comment.