Skip to content

Commit

Permalink
fix(sqllab): typeahead search is broken in db selector (apache#27181)
Browse files Browse the repository at this point in the history
  • Loading branch information
justinpark authored and sfirke committed Mar 22, 2024
1 parent 40f4be6 commit 8a2c1dc
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -229,6 +229,32 @@ test('Should database select display options', async () => {
expect(await screen.findByText('test-mysql')).toBeInTheDocument();
});

test('Should fetch the search keyword when total count exceeds initial options', async () => {
fetchMock.get(
databaseApiRoute,
{
...fakeDatabaseApiResult,
count: fakeDatabaseApiResult.result.length + 1,
},
{ overwriteRoutes: true },
);

const props = createProps();
render(<DatabaseSelector {...props} />, { useRedux: true, store });
const select = screen.getByRole('combobox', {
name: 'Select database or type to search databases',
});
await waitFor(() =>
expect(fetchMock.calls(databaseApiRoute)).toHaveLength(1),
);
expect(select).toBeInTheDocument();
userEvent.type(select, 'keywordtest');
await waitFor(() =>
expect(fetchMock.calls(databaseApiRoute)).toHaveLength(2),
);
expect(fetchMock.calls(databaseApiRoute)[1][0]).toContain('keywordtest');
});

test('should show empty state if there are no options', async () => {
fetchMock.reset();
fetchMock.get(databaseApiRoute, { result: [] });
Expand Down
4 changes: 2 additions & 2 deletions superset-frontend/src/components/DatabaseSelector/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -167,7 +167,7 @@ export default function DatabaseSelector({
});
const endpoint = `/api/v1/database/?q=${queryParams}`;
return SupersetClient.get({ endpoint }).then(({ json }) => {
const { result } = json;
const { result, count } = json;
if (getDbList) {
getDbList(result);
}
Expand All @@ -189,7 +189,7 @@ export default function DatabaseSelector({

return {
data: options,
totalCount: options.length,
totalCount: count ?? options.length,
};
});
},
Expand Down

0 comments on commit 8a2c1dc

Please sign in to comment.