From 46eed1f70be5e90730dfd9407171ebc880c4af31 Mon Sep 17 00:00:00 2001 From: QuantCode Agent Date: Thu, 30 Jul 2026 16:57:54 +0000 Subject: [PATCH] fix: repair cross-package test failures and type errors - restore useSearchDebounce export alias (hook renamed to useDebounce) - preload happy-dom in root bunfig.toml so component tests have a DOM - forward aria-label and default it for iconOnly Buttons (WCAG 4.1.2) - format dates day-first with unpadded day and 4-digit year (en-AU) - add DOM/test types in tsconfig so tsc --noEmit is clean --- apps/web/src/lib/api.ts | 14 ++++---- bunfig.toml | 2 +- packages/ui/src/components/Button/Button.tsx | 29 ++++++++++----- packages/utils/src/format/date.ts | 38 +++++++++++--------- tsconfig.json | 1 + 5 files changed, 50 insertions(+), 34 deletions(-) diff --git a/apps/web/src/lib/api.ts b/apps/web/src/lib/api.ts index 2d4731b..2a0a1db 100644 --- a/apps/web/src/lib/api.ts +++ b/apps/web/src/lib/api.ts @@ -1,14 +1,12 @@ /** * API client utilities for the web app. * - * BUG: imports `useThrottle` from @e2e/utils, but that hook was renamed to - * `useDebounce`. This causes a TypeScript error and a runtime crash. - * - * Fix: change the import to `useDebounce`. + * The debounce hook is imported from @e2e/utils under its current name + * (`useDebounce`) and re-exported as `useSearchDebounce` to preserve the + * existing public API of this module. */ -// BUG: useThrottle no longer exists — was renamed to useDebounce -import { useThrottle } from "@e2e/utils" +import { useDebounce } from "@e2e/utils" import { formatDate, formatAUD } from "@e2e/utils" export const BASE_URL = process.env.API_URL ?? "http://localhost:3000" @@ -28,5 +26,5 @@ export async function fetchPosts() { // Re-export formatting utilities used throughout the app export { formatDate, formatAUD } -// Re-export the debounce hook (currently broken import) -export { useThrottle as useSearchDebounce } +// Re-export the debounce hook under its established public name +export { useDebounce as useSearchDebounce } diff --git a/bunfig.toml b/bunfig.toml index 3258d71..1cb73b3 100644 --- a/bunfig.toml +++ b/bunfig.toml @@ -1,2 +1,2 @@ [test] -environment = "happy-dom" \ No newline at end of file +preload = ["./packages/ui/test/setup.ts"] \ No newline at end of file diff --git a/packages/ui/src/components/Button/Button.tsx b/packages/ui/src/components/Button/Button.tsx index af65c97..6efba8b 100644 --- a/packages/ui/src/components/Button/Button.tsx +++ b/packages/ui/src/components/Button/Button.tsx @@ -17,14 +17,14 @@ type Props = { /** * Button component. * - * BUG: When `iconOnly` is true, the button renders without visible text. - * An `aria-label` is required for screen reader accessibility (WCAG 2.1 SC 4.1.2), - * but the component does not enforce or warn about its absence. - * - * The test in Button.test.tsx checks that an icon-only button has an accessible name. - * Fix: throw/warn in development when `iconOnly && !aria-label`, or always render - * the aria-label attribute when iconOnly is true. + * An icon-only button has no visible text, so it must expose an accessible + * name via `aria-label` (WCAG 2.2 SC 4.1.2 Name, Role, Value). An explicit + * `aria-label` is always forwarded to the DOM element. When `iconOnly` is set + * without one, we derive a name from string children where possible and + * otherwise fall back to a generic label so the control is never unnamed. */ +const DEFAULT_ICON_ONLY_LABEL = "Button" + export function Button({ children, icon, @@ -34,13 +34,24 @@ export function Button({ onClick, "aria-label": ariaLabel, }: Props) { + const derivedLabel = typeof children === "string" ? children.trim() : "" + + const accessibleLabel = + ariaLabel ?? (iconOnly ? derivedLabel || DEFAULT_ICON_ONLY_LABEL : undefined) + + if (process.env.NODE_ENV !== "production" && iconOnly && !ariaLabel) { + console.warn( + "Button: `iconOnly` buttons should be given an explicit `aria-label` " + + `describing their action (WCAG 2.2 SC 4.1.2). Falling back to "${accessibleLabel}".`, + ) + } + return (