@@ -4,6 +4,7 @@ import userEvent from '@testing-library/user-event';
44import { http , HttpResponse } from 'msw' ;
55import { describe , expect , it , vi } from 'vitest' ;
66
7+ import { deferred } from '../../../__tests__/async' ;
78import { openDialog } from '../../../__tests__/feature/dialog' ;
89import { type FakeFapiSeed , fapiUrl , holdRequests , serveFapi , worker } from '../../../__tests__/feature/fake-fapi' ;
910import {
@@ -501,6 +502,25 @@ describe('APIKeysTable', () => {
501502 expect ( screen . getByRole ( 'alertdialog' , { name : 'Copy your API Key' } ) ) . toBeVisible ( ) ;
502503 } ) ;
503504
505+ it ( 'clears the copy error when an overlapping copy succeeds after one fails' , async ( ) => {
506+ const { user } = await renderTable ( ) ;
507+ const dialog = await openCreate ( user ) ;
508+ await fillCreate ( user , dialog , 'Deploy' , 'Never' ) ;
509+ await user . click ( within ( dialog ) . getByRole ( 'button' , { name : 'Add API Key' } ) ) ;
510+ await within ( dialog ) . findByRole ( 'textbox' , { name : 'API key' } ) ;
511+ const first = deferred < void > ( ) ;
512+ const second = deferred < void > ( ) ;
513+ vi . spyOn ( navigator . clipboard , 'writeText' ) . mockReturnValueOnce ( first . promise ) . mockReturnValueOnce ( second . promise ) ;
514+
515+ await user . click ( within ( dialog ) . getByRole ( 'button' , { name : 'Copy API key' } ) ) ;
516+ await user . click ( within ( dialog ) . getByRole ( 'button' , { name : 'Copy API key' } ) ) ;
517+ first . reject ( new Error ( 'blocked' ) ) ;
518+ await waitFor ( ( ) => expect ( within ( dialog ) . getByRole ( 'alert' ) ) . toHaveTextContent ( 'Could not copy' ) ) ;
519+ second . resolve ( ) ;
520+
521+ await waitFor ( ( ) => expect ( within ( dialog ) . getByRole ( 'alert' ) ) . not . toHaveTextContent ( 'Could not copy' ) ) ;
522+ } ) ;
523+
504524 it ( 'closes the secret on Escape after a failed copy' , async ( ) => {
505525 const { user } = await renderTable ( ) ;
506526 const dialog = await openCreate ( user ) ;
0 commit comments