@@ -7,8 +7,13 @@ import {Button} from 'sentry/components/core/button';
7
7
import { AutofixChanges } from 'sentry/components/events/autofix/autofixChanges' ;
8
8
import {
9
9
type AutofixChangesStep ,
10
+ AutofixStatus ,
10
11
AutofixStepType ,
11
12
} from 'sentry/components/events/autofix/types' ;
13
+ import {
14
+ useAutofixData ,
15
+ useAutofixRepos ,
16
+ } from 'sentry/components/events/autofix/useAutofix' ;
12
17
13
18
jest . mock ( 'sentry/components/core/button' , ( ) => ( {
14
19
Button : jest . fn ( props => {
@@ -20,6 +25,8 @@ jest.mock('sentry/components/core/button', () => ({
20
25
} ) ,
21
26
} ) ) ;
22
27
28
+ jest . mock ( 'sentry/components/events/autofix/useAutofix' ) ;
29
+
23
30
const mockButton = Button as jest . MockedFunction < typeof Button > ;
24
31
25
32
describe ( 'AutofixChanges' , ( ) => {
@@ -35,6 +42,24 @@ describe('AutofixChanges', () => {
35
42
beforeEach ( ( ) => {
36
43
MockApiClient . clearMockResponses ( ) ;
37
44
mockButton . mockClear ( ) ;
45
+ jest . mocked ( useAutofixRepos ) . mockReset ( ) ;
46
+ jest . mocked ( useAutofixData ) . mockReset ( ) ;
47
+ jest . mocked ( useAutofixRepos ) . mockReturnValue ( {
48
+ repos : [ ] ,
49
+ codebases : { } ,
50
+ } ) ;
51
+ jest . mocked ( useAutofixData ) . mockReturnValue ( {
52
+ data : {
53
+ request : {
54
+ repos : [ ] ,
55
+ } ,
56
+ codebases : { } ,
57
+ created_at : '2024-01-01T00:00:00Z' ,
58
+ run_id : '456' ,
59
+ status : AutofixStatus . COMPLETED ,
60
+ } ,
61
+ isPending : false ,
62
+ } ) ;
38
63
} ) ;
39
64
40
65
it ( 'passes correct analytics props for Create PR button when write access is enabled' , async ( ) => {
@@ -44,8 +69,33 @@ describe('AutofixChanges', () => {
44
69
body : {
45
70
genAIConsent : { ok : true } ,
46
71
integration : { ok : true } ,
47
- githubWriteIntegration : {
48
- repos : [ { ok : true , owner : 'owner' , name : 'hello-world' , id : 100 } ] ,
72
+ githubWriteIntegration : { } ,
73
+ } ,
74
+ } ) ;
75
+
76
+ MockApiClient . addMockResponse ( {
77
+ url : '/issues/123/autofix/update/' ,
78
+ method : 'POST' ,
79
+ body : { ok : true } ,
80
+ } ) ;
81
+
82
+ jest . mocked ( useAutofixRepos ) . mockReturnValue ( {
83
+ repos : [
84
+ {
85
+ name : 'org/repo' ,
86
+ owner : 'org' ,
87
+ provider : 'github' ,
88
+ provider_raw : 'github' ,
89
+ external_id : '100' ,
90
+ is_readable : true ,
91
+ is_writeable : true ,
92
+ } ,
93
+ ] ,
94
+ codebases : {
95
+ '100' : {
96
+ repo_external_id : '100' ,
97
+ is_readable : true ,
98
+ is_writeable : true ,
49
99
} ,
50
100
} ,
51
101
} ) ;
@@ -78,6 +128,27 @@ describe('AutofixChanges', () => {
78
128
} ,
79
129
} ) ;
80
130
131
+ jest . mocked ( useAutofixRepos ) . mockReturnValue ( {
132
+ repos : [
133
+ {
134
+ name : 'org/repo' ,
135
+ owner : 'org' ,
136
+ provider : 'github' ,
137
+ provider_raw : 'github' ,
138
+ external_id : 'repo-123' ,
139
+ is_readable : true ,
140
+ is_writeable : false ,
141
+ } ,
142
+ ] ,
143
+ codebases : {
144
+ 'repo-123' : {
145
+ repo_external_id : 'repo-123' ,
146
+ is_readable : true ,
147
+ is_writeable : false ,
148
+ } ,
149
+ } ,
150
+ } ) ;
151
+
81
152
render ( < AutofixChanges { ...defaultProps } /> ) ;
82
153
83
154
// Find the last call to Button that matches our Setup button
@@ -108,6 +179,27 @@ describe('AutofixChanges', () => {
108
179
} ,
109
180
} ) ;
110
181
182
+ jest . mocked ( useAutofixRepos ) . mockReturnValue ( {
183
+ repos : [
184
+ {
185
+ name : 'org/repo' ,
186
+ owner : 'org' ,
187
+ provider : 'github' ,
188
+ provider_raw : 'github' ,
189
+ external_id : 'repo-123' ,
190
+ is_readable : true ,
191
+ is_writeable : true ,
192
+ } ,
193
+ ] ,
194
+ codebases : {
195
+ 'repo-123' : {
196
+ repo_external_id : 'repo-123' ,
197
+ is_readable : true ,
198
+ is_writeable : true ,
199
+ } ,
200
+ } ,
201
+ } ) ;
202
+
111
203
render ( < AutofixChanges { ...defaultProps } /> ) ;
112
204
113
205
await userEvent . click ( screen . getByRole ( 'button' , { name : 'Check Out Locally' } ) ) ;
@@ -137,6 +229,27 @@ describe('AutofixChanges', () => {
137
229
} ,
138
230
} ) ;
139
231
232
+ jest . mocked ( useAutofixRepos ) . mockReturnValue ( {
233
+ repos : [
234
+ {
235
+ name : 'org/repo' ,
236
+ owner : 'org' ,
237
+ provider : 'github' ,
238
+ provider_raw : 'github' ,
239
+ external_id : 'repo-123' ,
240
+ is_readable : true ,
241
+ is_writeable : false ,
242
+ } ,
243
+ ] ,
244
+ codebases : {
245
+ 'repo-123' : {
246
+ repo_external_id : 'repo-123' ,
247
+ is_readable : true ,
248
+ is_writeable : false ,
249
+ } ,
250
+ } ,
251
+ } ) ;
252
+
140
253
render ( < AutofixChanges { ...defaultProps } /> ) ;
141
254
142
255
const setupButtonCall = mockButton . mock . calls . find (
0 commit comments