From b47174af4a9e14bda2cd3872482a67a358af5bce Mon Sep 17 00:00:00 2001 From: Pavel Mineev Date: Sun, 8 Aug 2021 16:47:55 +0300 Subject: [PATCH] add tests for sort picker and update select tests --- .../app/components/select/select.spec.tsx | 22 ++++++-- frontend/app/components/select/select.tsx | 9 ++-- .../sort-picker/sort-picker.spec.tsx | 53 +++++++++++++++++++ .../components/sort-picker/sort-picker.tsx | 11 ++-- frontend/app/tests/utils.tsx | 7 ++- 5 files changed, 86 insertions(+), 16 deletions(-) diff --git a/frontend/app/components/select/select.spec.tsx b/frontend/app/components/select/select.spec.tsx index a55aab73..6957a429 100644 --- a/frontend/app/components/select/select.spec.tsx +++ b/frontend/app/components/select/select.spec.tsx @@ -1,4 +1,5 @@ import '@testing-library/jest-dom'; +import { fireEvent, waitFor } from '@testing-library/preact'; import { h } from 'preact'; import { render } from 'tests/utils'; import { Select } from './select'; @@ -29,18 +30,31 @@ const items = [ describe('); + const selectElement = container.querySelector('.select-element'); expect(container.querySelector('.select')).toBeInTheDocument(); expect(container.querySelector('.select-arrow')).toBeInTheDocument(); - expect(container.querySelector('.select-element')).toBeInTheDocument(); + expect(selectElement).toBeInTheDocument(); + fireEvent.focus(selectElement as HTMLSelectElement); + expect(container.querySelector('.select_focused')).toBeInTheDocument(); }); it('should render selected item', () => { const { container, getAllByText } = render(); + const select = container.querySelector('select'); + + expect(container.querySelector('select')).toBeInTheDocument(); + fireEvent.focus(select as HTMLSelectElement); + expect(container.querySelector('.rootFocused')).toBeInTheDocument(); }); }); diff --git a/frontend/app/components/select/select.tsx b/frontend/app/components/select/select.tsx index b1ea7e32..51acbcfe 100644 --- a/frontend/app/components/select/select.tsx +++ b/frontend/app/components/select/select.tsx @@ -12,21 +12,20 @@ type Item = { type Props = { items: Item[]; selected: Item; - onChange?: JSX.GenericEventHandler; -}; +} & Omit, 'className' | 'onFocus' | 'onBlur' | 'selected'>; -export function Select({ items, selected, onChange }: Props) { +export function Select({ items, selected, ...props }: Props) { const [focus, setFocus] = useState(false); return ( - + {selected.label} +