metricHistory.spec.tsx 1.4 KB

1234567891011121314151617181920212223242526272829303132333435
  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')).toBeInTheDocument();
  13. expect(screen.getByText('12hr')).toBeInTheDocument();
  14. });
  15. it('collapses the incidents panel if the number of incidents > 3', async () => {
  16. const incidents = range(0, 10).map(id =>
  17. TestStubs.Incident({id: `${id}`, identifier: `${id}`})
  18. );
  19. render(<MetricHistory incidents={incidents} />);
  20. expect(screen.getAllByRole('link').length).toBe(3);
  21. await userEvent.click(screen.getByRole('button', {name: 'Show 7 Hidden Alerts'}));
  22. expect(screen.getAllByRole('link').length).toBe(incidents.length);
  23. });
  24. it('filters incidents with no activities (unexpected behavior)', () => {
  25. const incidents = [TestStubs.Incident({activities: []})];
  26. render(<MetricHistory incidents={incidents} />);
  27. expect(screen.getByText('No alerts triggered during this time.')).toBeInTheDocument();
  28. });
  29. });