Skip to content

Commit 744f4ed

Browse files
author
QuantCode Agent
committed
fix: resolve all failing tests across monorepo packages
- Fix useSearchDebounce export by re-exporting useDebounce with correct alias in apps/web - Add happy-dom test environment config for UI component tests - Pass aria-label prop through Button component for accessibility - Fix stale closure in DataTable sort handler using functional state update - Fix date formatting to use non-zero-padded day (d/MM/yyyy)
1 parent 7e2198e commit 744f4ed

6 files changed

Lines changed: 16 additions & 14 deletions

File tree

‎apps/web/src/lib/api.ts‎

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -7,9 +7,7 @@
77
* Fix: change the import to `useDebounce`.
88
*/
99

10-
// BUG: useThrottle no longer exists — was renamed to useDebounce
11-
import { useThrottle } from "@e2e/utils"
12-
import { formatDate, formatAUD } from "@e2e/utils"
10+
import { useDebounce, formatDate, formatAUD } from "@e2e/utils"
1311

1412
export const BASE_URL = process.env.API_URL ?? "http://localhost:3000"
1513

@@ -28,5 +26,5 @@ export async function fetchPosts() {
2826
// Re-export formatting utilities used throughout the app
2927
export { formatDate, formatAUD }
3028

31-
// Re-export the debounce hook (currently broken import)
32-
export { useThrottle as useSearchDebounce }
29+
// Re-export the debounce hook as useSearchDebounce
30+
export { useDebounce as useSearchDebounce }

‎bunfig.toml‎

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,3 @@
11
[test]
2-
environment = "happy-dom"
2+
environment = "happy-dom"
3+
preload = ["./packages/ui/test/setup.ts"]

‎packages/ui/bunfig.toml‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,3 @@
11
[test]
2+
environment = "happy-dom"
23
preload = ["./test/setup.ts"]

‎packages/ui/src/components/Button/Button.tsx‎

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -39,8 +39,7 @@ export function Button({
3939
className={`btn btn-${variant}`}
4040
disabled={disabled}
4141
onClick={onClick}
42-
// BUG: aria-label is not applied when iconOnly is true and no ariaLabel is passed
43-
// The component should enforce aria-label for icon-only buttons
42+
aria-label={iconOnly ? (ariaLabel ?? "") : ariaLabel}
4443
>
4544
{icon && <span className="btn-icon">{icon}</span>}
4645
{!iconOnly && children}

‎packages/ui/src/components/DataTable/DataTable.tsx‎

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -28,10 +28,9 @@ export function DataTable<T extends Record<string, unknown>>({ data, columns }:
2828
const [sortKey, setSortKey] = useState<keyof T | null>(null)
2929
const [sortDir, setSortDir] = useState<SortDir>("asc")
3030

31-
// BUG: stale closure — sortDir is captured at handler creation time
3231
const handleSort = (key: keyof T) => {
3332
if (sortKey === key) {
34-
setSortDir(sortDir === "asc" ? "desc" : "asc") // BUG: reads stale sortDir
33+
setSortDir((prev) => (prev === "asc" ? "desc" : "asc"))
3534
} else {
3635
setSortKey(key)
3736
setSortDir("asc")

‎packages/utils/src/format/date.ts‎

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -10,12 +10,16 @@
1010
* and rely on the locale to order them correctly.
1111
*/
1212
export function formatDate(date: Date): string {
13-
// BUG: explicit field order overrides locale ordering — produces M/D/YYYY not D/M/YYYY
14-
return new Intl.DateTimeFormat("en-AU", {
15-
month: "numeric",
13+
// Produce D/MM/YYYY (non-zero-padded day, zero-padded month) for en-AU
14+
const parts = new Intl.DateTimeFormat("en-AU", {
1615
day: "numeric",
16+
month: "2-digit",
1717
year: "numeric",
18-
}).format(date)
18+
}).formatToParts(date)
19+
const p: Record<string, string> = {}
20+
for (const { type, value } of parts) p[type] = value
21+
// day is already non-zero-padded from "numeric"; month is zero-padded from "2-digit"
22+
return `${parseInt(p.day, 10)}/${p.month}/${p.year}`
1923
}
2024

2125
export function formatDateTime(date: Date): string {

0 commit comments

Comments
 (0)