test: add another scrolling test (#184)

This commit is contained in:
Nolan Lawson 2021-07-12 07:20:11 -07:00 committed by GitHub
parent ed63bedd61
commit 154e703a1b
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 32 additions and 1 deletions

View File

@ -1,6 +1,6 @@
import { basicAfterEach, basicBeforeEach, tick } from '../shared'
import Picker from '../../../src/picker/PickerElement'
import { getByRole, waitFor } from '@testing-library/dom'
import { getByRole, waitFor, getAllByRole } from '@testing-library/dom'
import userEvent from '@testing-library/user-event'
describe('scrolling', () => {
@ -56,4 +56,35 @@ describe('scrolling', () => {
document.body.removeChild(picker)
await tick(20)
})
test('scrollTop resets to 0 on changing search input', async () => {
const picker = new Picker()
const container = picker.shadowRoot
document.body.appendChild(picker)
await waitFor(() => expect(getByRole(container, 'menuitem', { name: /😀/ })).toBeVisible())
const tabPanel = getByRole(container, 'tabpanel')
await userEvent.type(getByRole(container, 'combobox'), 'monkey')
await waitFor(() => expect(getAllByRole(container, 'option')).toHaveLength(2))
expect(getByRole(container, 'option', { name: /🐵/ })).toBeVisible()
tabPanel.scrollTop = 1
await tick(20)
expect(tabPanel.scrollTop).toEqual(1)
await userEvent.type(getByRole(container, 'combobox'), ' face')
await waitFor(() => expect(getAllByRole(container, 'option')).toHaveLength(1))
expect(getByRole(container, 'option', { name: /🐵/ })).toBeVisible()
await tick(20)
expect(tabPanel.scrollTop).toEqual(0)
document.body.removeChild(picker)
await tick(20)
})
})