metricHistory.spec.tsx 1.8 KB

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