detectorSection.spec.tsx 4.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142
  1. import {EventFixture} from 'sentry-fixture/event';
  2. import {GroupFixture} from 'sentry-fixture/group';
  3. import {OrganizationFixture} from 'sentry-fixture/organization';
  4. import {ProjectFixture} from 'sentry-fixture/project';
  5. import {render, screen} from 'sentry-test/reactTestingLibrary';
  6. import {IssueCategory, IssueType} from 'sentry/types/group';
  7. import {IssueDetailsContext} from 'sentry/views/issueDetails/streamline/context';
  8. import {
  9. DetectorSection,
  10. getDetectorDetails,
  11. } from 'sentry/views/issueDetails/streamline/sidebar/detectorSection';
  12. describe('DetectorSection', () => {
  13. const detectorId = '123';
  14. const organization = OrganizationFixture();
  15. const project = ProjectFixture();
  16. const issueDetailsContext = {
  17. sectionData: {},
  18. detectorDetails: {},
  19. isSidebarOpen: true,
  20. navScrollMargin: 0,
  21. eventCount: 0,
  22. dispatch: jest.fn(),
  23. };
  24. it('does not display detector details when no detector is found', () => {
  25. const event = EventFixture();
  26. const group = GroupFixture();
  27. const detectorDetails = getDetectorDetails({event, organization, project});
  28. const {container} = render(
  29. <IssueDetailsContext.Provider value={{...issueDetailsContext, detectorDetails}}>
  30. <DetectorSection group={group} project={project} />
  31. </IssueDetailsContext.Provider>
  32. );
  33. expect(container).toBeEmptyDOMElement();
  34. });
  35. it('displays the detector details for a metric issue', () => {
  36. const event = EventFixture({
  37. contexts: {
  38. metric_alert: {
  39. alert_rule_id: '123',
  40. },
  41. },
  42. });
  43. const group = GroupFixture({
  44. issueCategory: IssueCategory.METRIC_ALERT,
  45. issueType: IssueType.METRIC_ISSUE_POC,
  46. });
  47. const detectorDetails = getDetectorDetails({event, organization, project});
  48. render(
  49. <IssueDetailsContext.Provider value={{...issueDetailsContext, detectorDetails}}>
  50. <DetectorSection group={group} project={project} />
  51. </IssueDetailsContext.Provider>
  52. );
  53. expect(screen.getByText('Metric Alert Detector')).toBeInTheDocument();
  54. const link = screen.getByRole('button', {name: 'View detector details'});
  55. expect(link).toHaveAttribute(
  56. 'href',
  57. `/organizations/${organization.slug}/alerts/rules/details/${detectorId}/`
  58. );
  59. expect(
  60. screen.getByText(
  61. 'This issue was created by a metric alert detector. View the detector details to learn more.'
  62. )
  63. ).toBeInTheDocument();
  64. });
  65. it('displays the detector details for a cron monitor', () => {
  66. const event = EventFixture({
  67. tags: [
  68. {
  69. key: 'monitor.slug',
  70. value: detectorId,
  71. },
  72. ],
  73. });
  74. const group = GroupFixture({
  75. issueCategory: IssueCategory.CRON,
  76. issueType: IssueType.MONITOR_CHECK_IN_FAILURE,
  77. });
  78. const detectorDetails = getDetectorDetails({event, organization, project});
  79. render(
  80. <IssueDetailsContext.Provider value={{...issueDetailsContext, detectorDetails}}>
  81. <DetectorSection group={group} project={project} />
  82. </IssueDetailsContext.Provider>
  83. );
  84. expect(screen.getByText('Cron Monitor')).toBeInTheDocument();
  85. const link = screen.getByRole('button', {name: 'View monitor details'});
  86. expect(link).toHaveAttribute(
  87. 'href',
  88. `/organizations/${organization.slug}/alerts/rules/crons/${project.slug}/${detectorId}/details/`
  89. );
  90. expect(
  91. screen.getByText(
  92. 'This issue was created by a cron monitor. View the monitor details to learn more.'
  93. )
  94. ).toBeInTheDocument();
  95. });
  96. it('displays the detector details for an uptime monitor', () => {
  97. const event = EventFixture({
  98. tags: [
  99. {
  100. key: 'uptime_rule',
  101. value: detectorId,
  102. },
  103. ],
  104. });
  105. const group = GroupFixture({
  106. issueCategory: IssueCategory.UPTIME,
  107. issueType: IssueType.UPTIME_DOMAIN_FAILURE,
  108. });
  109. const detectorDetails = getDetectorDetails({event, organization, project});
  110. render(
  111. <IssueDetailsContext.Provider value={{...issueDetailsContext, detectorDetails}}>
  112. <DetectorSection group={group} project={project} />
  113. </IssueDetailsContext.Provider>
  114. );
  115. expect(screen.getByText('Uptime Monitor')).toBeInTheDocument();
  116. const link = screen.getByRole('button', {name: 'View alert details'});
  117. expect(link).toHaveAttribute(
  118. 'href',
  119. `/organizations/${organization.slug}/alerts/rules/uptime/${project.slug}/${detectorId}/details/`
  120. );
  121. expect(
  122. screen.getByText(
  123. 'This issue was created by an uptime monitoring alert rule after detecting 3 consecutive failed checks.'
  124. )
  125. ).toBeInTheDocument();
  126. });
  127. });