11import { OrganizationFixture } from 'sentry-fixture/organization' ;
22import { OrganizationIntegrationsFixture } from 'sentry-fixture/organizationIntegrations' ;
33
4- import { act , renderHookWithProviders , waitFor } from 'sentry-test/reactTestingLibrary' ;
4+ import { act , renderHookWithProviders } from 'sentry-test/reactTestingLibrary' ;
55
66import 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