Skip to content

Commit 6710b8f

Browse files
committed
tests
1 parent aafeb8d commit 6710b8f

File tree

7 files changed

+377
-240
lines changed

7 files changed

+377
-240
lines changed

static/app/components/events/autofix/autofixChanges.analytics.spec.tsx

Lines changed: 115 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,13 @@ import {Button} from 'sentry/components/core/button';
77
import {AutofixChanges} from 'sentry/components/events/autofix/autofixChanges';
88
import {
99
type AutofixChangesStep,
10+
AutofixStatus,
1011
AutofixStepType,
1112
} from 'sentry/components/events/autofix/types';
13+
import {
14+
useAutofixData,
15+
useAutofixRepos,
16+
} from 'sentry/components/events/autofix/useAutofix';
1217

1318
jest.mock('sentry/components/core/button', () => ({
1419
Button: jest.fn(props => {
@@ -20,6 +25,8 @@ jest.mock('sentry/components/core/button', () => ({
2025
}),
2126
}));
2227

28+
jest.mock('sentry/components/events/autofix/useAutofix');
29+
2330
const mockButton = Button as jest.MockedFunction<typeof Button>;
2431

2532
describe('AutofixChanges', () => {
@@ -35,6 +42,24 @@ describe('AutofixChanges', () => {
3542
beforeEach(() => {
3643
MockApiClient.clearMockResponses();
3744
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+
});
3863
});
3964

4065
it('passes correct analytics props for Create PR button when write access is enabled', async () => {
@@ -44,8 +69,33 @@ describe('AutofixChanges', () => {
4469
body: {
4570
genAIConsent: {ok: true},
4671
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,
4999
},
50100
},
51101
});
@@ -78,6 +128,27 @@ describe('AutofixChanges', () => {
78128
},
79129
});
80130

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+
81152
render(<AutofixChanges {...defaultProps} />);
82153

83154
// Find the last call to Button that matches our Setup button
@@ -108,6 +179,27 @@ describe('AutofixChanges', () => {
108179
},
109180
});
110181

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+
111203
render(<AutofixChanges {...defaultProps} />);
112204

113205
await userEvent.click(screen.getByRole('button', {name: 'Check Out Locally'}));
@@ -137,6 +229,27 @@ describe('AutofixChanges', () => {
137229
},
138230
});
139231

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+
140253
render(<AutofixChanges {...defaultProps} />);
141254

142255
const setupButtonCall = mockButton.mock.calls.find(

static/app/components/events/autofix/autofixChanges.tsx

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -384,7 +384,6 @@ function SetupAndCreatePRsButton({
384384
runId: string;
385385
}) {
386386
const {codebases} = useAutofixRepos(groupId);
387-
388387
if (
389388
!changes.every(
390389
change =>

0 commit comments

Comments
 (0)