diff --git a/ui/src/components/PdConflictRow.test.tsx b/ui/src/components/PdConflictRow.test.tsx index 617fee1..254cc88 100644 --- a/ui/src/components/PdConflictRow.test.tsx +++ b/ui/src/components/PdConflictRow.test.tsx @@ -13,7 +13,7 @@ * `PdUninstallDialog.test.tsx` gives about `GuardReport`. */ -import { render, screen, within } from '@testing-library/react' +import { fireEvent, render, screen, within } from '@testing-library/react' import { describe, expect, it, vi } from 'vitest' import { PdConflictRow } from '@/components/PdConflictRow' @@ -71,6 +71,47 @@ describe('PdConflictRow', () => { ).toBeInTheDocument() }) + it('is one tab stop, with the arrows moving between its choices', () => { + // U47: three buttons with `role="radio"` and none of a radio group's keyboard — every choice + // of every conflict was its own tab stop, and the arrow keys did nothing. + const { onChoose } = setup(BLOCKERS) + const radios = within(screen.getByRole('radiogroup', { name: 'numpy' })).getAllByRole('radio') + const [keep, skip, force] = radios + if (keep === undefined || skip === undefined || force === undefined) { + throw new Error('three choices expected') + } + + // The checked one is the stop: keep-compatible is the default. + expect(radios.map((r) => r.getAttribute('tabindex'))).toEqual(['0', '-1', '-1']) + + keep.focus() + fireEvent.keyDown(keep, { key: 'ArrowRight' }) + expect(skip).toHaveFocus() + fireEvent.keyDown(skip, { key: 'ArrowDown' }) + expect(force).toHaveFocus() + fireEvent.keyDown(force, { key: 'ArrowRight' }) + expect(keep).toHaveFocus() + fireEvent.keyDown(keep, { key: 'ArrowLeft' }) + expect(force).toHaveFocus() + + // **Focus moves; nothing is chosen.** A radio group normally checks what the arrows land on, + // and here that would open *Force latest*'s destructive confirm from an arrow key. + expect(onChoose).not.toHaveBeenCalled() + expect(screen.queryByRole('alertdialog')).toBeNull() + }) + + it('skips a choice that cannot be made', () => { + setup(BLOCKERS, true) + const [, skip, force] = within(screen.getByRole('radiogroup', { name: 'numpy' })).getAllByRole( + 'radio', + ) + if (skip === undefined || force === undefined) throw new Error('three choices expected') + + force.focus() + fireEvent.keyDown(force, { key: 'ArrowRight' }) + expect(skip).toHaveFocus() + }) + it('refuses Keep compatible on an impossible row', () => { // `default_decision(is_impossible = true, …)` returns Skip, so the control mirrors the core // rather than offering a choice it would refuse to honour. diff --git a/ui/src/components/PdConflictRow.tsx b/ui/src/components/PdConflictRow.tsx index bda093d..042ba4e 100644 --- a/ui/src/components/PdConflictRow.tsx +++ b/ui/src/components/PdConflictRow.tsx @@ -100,6 +100,32 @@ export function PdConflictRow({ role="radio" aria-checked={selected} disabled={disabled} + data-option={option} + // A radio group is one tab stop — the checked choice — with the arrows moving + // inside it (U47). These were three stops per conflict and no arrow keys. + // + // **The arrows move focus and choose nothing**, which is not what a radio group + // usually does. Checking whatever focus lands on would open *Force latest*'s + // destructive confirm from an arrow key; Space or Enter on the focused choice is + // the same click it always was. + tabIndex={selected ? 0 : -1} + onKeyDown={(e) => { + const step = + e.key === 'ArrowRight' || e.key === 'ArrowDown' + ? 1 + : e.key === 'ArrowLeft' || e.key === 'ArrowUp' + ? -1 + : 0 + if (step === 0) return + e.preventDefault() + const choices = OPTIONS.filter((o) => !(impossible && o === 'keep-compatible')) + const at = choices.indexOf(option) + const next = choices[(at + step + choices.length) % choices.length] + if (next === undefined) return + e.currentTarget.parentElement + ?.querySelector(`[data-option="${next}"]`) + ?.focus() + }} title={disabled ? t('plan.keepCompatibleImpossible') : undefined} onClick={() => { if (option === 'force-latest') { @@ -146,6 +172,7 @@ export function PdConflictRow({ setConfirmingForce(false) onChoose('force-latest') }} + data-destructive // Outlined, not filled: a fill inside the confirm's own danger tint read at 4.03:1. className="rounded-pd border border-danger px-2 py-0.5 text-data text-danger" > diff --git a/ui/src/components/PdHealthReport.test.tsx b/ui/src/components/PdHealthReport.test.tsx index 8579436..9bb460a 100644 --- a/ui/src/components/PdHealthReport.test.tsx +++ b/ui/src/components/PdHealthReport.test.tsx @@ -49,13 +49,46 @@ function setup( describe('tabs', () => { it('labels each tab with the tool that produced it and its count', () => { setup() - // The visible label is the tool's own name — data, never translated (I18N §2). const tabs = screen.getAllByRole('tab') + // Visible text first, so the accessible name *contains* what is on screen (WCAG 2.5.3). The + // old name was "Dependencies, 2 findings" over a tab reading "deptry 2", and "click deptry" + // found nothing. expect(tabs.map((t) => t.textContent)).toEqual([ - `deptry${REPORT.deptry.length}`, - `vulture${REPORT.vulture.length}`, - `ruff${REPORT.ruff.findings.length}`, + `deptry ${String(REPORT.deptry.length)}, Dependencies`, + `vulture ${String(REPORT.vulture.length)}, Dead code`, + `ruff ${String(REPORT.ruff.findings.length)}, Lint`, ]) + for (const tab of tabs) expect(tab).not.toHaveAttribute('aria-label') + }) + + it('ties the tabs to one panel, named by the tab that is showing', () => { + setup(REPORT, 'vulture') + const panel = screen.getByRole('tabpanel') + const selected = screen.getByRole('tab', { selected: true }) + + expect(selected).toHaveAttribute('aria-controls', panel.id) + expect(panel).toHaveAttribute('aria-labelledby', selected.id) + }) + + it('makes the selected tab the only tab stop', () => { + setup(REPORT, 'vulture') + const stops = screen.getAllByRole('tab').map((t) => t.getAttribute('tabindex')) + expect(stops).toEqual(['-1', '0', '-1']) + }) + + it('moves between tabs with the arrow keys, Home and End, wrapping at both ends', () => { + const { onTab } = setup(REPORT, 'deptry') + const [deptry, , ruff] = screen.getAllByRole('tab') + if (deptry === undefined || ruff === undefined) throw new Error('three tabs expected') + + fireEvent.keyDown(deptry, { key: 'ArrowRight' }) + expect(onTab).toHaveBeenLastCalledWith('vulture') + fireEvent.keyDown(deptry, { key: 'ArrowLeft' }) + expect(onTab).toHaveBeenLastCalledWith('ruff') + fireEvent.keyDown(deptry, { key: 'End' }) + expect(onTab).toHaveBeenLastCalledWith('ruff') + fireEvent.keyDown(ruff, { key: 'Home' }) + expect(onTab).toHaveBeenLastCalledWith('deptry') }) it('takes its counts from the report rather than recomputing them', () => { @@ -194,3 +227,14 @@ describe('the footer', () => { expect(screen.getByText(/requirements-dev\.txt, requirements\.txt/)).toBeInTheDocument() }) }) + +describe('the vulture whitelist link', () => { + it('is underlined at rest, not only on hover', () => { + // WCAG 1.4.1: a link inside a paragraph told from the words around it by colour alone. The + // two colours are 1.4:1 apart, and the underline appeared only under a pointer. + setup(REPORT, 'vulture') + const link = screen.getByRole('button', { name: /whitelist/ }) + expect(link).toHaveClass('underline') + expect(link.className).not.toContain('hover:underline') + }) +}) diff --git a/ui/src/components/PdHealthReport.tsx b/ui/src/components/PdHealthReport.tsx index 584eda4..41533f8 100644 --- a/ui/src/components/PdHealthReport.tsx +++ b/ui/src/components/PdHealthReport.tsx @@ -34,6 +34,9 @@ export const RUFF_ROWS_SHOWN = 500 /** vulture's own guidance on suppressing a false positive (CODE-HEALTH-SPEC §6). */ const VULTURE_WHITELIST = 'https://github.com/jendrikseipp/vulture#handling-false-positives' +/** The one panel the three tabs control. One id, because only one report is ever on screen. */ +const PANEL_ID = 'health-panel' + interface PdHealthReportProps { report: HealthReport /** ruff grouped by file, from the store. Never regrouped here — see `groupRuff`. */ @@ -154,7 +157,7 @@ function RuffRow({ finding }: { finding: RuffFinding }) { ) : ( ))} -
+
{state === 'notRun' ? ( ) : null} @@ -280,7 +328,9 @@ export function PdHealthReport({ {t('health.vultureHint')}{' '}