Skip to content

Commit b866d17

Browse files
committed
test(onboarding): Fix lint error and improve repo selection test coverage
Remove unnecessary async from handleRemove test to fix require-await lint error. Rename misleading test name to accurately reflect that only POST fails (GET succeeds with empty results). Add dedicated test for GET failure scenario. Simplify busy state test by removing waitFor dance that couldn't observe the intermediate state.
1 parent eca90ec commit b866d17

File tree

1 file changed

+28
-11
lines changed

1 file changed

+28
-11
lines changed

static/app/views/onboarding/components/useScmRepoSelection.spec.tsx

Lines changed: 28 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import {OrganizationFixture} from 'sentry-fixture/organization';
22
import {OrganizationIntegrationsFixture} from 'sentry-fixture/organizationIntegrations';
33

4-
import {act, renderHookWithProviders, waitFor} from 'sentry-test/reactTestingLibrary';
4+
import {act, renderHookWithProviders} from 'sentry-test/reactTestingLibrary';
55

66
import type {IntegrationRepository} from 'sentry/types/integrations';
77

@@ -116,7 +116,7 @@ describe('useScmRepoSelection', () => {
116116
);
117117
});
118118

119-
it('reverts onSelect when both GET and POST fail', async () => {
119+
it('reverts onSelect on POST failure', async () => {
120120
MockApiClient.addMockResponse({
121121
url: `/organizations/${organization.slug}/repos/`,
122122
body: [],
@@ -146,7 +146,30 @@ describe('useScmRepoSelection', () => {
146146
expect(onSelect).toHaveBeenCalledWith(undefined);
147147
});
148148

149-
it('handleRemove calls onSelect with undefined', async () => {
149+
it('reverts onSelect on GET failure', async () => {
150+
MockApiClient.addMockResponse({
151+
url: `/organizations/${organization.slug}/repos/`,
152+
statusCode: 500,
153+
body: {detail: 'Internal Error'},
154+
});
155+
156+
const {result} = renderHookWithProviders(
157+
() =>
158+
useScmRepoSelection({integration: mockIntegration, onSelect, reposByIdentifier}),
159+
{organization}
160+
);
161+
162+
await act(async () => {
163+
await result.current.handleSelect({value: 'getsentry/sentry'});
164+
});
165+
166+
expect(onSelect).toHaveBeenCalledWith(
167+
expect.objectContaining({id: '', name: 'sentry'})
168+
);
169+
expect(onSelect).toHaveBeenCalledWith(undefined);
170+
});
171+
172+
it('handleRemove calls onSelect with undefined', () => {
150173
const {result} = renderHookWithProviders(
151174
() =>
152175
useScmRepoSelection({integration: mockIntegration, onSelect, reposByIdentifier}),
@@ -160,7 +183,7 @@ describe('useScmRepoSelection', () => {
160183
expect(onSelect).toHaveBeenCalledWith(undefined);
161184
});
162185

163-
it('sets busy during selection and clears after', async () => {
186+
it('clears busy state after selection completes', async () => {
164187
MockApiClient.addMockResponse({
165188
url: `/organizations/${organization.slug}/repos/`,
166189
body: [
@@ -181,14 +204,8 @@ describe('useScmRepoSelection', () => {
181204

182205
expect(result.current.busy).toBe(false);
183206

184-
let selectPromise: Promise<void>;
185-
act(() => {
186-
selectPromise = result.current.handleSelect({value: 'getsentry/sentry'});
187-
});
188-
189-
await waitFor(() => expect(result.current.busy).toBe(false));
190207
await act(async () => {
191-
await selectPromise!;
208+
await result.current.handleSelect({value: 'getsentry/sentry'});
192209
});
193210

194211
expect(result.current.busy).toBe(false);

0 commit comments

Comments
 (0)