@@ -4,13 +4,17 @@ import { describe, it, expect, vi, beforeEach, afterEach } from 'vitest';
44import DashboardPage , { generateMetadata } from './page' ;
55import { getFullDashboardData } from '@/lib/github' ;
66
7+ const { mockNotFound } = vi . hoisted ( ( ) => ( {
8+ mockNotFound : vi . fn ( ) ,
9+ } ) ) ;
10+
711vi . mock ( 'next/navigation' , ( ) => ( {
12+ notFound : mockNotFound ,
813 useRouter : ( ) => ( {
914 push : vi . fn ( ) ,
1015 replace : vi . fn ( ) ,
1116 refresh : vi . fn ( ) ,
1217 } ) ,
13-
1418 useSearchParams : ( ) => ( {
1519 get : vi . fn ( ) ,
1620 } ) ,
@@ -20,7 +24,6 @@ vi.mock('@/lib/github', () => ({
2024 getFullDashboardData : vi . fn ( ) ,
2125} ) ) ;
2226
23- // Mock the dashboard components to keep the test focused on the page rendering logic
2427vi . mock ( '@/components/dashboard/ProfileCard' , ( ) => ( {
2528 default : ( ) => < div data-testid = "profile-card" > ProfileCard</ div > ,
2629} ) ) ;
@@ -159,17 +162,28 @@ describe('DashboardPage', () => {
159162 bypassCache : true ,
160163 } ) ;
161164 } ) ;
162- } ) ;
163165
164- it ( 'passes the correct activity data to Heatmap' , async ( ) => {
165- const PageContent = await DashboardPage ( {
166- params : Promise . resolve ( { username : 'octocat' } ) ,
167- searchParams : Promise . resolve ( { } ) ,
166+ it ( 'passes the correct activity data to Heatmap' , async ( ) => {
167+ const PageContent = await DashboardPage ( {
168+ params : Promise . resolve ( { username : 'octocat' } ) ,
169+ searchParams : Promise . resolve ( { } ) ,
170+ } ) ;
171+
172+ render ( PageContent ) ;
173+
174+ const heatmap = screen . getByTestId ( 'heatmap' ) ;
175+ expect ( JSON . parse ( heatmap . getAttribute ( 'data-prop' ) ?? '[]' ) ) . toEqual ( mockData . activity ) ;
168176 } ) ;
169177
170- render ( PageContent ) ;
178+ it ( 'calls notFound when dashboard data fetch throws an error' , async ( ) => {
179+ vi . mocked ( getFullDashboardData ) . mockRejectedValueOnce ( new Error ( 'User not found' ) ) ;
171180
172- const heatmap = screen . getByTestId ( 'heatmap' ) ;
173- expect ( JSON . parse ( heatmap . getAttribute ( 'data-prop' ) ?? '[]' ) ) . toEqual ( mockData . activity ) ;
181+ await DashboardPage ( {
182+ params : Promise . resolve ( { username : 'missing-user' } ) ,
183+ searchParams : Promise . resolve ( { } ) ,
184+ } ) ;
185+
186+ expect ( mockNotFound ) . toHaveBeenCalledOnce ( ) ;
187+ } ) ;
174188 } ) ;
175189} ) ;
0 commit comments