@@ -202,3 +202,106 @@ func TestSessionBrowserScrolling(t *testing.T) {
202202 expectedTitle := fmt .Sprintf ("Session %d" , d .selected + 1 )
203203 require .Contains (t , view , expectedTitle , "view should contain selected session" )
204204}
205+
206+ func TestSessionBrowserMouseClickSelectsSession (t * testing.T ) {
207+ sessions := []session.Summary {
208+ {ID : "1" , Title : "Session 1" , CreatedAt : time .Now ()},
209+ {ID : "2" , Title : "Session 2" , CreatedAt : time .Now ()},
210+ {ID : "3" , Title : "Session 3" , CreatedAt : time .Now ()},
211+ }
212+
213+ dialog := NewSessionBrowserDialog (sessions )
214+ d := dialog .(* sessionBrowserDialog )
215+ d .Init ()
216+ d .Update (tea.WindowSizeMsg {Width : 100 , Height : 50 })
217+
218+ // Initially selected should be 0
219+ require .Equal (t , 0 , d .selected )
220+
221+ // Get the dialog position to calculate where to click
222+ dialogRow , _ := d .Position ()
223+ listStartY := dialogRow + sessionBrowserListStartY
224+
225+ // Single-click on the second session (line index 1)
226+ clickMsg := tea.MouseClickMsg {
227+ X : 20 ,
228+ Y : listStartY + 1 ,
229+ Button : tea .MouseLeft ,
230+ }
231+ updated , cmd := d .Update (clickMsg )
232+ d = updated .(* sessionBrowserDialog )
233+
234+ // Selection should have moved to session 2
235+ require .Equal (t , 1 , d .selected , "single click should select session" )
236+ // Single click should not produce a load command
237+ require .Nil (t , cmd , "single click should not trigger load" )
238+
239+ // Single-click on the third session
240+ clickMsg = tea.MouseClickMsg {
241+ X : 20 ,
242+ Y : listStartY + 2 ,
243+ Button : tea .MouseLeft ,
244+ }
245+ updated , cmd = d .Update (clickMsg )
246+ d = updated .(* sessionBrowserDialog )
247+
248+ require .Equal (t , 2 , d .selected , "single click should select third session" )
249+ require .Nil (t , cmd , "single click on different session should not trigger load" )
250+ }
251+
252+ func TestSessionBrowserDoubleClickOpensSession (t * testing.T ) {
253+ sessions := []session.Summary {
254+ {ID : "sess-1" , Title : "Session 1" , CreatedAt : time .Now ()},
255+ {ID : "sess-2" , Title : "Session 2" , CreatedAt : time .Now ()},
256+ {ID : "sess-3" , Title : "Session 3" , CreatedAt : time .Now ()},
257+ }
258+
259+ dialog := NewSessionBrowserDialog (sessions )
260+ d := dialog .(* sessionBrowserDialog )
261+ d .Init ()
262+ d .Update (tea.WindowSizeMsg {Width : 100 , Height : 50 })
263+
264+ dialogRow , _ := d .Position ()
265+ listStartY := dialogRow + sessionBrowserListStartY
266+
267+ // First click selects
268+ clickMsg := tea.MouseClickMsg {
269+ X : 20 ,
270+ Y : listStartY + 1 ,
271+ Button : tea .MouseLeft ,
272+ }
273+ updated , _ := d .Update (clickMsg )
274+ d = updated .(* sessionBrowserDialog )
275+ require .Equal (t , 1 , d .selected )
276+
277+ // Second click on the same item (double-click) should trigger load
278+ updated , cmd := d .Update (clickMsg )
279+ d = updated .(* sessionBrowserDialog )
280+ require .Equal (t , 1 , d .selected , "selection should stay on double-clicked session" )
281+ require .NotNil (t , cmd , "double-click should produce a command to load the session" )
282+ }
283+
284+ func TestSessionBrowserClickOutsideListIgnored (t * testing.T ) {
285+ sessions := []session.Summary {
286+ {ID : "1" , Title : "Session 1" , CreatedAt : time .Now ()},
287+ {ID : "2" , Title : "Session 2" , CreatedAt : time .Now ()},
288+ }
289+
290+ dialog := NewSessionBrowserDialog (sessions )
291+ d := dialog .(* sessionBrowserDialog )
292+ d .Init ()
293+ d .Update (tea.WindowSizeMsg {Width : 100 , Height : 50 })
294+
295+ // Click way outside the list area
296+ clickMsg := tea.MouseClickMsg {
297+ X : 5 ,
298+ Y : 0 ,
299+ Button : tea .MouseLeft ,
300+ }
301+ updated , cmd := d .Update (clickMsg )
302+ d = updated .(* sessionBrowserDialog )
303+
304+ // Selection should remain at 0
305+ require .Equal (t , 0 , d .selected , "click outside list should not change selection" )
306+ require .Nil (t , cmd , "click outside list should not produce a command" )
307+ }
0 commit comments