From 154e703a1b17e21b1ec2272cf06d848b955d2591 Mon Sep 17 00:00:00 2001 From: Nolan Lawson Date: Mon, 12 Jul 2021 07:20:11 -0700 Subject: [PATCH] test: add another scrolling test (#184) --- test/spec/picker/scrolling.test.js | 33 +++++++++++++++++++++++++++++- 1 file changed, 32 insertions(+), 1 deletion(-) diff --git a/test/spec/picker/scrolling.test.js b/test/spec/picker/scrolling.test.js index f2f03df..397da72 100644 --- a/test/spec/picker/scrolling.test.js +++ b/test/spec/picker/scrolling.test.js @@ -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) + }) })