11import { SnubaQueryDataSourceFixture } from 'sentry-fixture/detectors' ;
22import { EventFixture } from 'sentry-fixture/event' ;
3+ import { GroupFixture } from 'sentry-fixture/group' ;
34
4- import { render , screen } from 'sentry-test/reactTestingLibrary' ;
5+ import { render , screen , waitFor } from 'sentry-test/reactTestingLibrary' ;
56
67import { DataConditionType } from 'sentry/types/workflowEngine/dataConditions' ;
78import type { MetricCondition } from 'sentry/types/workflowEngine/detectors' ;
@@ -16,6 +17,18 @@ describe('MetricDetectorTriggeredSection', () => {
1617 } ;
1718 const dataSource = SnubaQueryDataSourceFixture ( ) ;
1819
20+ beforeEach ( ( ) => {
21+ MockApiClient . clearMockResponses ( ) ;
22+ MockApiClient . addMockResponse ( {
23+ url : '/organizations/org-slug/members/' ,
24+ body : [ ] ,
25+ } ) ;
26+ MockApiClient . addMockResponse ( {
27+ url : '/organizations/org-slug/users/' ,
28+ body : [ ] ,
29+ } ) ;
30+ } ) ;
31+
1932 it ( 'renders nothing when event has no occurrence' , ( ) => {
2033 const event = EventFixture ( {
2134 occurrence : null ,
@@ -76,6 +89,7 @@ describe('MetricDetectorTriggeredSection', () => {
7689
7790 it ( 'renders metric detector details with static condition' , ( ) => {
7891 const event = EventFixture ( {
92+ dateCreated : undefined ,
7993 occurrence : {
8094 id : '1' ,
8195 eventId : 'event-1' ,
@@ -116,4 +130,47 @@ describe('MetricDetectorTriggeredSection', () => {
116130 expect ( screen . getByRole ( 'cell' , { name : 'Evaluated Value' } ) ) . toBeInTheDocument ( ) ;
117131 expect ( screen . getByRole ( 'cell' , { name : '150' } ) ) . toBeInTheDocument ( ) ;
118132 } ) ;
133+
134+ it ( 'renders contributing issues section for errors dataset' , async ( ) => {
135+ const eventDateCreated = '2024-01-01T00:00:00Z' ;
136+ // Start date is eventDateCreated minus the timeWindow (60 seconds) minus 1 extra minute
137+ const startDate = '2023-12-31T23:58:00.000Z' ;
138+
139+ const contributingIssuesMock = MockApiClient . addMockResponse ( {
140+ url : `/organizations/org-slug/issues/?end=2017-10-17T02%3A41%3A20.000Z&limit=5&query=issue.type%3Aerror%20event.type%3Aerror%20is%3Aunresolved&sort=freq&start=${ encodeURIComponent ( startDate ) } ` ,
141+ body : [ GroupFixture ( ) ] ,
142+ } ) ;
143+
144+ const event = EventFixture ( {
145+ dateCreated : eventDateCreated ,
146+ occurrence : {
147+ id : '1' ,
148+ eventId : 'event-1' ,
149+ fingerprint : [ 'fingerprint' ] ,
150+ issueTitle : 'Test Issue' ,
151+ subtitle : 'Subtitle' ,
152+ resourceId : 'resource-1' ,
153+ evidenceData : {
154+ conditions : [ condition ] ,
155+ dataSources : [ dataSource ] ,
156+ value : 150 ,
157+ } ,
158+ evidenceDisplay : [ ] ,
159+ type : 8001 ,
160+ detectionTime : '2024-01-01T00:00:00Z' ,
161+ } ,
162+ } ) ;
163+
164+ render ( < MetricDetectorTriggeredSection event = { event } /> ) ;
165+
166+ await waitFor ( ( ) => {
167+ expect (
168+ screen . getByRole ( 'region' , { name : 'Contributing Issues' } )
169+ ) . toBeInTheDocument ( ) ;
170+ } ) ;
171+
172+ expect ( contributingIssuesMock ) . toHaveBeenCalled ( ) ;
173+
174+ await screen . findByRole ( 'link' , { name : 'RequestError' } ) ;
175+ } ) ;
119176} ) ;
0 commit comments