metricHistory.spec.tsx 1.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546
  1. import range from 'lodash/range';
  2. import {render, screen, userEvent} from 'sentry-test/reactTestingLibrary';
  3. import MetricHistory from './metricHistory';
  4. describe('MetricHistory', () => {
  5. it('renders empty state', () => {
  6. render(<MetricHistory incidents={[]} />);
  7. expect(screen.getByText('No alerts triggered during this time.')).toBeInTheDocument();
  8. });
  9. it('renders a critical incident', () => {
  10. render(<MetricHistory incidents={[TestStubs.Incident()]} />);
  11. expect(screen.getByRole('link', {name: '#123'})).toBeInTheDocument();
  12. expect(screen.getByText('Number of errors above 70 in 1 hour')).toBeInTheDocument();
  13. expect(screen.getByText('12hr')).toBeInTheDocument();
  14. });
  15. it('renders a critical % change incident', () => {
  16. const incident = TestStubs.Incident();
  17. incident.alertRule.comparisonDelta = 60;
  18. render(<MetricHistory incidents={[incident]} />);
  19. expect(
  20. screen.getByText(
  21. 'Number of errors 70% higher in 1 hour compared to the same time one hour ago'
  22. )
  23. ).toBeInTheDocument();
  24. });
  25. it('collapses the incidents panel if the number of incidents > 3', async () => {
  26. const incidents = range(0, 10).map(id =>
  27. TestStubs.Incident({id: `${id}`, identifier: `${id}`})
  28. );
  29. render(<MetricHistory incidents={incidents} />);
  30. expect(screen.getAllByRole('link').length).toBe(3);
  31. await userEvent.click(screen.getByRole('button', {name: 'Show 7 Hidden Alerts'}));
  32. expect(screen.getAllByRole('link').length).toBe(incidents.length);
  33. });
  34. it('filters incidents with no activities (unexpected behavior)', () => {
  35. const incidents = [TestStubs.Incident({activities: []})];
  36. render(<MetricHistory incidents={incidents} />);
  37. expect(screen.getByText('No alerts triggered during this time.')).toBeInTheDocument();
  38. });
  39. });