@@ -3,32 +3,41 @@ import { render, screen } from "@testing-library/react";
33import { describe , it , expect , beforeEach } from "vitest" ;
44import DashboardPage from "../page" ;
55
6- // Mock next/navigation to prevent redirect calls
6+ // Mock next/navigation
77vi . mock ( "next/navigation" , ( ) => ( {
88 redirect : vi . fn ( ) ,
99} ) ) ;
1010
1111// Mock next/font/google
1212vi . mock ( "next/font/google" , ( ) => ( {
13- Cinzel : ( ) => ( {
14- className : "mocked-cinzel-font" ,
15- } ) ,
13+ Cinzel : ( ) => ( { className : "mocked-cinzel-font" } ) ,
1614} ) ) ;
1715
18- // Mock Supabase server client to return a fake authenticated user
16+ // Mock for .from().select().eq()
17+ const mockFrom = vi . fn ( ) ;
18+ const mockSelect = vi . fn ( ) ;
19+ const mockEq = vi . fn ( ) ;
20+
21+ mockFrom . mockReturnValue ( {
22+ select : mockSelect . mockReturnValue ( {
23+ eq : mockEq . mockResolvedValue ( {
24+ data : [ ] , // Default: No completed quizzes
25+ error : null ,
26+ } ) ,
27+ } ) ,
28+ } ) ;
29+
1930vi . mock ( "../../../lib/supabase/server" , ( ) => ( {
2031 createClient : vi . fn ( async ( ) => ( {
2132 auth : {
2233 getUser : vi . fn ( async ( ) => ( {
2334 data : {
24- user : {
25- 26- id : "test-user-id" ,
27- } ,
35+ user :
{ email :
"[email protected] " , id :
"test-user-id" } , 2836 } ,
2937 } ) ) ,
3038 signOut : vi . fn ( ) ,
3139 } ,
40+ from : mockFrom ,
3241 } ) ) ,
3342} ) ) ;
3443
@@ -66,4 +75,19 @@ describe("Dashboard Page Tests", () => {
6675 render ( page ) ;
6776 expect ( screen . getByRole ( "link" , { name : / P r o f i l e / i } ) ) . toBeInTheDocument ( ) ;
6877 } ) ;
78+
79+ it ( "should show Green button for Hello World if completed" , async ( ) => {
80+ // Override the mock for THIS test to simulate completion
81+ mockEq . mockResolvedValue ( {
82+ data : [ { quiz_id : "hello-world" } ] ,
83+ error : null ,
84+ } ) ;
85+
86+ const page = await DashboardPage ( ) ;
87+ render ( page ) ;
88+
89+ const link = screen . getByRole ( "link" , { name : / H e l l o W o r l d / i } ) ;
90+ // Check if link is green
91+ expect ( link . className ) . toContain ( "text-emerald-400" ) ;
92+ } ) ;
6993} ) ;
0 commit comments