@@ -111,10 +111,14 @@ describe('AgentGroup inline main activity', () => {
111111 beforeEach ( ( ) => {
112112 ; ( globalThis as { IS_REACT_ACT_ENVIRONMENT ?: boolean } ) . IS_REACT_ACT_ENVIRONMENT = true
113113 container = document . createElement ( 'div' )
114+ document . body . appendChild ( container )
114115 root = createRoot ( container )
115116 } )
116117
117- afterEach ( ( ) => act ( ( ) => root . unmount ( ) ) )
118+ afterEach ( ( ) => {
119+ act ( ( ) => root . unmount ( ) )
120+ container . remove ( )
121+ } )
118122
119123 it ( 'replaces the active status in place and expands the full completed history' , ( ) => {
120124 const first : AgentGroupItem = {
@@ -206,8 +210,10 @@ describe('AgentGroup inline main activity', () => {
206210 )
207211 } )
208212
209- it ( 'starts a fresh countdown when the latest wait tool changes' , ( ) => {
213+ it ( 'shares one countdown and preserves the viewport across active tool changes' , ( ) => {
210214 vi . useFakeTimers ( )
215+ const setIntervalSpy = vi . spyOn ( globalThis , 'setInterval' )
216+ const clearIntervalSpy = vi . spyOn ( globalThis , 'clearInterval' )
211217 try {
212218 const wait : AgentGroupItem = {
213219 type : 'tool' ,
@@ -233,12 +239,36 @@ describe('AgentGroup inline main activity', () => {
233239 render ( [ wait ] )
234240 act ( ( ) => vi . advanceTimersByTime ( 2000 ) )
235241 expect ( container . textContent ) . toBe ( 'Waiting 1s' )
242+ const header = container . querySelector ( 'button' )
243+ act ( ( ) => header ?. click ( ) )
244+ expect ( header ?. hasAttribute ( 'aria-label' ) ) . toBe ( false )
245+ expect ( header ?. textContent ) . toBe ( 'Waiting 1s' )
246+ expect ( header ) . toHaveAccessibleName ( 'Waiting 1s' )
247+ expect ( container . querySelector ( '[data-state="open"]' ) ?. textContent ) . toBe ( 'Waiting 1s' )
248+ expect ( setIntervalSpy ) . toHaveBeenCalledTimes ( 1 )
249+ act ( ( ) => header ?. click ( ) )
250+ act ( ( ) => header ?. click ( ) )
251+ expect ( container . querySelector ( '[data-state="open"]' ) ?. textContent ) . toBe ( 'Waiting 1s' )
252+ const viewport = container . querySelector ( '.overflow-y-auto' )
236253 render ( [
237254 { ...wait , data : { ...wait . data , status : 'success' } } ,
238255 { ...wait , data : { ...wait . data , id : 'wait-second' } } ,
239256 ] )
240- expect ( container . textContent ) . toBe ( 'Waiting 3s' )
257+ expect ( header ?. textContent ) . toBe ( 'Waiting 3s' )
258+ expect ( header ) . toHaveAccessibleName ( 'Waiting 3s' )
259+ expect ( container . querySelector ( '.overflow-y-auto' ) ) . toBe ( viewport )
260+ expect ( container . querySelector ( '[data-state="open"]' ) ?. textContent ) . toBe ( 'WaitedWaiting 3s' )
261+ expect ( setIntervalSpy ) . toHaveBeenCalledTimes ( 2 )
262+ render ( [
263+ { ...wait , data : { ...wait . data , status : 'success' } } ,
264+ { ...wait , data : { ...wait . data , id : 'wait-second' , status : 'success' } } ,
265+ ] )
266+ expect ( header ?. textContent ) . toBe ( 'Waited' )
267+ expect ( container . querySelector ( '.overflow-y-auto' ) ) . toBe ( viewport )
268+ expect ( clearIntervalSpy ) . toHaveBeenCalledTimes ( 2 )
241269 } finally {
270+ setIntervalSpy . mockRestore ( )
271+ clearIntervalSpy . mockRestore ( )
242272 vi . clearAllTimers ( )
243273 vi . useRealTimers ( )
244274 }
@@ -256,9 +286,10 @@ describe('AgentGroup inline main activity', () => {
256286 type : 'tool' ,
257287 data : {
258288 id : 'run' ,
259- toolName : 'terminal_run ' ,
289+ toolName : 'terminal ' ,
260290 displayTitle : 'Running checks' ,
261291 status : 'success' ,
292+ params : { operation : 'run' } ,
262293 } ,
263294 } ,
264295 ]
@@ -274,7 +305,8 @@ describe('AgentGroup inline main activity', () => {
274305 )
275306 )
276307 const header = container . querySelector ( 'button' )
277- expect ( header ?. getAttribute ( 'aria-label' ) ) . toBe ( 'Agent — Read files, ran commands' )
308+ expect ( header ?. textContent ) . toBe ( 'Agent — Read files, ran commands' )
309+ expect ( header ) . toHaveAccessibleName ( 'Agent — Read files, ran commands' )
278310 expect ( container . querySelectorAll ( '[data-tool-call-id]' ) ) . toHaveLength ( 0 )
279311 act ( ( ) => header ?. click ( ) )
280312 expect (
@@ -309,8 +341,10 @@ describe('AgentGroup inline main activity', () => {
309341 } ,
310342 ] ) ,
311343 ] ,
312- ToolCallComponent : ( { toolCallId, displayTitle } : ToolCallItemProps ) =>
313- createElement ( 'div' , { 'data-tool-call-id' : toolCallId } , displayTitle ) ,
344+ ToolCallComponent : ( { toolCallId, displayTitle, renderStatus } : ToolCallItemProps ) => {
345+ const status = createElement ( 'div' , { 'data-tool-call-id' : toolCallId } , displayTitle )
346+ return renderStatus ? renderStatus ( status ) : status
347+ } ,
314348 } )
315349 )
316350 )
@@ -413,8 +447,10 @@ describe('AgentGroup inline main activity', () => {
413447 agentLabel : 'Sim' ,
414448 items,
415449 isStreaming : true ,
416- ToolCallComponent : ( { toolCallId, displayTitle } : ToolCallItemProps ) =>
417- createElement ( 'div' , { 'data-tool-call-id' : toolCallId } , displayTitle ) ,
450+ ToolCallComponent : ( { toolCallId, displayTitle, renderStatus } : ToolCallItemProps ) => {
451+ const status = createElement ( 'div' , { 'data-tool-call-id' : toolCallId } , displayTitle )
452+ return renderStatus ? renderStatus ( status ) : status
453+ } ,
418454 } )
419455 )
420456 } )
0 commit comments