@@ -3,51 +3,27 @@ import { computeVisibleCount } from "@/ui/components/topbar/TopBarFit"
33
44const GAP = 12
55const BUTTON = 40
6- const SLACK = 8
6+ const SUBPIXEL_SLACK_PX = 8
77
88const BUTTONS = Array < number > ( 6 ) . fill ( BUTTON )
99
10- const budgetFor = ( n : number ) => n * ( BUTTON + GAP ) + SLACK
10+ const leastBudgetFitting = ( n : number ) => n * ( BUTTON + GAP ) + SUBPIXEL_SLACK_PX
1111
1212describe ( "computeVisibleCount" , ( ) => {
13- test ( "shows everything when there is room to spare" , ( ) => {
14- expect ( computeVisibleCount ( budgetFor ( 6 ) + 100 , BUTTONS , GAP ) ) . toBe ( 6 )
15- } )
16-
17- test ( "shows everything at exactly the budget it needs" , ( ) => {
18- expect ( computeVisibleCount ( budgetFor ( 6 ) , BUTTONS , GAP ) ) . toBe ( 6 )
19- } )
20-
21- test ( "holds back slack so a sub-pixel measurement error cannot overflow the row" , ( ) => {
22- expect ( computeVisibleCount ( budgetFor ( 6 ) - 1 , BUTTONS , GAP ) ) . toBe ( 5 )
23- expect ( computeVisibleCount ( budgetFor ( 6 ) - SLACK , BUTTONS , GAP ) ) . toBe ( 5 )
24- } )
25-
26- test ( "drops one item at a time as the budget shrinks" , ( ) => {
27- for ( let visible = 0 ; visible <= 6 ; visible ++ ) {
28- expect ( computeVisibleCount ( budgetFor ( visible ) , BUTTONS , GAP ) ) . toBe ( visible )
29- expect ( computeVisibleCount ( budgetFor ( visible + 1 ) - 1 , BUTTONS , GAP ) ) . toBe ( visible )
13+ test ( "drops exactly one item per item-width of budget, holding back slack" , ( ) => {
14+ for ( let visible = 0 ; visible <= BUTTONS . length ; visible ++ ) {
15+ expect ( computeVisibleCount ( leastBudgetFitting ( visible ) , BUTTONS , GAP ) ) . toBe ( visible )
16+ expect ( computeVisibleCount ( leastBudgetFitting ( visible + 1 ) - 1 , BUTTONS , GAP ) ) . toBe ( visible )
3017 }
3118 } )
3219
33- test ( "drops from the end, so the front of the list is the last to go" , ( ) => {
34- const widths = [ BUTTON , BUTTON , 200 ]
35-
36- expect ( computeVisibleCount ( budgetFor ( 2 ) + 200 + GAP , widths , GAP ) ) . toBe ( 3 )
37- expect ( computeVisibleCount ( budgetFor ( 2 ) , widths , GAP ) ) . toBe ( 2 )
38- expect ( computeVisibleCount ( budgetFor ( 1 ) , widths , GAP ) ) . toBe ( 1 )
39- } )
40-
4120 test ( "stops at an item too wide to fit rather than skipping past it" , ( ) => {
42- expect ( computeVisibleCount ( budgetFor ( 3 ) , [ 200 , BUTTON , BUTTON , BUTTON ] , GAP ) ) . toBe ( 0 )
21+ expect ( computeVisibleCount ( leastBudgetFitting ( 3 ) , [ 200 , BUTTON , BUTTON , BUTTON ] , GAP ) ) . toBe ( 0 )
4322 } )
4423
45- test ( "shows nothing when the budget is gone or negative " , ( ) => {
24+ test ( "shows nothing for an exhausted budget or an empty list " , ( ) => {
4625 expect ( computeVisibleCount ( 0 , BUTTONS , GAP ) ) . toBe ( 0 )
4726 expect ( computeVisibleCount ( - 500 , BUTTONS , GAP ) ) . toBe ( 0 )
48- } )
49-
50- test ( "handles an empty item list" , ( ) => {
5127 expect ( computeVisibleCount ( 1000 , [ ] , GAP ) ) . toBe ( 0 )
5228 } )
5329} )
0 commit comments