metricReadout.spec.tsx 2.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273
  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 percentages', () => {
  47. render(<MetricReadout title="Percentage" unit="percentage" value={0.2352} />);
  48. expect(screen.getByRole('heading', {name: 'Percentage'})).toBeInTheDocument();
  49. expect(screen.getByText('23.52%')).toBeInTheDocument();
  50. });
  51. it('renders counts', () => {
  52. render(<MetricReadout title="Count" unit="count" value={7800123} />);
  53. expect(screen.getByRole('heading', {name: 'Count'})).toBeInTheDocument();
  54. expect(screen.getByText('7.8m')).toBeInTheDocument();
  55. });
  56. });