metricHistory.spec.tsx 2.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273
  1. import range from 'lodash/range';
  2. import {IncidentFixture} from 'sentry-fixture/incident';
  3. // import {MetricRuleActivationFixture} from 'sentry-fixture/metricRuleActivation';
  4. import {render, screen, userEvent} from 'sentry-test/reactTestingLibrary';
  5. import MetricHistory from './metricHistory';
  6. describe('MetricHistory', () => {
  7. it('renders empty state', () => {
  8. render(<MetricHistory incidents={[]} />);
  9. expect(screen.getByText('No alerts triggered during this time.')).toBeInTheDocument();
  10. });
  11. it('renders a critical incident', () => {
  12. render(<MetricHistory incidents={[IncidentFixture()]} />);
  13. expect(screen.getByRole('link', {name: '#123'})).toBeInTheDocument();
  14. expect(
  15. screen.getByText('Number of errors above 70 within 1 hour')
  16. ).toBeInTheDocument();
  17. expect(screen.getByText('12hr')).toBeInTheDocument();
  18. });
  19. it('renders a critical % change incident', () => {
  20. const incident = IncidentFixture();
  21. incident.alertRule.comparisonDelta = 60;
  22. render(<MetricHistory incidents={[incident]} />);
  23. expect(
  24. screen.getByText(
  25. 'Number of errors 70% higher in 1 hour compared to the same time one hour ago'
  26. )
  27. ).toBeInTheDocument();
  28. });
  29. it('collapses the incidents panel if the number of incidents > 3', async () => {
  30. const incidents = range(0, 10).map(id =>
  31. IncidentFixture({id: `${id}`, identifier: `${id}`})
  32. );
  33. render(<MetricHistory incidents={incidents} />);
  34. expect(screen.getAllByRole('link').length).toBe(3);
  35. await userEvent.click(screen.getByRole('button', {name: 'Show 7 Hidden Alerts'}));
  36. expect(screen.getAllByRole('link').length).toBe(incidents.length);
  37. });
  38. it('filters incidents with no activities (unexpected behavior)', () => {
  39. const incidents = [IncidentFixture({activities: []})];
  40. render(<MetricHistory incidents={incidents} />);
  41. expect(screen.getByText('No alerts triggered during this time.')).toBeInTheDocument();
  42. });
  43. // it('renders activation starts and ends', () => {
  44. // // render 1 activation that has completed
  45. // // render 1 activation that has not finished yet
  46. // const activations = [
  47. // MetricRuleActivationFixture({
  48. // id: `1`,
  49. // activator: '1',
  50. // dateCreated: '2024-05-02T12:00:00.123Z',
  51. // isComplete: true,
  52. // finishedAt: '2024-05-02T13:00:00.123Z',
  53. // }),
  54. // MetricRuleActivationFixture({
  55. // id: `2`,
  56. // activator: '2',
  57. // dateCreated: '2024-05-02T17:00:00.123Z',
  58. // }),
  59. // ];
  60. // render(<MetricHistory incidents={[]} activations={activations} />);
  61. // expect(screen.getAllByText('Start monitoring.').length).toBe(2);
  62. // expect(screen.getAllByText('Finish monitoring.').length).toBe(1);
  63. // });
  64. });