Skip to content

Commit

Permalink
Adding DropdownMenu test
Browse files Browse the repository at this point in the history
  • Loading branch information
corbanbrook committed Sep 14, 2023
1 parent 49a513b commit c02c16c
Show file tree
Hide file tree
Showing 3 changed files with 71 additions and 3 deletions.
8 changes: 5 additions & 3 deletions src/components/Button/Button.test.tsx
Original file line number Diff line number Diff line change
@@ -1,18 +1,20 @@
import { cleanup, render, screen, fireEvent } from '@testing-library/react'
import { cleanup, render, screen } from '@testing-library/react'
import { vi } from 'vitest'
import { Button } from './Button'
import userEvent from '@testing-library/user-event'

describe('<Button />', () => {
afterEach(cleanup)

it('renders', () => {
it('renders', async () => {
const user = userEvent.setup()
const handleClick = vi.fn()

render(<Button label="Hello, world!" onClick={handleClick} />)

expect(screen.getByText('Hello, world!')).toBeInTheDocument()

fireEvent.click(screen.getByRole('button'))
await user.click(screen.getByRole('button'))

expect(handleClick).toHaveBeenCalledTimes(1)
})
Expand Down
1 change: 1 addition & 0 deletions src/components/Collapsible/Collapsible.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ describe('<Collapsible />', () => {
it('renders', () => {
render(<Collapsible label="Hello">World</Collapsible>)
expect(screen.getByText(/Hello/)).toBeInTheDocument()
expect(screen.queryByText(/World/)).toBeNull()

fireEvent.click(screen.getByRole('button'))

Expand Down
65 changes: 65 additions & 0 deletions src/components/DropdownMenu/DropdownMenu.test.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
import { cleanup, render, screen } from '@testing-library/react'
import userEvent from '@testing-library/user-event'

import {
DropdownMenuCheckboxItem,
DropdownMenuContent,
DropdownMenuItem,
DropdownMenuRoot,
DropdownMenuTrigger,
DropdownMenuSeparator,
DropdownMenuRadioItem,
DropdownMenuRadioGroup,
} from './DropdownMenu'

describe('<DropdownMenu />', () => {
afterEach(cleanup)

it('renders', async () => {
const user = userEvent.setup()

render(
<DropdownMenuRoot>
<DropdownMenuTrigger>Menu</DropdownMenuTrigger>
<DropdownMenuContent>
<DropdownMenuItem>New Tab</DropdownMenuItem>
<DropdownMenuItem>New Window</DropdownMenuItem>
<DropdownMenuItem disabled>New Private Tab</DropdownMenuItem>
<DropdownMenuItem>Item 4</DropdownMenuItem>
<DropdownMenuItem>Item 5</DropdownMenuItem>

<DropdownMenuSeparator />

{/* <DropdownMenuCheckboxItem
checked={showBookmarks}
onCheckedChange={value => setShowBookmarks(!!value)}
>
Show Bookmarks
</DropdownMenuCheckboxItem>
<DropdownMenuCheckboxItem
checked={showFullURLs}
onCheckedChange={value => setShowFullURLs(!!value)}
>
Show Full URLs
</DropdownMenuCheckboxItem> */}

<DropdownMenuSeparator />

{/* <DropdownMenuRadioGroup
value={mode}
onValueChange={value => setMode(value as any)}
>
<DropdownMenuRadioItem value="list">List</DropdownMenuRadioItem>
<DropdownMenuRadioItem value="grid">Grid</DropdownMenuRadioItem>
</DropdownMenuRadioGroup> */}
</DropdownMenuContent>
</DropdownMenuRoot>
)

expect(screen.getByText(/Menu/)).toBeInTheDocument()

await user.click(screen.getByRole('button'))

expect(screen.getByText(/New Tab/)).toBeInTheDocument()
})
})

0 comments on commit c02c16c

Please sign in to comment.