From 8a19ba541eb077ef6f44dfc9e16a1bb9e75352e2 Mon Sep 17 00:00:00 2001 From: Max Brunsfeld Date: Sun, 15 Mar 2026 17:01:45 -0700 Subject: [PATCH] Fix code for setting up agent panel and threads panel in tests --- crates/agent_ui/src/threads_panel.rs | 45 ++++++++++++++++++++-------- 1 file changed, 33 insertions(+), 12 deletions(-) diff --git a/crates/agent_ui/src/threads_panel.rs b/crates/agent_ui/src/threads_panel.rs index aa562538ad6addaaf53305a82b9e3e68cf833b53..af29e1de23a6ecf1e6794170d1c17cb276e5cdd1 100644 --- a/crates/agent_ui/src/threads_panel.rs +++ b/crates/agent_ui/src/threads_panel.rs @@ -2187,8 +2187,10 @@ mod tests { }); cx.run_until_parked(); let multi_workspace_entity = multi_workspace.clone(); - let sidebar = workspace.update_in(cx, |_, window, cx| { - cx.new(|cx| ThreadsPanel::new(multi_workspace_entity, window, cx)) + let sidebar = workspace.update_in(cx, |workspace, window, cx| { + let panel = cx.new(|cx| ThreadsPanel::new(multi_workspace_entity, window, cx)); + workspace.add_panel(panel.clone(), window, cx); + panel }); (sidebar, panel) } @@ -2239,10 +2241,17 @@ mod tests { fn open_and_focus_sidebar(sidebar: &Entity, cx: &mut gpui::VisualTestContext) { cx.run_until_parked(); - sidebar.update_in(cx, |sidebar, window, cx| { - sidebar.set_open(true, cx); - cx.focus_self(window); + let workspace = sidebar.read_with(cx, |sidebar, cx| { + sidebar + .multi_workspace + .upgrade() + .map(|mw| mw.read(cx).workspace().clone()) }); + if let Some(workspace) = workspace { + workspace.update_in(cx, |workspace, window, cx| { + workspace.focus_panel::(window, cx); + }); + } cx.run_until_parked(); } @@ -2906,8 +2915,16 @@ mod tests { }); cx.run_until_parked(); - // Add an agent panel to workspace 1 so the sidebar renders when it's active. + // Switch to workspace 1 and add panels so the sidebar renders when it's active. + multi_workspace.update_in(cx, |mw, window, cx| { + mw.activate_index(1, window, cx); + }); setup_sidebar_with_agent_panel(&multi_workspace, cx); + // Switch back to workspace 0. + multi_workspace.update_in(cx, |mw, window, cx| { + mw.activate_index(0, window, cx); + }); + cx.run_until_parked(); let path_list = PathList::new(&[std::path::PathBuf::from("/my-project")]); save_n_test_threads(1, &path_list, cx).await; @@ -2934,9 +2951,14 @@ mod tests { 1 ); + // Get workspace 1's ThreadsPanel (each workspace has its own). + let sidebar_1 = multi_workspace.read_with(cx, |mw, cx| { + mw.workspace().read(cx).panel::(cx).unwrap() + }); + // Focus the sidebar and manually select the header (index 0) - open_and_focus_sidebar(&sidebar, cx); - sidebar.update_in(cx, |sidebar, _window, _cx| { + open_and_focus_sidebar(&sidebar_1, cx); + sidebar_1.update_in(cx, |sidebar, _window, _cx| { sidebar.selection = Some(0); }); @@ -4092,15 +4114,14 @@ mod tests { ); }); - workspace_a.read_with(cx, |workspace, cx| { + workspace_a.read_with(cx, |workspace, _cx| { assert!( workspace.drawer::().is_some(), "Agent panel should exist" ); - let dock = workspace.right_dock().read(cx); assert!( - dock.is_open(), - "Clicking a thread should open the agent panel dock" + workspace.drawer_is_open::(), + "Clicking a thread should open the agent panel drawer" ); });