errorMigrationWarning.spec.tsx 1.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364
  1. import {MetricRule} from 'sentry-fixture/metricRule';
  2. import {Organization} from 'sentry-fixture/organization';
  3. import {Project} from 'sentry-fixture/project';
  4. import {render, screen, userEvent} from 'sentry-test/reactTestingLibrary';
  5. import {Dataset} from 'sentry/views/alerts/rules/metric/types';
  6. import {ErrorMigrationWarning} from './errorMigrationWarning';
  7. describe('ErrorMigrationWarning', () => {
  8. const project = Project();
  9. const organization = Organization({features: ['metric-alert-ignore-archived']});
  10. afterEach(() => {
  11. MockApiClient.clearMockResponses();
  12. });
  13. it('renders migration message for filtering archived issues', async () => {
  14. const rule = MetricRule({
  15. projects: [project.slug],
  16. latestIncident: null,
  17. dataset: Dataset.ERRORS,
  18. query: '',
  19. });
  20. MockApiClient.addMockResponse({
  21. url: '/prompts-activity/',
  22. body: {},
  23. });
  24. render(<ErrorMigrationWarning project={project} rule={rule} />, {
  25. organization,
  26. });
  27. expect(
  28. await screen.findByRole('button', {name: 'Exclude archived issues'})
  29. ).toBeInTheDocument();
  30. });
  31. it('dismisses migration message', async () => {
  32. const rule = MetricRule({
  33. projects: [project.slug],
  34. latestIncident: null,
  35. dataset: Dataset.ERRORS,
  36. query: '',
  37. });
  38. MockApiClient.addMockResponse({
  39. url: '/prompts-activity/',
  40. body: {},
  41. });
  42. const dismissMock = MockApiClient.addMockResponse({
  43. url: '/prompts-activity/',
  44. method: 'PUT',
  45. body: {},
  46. });
  47. const {container} = render(<ErrorMigrationWarning project={project} rule={rule} />, {
  48. organization,
  49. });
  50. await userEvent.click(await screen.findByRole('button', {name: 'Dismiss Alert'}));
  51. expect(container).toBeEmptyDOMElement();
  52. expect(dismissMock).toHaveBeenCalledTimes(1);
  53. });
  54. });