diff --git a/src/renderer/src/components/orca-cloud/cloud-card-primary-action.test.tsx b/src/renderer/src/components/orca-cloud/cloud-card-primary-action.test.tsx new file mode 100644 index 00000000000..52d1c4b1f77 --- /dev/null +++ b/src/renderer/src/components/orca-cloud/cloud-card-primary-action.test.tsx @@ -0,0 +1,44 @@ +// @vitest-environment happy-dom +// CLOUD-CARD-RESTARTING-CLICK: while a restart runs, the card's "Restarting…" button is inert (and +// announced busy): a click never starts a second restart. Restart itself still works. + +import { cleanup, fireEvent, render } from '@testing-library/react' +import { afterEach, describe, expect, it, vi } from 'vitest' +import { CloudCardPrimaryAction } from './cloud-card-primary-action' +import type { CloudPanelActions } from './CloudWorkspaceStatusPanel' + +afterEach(() => cleanup()) + +function renderRestart(restarting: boolean, anyBusy = false) { + const onRestart = vi.fn() + const actions: CloudPanelActions = { onRestart } + const { getByRole } = render( + + ) + return { onRestart, button: getByRole('button') } +} + +describe('cloud card primary action: Restart', () => { + it('restarts on click when no restart is running', () => { + const { onRestart, button } = renderRestart(false) + expect(button.textContent).toContain('Restart') + fireEvent.click(button) + expect(onRestart).toHaveBeenCalledTimes(1) + }) + + it('is inert while a restart runs, even one this card did not start (nothing else busy)', () => { + const { onRestart, button } = renderRestart(true) + expect(button.textContent).toContain('Restarting') + expect(button.getAttribute('aria-disabled')).toBe('true') + expect(button.getAttribute('aria-busy')).toBe('true') + fireEvent.click(button) + fireEvent.click(button) + expect(onRestart).not.toHaveBeenCalled() + }) +}) diff --git a/src/renderer/src/components/orca-cloud/cloud-card-primary-action.tsx b/src/renderer/src/components/orca-cloud/cloud-card-primary-action.tsx index 03494b71138..905cb53a1c3 100644 --- a/src/renderer/src/components/orca-cloud/cloud-card-primary-action.tsx +++ b/src/renderer/src/components/orca-cloud/cloud-card-primary-action.tsx @@ -67,7 +67,9 @@ export function CloudCardPrimaryAction({ ) : null case 'restart': return actions.onRestart ? ( -