@@ -8,7 +8,7 @@ import type { LimitPresentations } from "@t3tools/shared/usageLimits";
88import { act } from "react" ;
99import { createRoot , type Root } from "react-dom/client" ;
1010import { afterEach , beforeEach , expect , it , vi } from "vite-plus/test" ;
11- import { userEvent } from "vite-plus/test/browser" ;
11+ import { page , userEvent } from "vite-plus/test/browser" ;
1212
1313// Real pointer clicks need the dialog's stacking styles to land above Base UI's modal overlay.
1414import "~/index.css" ;
@@ -26,47 +26,48 @@ vi.mock("../settings/RedactedSensitiveText", () => ({ RedactedSensitiveText: ()
2626
2727import { UsageLimitsPooled } from "./UsageLimitsPooled" ;
2828
29- const presentations : LimitPresentations = new Map ( [
30- [
31- EnvironmentId . make ( "env-a" ) ,
32- {
33- entry : { target : { label : "Test" } } ,
34- serverConfig : {
35- usageLimitSources : [ ] ,
36- providers : [
37- {
38- instanceId : ProviderInstanceId . make ( "alpha" ) ,
39- driver : ProviderDriverKind . make ( "codex" ) ,
40- displayName : "Alpha" ,
41- enabled : true ,
42- installed : true ,
43- version : null ,
44- status : "ready" ,
45- auth :
{ status :
"authenticated" , email :
"[email protected] " } , 46- checkedAt : "2026-09-03T11:00:00Z" ,
47- models : [ ] ,
48- slashCommands : [ ] ,
49- skills : [ ] ,
50- usageLimits : {
29+ const presentations = ( resetsAt : string | undefined , availableCount : number ) : LimitPresentations =>
30+ new Map ( [
31+ [
32+ EnvironmentId . make ( "env-a" ) ,
33+ {
34+ entry : { target : { label : "Test" } } ,
35+ serverConfig : {
36+ usageLimitSources : [ ] ,
37+ providers : [
38+ {
39+ instanceId : ProviderInstanceId . make ( "alpha" ) ,
40+ driver : ProviderDriverKind . make ( "codex" ) ,
41+ displayName : "Alpha" ,
42+ enabled : true ,
43+ installed : true ,
44+ version : null ,
45+ status : "ready" ,
46+ auth :
{ status :
"authenticated" , email :
"[email protected] " } , 5147 checkedAt : "2026-09-03T11:00:00Z" ,
52- resetCredits : { availableCount : 1 } ,
53- windows : [
54- {
55- id : "five_hour" ,
56- kind : "session" ,
57- label : "Session" ,
58- usedPercent : 40 ,
59- windowDurationMins : 300 ,
60- resetsAt : "2026-09-03T14:00:00Z" ,
61- } ,
62- ] ,
63- } ,
64- } satisfies ServerProvider ,
65- ] ,
48+ models : [ ] ,
49+ slashCommands : [ ] ,
50+ skills : [ ] ,
51+ usageLimits : {
52+ checkedAt : "2026-09-03T11:00:00Z" ,
53+ resetCredits : { availableCount } ,
54+ windows : [
55+ {
56+ id : "five_hour" ,
57+ kind : "session" ,
58+ label : "Session" ,
59+ usedPercent : resetsAt ? 40 : 0 ,
60+ windowDurationMins : 300 ,
61+ ...( resetsAt ? { resetsAt } : { } ) ,
62+ } ,
63+ ] ,
64+ } ,
65+ } satisfies ServerProvider ,
66+ ] ,
67+ } ,
6668 } ,
67- } ,
68- ] ,
69- ] ) ;
69+ ] ,
70+ ] ) ;
7071
7172let root : Root ;
7273let container : HTMLDivElement ;
@@ -77,7 +78,11 @@ beforeEach(async () => {
7778 container = document . createElement ( "div" ) ;
7879 document . body . append ( container ) ;
7980 root = createRoot ( container ) ;
80- await act ( ( ) => root . render ( < UsageLimitsPooled presentations = { presentations } now = { 0 } /> ) ) ;
81+ await act ( ( ) =>
82+ root . render (
83+ < UsageLimitsPooled presentations = { presentations ( "2026-09-03T14:00:00Z" , 1 ) } now = { 0 } /> ,
84+ ) ,
85+ ) ;
8186} ) ;
8287
8388afterEach ( async ( ) => {
@@ -130,3 +135,32 @@ it.each([
130135 await act ( async ( ) => answer ( result ) ) ;
131136 expect ( status ?. textContent ) . toBe ( `Alpha ${ text } ` ) ;
132137} ) ;
138+
139+ it ( "omits an empty reset plate but keeps countdowns and banked credits visible" , async ( ) => {
140+ await page . viewport ( 1440 , 900 ) ;
141+ const now = Date . parse ( "2026-09-03T11:00:00Z" ) ;
142+ const segment = page . getByRole ( "button" , { name : / ^ A l p h a : / } ) ;
143+ // The empty plate has no accessible text; select its painted background inside the real bar.
144+ const plate = ( ) =>
145+ segment . element ( ) . querySelector < HTMLSpanElement > ( '[class~="bg-background/85"]' ) ;
146+
147+ await act ( ( ) =>
148+ root . render ( < UsageLimitsPooled presentations = { presentations ( undefined , 0 ) } now = { now } /> ) ,
149+ ) ;
150+ await expect . element ( segment . getByText ( "100%" , { exact : true } ) ) . toBeVisible ( ) ;
151+ expect ( plate ( ) ) . toBeNull ( ) ;
152+
153+ await act ( ( ) =>
154+ root . render (
155+ < UsageLimitsPooled presentations = { presentations ( "2026-09-03T14:00:00Z" , 0 ) } now = { now } /> ,
156+ ) ,
157+ ) ;
158+ await expect . element ( plate ( ) ) . toBeVisible ( ) ;
159+ expect ( plate ( ) ?. textContent ) . toBe ( "↻ 3h 0m" ) ;
160+
161+ await act ( ( ) =>
162+ root . render ( < UsageLimitsPooled presentations = { presentations ( undefined , 1 ) } now = { now } /> ) ,
163+ ) ;
164+ await expect . element ( plate ( ) ) . toBeVisible ( ) ;
165+ expect ( plate ( ) ?. textContent ) . toBe ( "1" ) ;
166+ } ) ;
0 commit comments