panelTable.spec.jsx 2.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081
  1. import {render, screen} from 'sentry-test/reactTestingLibrary';
  2. import PanelTable from 'sentry/components/panels/panelTable';
  3. describe('PanelTable', function () {
  4. const createWrapper = (props = {}) =>
  5. render(
  6. <PanelTable headers={['Header 1', 'Header 2', 'Header 3']} {...props}>
  7. <div data-test-id="cell">Cell 1</div>
  8. <div data-test-id="cell">Cell 2</div>
  9. <div data-test-id="cell">Cell 3</div>
  10. </PanelTable>
  11. );
  12. it('renders headers', function () {
  13. createWrapper();
  14. expect(screen.getAllByText(/Header [1-3]/)).toHaveLength(3);
  15. // 3 divs from headers, 3 from "body"
  16. expect(screen.getAllByTestId('cell')).toHaveLength(3);
  17. expect(screen.getByText('Header 1')).toBeInTheDocument();
  18. });
  19. it('renders loading', function () {
  20. createWrapper({isLoading: true});
  21. // Does not render content
  22. expect(screen.queryByTestId('cell')).not.toBeInTheDocument();
  23. // renders loading
  24. expect(screen.getByTestId('loading-indicator')).toBeInTheDocument();
  25. });
  26. it('renders custom loader', function () {
  27. createWrapper({
  28. isLoading: true,
  29. loader: <span data-test-id="custom-loader">loading</span>,
  30. });
  31. // Does not render content
  32. expect(screen.queryByTestId('cell')).not.toBeInTheDocument();
  33. // no default loader
  34. expect(screen.queryByTestId('loading-indicator')).not.toBeInTheDocument();
  35. // has custom loader
  36. expect(screen.getByTestId('custom-loader')).toBeInTheDocument();
  37. });
  38. it('ignores empty state when loading', function () {
  39. createWrapper({isLoading: true, isEmpty: true});
  40. // renders loading
  41. expect(screen.getByTestId('loading-indicator')).toBeInTheDocument();
  42. expect(screen.queryByText('There are no items to display')).not.toBeInTheDocument();
  43. });
  44. it('renders empty state with custom message', function () {
  45. createWrapper({isEmpty: true, emptyMessage: 'I am empty inside'});
  46. // Does not render content
  47. expect(screen.queryByTestId('cell')).not.toBeInTheDocument();
  48. // renders empty state
  49. expect(screen.getByText('I am empty inside')).toBeInTheDocument();
  50. });
  51. it('children can be a render function', function () {
  52. render(
  53. <PanelTable
  54. headers={[<div key="1">1</div>, <div key="2">2</div>, <div key="3">3</div>]}
  55. >
  56. {() => <p>I am child</p>}
  57. </PanelTable>
  58. );
  59. expect(screen.getByText('I am child')).toBeInTheDocument();
  60. });
  61. });