loadingContainer.spec.jsx 1.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243
  1. import {cleanup, render, screen} from 'sentry-test/reactTestingLibrary';
  2. import LoadingContainer from 'sentry/components/loading/loadingContainer';
  3. function renderComponent(props) {
  4. return render(
  5. <LoadingContainer {...props}>
  6. <div>hello!</div>
  7. </LoadingContainer>
  8. );
  9. }
  10. describe('LoadingContainer', () => {
  11. afterEach(cleanup);
  12. it('handles normal state', () => {
  13. renderComponent();
  14. expect(screen.getByText('hello!')).toBeInTheDocument();
  15. expect(() => screen.getByTestId('loading-indicator')).toThrow();
  16. });
  17. it('handles loading state', () => {
  18. const {rerender} = renderComponent({
  19. isLoading: true,
  20. });
  21. expect(screen.getByText('hello!')).toBeInTheDocument();
  22. expect(screen.getByTestId('loading-indicator')).toBeInTheDocument();
  23. rerender(<LoadingContainer isLoading />);
  24. expect(screen.queryByText('hello!')).not.toBeInTheDocument();
  25. expect(screen.getByTestId('loading-indicator')).toBeInTheDocument();
  26. });
  27. it('handles reloading state', () => {
  28. const {rerender} = renderComponent({
  29. isReloading: true,
  30. });
  31. expect(screen.getByText('hello!')).toBeInTheDocument();
  32. expect(screen.getByTestId('loading-indicator')).toBeInTheDocument();
  33. rerender(<LoadingContainer isReloading />);
  34. expect(screen.queryByText('hello!')).not.toBeInTheDocument();
  35. expect(screen.getByTestId('loading-indicator')).toBeInTheDocument();
  36. });
  37. });