@@ -33,6 +33,15 @@ function setup() {
3333 } ;
3434}
3535
36+ /** Mirrors MessagesTimeline's scroller, which takes focus so the keyboard scrolls it. */
37+ function conversationScroller ( height : number ) {
38+ const timeline = document . createElement ( "div" ) ;
39+ timeline . style . cssText = `height: ${ height } px; overflow-y: auto` ;
40+ timeline . tabIndex = - 1 ;
41+ timeline . dataset . workspaceFocusDefault = "" ;
42+ return timeline ;
43+ }
44+
3645describe ( "workspace area focus" , ( ) => {
3746 it ( "cycles in workspace order in both directions, independent of DOM order" , ( ) => {
3847 using fixture = setup ( ) ;
@@ -42,7 +51,7 @@ describe("workspace area focus", () => {
4251 const composer = fixture . area ( "composer" , 2 ) ;
4352 sidebar . button . focus ( ) ;
4453 fixture . controller . move ( 1 ) ;
45- // The conversation is a region; it takes focus itself rather than its first button.
54+ // Without a timeline (an empty thread), the region takes focus rather than its first button.
4655 expect ( document . activeElement ) . toBe ( conversation . element ) ;
4756 fixture . controller . move ( 1 ) ;
4857 expect ( document . activeElement ) . toBe ( composer . button ) ;
@@ -204,8 +213,7 @@ describe("workspace area focus", () => {
204213 it ( "does not scroll the conversation to an old control" , ( ) => {
205214 using fixture = setup ( ) ;
206215 const conversation = fixture . area ( "conversation" , 1 ) ;
207- const timeline = document . createElement ( "div" ) ;
208- timeline . style . cssText = "height: 50px; overflow-y: auto" ;
216+ const timeline = conversationScroller ( 50 ) ;
209217 const copy = document . createElement ( "button" ) ;
210218 copy . textContent = "Copy" ;
211219 timeline . append ( copy , Object . assign ( document . createElement ( "div" ) , { style : "height: 400px" } ) ) ;
@@ -217,10 +225,28 @@ describe("workspace area focus", () => {
217225 // Live follow moved the timeline to the newest output.
218226 timeline . scrollTop = 300 ;
219227 fixture . controller . move ( - 1 ) ;
220- expect ( document . activeElement ) . toBe ( conversation . element ) ;
228+ expect ( document . activeElement ) . toBe ( timeline ) ;
221229 expect ( timeline . scrollTop ) . toBe ( 300 ) ;
222230 } ) ;
223231
232+ it ( "scrolls the conversation with the keyboard once an empty thread gets a timeline" , async ( ) => {
233+ using fixture = setup ( ) ;
234+ const conversation = fixture . area ( "conversation" , 1 ) ;
235+ conversation . button . remove ( ) ;
236+ conversation . element . style . height = "200px" ;
237+ const composer = fixture . area ( "composer" , 2 ) ;
238+ composer . button . focus ( ) ;
239+ fixture . controller . move ( - 1 ) ;
240+ expect ( document . activeElement ) . toBe ( conversation . element ) ;
241+ fixture . controller . move ( 1 ) ;
242+ const timeline = conversationScroller ( 200 ) ;
243+ timeline . append ( Object . assign ( document . createElement ( "div" ) , { style : "height: 2000px" } ) ) ;
244+ conversation . element . append ( timeline ) ;
245+ fixture . controller . move ( - 1 ) ;
246+ await userEvent . keyboard ( "{ArrowDown}{PageDown}" ) ;
247+ await vi . waitFor ( ( ) => expect ( timeline . scrollTop ) . toBeGreaterThan ( 0 ) ) ;
248+ } ) ;
249+
224250 it . each ( [
225251 [ "panel" , "panel" , "removed" ] ,
226252 [ "conversation" , "composer" , "removed" ] ,
@@ -281,7 +307,9 @@ describe("workspace area focus", () => {
281307 bringBack . textContent = "Bring back" ;
282308 content . append ( bringBack ) ;
283309 panel . element . append ( content ) ;
284- fixture . area ( "conversation" , 1 , content ) ;
310+ const timeline = conversationScroller ( 50 ) ;
311+ timeline . append ( Object . assign ( document . createElement ( "div" ) , { style : "height: 400px" } ) ) ;
312+ fixture . area ( "conversation" , 1 , content ) . element . append ( timeline ) ;
285313 const composer = fixture . area ( "composer" , 2 , content ) ;
286314 const editor = document . createElement ( "div" ) ;
287315 editor . contentEditable = "true" ;
0 commit comments