1+ import { describe , it , expect } from 'vitest' ;
2+ import { render } from '@testing-library/react' ;
3+ import { Table , TableBody , TableCell , TableHead , TableHeader , TableRow } from '../components/ui/table' ;
4+
5+ describe ( 'Individual Power Users Numbering' , ( ) => {
6+ it ( 'should display numbered rows in Individual Power Users table' , ( ) => {
7+ // Mock power users data
8+ const mockPowerUsers = [
9+ { user : 'alice' , totalRequests : 300 , exceedingRequests : 50 , requestsByModel : { 'gpt-4' : 200 , 'claude' : 100 } } ,
10+ { user : 'bob' , totalRequests : 250 , exceedingRequests : 25 , requestsByModel : { 'gpt-4' : 250 } } ,
11+ { user : 'charlie' , totalRequests : 200 , exceedingRequests : 0 , requestsByModel : { 'gpt-4' : 150 , 'claude' : 50 } }
12+ ] ;
13+
14+ // Render the table structure with numbering like in App.tsx
15+ const { container } = render (
16+ < Table >
17+ < TableHeader >
18+ < TableRow >
19+ < TableHead className = "w-12" > #</ TableHead >
20+ < TableHead > User</ TableHead >
21+ < TableHead className = "text-right" > Total Requests</ TableHead >
22+ < TableHead className = "text-right" > Exceeding Requests</ TableHead >
23+ < TableHead className = "text-right" > Models Used</ TableHead >
24+ </ TableRow >
25+ </ TableHeader >
26+ < TableBody >
27+ { mockPowerUsers . map ( ( user , index ) => (
28+ < TableRow key = { user . user } >
29+ < TableCell className = "text-center text-muted-foreground font-medium" >
30+ { index + 1 }
31+ </ TableCell >
32+ < TableCell className = "font-medium" >
33+ { user . user }
34+ </ TableCell >
35+ < TableCell className = "text-right" > { user . totalRequests } </ TableCell >
36+ < TableCell className = "text-right" > { user . exceedingRequests } </ TableCell >
37+ < TableCell className = "text-right" > { Object . keys ( user . requestsByModel ) . length } </ TableCell >
38+ </ TableRow >
39+ ) ) }
40+ </ TableBody >
41+ </ Table >
42+ ) ;
43+
44+ // Check that the # header is present
45+ expect ( container . querySelector ( 'th' ) ) . toHaveTextContent ( '#' ) ;
46+
47+ // Check that numbering starts from 1 and increments correctly
48+ const numberCells = container . querySelectorAll ( 'td:first-child' ) ;
49+ expect ( numberCells [ 0 ] ) . toHaveTextContent ( '1' ) ;
50+ expect ( numberCells [ 1 ] ) . toHaveTextContent ( '2' ) ;
51+ expect ( numberCells [ 2 ] ) . toHaveTextContent ( '3' ) ;
52+
53+ // Verify users are in the expected order
54+ const userCells = container . querySelectorAll ( 'td:nth-child(2)' ) ;
55+ expect ( userCells [ 0 ] ) . toHaveTextContent ( 'alice' ) ;
56+ expect ( userCells [ 1 ] ) . toHaveTextContent ( 'bob' ) ;
57+ expect ( userCells [ 2 ] ) . toHaveTextContent ( 'charlie' ) ;
58+ } ) ;
59+
60+ it ( 'should handle single power user correctly' , ( ) => {
61+ const singlePowerUser = [
62+ { user : 'single-user' , totalRequests : 100 , exceedingRequests : 10 , requestsByModel : { 'gpt-4' : 100 } }
63+ ] ;
64+
65+ const { container } = render (
66+ < Table >
67+ < TableHeader >
68+ < TableRow >
69+ < TableHead className = "w-12" > #</ TableHead >
70+ < TableHead > User</ TableHead >
71+ < TableHead className = "text-right" > Total Requests</ TableHead >
72+ < TableHead className = "text-right" > Exceeding Requests</ TableHead >
73+ < TableHead className = "text-right" > Models Used</ TableHead >
74+ </ TableRow >
75+ </ TableHeader >
76+ < TableBody >
77+ { singlePowerUser . map ( ( user , index ) => (
78+ < TableRow key = { user . user } >
79+ < TableCell className = "text-center text-muted-foreground font-medium" >
80+ { index + 1 }
81+ </ TableCell >
82+ < TableCell className = "font-medium" >
83+ { user . user }
84+ </ TableCell >
85+ < TableCell className = "text-right" > { user . totalRequests } </ TableCell >
86+ < TableCell className = "text-right" > { user . exceedingRequests } </ TableCell >
87+ < TableCell className = "text-right" > { Object . keys ( user . requestsByModel ) . length } </ TableCell >
88+ </ TableRow >
89+ ) ) }
90+ </ TableBody >
91+ </ Table >
92+ ) ;
93+
94+ // Should show "1" for the single user
95+ const numberCell = container . querySelector ( 'td:first-child' ) ;
96+ expect ( numberCell ) . toHaveTextContent ( '1' ) ;
97+ } ) ;
98+ } ) ;
0 commit comments