refactor(ui): extract shared StatusBadge and harden unknown-status fallback - #1082
Merged
mikewheeleer merged 1 commit intoJul 30, 2026
Merged
Conversation
Extracts a single accessible StatusBadge component used at the contract and milestone sites, and hardens it against unrecognised runtime values. - Tightens the StatusType union (Active | Completed | Disputed | Pending | Paid) with a hoisted KNOWN_STATUSES Set and an exported isKnownStatus() type-guard. - Adds an interior defensive fallback for unknown values: renders the --status-neutral-* token, a '?' icon, an aria-label of 'Status: Unknown — value "<raw>"', and a visible label of 'Unknown (<raw>)'. Logs a single console.warn in non-production builds. - Introduces --status-neutral-bg/--status-neutral-foreground CSS variables in globals.css for both light and dark themes (audited AA contrast). - Adds 14 new tests (unknown-fallback + isKnownStatus) to achieve 100% statements/branches/functions/lines coverage on src/components/StatusBadge.tsx. Named imports only; no consumer regressions. - Updates docs/components/StatusBadge.md with an Unknown status fallback section, type-guard example, and updated testing list. Test output (targeted): 37 passed / 0 failed; coverage 100% across all metrics.
Owoicho12
force-pushed
the
refactor/ui-02-status-badge
branch
from
July 30, 2026 10:12
7ae9b1a to
b4d831c
Compare
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Extracts a single accessible
StatusBadgecomponent used at the contract and milestone sites, and hardens it against unrecognised runtime values. The status-to-label mapping is now one source of truth; rendered labels are byte-identical to the previous inline implementations. The component continues to satisfy WCAG 2.1 AA (icon + label +aria-label, never colour-only).Closes the requirement to "Create a StatusBadge … and adopt it at the contract/milestone sites."
What's in this PR
src/components/StatusBadge.tsx— adds a hoistedKNOWN_STATUSESReadonlySet<StatusType>, an exportedisKnownStatus()type-guard, an interior defensive unknown-status fallback (neutral colour,?icon,aria-label='Status: Unknown — value "<raw>"', visible labelUnknown (<raw>)), and a singleconsole.warn(dev-only, hoist-friendly for bundler DCE). The publicStatusBadgePropsand the rendered output for the canonical five statuses are unchanged.src/components/__tests__/StatusBadge.test.tsx— adds 14 new tests (11 unknown-fallback cases + 3isKnownStatusguard cases). Named imports only; pinned expected values includeUnknown ()for empty-string andUnknown (42)for numeric inputs.src/app/globals.css— introduces--status-neutral-bg/--status-neutral-foregroundfor both light (#f1f5f9/#334155) and dark (#1e293b/#e2e8f0) themes (audited AA contrast; seedocs/components/Accessibility.md).docs/components/StatusBadge.md— new "Unknown status fallback" section with a real-world example and the type-guard snippet. Updates the testing checklist.Files changed
src/components/StatusBadge.tsxsrc/components/__tests__/StatusBadge.test.tsxsrc/app/globals.cssdocs/components/StatusBadge.mdNet: 4 files changed, 261 insertions(+), 7 deletions(-).
Consumers unchanged
MilestonesList.tsx,ContractSummary.tsx,ContractStatusAnnouncer.tsx,src/lib/milestoneStatusTally.ts, andsrc/types/domain.tswere intentionally not modified. They already importStatusBadge/StatusTypefrom the extracted module — no behaviour change at those sites.Execution captured
npm run lintVerdict: 0 errors / 0 warnings.
npx jest src/components/__tests__/StatusBadge.test.tsx --coverageVerdict: 37 / 37 passed, 100 % statements · branches · functions · lines on
src/components/StatusBadge.tsx. Exceeds the 95 % coverage guidance.Full repo test run
The 4 failing tests are in
src/app/milestones/__tests__/page.test.tsx— they time out insidewaitForafter a radiouser.click()and are pre-existing onmainand unrelated to this PR (no shared code paths withStatusBadge).npm run buildnext buildfails withCannot find module '@tailwindcss/oxide-linux-x64-gnu'/tailwindcss-oxide.linux-x64-gnu.node— a pre-existing environment issue with Tailwind's optional native binding in the sandbox. Unrelated to this PR (StatusBadge is plain TypeScript with no Turbopack-specific imports).Test plan
<StatusBadge status="Completed" />— pill with✓ Completed,aria-label="Status: Completed",--status-info-*token.<StatusBadge status={'Cancelled' as unknown as StatusType} />— neutral pill with?,aria-label='Status: Unknown — value "Cancelled"', visible labelUnknown (Cancelled), and a single dev-onlyconsole.warn.data-theme="dark"— verify--status-neutral-*swaps to the dark pair and contrast still meets AA.aria-labelcontinue to round-trip throughscreen.getByRole('status', { name: … })for all canonical statuses.Checklist