metricReadout.spec.tsx 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687
  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('limits smallest rate', () => {
  35. render(<MetricReadout title="Rate" unit={RateUnit.PER_MINUTE} value={0.0002441} />);
  36. expect(screen.getByRole('heading', {name: 'Rate'})).toBeInTheDocument();
  37. expect(screen.getByText('<0.01/min')).toBeInTheDocument();
  38. });
  39. it('renders milliseconds', () => {
  40. render(
  41. <MetricReadout title="Duration" unit={DurationUnit.MILLISECOND} value={223142123} />
  42. );
  43. expect(screen.getByRole('heading', {name: 'Duration'})).toBeInTheDocument();
  44. expect(screen.getByText('2.58d')).toBeInTheDocument();
  45. });
  46. it('renders bytes', () => {
  47. render(<MetricReadout title="Size" unit={SizeUnit.BYTE} value={1172316} />);
  48. expect(screen.getByRole('heading', {name: 'Size'})).toBeInTheDocument();
  49. expect(screen.getByText('1.1 MiB')).toBeInTheDocument();
  50. });
  51. it('renders percentages', () => {
  52. render(<MetricReadout title="Percentage" unit="percentage" value={0.2352} />);
  53. expect(screen.getByRole('heading', {name: 'Percentage'})).toBeInTheDocument();
  54. expect(screen.getByText('23.52%')).toBeInTheDocument();
  55. });
  56. it('limits smallest percentage', () => {
  57. render(<MetricReadout title="Percentage" unit="percentage" value={0.000022317} />);
  58. expect(screen.getByRole('heading', {name: 'Percentage'})).toBeInTheDocument();
  59. expect(screen.getByText('<0.01%')).toBeInTheDocument();
  60. });
  61. it('renders counts', () => {
  62. render(<MetricReadout title="Count" unit="count" value={7800123} />);
  63. expect(screen.getByRole('heading', {name: 'Count'})).toBeInTheDocument();
  64. expect(screen.getByText('7.8m')).toBeInTheDocument();
  65. });
  66. });