@@ -241,6 +241,51 @@ describe('ProjectMapperAdapter', () => {
241241 expect ( addButton ) . toBeEnabled ( ) ;
242242 } ) ;
243243
244+ it ( 'controls disabled during in-flight mutation' , async ( ) => {
245+ let resolveMutation ! : ( ) => void ;
246+ const pendingMutationOptions = {
247+ mutationFn : jest . fn (
248+ ( ) => new Promise < void > ( resolve => ( resolveMutation = resolve ) )
249+ ) ,
250+ } ;
251+
252+ render (
253+ < BackendJsonAutoSaveForm
254+ field = { makeConfig ( ) }
255+ initialValue = { [
256+ [ 101 , 'proj-1' ] ,
257+ [ 102 , 'proj-2' ] ,
258+ ] }
259+ mutationOptions = { pendingMutationOptions }
260+ /> ,
261+ { organization : org }
262+ ) ;
263+
264+ // Delete buttons should be enabled initially
265+ const deleteButtons = screen . getAllByRole ( 'button' , { name : 'Delete' } ) ;
266+ expect ( deleteButtons [ 0 ] ) . toBeEnabled ( ) ;
267+
268+ // Delete to trigger mutation
269+ await userEvent . click ( deleteButtons [ 0 ] ! ) ;
270+
271+ await waitFor ( ( ) => {
272+ expect ( pendingMutationOptions . mutationFn ) . toHaveBeenCalled ( ) ;
273+ } ) ;
274+
275+ // Delete buttons should be disabled during mutation
276+ const disabledButtons = screen . getAllByRole ( 'button' , { name : 'Delete' } ) ;
277+ expect ( disabledButtons . every ( btn => btn . hasAttribute ( 'disabled' ) ) ) . toBe ( true ) ;
278+
279+ // Resolve the mutation
280+ resolveMutation ( ) ;
281+
282+ // Controls should be re-enabled after mutation resolves
283+ await waitFor ( ( ) => {
284+ const enabledButtons = screen . getAllByRole ( 'button' , { name : 'Delete' } ) ;
285+ expect ( enabledButtons . some ( btn => ! btn . hasAttribute ( 'disabled' ) ) ) . toBe ( true ) ;
286+ } ) ;
287+ } ) ;
288+
244289 describe ( 'next button' , ( ) => {
245290 const nextButtonConfig = {
246291 nextButton : {
@@ -321,49 +366,4 @@ describe('ProjectMapperAdapter', () => {
321366 expect ( screen . queryByText ( 'Complete on Vercel' ) ) . not . toBeInTheDocument ( ) ;
322367 } ) ;
323368 } ) ;
324-
325- it ( 'controls disabled during in-flight mutation' , async ( ) => {
326- let resolveMutation ! : ( ) => void ;
327- const pendingMutationOptions = {
328- mutationFn : jest . fn (
329- ( ) => new Promise < void > ( resolve => ( resolveMutation = resolve ) )
330- ) ,
331- } ;
332-
333- render (
334- < BackendJsonAutoSaveForm
335- field = { makeConfig ( ) }
336- initialValue = { [
337- [ 101 , 'proj-1' ] ,
338- [ 102 , 'proj-2' ] ,
339- ] }
340- mutationOptions = { pendingMutationOptions }
341- /> ,
342- { organization : org }
343- ) ;
344-
345- // Delete buttons should be enabled initially
346- const deleteButtons = screen . getAllByRole ( 'button' , { name : 'Delete' } ) ;
347- expect ( deleteButtons [ 0 ] ) . toBeEnabled ( ) ;
348-
349- // Delete to trigger mutation
350- await userEvent . click ( deleteButtons [ 0 ] ! ) ;
351-
352- await waitFor ( ( ) => {
353- expect ( pendingMutationOptions . mutationFn ) . toHaveBeenCalled ( ) ;
354- } ) ;
355-
356- // Delete buttons should be disabled during mutation
357- const disabledButtons = screen . getAllByRole ( 'button' , { name : 'Delete' } ) ;
358- expect ( disabledButtons . every ( btn => btn . hasAttribute ( 'disabled' ) ) ) . toBe ( true ) ;
359-
360- // Resolve the mutation
361- resolveMutation ( ) ;
362-
363- // Controls should be re-enabled after mutation resolves
364- await waitFor ( ( ) => {
365- const enabledButtons = screen . getAllByRole ( 'button' , { name : 'Delete' } ) ;
366- expect ( enabledButtons . some ( btn => ! btn . hasAttribute ( 'disabled' ) ) ) . toBe ( true ) ;
367- } ) ;
368- } ) ;
369369} ) ;
0 commit comments