metricReadout.spec.tsx 2.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566
  1. import {render, screen} from 'sentry-test/reactTestingLibrary';
  2. import {DurationUnit, RateUnit, SizeUnit} from 'sentry/utils/discover/fields';
  3. import {MetricReadout} from 'sentry/views/performance/metricReadout';
  4. describe('MetricReadout', function () {
  5. it('shows a loading spinner if data is loading', () => {
  6. render(
  7. <MetricReadout
  8. title="Duration"
  9. unit={DurationUnit.MILLISECOND}
  10. value={undefined}
  11. isLoading
  12. />
  13. );
  14. expect(screen.getByText('Duration')).toBeInTheDocument();
  15. expect(screen.getByTestId('loading-indicator')).toBeInTheDocument();
  16. });
  17. it('shows placeholder text if data is missing', () => {
  18. render(
  19. <MetricReadout title="Duration" unit={DurationUnit.MILLISECOND} value={undefined} />
  20. );
  21. expect(screen.getByRole('heading', {name: 'Duration'})).toBeInTheDocument();
  22. expect(screen.getByText('--')).toBeInTheDocument();
  23. });
  24. it('parses strings', () => {
  25. render(<MetricReadout title="Rate" unit={RateUnit.PER_MINUTE} value={'17.8'} />);
  26. expect(screen.getByRole('heading', {name: 'Rate'})).toBeInTheDocument();
  27. expect(screen.getByText('17.8/min')).toBeInTheDocument();
  28. });
  29. it('renders rates', () => {
  30. render(<MetricReadout title="Rate" unit={RateUnit.PER_MINUTE} value={17.8} />);
  31. expect(screen.getByRole('heading', {name: 'Rate'})).toBeInTheDocument();
  32. expect(screen.getByText('17.8/min')).toBeInTheDocument();
  33. });
  34. it('renders milliseconds', () => {
  35. render(
  36. <MetricReadout title="Duration" unit={DurationUnit.MILLISECOND} value={223142123} />
  37. );
  38. expect(screen.getByRole('heading', {name: 'Duration'})).toBeInTheDocument();
  39. expect(screen.getByText('2.58d')).toBeInTheDocument();
  40. });
  41. it('renders bytes', () => {
  42. render(<MetricReadout title="Size" unit={SizeUnit.BYTE} value={1172316} />);
  43. expect(screen.getByRole('heading', {name: 'Size'})).toBeInTheDocument();
  44. expect(screen.getByText('1.1 MiB')).toBeInTheDocument();
  45. });
  46. it('renders counts', () => {
  47. render(<MetricReadout title="Count" unit="count" value={7800123} />);
  48. expect(screen.getByRole('heading', {name: 'Count'})).toBeInTheDocument();
  49. expect(screen.getByText('7.8m')).toBeInTheDocument();
  50. });
  51. });