fix: sort items in typeahead dropdown (#387)

This commit is contained in:
Kristin Aoki
2023-09-12 09:48:43 -04:00
committed by GitHub
parent c44c72cec0
commit 4f76b7c85e
2 changed files with 5 additions and 4 deletions

View File

@@ -45,7 +45,7 @@ class TypeaheadDropdown extends React.Component {
options = options.filter((option) => (option.toLowerCase().includes(strToFind.toLowerCase())));
}
return options.map((opt) => {
return options.sort().map((opt) => {
let value = opt;
if (value.length > 30) {
value = value.substring(0, 30).concat('...');

View File

@@ -3,6 +3,7 @@ import {
fireEvent,
render,
screen,
waitFor,
within,
} from '@testing-library/react';
import userEvent from '@testing-library/user-event';
@@ -50,11 +51,11 @@ describe('common/OrganizationDropdown.jsx', () => {
fireEvent.focusOut(formInput);
expect(mockHandleBlur).toHaveBeenCalled();
});
it('renders component with options', () => {
const newProps = { ...defaultProps, options: ['opt1', 'opt2'] };
it('renders component with options', async () => {
const newProps = { ...defaultProps, options: ['opt2', 'opt1'] };
renderComponent(newProps);
const formInput = screen.getByTestId('formControl');
fireEvent.click(formInput);
await waitFor(() => fireEvent.click(formInput));
const optionsList = within(screen.getByTestId('dropdown-container')).getAllByRole('button');
expect(optionsList.length).toEqual(newProps.options.length);
});