@@ -4,6 +4,7 @@ import { ThemeProvider } from "@mui/material";
44import { appTheme } from "../../components/common/styles/theme" ;
55import Home from "./Home" ;
66import * as apiHook from "../../lib/hooks/useApi" ;
7+ import * as dateUtils from "../../lib/date/utils" ;
78import { vi , expect , it , describe , beforeEach } from "vitest" ;
89
910// Mock the API hook
@@ -66,7 +67,6 @@ describe("Home", () => {
6667
6768 // Page structure is visible during loading
6869 expect ( screen . getByText ( "Leaderboards" ) ) . toBeInTheDocument ( ) ;
69- expect ( screen . getByText ( "Submit your first kernel" ) ) . toBeInTheDocument ( ) ;
7070 // Loading indicator is present
7171 expect ( screen . getByRole ( "progressbar" ) ) . toBeInTheDocument ( ) ;
7272 } ) ;
@@ -311,6 +311,116 @@ describe("Home", () => {
311311 expect ( screen . getByText ( "L4" ) ) . toBeInTheDocument ( ) ;
312312 } ) ;
313313
314+ it ( "shows active private competitions in their own section before closed competitions" , ( ) => {
315+ vi . mocked ( dateUtils . isExpired ) . mockImplementation ( ( deadline : string | Date ) => {
316+ if ( deadline instanceof Date ) return deadline . getTime ( ) < Date . now ( ) ;
317+ return deadline === "2024-01-01T00:00:00Z" ;
318+ } ) ;
319+
320+ const mockData = {
321+ leaderboards : [
322+ {
323+ id : 1 ,
324+ name : "public-competition" ,
325+ visibility : "public" ,
326+ deadline : "2025-12-31T23:59:59Z" ,
327+ gpu_types : [ "T4" ] ,
328+ priority_gpu_type : "T4" ,
329+ top_users : null ,
330+ } ,
331+ {
332+ id : 2 ,
333+ name : "private-competition" ,
334+ visibility : "closed" ,
335+ deadline : "2025-12-31T23:59:59Z" ,
336+ gpu_types : [ "A100" ] ,
337+ priority_gpu_type : "A100" ,
338+ top_users : null ,
339+ } ,
340+ {
341+ id : 3 ,
342+ name : "expired-public-competition" ,
343+ visibility : "public" ,
344+ deadline : "2024-01-01T00:00:00Z" ,
345+ gpu_types : [ "L4" ] ,
346+ priority_gpu_type : "L4" ,
347+ top_users : null ,
348+ } ,
349+ ] ,
350+ now : "2025-01-01T00:00:00Z" ,
351+ } ;
352+
353+ const mockHookReturn = {
354+ data : mockData ,
355+ loading : false ,
356+ hasLoaded : true ,
357+ error : null ,
358+ errorStatus : null ,
359+ call : mockCall ,
360+ } ;
361+
362+ ( apiHook . fetcherApiCallback as ReturnType < typeof vi . fn > ) . mockReturnValue (
363+ mockHookReturn ,
364+ ) ;
365+
366+ renderWithProviders ( < Home /> ) ;
367+
368+ expect ( screen . getByText ( "Active Competitions" ) ) . toBeInTheDocument ( ) ;
369+ expect ( screen . getByText ( "Private Competitions" ) ) . toBeInTheDocument ( ) ;
370+ expect ( screen . getByText ( "Closed Competitions" ) ) . toBeInTheDocument ( ) ;
371+ expect ( screen . getByText ( "private-competition" ) ) . toBeInTheDocument ( ) ;
372+
373+ const privateHeading = screen . getByText ( "Private Competitions" ) ;
374+ const closedHeading = screen . getByText ( "Closed Competitions" ) ;
375+ expect (
376+ Boolean (
377+ privateHeading . compareDocumentPosition ( closedHeading ) &
378+ Node . DOCUMENT_POSITION_FOLLOWING ,
379+ ) ,
380+ ) . toBe ( true ) ;
381+ } ) ;
382+
383+ it ( "keeps expired private competitions in the closed competitions section" , ( ) => {
384+ vi . mocked ( dateUtils . isExpired ) . mockImplementation ( ( deadline : string | Date ) => {
385+ if ( deadline instanceof Date ) return deadline . getTime ( ) < Date . now ( ) ;
386+ return deadline === "2024-01-01T00:00:00Z" ;
387+ } ) ;
388+
389+ const mockData = {
390+ leaderboards : [
391+ {
392+ id : 1 ,
393+ name : "expired-private-competition" ,
394+ visibility : "closed" ,
395+ deadline : "2024-01-01T00:00:00Z" ,
396+ gpu_types : [ "H100" ] ,
397+ priority_gpu_type : "H100" ,
398+ top_users : null ,
399+ } ,
400+ ] ,
401+ now : "2025-01-01T00:00:00Z" ,
402+ } ;
403+
404+ const mockHookReturn = {
405+ data : mockData ,
406+ loading : false ,
407+ hasLoaded : true ,
408+ error : null ,
409+ errorStatus : null ,
410+ call : mockCall ,
411+ } ;
412+
413+ ( apiHook . fetcherApiCallback as ReturnType < typeof vi . fn > ) . mockReturnValue (
414+ mockHookReturn ,
415+ ) ;
416+
417+ renderWithProviders ( < Home /> ) ;
418+
419+ expect ( screen . queryByText ( "Private Competitions" ) ) . not . toBeInTheDocument ( ) ;
420+ expect ( screen . getByText ( "Closed Competitions" ) ) . toBeInTheDocument ( ) ;
421+ expect ( screen . getByText ( "expired-private-competition" ) ) . toBeInTheDocument ( ) ;
422+ } ) ;
423+
314424 describe ( "LeaderboardTile functionality" , ( ) => {
315425 it ( "displays time left correctly" , ( ) => {
316426 const mockData = {
0 commit comments