metricReadout.spec.tsx 3.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105
  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. describe('percent_change', () => {
  62. it('renders negative percent change', () => {
  63. render(
  64. <MetricReadout title="% Difference" unit="percent_change" value={-0.2352} />
  65. );
  66. expect(screen.getByRole('heading', {name: '% Difference'})).toBeInTheDocument();
  67. expect(screen.getByText('-23.52%')).toBeInTheDocument();
  68. });
  69. it('renders positive percent change', () => {
  70. render(<MetricReadout title="% Difference" unit="percent_change" value={0.0552} />);
  71. expect(screen.getByRole('heading', {name: '% Difference'})).toBeInTheDocument();
  72. expect(screen.getByText('+5.52%')).toBeInTheDocument();
  73. });
  74. });
  75. it('renders counts', () => {
  76. render(<MetricReadout title="Count" unit="count" value={7800123} />);
  77. expect(screen.getByRole('heading', {name: 'Count'})).toBeInTheDocument();
  78. expect(screen.getByText('7.8m')).toBeInTheDocument();
  79. });
  80. });