Skip to content

Commit

Permalink
fix tests
Browse files Browse the repository at this point in the history
  • Loading branch information
villebro committed Apr 27, 2022
1 parent d62aa96 commit 801100d
Show file tree
Hide file tree
Showing 6 changed files with 88 additions and 70 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -122,12 +122,12 @@ describe('Test datatable', () => {
});
it('Data Pane opens and loads results', () => {
cy.contains('Results').click();
cy.get('[data-test="row-count-label"]').contains('26 rows retrieved');
cy.get('[data-test="row-count-label"]').contains('26 rows');
cy.get('.ant-empty-description').should('not.exist');
});
it('Datapane loads view samples', () => {
cy.contains('Samples').click();
cy.get('[data-test="row-count-label"]').contains('1k rows retrieved');
cy.get('[data-test="row-count-label"]').contains('1k rows');
cy.get('.ant-empty-description').should('not.exist');
});
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,9 +20,14 @@ import React from 'react';
import { render, screen } from 'spec/helpers/testing-library';
import { RowCount } from '.';

test('Render a RowCount', () => {
test('Render a RowCount with a single row', () => {
render(<RowCount data={[{}]} loading={false} />);
expect(screen.getByText('1 row')).toBeInTheDocument();
});

test('Render a RowCount with multiple rows', () => {
render(<RowCount data={[{}, {}, {}]} loading={false} />);
expect(screen.getByText('3 rows retrieved')).toBeInTheDocument();
expect(screen.getByText('3 rows')).toBeInTheDocument();
});

test('Render a RowCount on loading', () => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,7 @@ describe('DataTablesPane', () => {
useRedux: true,
});
userEvent.click(screen.getByText('Results'));
expect(await screen.findByText('0 rows retrieved')).toBeVisible();
expect(await screen.findByText('0 rows')).toBeVisible();
expect(await screen.findByLabelText('Collapse data panel')).toBeVisible();
localStorage.clear();
});
Expand All @@ -114,7 +114,7 @@ describe('DataTablesPane', () => {
useRedux: true,
});
userEvent.click(screen.getByText('Samples'));
expect(await screen.findByText('0 rows retrieved')).toBeVisible();
expect(await screen.findByText('0 rows')).toBeVisible();
expect(await screen.findByLabelText('Collapse data panel')).toBeVisible();
});

Expand Down Expand Up @@ -158,7 +158,7 @@ describe('DataTablesPane', () => {
},
);
userEvent.click(screen.getByText('Results'));
expect(await screen.findByText('1 rows retrieved')).toBeVisible();
expect(await screen.findByText('1 row')).toBeVisible();

userEvent.click(screen.getByLabelText('Copy'));
expect(copyToClipboardSpy).toHaveBeenCalledWith(
Expand Down Expand Up @@ -210,7 +210,7 @@ describe('DataTablesPane', () => {
},
);
userEvent.click(screen.getByText('Results'));
expect(await screen.findByText('2 rows retrieved')).toBeVisible();
expect(await screen.findByText('2 rows')).toBeVisible();
expect(screen.getByText('Action')).toBeVisible();
expect(screen.getByText('Horror')).toBeVisible();

Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
/**
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. The ASF licenses this file
* to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance
* with the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*/
import React from 'react';
import { render, screen } from 'spec/helpers/testing-library';
import userEvent from '@testing-library/user-event';

import RowCountLabel from '.';

test('RowCountLabel renders singular result', () => {
render(<RowCountLabel rowcount={1} limit={100} />);
const expectedText = '1 row';
expect(screen.getByText(expectedText)).toBeInTheDocument();
userEvent.hover(screen.getByText(expectedText));
expect(screen.queryByRole('tooltip')).not.toBeInTheDocument();
});

test('RowCountLabel renders plural result', () => {
render(<RowCountLabel rowcount={2} limit={100} />);
const expectedText = '2 rows';
expect(screen.getByText(expectedText)).toBeInTheDocument();
userEvent.hover(screen.getByText(expectedText));
expect(screen.queryByRole('tooltip')).not.toBeInTheDocument();
});

test('RowCountLabel renders limit with danger and tooltip', async () => {
render(<RowCountLabel rowcount={100} limit={100} />);
const expectedText = '100 rows';
expect(screen.getByText(expectedText)).toBeInTheDocument();
userEvent.hover(screen.getByText(expectedText));
const tooltip = await screen.findByRole('tooltip');
expect(tooltip).toHaveTextContent('Limit reached');
expect(tooltip).toHaveStyle('background: rgba(0, 0, 0, 0.902);');
});

test('RowCountLabel renders loading', () => {
render(<RowCountLabel loading />);
const expectedText = 'Loading...';
expect(screen.getByText(expectedText)).toBeInTheDocument();
userEvent.hover(screen.getByText(expectedText));
expect(screen.queryByRole('tooltip')).not.toBeInTheDocument();
});
30 changes: 18 additions & 12 deletions superset-frontend/src/explore/components/RowCountLabel/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -34,20 +34,26 @@ export default function RowCountLabel(props: RowCountLabelProps) {
const type =
limitReached || (rowcount === 0 && !loading) ? 'danger' : 'default';
const formattedRowCount = getNumberFormatter()(rowcount);
const tooltip = (limitReached || loading) && (
<span>
{limitReached && <div>{t('Limit reached')}</div>}
{loading ? 'Loading' : rowcount}
</span>
const label = (
<Label type={type} data-test="row-count-label">
{loading
? 'Loading...'
: tn('%s row', '%s rows', rowcount, formattedRowCount)}
</Label>
);
return (
<Tooltip id="tt-rowcount-tooltip" title={tooltip}>
<Label type={type} data-test="row-count-label">
{loading
? 'Loading...'
: tn('%s row', '%s rows', rowcount, formattedRowCount)}
</Label>
return limitReached ? (
<Tooltip
id="tt-rowcount-tooltip"
title={
<span>
<div>{t('Limit reached')}</div>
</span>
}
>
{label}
</Tooltip>
) : (
label
);
}

Expand Down

0 comments on commit 801100d

Please sign in to comment.