@@ -16,22 +16,22 @@ const complete: AgentTurnUsage = {
1616 countedCallCount : 3 ,
1717 status : "complete" ,
1818} ;
19- const show = ( usage ?: AgentTurnUsage ) =>
19+ const show = ( usage ?: AgentTurnUsage , durationMs ?: number , running = false ) =>
2020 render (
2121 < I18nProvider >
2222 < TooltipProvider >
23- < ChatUsageSummary usage = { usage } />
23+ < ChatUsageSummary usage = { usage } durationMs = { durationMs } running = { running } />
2424 </ TooltipProvider >
2525 </ I18nProvider > ,
2626 ) ;
2727describe ( "ChatUsageSummary" , ( ) => {
28- it ( "shows totals and model calls with accessible accounting details" , ( ) => {
28+ it ( "shows a concise total with accounting details in the tooltip " , ( ) => {
2929 const view = show ( complete ) ;
30- expect ( view . getByText ( "660 tokens · 3 model calls " ) ) . toHaveAttribute (
30+ expect ( view . getByText ( "660 tokens" ) ) . toHaveAttribute (
3131 "aria-label" ,
3232 expect . stringContaining ( "Input: 500" ) ,
3333 ) ;
34- expect ( view . getByText ( "660 tokens · 3 model calls " ) ) . toHaveAttribute (
34+ expect ( view . getByText ( "660 tokens" ) ) . toHaveAttribute (
3535 "aria-label" ,
3636 expect . stringContaining ( "3 of 3 model calls counted" ) ,
3737 ) ;
@@ -53,22 +53,40 @@ describe("ChatUsageSummary", () => {
5353 } ) ;
5454 it ( "shows explicitly reported zero" , ( ) => {
5555 expect (
56- show ( { ...complete , inputTokens : 0 , outputTokens : 0 , totalTokens : 0 } ) . getByText (
57- "0 tokens · 3 model calls" ,
58- ) ,
56+ show ( { ...complete , inputTokens : 0 , outputTokens : 0 , totalTokens : 0 } ) . getByText ( "0 tokens" ) ,
5957 ) . toBeInTheDocument ( ) ;
6058 } ) ;
6159 it ( "labels optional details as reported counts and omits missing details" , ( ) => {
6260 const view = show ( { ...complete , cachedInputTokens : 0 , reasoningOutputTokens : 12 } ) ;
63- const label = view . getByText ( "660 tokens · 3 model calls " ) . getAttribute ( "aria-label" ) ;
61+ const label = view . getByText ( "660 tokens" ) . getAttribute ( "aria-label" ) ;
6462 expect ( label ) . toContain ( "Reported cached input: 0" ) ;
6563 expect ( label ) . toContain ( "Reported reasoning output: 12" ) ;
6664 expect ( label ) . not . toContain ( "cache creation" ) ;
6765 } ) ;
6866 it ( "formats counts for the selected locale" , ( ) => {
6967 localStorage . setItem ( "openscreen-locale" , "de" ) ;
70- const view = show ( { ...complete , totalTokens : 1234 } ) ;
71- expect ( view . getByText ( / 1 . 2 3 4 / ) ) . toBeInTheDocument ( ) ;
68+ const view = show ( { ...complete , totalTokens : 12340 } ) ;
69+ expect ( view . getByText ( / 1 2 , 3 k / ) ) . toBeInTheDocument ( ) ;
7270 localStorage . clear ( ) ;
7371 } ) ;
72+ it ( "shows compact totals and elapsed time, with no visible breakdown or model-call count" , ( ) => {
73+ const view = show ( { ...complete , totalTokens : 12340 } , 45000 ) ;
74+ expect ( view . getByText ( "12.3k tokens · 45s" ) ) . toBeInTheDocument ( ) ;
75+ expect ( view . container . textContent ) . not . toMatch ( / I n p u t : | O u t p u t : | m o d e l c a l l s / ) ;
76+ } ) ;
77+ it ( "keeps elapsed time on unavailable usage without claiming zero tokens" , ( ) => {
78+ const view = show (
79+ { ...complete , status : "unavailable" , countedCallCount : 0 , totalTokens : 0 } ,
80+ 1200 ,
81+ ) ;
82+ expect ( view . getByText ( "Token usage unavailable · 1s" ) ) . toBeInTheDocument ( ) ;
83+ } ) ;
84+ it ( "shows reported running counts as a lower bound and hides unavailable running usage" , ( ) => {
85+ const view = show ( complete , undefined , true ) ;
86+ expect ( view . getByText ( "≥660 tokens" ) ) . toBeInTheDocument ( ) ;
87+ view . unmount ( ) ;
88+ expect (
89+ show ( { ...complete , status : "unavailable" } , undefined , true ) . container ,
90+ ) . toBeEmptyDOMElement ( ) ;
91+ } ) ;
7492} ) ;
0 commit comments