Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -135,4 +135,30 @@ describe('HandoverPanel error and refresh', () => {
})
await waitFor(() => expect(vi.mocked(opsApi.handover).mock.calls.length).toBeGreaterThan(before))
})

it('keeps keyboard focus on Refresh while it runs, and ignores a second press', async () => {
// A native `disabled` takes the focused button out of the tab order, so a
// keyboard press dropped focus to the page for the whole refresh.
renderWithProviders(<HandoverPanel />)
const label = await screen.findByText(i18nT('apps.opsMissionControl.handoverPanel.refresh'))
const button = label.closest('button') as HTMLButtonElement
let release: (v: unknown) => void = () => {}
vi.mocked(opsApi.handover).mockReturnValue(new Promise(resolve => { release = resolve }) as never)
const calls = vi.mocked(opsApi.handover).mock.calls.length

button.focus()
fireEvent.click(button)
await screen.findByText(i18nT('apps.opsMissionControl.handoverPanel.refreshing'))
expect(button).toHaveAttribute('aria-disabled', 'true')
expect(button).not.toBeDisabled()
expect(button).toHaveFocus()

fireEvent.click(button)
expect(vi.mocked(opsApi.handover).mock.calls.length).toBe(calls + 1)

await act(async () => { release(digest()) })
await screen.findByText(i18nT('apps.opsMissionControl.handoverPanel.refresh'))
expect(button).not.toHaveAttribute('aria-disabled')
expect(button).toHaveFocus()
})
})
8 changes: 7 additions & 1 deletion website/src/apps/ops-mission-control/HandoverPanel.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -172,7 +172,13 @@ export default function HandoverPanel() {
{/* The one line someone gets if they read nothing else. */}
<p className="text-sm mb-3">{digest?.headline}</p>
<div className="flex items-center gap-2">
<Btn disabled={query.isFetching} onClick={() => query.refetch()}>
{/* `aria-disabled` plus the guard, NOT `disabled`, which leaves the tab
order and drops a keyboard user's focus to the page while it runs. */}
<Btn
aria-disabled={query.isFetching || undefined}
className="aria-disabled:opacity-30 aria-disabled:cursor-default"
onClick={() => { if (!query.isFetching) void query.refetch() }}
>
<RefreshCw className="lucide-inline" />{' '}
{query.isFetching
? i18nT('apps.opsMissionControl.handoverPanel.refreshing')
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -402,7 +402,7 @@ describe('SignalsPanel', () => {
fireEvent.click(button)

const polling = await screen.findByRole('button', { name: /Polling…/ })
expect(polling).toBeDisabled()
expect(polling).toHaveAttribute('aria-disabled', 'true')

await act(async () => {
reject(new Error('the /signals route refused the poll'))
Expand All @@ -414,7 +414,37 @@ describe('SignalsPanel', () => {
timeout: 5_000,
}),
).toBeInTheDocument()
expect(screen.getByRole('button', { name: /Poll now/ })).toBeEnabled()
expect(screen.getByRole('button', { name: /Poll now/ })).not.toHaveAttribute('aria-disabled')
})

it('keeps keyboard focus on Poll now while polling, and ignores a second press', async () => {
// A native `disabled` takes the focused button out of the tab order, so a
// keyboard press dropped focus to the page for the whole poll.
await renderPanel()
let resolve: (v: SignalsResult) => void = () => {}
vi.mocked(opsApi.signals).mockReturnValue(
new Promise<SignalsResult>(res => {
resolve = res
}),
)
const calls = vi.mocked(opsApi.signals).mock.calls.length

const button = screen.getByRole('button', { name: /Poll now/ })
button.focus()
fireEvent.click(button)
await screen.findByRole('button', { name: /Polling…/ })
expect(button).not.toBeDisabled()
expect(button).toHaveFocus()

fireEvent.click(button)
expect(vi.mocked(opsApi.signals).mock.calls.length).toBe(calls + 1)

await act(async () => {
resolve(mkSignalsResult())
await Promise.resolve()
})
await screen.findByRole('button', { name: /Poll now/ })
expect(button).toHaveFocus()
})

it('reports an exact ledger match and a cleared fast path on the claim receipt', async () => {
Expand Down
7 changes: 5 additions & 2 deletions website/src/apps/ops-mission-control/SignalsPanel.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -333,9 +333,12 @@ export default function SignalsPanel() {
)}

<div className="flex items-center gap-2 mt-3">
{/* `aria-disabled` plus the guard, NOT `disabled`, which leaves the tab
order and drops a keyboard user's focus to the page while it polls. */}
<Btn
disabled={signalsQuery.isFetching}
onClick={() => signalsQuery.refetch()}
aria-disabled={signalsQuery.isFetching || undefined}
className="aria-disabled:opacity-30 aria-disabled:cursor-default"
onClick={() => { if (!signalsQuery.isFetching) void signalsQuery.refetch() }}
title={i18nT('apps.opsMissionControl.signalsPanel.poll_every_configured_source_now_read_only')}
>
<RefreshCw className="lucide-inline" />{' '}
Expand Down
Loading