Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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