Skip to content

Commit

Permalink
fix tests
Browse files Browse the repository at this point in the history
  • Loading branch information
mistercrunch committed Mar 29, 2024
1 parent acc8596 commit ac1d5f7
Show file tree
Hide file tree
Showing 16 changed files with 43 additions and 54 deletions.
1 change: 1 addition & 0 deletions superset-frontend/package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,7 @@ export interface ChartDataResponseResult {
is_cached: boolean;
query: string;
rowcount: number;
sql_rowcount: number;
stacktrace: string | null;
status:
| 'stopped'
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,7 @@ const basicQueryResult: ChartDataResponseResult = {
is_cached: false,
query: 'SELECT ...',
rowcount: 100,
sql_rowcount: 100,
stacktrace: null,
status: 'success',
from_dttm: null,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ export const useResultsTableView = (
<SingleQueryResultPane
colnames={chartDataResult[0].colnames}
coltypes={chartDataResult[0].coltypes}
rowcount={chartDataResult[0].sql_rowcount}
data={chartDataResult[0].data}
dataSize={DATA_SIZE}
datasourceId={datasourceId}
Expand All @@ -61,6 +62,7 @@ export const useResultsTableView = (
colnames={res.colnames}
coltypes={res.coltypes}
data={res.data}
rowcount={res.sql_rowcount}
dataSize={DATA_SIZE}
datasourceId={datasourceId}
isVisible
Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,6 @@ import Button from 'src/components/Button';
import Popover from 'src/components/Popover';
import { prepareCopyToClipboardTabularData } from 'src/utils/common';
import CopyToClipboard from 'src/components/CopyToClipboard';
import RowCountLabel from 'src/explore/components/RowCountLabel';
import { getTimeColumns, setTimeColumns } from './utils';

export const CellNull = styled('span')`
Expand Down Expand Up @@ -118,14 +117,6 @@ export const FilterInput = ({
);
};

export const RowCount = ({
data,
loading,
}: {
data?: Record<string, any>[];
loading: boolean;
}) => <RowCountLabel rowcount={data?.length ?? 0} loading={loading} />;

enum FormatPickerValue {
Formatted = 'formatted',
Original = 'original',
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,10 +22,10 @@ import { css, GenericDataType, styled } from '@superset-ui/core';
import {
CopyToClipboardButton,
FilterInput,
RowCount,
} from 'src/explore/components/DataTableControl';
import { applyFormattingToTabularData } from 'src/utils/common';
import { getTimeColumns } from 'src/explore/components/DataTableControl/utils';
import RowCountLabel from 'src/explore/components/RowCountLabel';
import { TableControlsProps } from '../types';

export const TableControlsWrapper = styled.div`
Expand All @@ -47,6 +47,7 @@ export const TableControls = ({
onInputChange,
columnNames,
columnTypes,
rowcount,
isLoading,
}: TableControlsProps) => {
const originalTimeColumns = getTimeColumns(datasourceId);
Expand Down Expand Up @@ -74,7 +75,7 @@ export const TableControls = ({
align-items: center;
`}
>
<RowCount data={data} loading={isLoading} />
<RowCountLabel rowcount={rowcount} loading={isLoading} />
<CopyToClipboardButton data={formattedData} columns={columnNames} />
</div>
</TableControlsWrapper>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@ export const SamplesPane = ({
const [colnames, setColnames] = useState<string[]>([]);
const [coltypes, setColtypes] = useState<GenericDataType[]>([]);
const [isLoading, setIsLoading] = useState<boolean>(false);
const [rowcount, setRowCount] = useState<number>(0);
const [responseError, setResponseError] = useState<string>('');
const datasourceId = useMemo(
() => `${datasource.id}__${datasource.type}`,
Expand All @@ -66,6 +67,7 @@ export const SamplesPane = ({
setData(ensureIsArray(response.data));
setColnames(ensureIsArray(response.colnames));
setColtypes(ensureIsArray(response.coltypes));
setRowCount(response.rowcount);
setResponseError('');
cache.add(datasource);
if (queryForce && actions) {
Expand Down Expand Up @@ -108,6 +110,7 @@ export const SamplesPane = ({
data={filteredData}
columnNames={colnames}
columnTypes={coltypes}
rowcount={rowcount}
datasourceId={datasourceId}
onInputChange={input => setFilterText(input)}
isLoading={isLoading}
Expand All @@ -128,6 +131,7 @@ export const SamplesPane = ({
data={filteredData}
columnNames={colnames}
columnTypes={coltypes}
rowcount={rowcount}
datasourceId={datasourceId}
onInputChange={input => setFilterText(input)}
isLoading={isLoading}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ export const SingleQueryResultPane = ({
data,
colnames,
coltypes,
rowcount,
datasourceId,
dataSize = 50,
isVisible,
Expand All @@ -55,6 +56,7 @@ export const SingleQueryResultPane = ({
data={filteredData}
columnNames={colnames}
columnTypes={coltypes}
rowcount={rowcount}
datasourceId={datasourceId}
onInputChange={input => setFilterText(input)}
isLoading={false}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -119,6 +119,7 @@ export const useResultsPane = ({
data={[]}
columnNames={[]}
columnTypes={[]}
rowcount={0}
datasourceId={queryFormData.datasource}
onInputChange={() => {}}
isLoading={false}
Expand All @@ -135,14 +136,14 @@ export const useResultsPane = ({
<EmptyStateMedium image="document.svg" title={title} />,
);
}

return resultResp
.slice(0, queryCount)
.map((result, idx) => (
<SingleQueryResultPane
data={result.data}
colnames={result.colnames}
coltypes={result.coltypes}
rowcount={result.rowcount}
dataSize={dataSize}
datasourceId={queryFormData.datasource}
key={idx}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,8 @@ describe('DataTablesPane', () => {
data: [{ __timestamp: 1230768000000, genre: 'Action' }],
colnames: ['__timestamp', 'genre'],
coltypes: [2, 1],
rowcount: 1,
sql_rowcount: 1,
},
],
},
Expand All @@ -103,7 +105,9 @@ describe('DataTablesPane', () => {
useRedux: true,
});
userEvent.click(screen.getByText('Results'));
expect(await screen.findByText('1 row')).toBeVisible();
expect(screen.container.querySelector('.row-count-label').textContent).toBe(

Check failure on line 108 in superset-frontend/src/explore/components/DataTablesPane/test/DataTablesPane.test.tsx

View workflow job for this annotation

GitHub Actions / frontend-build

Use toHaveTextContent instead of asserting on DOM node attributes
'1 row',
);

userEvent.click(screen.getByLabelText('Copy'));
expect(copyToClipboardSpy).toHaveBeenCalledTimes(1);
Expand All @@ -125,6 +129,8 @@ describe('DataTablesPane', () => {
],
colnames: ['__timestamp', 'genre'],
coltypes: [2, 1],
rowcount: 2,
sql_rowcount: 2,
},
],
},
Expand All @@ -134,7 +140,10 @@ describe('DataTablesPane', () => {
useRedux: true,
});
userEvent.click(screen.getByText('Results'));
expect(await screen.findByText('2 rows')).toBeVisible();
expect(screen.container.querySelector('.row-count-label').textContent).toBe(

Check failure on line 143 in superset-frontend/src/explore/components/DataTablesPane/test/DataTablesPane.test.tsx

View workflow job for this annotation

GitHub Actions / frontend-build

Use toHaveTextContent instead of asserting on DOM node attributes
'2 rows',
);

expect(screen.getByText('Action')).toBeVisible();
expect(screen.getByText('Horror')).toBeVisible();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,8 @@ describe('ResultsPaneOnDashboard', () => {
],
colnames: ['__timestamp', 'genre'],
coltypes: [2, 1],
rowcount: 2,
sql_rowcount: 2,
},
],
},
Expand Down Expand Up @@ -78,6 +80,8 @@ describe('ResultsPaneOnDashboard', () => {
data: [{ genre: 'Action' }, { genre: 'Horror' }],
colnames: ['genre'],
coltypes: [1],
rowcount: 2,
sql_rowcount: 2,
},
],
},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,8 @@ describe('SamplesPane', () => {
],
colnames: ['__timestamp', 'genre'],
coltypes: [2, 1],
rowcount: 2,
sql_rowcount: 2,
},
},
);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -71,11 +71,13 @@ export interface TableControlsProps {
columnNames: string[];
columnTypes: GenericDataType[];
isLoading: boolean;
rowcount: number;
}

export interface QueryResultInterface {
colnames: string[];
coltypes: GenericDataType[];
rowcount: number;
data: Record<string, any>[][];
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ test('RowCountLabel renders limit with danger and tooltip', async () => {
expect(screen.getByText(expectedText)).toBeInTheDocument();
userEvent.hover(screen.getByText(expectedText));
const tooltip = await screen.findByRole('tooltip');
expect(tooltip).toHaveTextContent('Limit reached');
expect(tooltip).toHaveTextContent('The row limit');
expect(tooltip).toHaveStyle('background: rgba(0, 0, 0, 0.902);');
});

Expand Down
10 changes: 7 additions & 3 deletions superset-frontend/src/explore/components/RowCountLabel/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -28,9 +28,13 @@ type RowCountLabelProps = {
loading?: boolean;
};

const limitReachedMsg = t(
'The row limit set for the chart was reached. The chart may show partial data.',
);

export default function RowCountLabel(props: RowCountLabelProps) {
const { rowcount = 0, limit, loading } = props;
const limitReached = rowcount === limit;
const { rowcount = 0, limit = null, loading } = props;
const limitReached = limit && rowcount >= limit;
const type =
limitReached || (rowcount === 0 && !loading) ? 'danger' : 'default';
const formattedRowCount = getNumberFormatter()(rowcount);
Expand All @@ -46,7 +50,7 @@ export default function RowCountLabel(props: RowCountLabelProps) {
</Label>
);
return limitReached ? (
<Tooltip id="tt-rowcount-tooltip" title={<span>{t('Limit reached')}</span>}>
<Tooltip id="tt-rowcount-tooltip" title={<span>{limitReachedMsg}</span>}>
{label}
</Tooltip>
) : (
Expand Down

0 comments on commit ac1d5f7

Please sign in to comment.