mirror of
https://github.com/apache/superset.git
synced 2026-07-09 08:15:49 +00:00
feat(sqllab): Dynamic query limit dropdown (#25855)
This commit is contained in:
@@ -25,7 +25,6 @@ import { render, fireEvent, waitFor } from 'spec/helpers/testing-library';
|
||||
import userEvent from '@testing-library/user-event';
|
||||
import { initialState, defaultQueryEditor } from 'src/SqlLab/fixtures';
|
||||
import QueryLimitSelect, {
|
||||
LIMIT_DROPDOWN,
|
||||
QueryLimitSelectProps,
|
||||
convertToNumWithSpaces,
|
||||
} from 'src/SqlLab/components/QueryLimitSelect';
|
||||
@@ -106,13 +105,67 @@ describe('QueryLimitSelect', () => {
|
||||
});
|
||||
|
||||
it('renders dropdown select', async () => {
|
||||
const { baseElement, getByRole } = setup({}, mockStore(initialState));
|
||||
const { baseElement, getAllByRole, getByRole } = setup(
|
||||
{ maxRow: 50000 },
|
||||
mockStore(initialState),
|
||||
);
|
||||
const dropdown = baseElement.getElementsByClassName(
|
||||
'ant-dropdown-trigger',
|
||||
)[0];
|
||||
|
||||
userEvent.click(dropdown);
|
||||
await waitFor(() => expect(getByRole('menu')).toBeInTheDocument());
|
||||
|
||||
const expectedLabels = [10, 100, 1000, 10000, 50000].map(i =>
|
||||
convertToNumWithSpaces(i),
|
||||
);
|
||||
const actualLabels = getAllByRole('menuitem').map(elem =>
|
||||
elem.textContent?.trim(),
|
||||
);
|
||||
|
||||
expect(actualLabels).toEqual(expectedLabels);
|
||||
});
|
||||
|
||||
it('renders dropdown select correctly when maxRow is less than 10', async () => {
|
||||
const { baseElement, getAllByRole, getByRole } = setup(
|
||||
{ maxRow: 5 },
|
||||
mockStore(initialState),
|
||||
);
|
||||
const dropdown = baseElement.getElementsByClassName(
|
||||
'ant-dropdown-trigger',
|
||||
)[0];
|
||||
|
||||
userEvent.click(dropdown);
|
||||
await waitFor(() => expect(getByRole('menu')).toBeInTheDocument());
|
||||
|
||||
const expectedLabels = [5].map(i => convertToNumWithSpaces(i));
|
||||
const actualLabels = getAllByRole('menuitem').map(elem =>
|
||||
elem.textContent?.trim(),
|
||||
);
|
||||
|
||||
expect(actualLabels).toEqual(expectedLabels);
|
||||
});
|
||||
|
||||
it('renders dropdown select correctly when maxRow is a multiple of 10', async () => {
|
||||
const { baseElement, getAllByRole, getByRole } = setup(
|
||||
{ maxRow: 10000 },
|
||||
mockStore(initialState),
|
||||
);
|
||||
const dropdown = baseElement.getElementsByClassName(
|
||||
'ant-dropdown-trigger',
|
||||
)[0];
|
||||
|
||||
userEvent.click(dropdown);
|
||||
await waitFor(() => expect(getByRole('menu')).toBeInTheDocument());
|
||||
|
||||
const expectedLabels = [10, 100, 1000, 10000].map(i =>
|
||||
convertToNumWithSpaces(i),
|
||||
);
|
||||
const actualLabels = getAllByRole('menuitem').map(elem =>
|
||||
elem.textContent?.trim(),
|
||||
);
|
||||
|
||||
expect(actualLabels).toEqual(expectedLabels);
|
||||
});
|
||||
|
||||
it('dispatches QUERY_EDITOR_SET_QUERY_LIMIT action on dropdown menu click', async () => {
|
||||
@@ -133,7 +186,7 @@ describe('QueryLimitSelect', () => {
|
||||
expect(store.getActions()).toEqual([
|
||||
{
|
||||
type: 'QUERY_EDITOR_SET_QUERY_LIMIT',
|
||||
queryLimit: LIMIT_DROPDOWN[expectedIndex],
|
||||
queryLimit: 100,
|
||||
queryEditor: {
|
||||
id: defaultQueryEditor.id,
|
||||
},
|
||||
|
||||
Reference in New Issue
Block a user