forked from reach/reach-ui
-
Notifications
You must be signed in to change notification settings - Fork 0
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
Chance Strickland
committed
Mar 11, 2020
1 parent
e08bf00
commit 940a5fd
Showing
4 changed files
with
56 additions
and
12 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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
import React from "react"; | ||
import { render, act, withMarkup, fireEvent } from "$test/utils"; | ||
import { axe } from "jest-axe"; | ||
import { Menu, MenuList, MenuButton, MenuItem } from "@reach/menu-button"; | ||
|
||
describe("<MenuButton />", () => { | ||
it("should not have basic a11y issues", async () => { | ||
let { container } = render(<BasicMenuButton />); | ||
expect(await axe(container)).toHaveNoViolations(); | ||
}); | ||
|
||
it("should toggle on button click", () => { | ||
let { getByRole, getByText, queryByText } = render(<BasicMenuButton />); | ||
let getByTextWithMarkup = withMarkup(getByText); | ||
let queryByTextWithMarkup = withMarkup(queryByText); | ||
|
||
// Menu opens on mousedown, not click! | ||
function clickButton() { | ||
fireEvent.mouseDown(getByRole("button")); | ||
fireEvent.mouseUp(getByRole("button")); | ||
} | ||
|
||
expect(queryByTextWithMarkup("Create a Copy")).not.toBeTruthy(); | ||
act(clickButton); | ||
expect(getByTextWithMarkup("Create a Copy")).toBeInTheDocument(); | ||
}); | ||
}); | ||
|
||
function BasicMenuButton() { | ||
return ( | ||
<Menu> | ||
<MenuButton id="example-button"> | ||
Actions <span aria-hidden="true">▾</span> | ||
</MenuButton> | ||
<MenuList> | ||
<input type="text" /> | ||
<MenuItem onSelect={() => jest.fn()}>Download</MenuItem> | ||
<MenuItem onSelect={() => jest.fn()}>Create a Copy</MenuItem> | ||
<MenuItem onSelect={() => jest.fn()}>Mark as Draft</MenuItem> | ||
<MenuItem onSelect={() => jest.fn()}>Delete</MenuItem> | ||
</MenuList> | ||
</Menu> | ||
); | ||
} |
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