import {render, screen} from 'sentry-test/reactTestingLibrary';
import PanelTable from 'sentry/components/panels/panelTable';
describe('PanelTable', function () {
const createWrapper = (props = {}) =>
render(
Cell 1
Cell 2
Cell 3
);
it('renders headers', function () {
createWrapper();
expect(screen.getAllByText(/Header [1-3]/)).toHaveLength(3);
// 3 divs from headers, 3 from "body"
expect(screen.getAllByTestId('cell')).toHaveLength(3);
expect(screen.getByText('Header 1')).toBeInTheDocument();
});
it('renders loading', function () {
createWrapper({isLoading: true});
// Does not render content
expect(screen.queryByTestId('cell')).not.toBeInTheDocument();
// renders loading
expect(screen.getByTestId('loading-indicator')).toBeInTheDocument();
});
it('renders custom loader', function () {
createWrapper({
isLoading: true,
loader: loading,
});
// Does not render content
expect(screen.queryByTestId('cell')).not.toBeInTheDocument();
// no default loader
expect(screen.queryByTestId('loading-indicator')).not.toBeInTheDocument();
// has custom loader
expect(screen.getByTestId('custom-loader')).toBeInTheDocument();
});
it('ignores empty state when loading', function () {
createWrapper({isLoading: true, isEmpty: true});
// renders loading
expect(screen.getByTestId('loading-indicator')).toBeInTheDocument();
expect(screen.queryByText('There are no items to display')).not.toBeInTheDocument();
});
it('renders empty state with custom message', function () {
createWrapper({isEmpty: true, emptyMessage: 'I am empty inside'});
// Does not render content
expect(screen.queryByTestId('cell')).not.toBeInTheDocument();
// renders empty state
expect(screen.getByText('I am empty inside')).toBeInTheDocument();
});
it('children can be a render function', function () {
render(
1, 2
, 3
]}
>
{() => I am child
}
);
expect(screen.getByText('I am child')).toBeInTheDocument();
});
});