errorMigrationWarning.spec.tsx 2.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384
  1. import {MetricRuleFixture} from 'sentry-fixture/metricRule';
  2. import {OrganizationFixture} from 'sentry-fixture/organization';
  3. import {ProjectFixture} 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 = ProjectFixture();
  9. const organization = OrganizationFixture();
  10. afterEach(() => {
  11. MockApiClient.clearMockResponses();
  12. });
  13. it('renders migration message for filtering archived issues', async () => {
  14. const rule = MetricRuleFixture({
  15. projects: [project.slug],
  16. latestIncident: null,
  17. dataset: Dataset.ERRORS,
  18. query: '',
  19. });
  20. MockApiClient.addMockResponse({
  21. url: `/organizations/${organization.slug}/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 = MetricRuleFixture({
  33. projects: [project.slug],
  34. latestIncident: null,
  35. dataset: Dataset.ERRORS,
  36. query: '',
  37. });
  38. MockApiClient.addMockResponse({
  39. url: `/organizations/${organization.slug}/prompts-activity/`,
  40. body: {},
  41. });
  42. const dismissMock = MockApiClient.addMockResponse({
  43. url: `/organizations/${organization.slug}/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. it('renders nothing if the alert was created after the `is:unresolved` feature became available', () => {
  55. const rule = MetricRuleFixture({
  56. projects: [project.slug],
  57. latestIncident: null,
  58. dataset: Dataset.ERRORS,
  59. query: '',
  60. dateCreated: '2024-01-01T00:00:00Z',
  61. });
  62. const promptApi = MockApiClient.addMockResponse({
  63. url: `/organizations/${organization.slug}/prompts-activity/`,
  64. body: {},
  65. });
  66. const {container} = render(<ErrorMigrationWarning project={project} rule={rule} />, {
  67. organization,
  68. });
  69. expect(container).toBeEmptyDOMElement();
  70. expect(promptApi).not.toHaveBeenCalled();
  71. });
  72. });