-
Notifications
You must be signed in to change notification settings - Fork 9
/
dropdown.test.js
39 lines (29 loc) · 1 KB
/
dropdown.test.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
import React from 'react'
import { render, fireEvent } from '@testing-library/react'
import Dropdown from '../dropdown'
describe(`Dropdown`, () => {
it(`renders activatorText`, () => {
const activatorText = `Hamburgers`
const { getByText } = render(<Dropdown activatorText={activatorText} />)
const text = getByText(activatorText)
expect(text).toBeInTheDocument()
})
it(`renders a focusable button that activates the dropdown`, () => {
const activatorText = `Dogs`
const items = [{
text: 'item 1',
url: '#'
}, {
text: 'item 2',
url: '#'
}]
const dropdown = render(<Dropdown activatorText={activatorText} items={items} />)
const activator = dropdown.getByTestId('dropdown-activator')
activator.focus()
expect(activator).toHaveFocus()
fireEvent.click(activator)
const dropdownList = dropdown.getByTestId('dropdown-itemList')
const firstAnchor = dropdownList.querySelector('a')
expect(firstAnchor).toHaveFocus()
})
})