Fix failing tests

K Simmons created

Change summary

crates/collab/src/integration_tests.rs | 32 +++++++++++++++++++++++----
crates/gpui/src/app.rs                 |  3 +
crates/workspace/src/workspace.rs      | 13 +++++++++-
3 files changed, 40 insertions(+), 8 deletions(-)

Detailed changes

crates/collab/src/integration_tests.rs 🔗

@@ -4246,7 +4246,10 @@ async fn test_peers_following_each_other(cx_a: &mut TestAppContext, cx_b: &mut T
     // Clients A and B follow each other in split panes
     workspace_a.update(cx_a, |workspace, cx| {
         workspace.split_pane(workspace.active_pane().clone(), SplitDirection::Right, cx);
-        assert_ne!(*workspace.active_pane(), pane_a1);
+        let pane_a1 = pane_a1.clone();
+        cx.defer(move |workspace, _| {
+            assert_ne!(*workspace.active_pane(), pane_a1);
+        });
     });
     workspace_a
         .update(cx_a, |workspace, cx| {
@@ -4259,7 +4262,10 @@ async fn test_peers_following_each_other(cx_a: &mut TestAppContext, cx_b: &mut T
         .unwrap();
     workspace_b.update(cx_b, |workspace, cx| {
         workspace.split_pane(workspace.active_pane().clone(), SplitDirection::Right, cx);
-        assert_ne!(*workspace.active_pane(), pane_b1);
+        let pane_b1 = pane_b1.clone();
+        cx.defer(move |workspace, _| {
+            assert_ne!(*workspace.active_pane(), pane_b1);
+        });
     });
     workspace_b
         .update(cx_b, |workspace, cx| {
@@ -4271,17 +4277,26 @@ async fn test_peers_following_each_other(cx_a: &mut TestAppContext, cx_b: &mut T
         .await
         .unwrap();
 
+    workspace_a.update(cx_a, |workspace, cx| {
+        workspace.activate_next_pane(cx);
+    });
+    // Wait for focus effects to be fully flushed
+    workspace_a.update(cx_a, |workspace, _| {
+        assert_eq!(*workspace.active_pane(), pane_a1);
+    });
+
     workspace_a
         .update(cx_a, |workspace, cx| {
-            workspace.activate_next_pane(cx);
-            assert_eq!(*workspace.active_pane(), pane_a1);
             workspace.open_path((worktree_id, "3.txt"), true, cx)
         })
         .await
         .unwrap();
+    workspace_b.update(cx_b, |workspace, cx| {
+        workspace.activate_next_pane(cx);
+    });
+
     workspace_b
         .update(cx_b, |workspace, cx| {
-            workspace.activate_next_pane(cx);
             assert_eq!(*workspace.active_pane(), pane_b1);
             workspace.open_path((worktree_id, "4.txt"), true, cx)
         })
@@ -4311,17 +4326,24 @@ async fn test_peers_following_each_other(cx_a: &mut TestAppContext, cx_b: &mut T
             Some((worktree_id, "3.txt").into())
         );
         workspace.activate_next_pane(cx);
+    });
+
+    workspace_a.update(cx_a, |workspace, cx| {
         assert_eq!(
             workspace.active_item(cx).unwrap().project_path(cx),
             Some((worktree_id, "4.txt").into())
         );
     });
+
     workspace_b.update(cx_b, |workspace, cx| {
         assert_eq!(
             workspace.active_item(cx).unwrap().project_path(cx),
             Some((worktree_id, "4.txt").into())
         );
         workspace.activate_next_pane(cx);
+    });
+
+    workspace_b.update(cx_b, |workspace, cx| {
         assert_eq!(
             workspace.active_item(cx).unwrap().project_path(cx),
             Some((worktree_id, "3.txt").into())

crates/gpui/src/app.rs 🔗

@@ -7089,7 +7089,7 @@ mod tests {
 
         let (window_id, view_1) = cx.add_window(Default::default(), |_| view_1);
         let view_2 = cx.add_view(&view_1, |_| view_2);
-        cx.add_view(&view_2, |cx| {
+        let _view_3 = cx.add_view(&view_2, |cx| {
             cx.focus_self();
             view_3
         });
@@ -7135,6 +7135,7 @@ mod tests {
         assert_eq!(&*actions.borrow(), &["2 a"]);
 
         actions.borrow_mut().clear();
+
         cx.dispatch_keystroke(window_id, &Keystroke::parse("b").unwrap());
 
         assert_eq!(&*actions.borrow(), &["3 b", "2 b", "1 b", "global b"]);

crates/workspace/src/workspace.rs 🔗

@@ -1,3 +1,7 @@
+/// NOTE: Focus only 'takes' after an update has flushed_effects. Pane sends an event in on_focus_in
+/// which the workspace uses to change the activated pane.
+/// This may cause issues when you're trying to write tests that use workspace focus to add items at
+/// specific locations.
 pub mod pane;
 pub mod pane_group;
 pub mod sidebar;
@@ -3088,16 +3092,21 @@ mod tests {
             workspace
                 .split_pane(left_pane.clone(), SplitDirection::Right, cx)
                 .unwrap();
-            workspace.add_item(Box::new(cx.add_view(|_| item_3_4.clone())), cx);
 
             left_pane
         });
 
+        //Need to cause an effect flush in order to respect new focus
+        workspace.update(cx, |workspace, cx| {
+            workspace.add_item(Box::new(cx.add_view(|_| item_3_4.clone())), cx);
+            cx.focus(left_pane.clone());
+        });
+
         // When closing all of the items in the left pane, we should be prompted twice:
         // once for project entry 0, and once for project entry 2. After those two
         // prompts, the task should complete.
+
         let close = workspace.update(cx, |workspace, cx| {
-            cx.focus(left_pane.clone());
             Pane::close_items(workspace, left_pane.clone(), cx, |_| true)
         });