loadingContainer.spec.tsx 1.4 KB

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