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('', () => {
it('should has static class names', () => {
const { container } = render();
+ 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 selectedOption = container.querySelectorAll('option')[0];
+ const selectedOption = container.querySelector('option');
expect(getAllByText(items[0].label)).toHaveLength(2);
- expect(selectedOption.selected).toBeTruthy();
- expect(selectedOption.textContent).toBe(items[0].label);
+ expect(selectedOption).toBeInTheDocument();
+ expect(selectedOption?.selected).toBeTruthy();
+ expect(selectedOption?.textContent).toBe(items[0].label);
+ });
+
+ it('should highlight selet on focus', async () => {
+ const { container } = 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}