From fb35eff09b96e5eae79b480c134fa3ab33525d3e Mon Sep 17 00:00:00 2001 From: QuantCode Agent Date: Thu, 10 Sep 2026 00:51:12 +0000 Subject: [PATCH] fix: repair 5 failing tests across ui, utils, and web packages MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - fix(web): reconcile renamed debounce hook — export useSearchDebounce from @e2e/utils and fix stale import in apps/web/src/lib/api.ts - fix(a11y): apply aria-label to icon-only Button with a fallback accessible name (WCAG 2.2 SC 4.1.2) - fix(utils): format dates day-first without leading zero via en-GB locale (en-AU forces 2-digit day under this ICU build) - fix(ui): collapse DataTable sort key+direction into one state atom with a pure functional updater, removing a stale-closure bug - chore(tsconfig): register bun-types with the compiler --- apps/web/src/lib/api.ts | 13 ++------ packages/ui/src/components/Button/Button.tsx | 33 ++++++++++++++----- .../ui/src/components/DataTable/DataTable.tsx | 27 +++++++-------- packages/utils/src/format/date.ts | 17 +++++----- packages/utils/src/index.ts | 2 +- tsconfig.json | 1 + 6 files changed, 49 insertions(+), 44 deletions(-) diff --git a/apps/web/src/lib/api.ts b/apps/web/src/lib/api.ts index 2d4731b..9153a51 100644 --- a/apps/web/src/lib/api.ts +++ b/apps/web/src/lib/api.ts @@ -1,15 +1,8 @@ /** * 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`. */ -// BUG: useThrottle no longer exists — was renamed to useDebounce -import { useThrottle } from "@e2e/utils" -import { formatDate, formatAUD } from "@e2e/utils" +import { useSearchDebounce, formatDate, formatAUD } from "@e2e/utils" export const BASE_URL = process.env.API_URL ?? "http://localhost:3000" @@ -28,5 +21,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 used for search inputs +export { useSearchDebounce } diff --git a/packages/ui/src/components/Button/Button.tsx b/packages/ui/src/components/Button/Button.tsx index af65c97..126c74e 100644 --- a/packages/ui/src/components/Button/Button.tsx +++ b/packages/ui/src/components/Button/Button.tsx @@ -17,14 +17,23 @@ 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. + * An icon-only button renders no visible text, so it must expose an accessible + * name via `aria-label` (WCAG 2.2 SC 4.1.2 Name, Role, Value). * - * 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. + * `aria-label` is always forwarded to the underlying element. When `iconOnly` + * is set and no label is supplied we fall back to any plain-text `children`, + * then to a generic "Button" label, so the control is never left unnamed. A + * development-only warning flags the missing label so it gets fixed at source. */ +function textFromChildren(children: React.ReactNode): string | undefined { + const text = React.Children.toArray(children) + .filter((child): child is string | number => typeof child === "string" || typeof child === "number") + .join(" ") + .trim() + + return text.length > 0 ? text : undefined +} + export function Button({ children, icon, @@ -34,13 +43,21 @@ export function Button({ onClick, "aria-label": ariaLabel, }: Props) { + const accessibleName = iconOnly ? (ariaLabel ?? textFromChildren(children) ?? "Button") : ariaLabel + + if (process.env.NODE_ENV !== "production" && iconOnly && !ariaLabel) { + console.warn( + `Button: an icon-only button requires an explicit \`aria-label\` for screen reader users (WCAG 2.2 SC 4.1.2). ` + + `Falling back to "${accessibleName}".`, + ) + } + return (