From 047851a8240df19be9e5fabdf02055c0d348fdf0 Mon Sep 17 00:00:00 2001 From: Johnero542 Date: Thu, 26 Nov 2026 08:02:01 +0100 Subject: [PATCH] Fix StatusBadge/Skeleton test bugs; verify StatusTimeline and CreatorMarketplace already correct MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit #1145: StatusBadge.test.tsx had comma-operator bugs where toHaveClass(a), b, c; silently dropped all but the first class argument, and badge.getAttribute("tabIndex") used the wrong DOM attribute casing (React's tabIndex prop renders as the lowercase HTML attribute "tabindex", so getAttribute("tabIndex") always returned null). Fixed both in the test file. Separately, STATUS_CONFIG in src/lib/invoiceStatus.ts was missing description and icon entirely for every status, and had no entries at all for Active/Frozen/Expired (statuses the test's "all status types render without error" case exercises), so StatusBadge's tooltip never rendered (tooltipText was always falsy) and three statuses crashed with "Cannot read properties of undefined" when the test accessed STATUS_CONFIG[status].label. Added description/icon to every status and the three missing entries. #1146: Skeleton.test.tsx imported a component named InvoiceCardSkeleton from @/components/Skeleton that does not exist there (the real export is SkeletonCard), so the import resolved to undefined, React threw rendering it, and container.querySelector('[role="status"]') returned null — calling .getAttribute() on that null is the literal "getAttribute error" in the issue title. Fixed the import and usage to reference the real SkeletonCard export. Skeleton.snapshot.test.tsx was already correct and needed no changes. #1144: read StatusTimeline.tsx and StatusTimeline.test.tsx fully; found the component already renders the desktop timeline, Fully Funded event, mobile stepper, and active-step styling exactly as every test in the file expects. No getAttribute-null failure path exists currently (confirmed this file was part of an earlier "Add class names to all 26 toHaveClass() calls" fix). No code change made; closing as verified-correct with existing coverage. #1147: read CreatorMarketplace.test.tsx, the real component at src/components/marketplace/CreatorMarketplace.tsx, and src/lib/creatorMarketplace.ts fully. Filtering (search by name/tag, category select, verified-only checkbox, three sort modes), the profile link's href, and the "No creators found." empty state are all already implemented and match the test's expectations exactly; next/link is already mocked globally in vitest.setup.ts so it renders a real in jsdom. Note: a second, unrelated component also named CreatorMarketplace exists at src/components/CreatorMarketplace.tsx (a mentor-matching UI with a different Creator shape) but the test imports from the correct marketplace path, so this is not a source of confusion for the test suite itself. No code change made; closing as verified-correct with existing coverage. Closes #1144 Closes #1145 Closes #1146 Closes #1147 --- src/__tests__/Skeleton.test.tsx | 6 +++--- src/__tests__/StatusBadge.test.tsx | 10 +++++----- src/lib/invoiceStatus.ts | 19 +++++++++++-------- 3 files changed, 19 insertions(+), 16 deletions(-) diff --git a/src/__tests__/Skeleton.test.tsx b/src/__tests__/Skeleton.test.tsx index 23379d4c..9cb94b66 100644 --- a/src/__tests__/Skeleton.test.tsx +++ b/src/__tests__/Skeleton.test.tsx @@ -1,6 +1,6 @@ import { render } from '@testing-library/react'; import { describe, it, expect } from 'vitest'; -import { Skeleton, InvoiceCardSkeleton } from '@/components/Skeleton'; +import { Skeleton, SkeletonCard } from '@/components/Skeleton'; describe('Skeleton', () => { it('renders with skeleton-shimmer class', () => { @@ -25,8 +25,8 @@ describe('Skeleton', () => { expect(skeletonDiv).toHaveClass('rounded'); }); - it('renders InvoiceCardSkeleton with proper ARIA attributes', () => { - const { container } = render(); + it('renders SkeletonCard with proper ARIA attributes', () => { + const { container } = render(); const skeleton = container.querySelector('[role="status"]'); expect(skeleton.getAttribute('aria-busy')).toBe('true'); expect(skeleton.getAttribute('aria-label')).toBe('Loading invoice data'); diff --git a/src/__tests__/StatusBadge.test.tsx b/src/__tests__/StatusBadge.test.tsx index 4f683e07..419b4cc7 100644 --- a/src/__tests__/StatusBadge.test.tsx +++ b/src/__tests__/StatusBadge.test.tsx @@ -13,7 +13,7 @@ describe("StatusBadge", () => { test("applies correct color class based on status", () => { render(); const badge = screen.getByRole("status"); - expect(badge).toHaveClass('bg-green-500/20'), "text-green-400"; + expect(badge).toHaveClass('bg-green-500/20', 'text-green-400'); }); test("renders icon when available", () => { @@ -86,19 +86,19 @@ describe("StatusBadge", () => { test("applies correct size classes", () => { const { rerender } = render(); - expect(screen.getByRole("status")).toHaveClass('text-xs'), "px-2", "py-0.5"; + expect(screen.getByRole("status")).toHaveClass('text-xs', 'px-2', 'py-0.5'); rerender(); - expect(screen.getByRole("status")).toHaveClass('text-sm'), "px-3", "py-1"; + expect(screen.getByRole("status")).toHaveClass('text-sm', 'px-3', 'py-1'); rerender(); - expect(screen.getByRole("status")).toHaveClass('text-base'), "px-4", "py-1.5"; + expect(screen.getByRole("status")).toHaveClass('text-base', 'px-4', 'py-1.5'); }); test("badge is focusable with tabIndex", () => { render(); const badge = screen.getByRole("status"); - expect(badge.getAttribute("tabIndex")).toBe("0"); + expect(badge.getAttribute("tabindex")).toBe("0"); }); test("all status types render without error", () => { diff --git a/src/lib/invoiceStatus.ts b/src/lib/invoiceStatus.ts index 3a7f605e..d5e3156e 100644 --- a/src/lib/invoiceStatus.ts +++ b/src/lib/invoiceStatus.ts @@ -1,14 +1,17 @@ import { getMilestones } from "./invoiceMilestones"; import { getDisputesByInvoice } from "./arbitrators"; -export const STATUS_CONFIG: Record = { - Pending: { color: 'blue', label: 'Pending' }, - Funded: { color: 'green', label: 'Funded' }, - Released: { color: 'green', label: 'Released' }, - Refunded: { color: 'red', label: 'Refunded' }, - Cancelled: { color: 'gray', label: 'Cancelled' }, - Disputed: { color: 'yellow', label: 'Disputed' }, - Archived: { color: 'gray', label: 'Archived' }, +export const STATUS_CONFIG: Record = { + Pending: { color: 'blue', label: 'Pending', icon: '⏳', description: 'Awaiting funding from the payer.' }, + Active: { color: 'blue', label: 'Active', icon: '🔄', description: 'Invoice is active and awaiting completion.' }, + Funded: { color: 'green', label: 'Funded', icon: '💰', description: 'Invoice has been fully funded.' }, + Released: { color: 'green', label: 'Released', icon: '✓', description: 'Funds have been released to the recipient.' }, + Refunded: { color: 'red', label: 'Refunded', icon: '↩', description: 'Funds have been refunded to the payer.' }, + Cancelled: { color: 'gray', label: 'Cancelled', icon: '✕', description: 'Invoice was cancelled.' }, + Disputed: { color: 'yellow', label: 'Disputed', icon: '⚠', description: 'Invoice is under dispute.' }, + Frozen: { color: 'gray', label: 'Frozen', icon: '🧊', description: 'Invoice is frozen pending resolution.' }, + Archived: { color: 'gray', label: 'Archived', icon: '📦', description: 'Invoice has been archived.' }, + Expired: { color: 'red', label: 'Expired', icon: '⏰', description: 'Invoice deadline has passed.' }, }; export type InvoiceStatus =