From 59208b214e485e1ec0a269a7420cc39eb4f9249a Mon Sep 17 00:00:00 2001 From: Aman koli <2025.amana@isu.ac.in> Date: Sat, 25 Jul 2026 23:30:53 +0530 Subject: [PATCH] test: add empty/loading/error state coverage for ContributionsTab --- .../components/ContributionsTab.test.tsx | 19 ++++++++++++++++- .../dashboard/components/ContributionsTab.tsx | 21 +++++++++++++++++++ 2 files changed, 39 insertions(+), 1 deletion(-) diff --git a/src/features/dashboard/components/ContributionsTab.test.tsx b/src/features/dashboard/components/ContributionsTab.test.tsx index a84132d0..50369bde 100644 --- a/src/features/dashboard/components/ContributionsTab.test.tsx +++ b/src/features/dashboard/components/ContributionsTab.test.tsx @@ -87,12 +87,29 @@ describe('ContributionsTab', () => { expect(mockGetProfileContributions).toHaveBeenCalledTimes(1) }) - it('shows loading skeletons while contribution items are loading', () => { + it('shows loading skeletons while contribution items are loading without flashing empty state', () => { mockGetProfileContributions.mockReturnValue(new Promise(() => {})) renderContributionsTab() expect(screen.getByLabelText('Loading contributions')).toHaveAttribute('aria-busy', 'true') + expect(screen.queryByTestId('contribution-empty-board')).not.toBeInTheDocument() + expect(screen.queryByText(/no contributions yet/i)).not.toBeInTheDocument() + }) + + it('shows a friendly empty state when a user has zero total contributions', async () => { + mockGetProfileContributions.mockResolvedValue({ contributions: [] }) + + renderContributionsTab() + + const emptyBoard = await screen.findByTestId('contribution-empty-board') + expect(emptyBoard).toBeInTheDocument() + expect(screen.getByText('No contributions yet')).toBeInTheDocument() + expect(screen.getByText(/when you start contributing to projects/i)).toBeInTheDocument() + + // Ensure 4 blank columns are not shown + expect(screen.queryByText('No applied contributions')).not.toBeInTheDocument() + expect(screen.queryByText('No complete contributions')).not.toBeInTheDocument() }) it('shows an empty state for each column that has no matching contributions', async () => { diff --git a/src/features/dashboard/components/ContributionsTab.tsx b/src/features/dashboard/components/ContributionsTab.tsx index 980892bc..4ade61a0 100644 --- a/src/features/dashboard/components/ContributionsTab.tsx +++ b/src/features/dashboard/components/ContributionsTab.tsx @@ -265,6 +265,25 @@ function ContributionError({ theme, onRetry }: { theme: string; onRetry: () => v ) } +function ContributionEmptyBoard({ theme }: { theme: string }) { + return ( +
No contributions yet
++ When you start contributing to projects, your progress and history will be tracked here. +
+