Fix tests that failed due to defaulting the grouping interval to zero in tests

Nathan Sobo created

Change summary

crates/collab/src/tests/integration_tests.rs |  7 ++++++-
crates/editor/src/editor.rs                  |  2 ++
crates/editor/src/editor_tests.rs            |  8 +++++++-
crates/language/src/buffer_tests.rs          | 11 ++++++++++-
4 files changed, 25 insertions(+), 3 deletions(-)

Detailed changes

crates/collab/src/tests/integration_tests.rs 🔗

@@ -1131,6 +1131,7 @@ async fn test_unshare_project(
         .unwrap();
     let worktree_a = project_a.read_with(cx_a, |project, cx| project.worktrees(cx).next().unwrap());
     let project_b = client_b.build_remote_project(project_id, cx_b).await;
+    deterministic.run_until_parked();
     assert!(worktree_a.read_with(cx_a, |tree, _| tree.as_local().unwrap().is_shared()));
 
     project_b
@@ -1160,6 +1161,7 @@ async fn test_unshare_project(
         .await
         .unwrap();
     let project_c2 = client_c.build_remote_project(project_id, cx_c).await;
+    deterministic.run_until_parked();
     assert!(worktree_a.read_with(cx_a, |tree, _| tree.as_local().unwrap().is_shared()));
     project_c2
         .update(cx_c, |p, cx| p.open_buffer((worktree_id, "a.txt"), cx))
@@ -1213,6 +1215,7 @@ async fn test_host_disconnect(
         .unwrap();
 
     let project_b = client_b.build_remote_project(project_id, cx_b).await;
+    deterministic.run_until_parked();
     assert!(worktree_a.read_with(cx_a, |tree, _| tree.as_local().unwrap().is_shared()));
 
     let (_, workspace_b) = cx_b.add_window(|cx| {
@@ -1467,7 +1470,7 @@ async fn test_project_reconnect(
         .read_with(cx_a, |tree, _| tree.as_local().unwrap().scan_complete())
         .await;
     let worktree3_id = worktree_a3.read_with(cx_a, |tree, _| {
-        assert!(tree.as_local().unwrap().is_shared());
+        assert!(!tree.as_local().unwrap().is_shared());
         tree.id()
     });
     deterministic.run_until_parked();
@@ -1489,6 +1492,7 @@ async fn test_project_reconnect(
     deterministic.run_until_parked();
     project_a1.read_with(cx_a, |project, cx| {
         assert!(project.is_shared());
+        assert!(worktree_a1.read(cx).as_local().unwrap().is_shared());
         assert_eq!(
             worktree_a1
                 .read(cx)
@@ -1510,6 +1514,7 @@ async fn test_project_reconnect(
                 "subdir2/i.txt"
             ]
         );
+        assert!(worktree_a3.read(cx).as_local().unwrap().is_shared());
         assert_eq!(
             worktree_a3
                 .read(cx)

crates/editor/src/editor.rs 🔗

@@ -3611,7 +3611,9 @@ impl Editor {
     }
 
     pub fn undo(&mut self, _: &Undo, cx: &mut ViewContext<Self>) {
+        dbg!("undo");
         if let Some(tx_id) = self.buffer.update(cx, |buffer, cx| buffer.undo(cx)) {
+            dbg!(tx_id);
             if let Some((selections, _)) = self.selection_history.transaction(tx_id).cloned() {
                 self.change_selections(None, cx, |s| {
                     s.select_anchors(selections.to_vec());

crates/editor/src/editor_tests.rs 🔗

@@ -29,7 +29,11 @@ use workspace::{
 #[gpui::test]
 fn test_edit_events(cx: &mut MutableAppContext) {
     cx.set_global(Settings::test(cx));
-    let buffer = cx.add_model(|cx| language::Buffer::new(0, "123456", cx));
+    let buffer = cx.add_model(|cx| {
+        let mut buffer = language::Buffer::new(0, "123456", cx);
+        buffer.set_group_interval(Duration::from_secs(1));
+        buffer
+    });
 
     let events = Rc::new(RefCell::new(Vec::new()));
     let (_, editor1) = cx.add_window(Default::default(), {
@@ -3502,6 +3506,8 @@ async fn test_surround_with_pair(cx: &mut gpui::TestAppContext) {
             ]
         );
 
+        view.undo(&Undo, cx);
+        view.undo(&Undo, cx);
         view.undo(&Undo, cx);
         assert_eq!(
             view.text(cx),

crates/language/src/buffer_tests.rs 🔗

@@ -289,6 +289,9 @@ async fn test_reparse(cx: &mut gpui::TestAppContext) {
     );
 
     buffer.update(cx, |buf, cx| {
+        buf.undo(cx);
+        buf.undo(cx);
+        buf.undo(cx);
         buf.undo(cx);
         assert_eq!(buf.text(), "fn a() {}");
         assert!(buf.is_parsing());
@@ -304,6 +307,9 @@ async fn test_reparse(cx: &mut gpui::TestAppContext) {
     );
 
     buffer.update(cx, |buf, cx| {
+        buf.redo(cx);
+        buf.redo(cx);
+        buf.redo(cx);
         buf.redo(cx);
         assert_eq!(buf.text(), "fn a(b: C) { d.e::<G>(f); }");
         assert!(buf.is_parsing());
@@ -1022,8 +1028,11 @@ fn test_autoindent_block_mode(cx: &mut MutableAppContext) {
             .unindent()
         );
 
+        // Grouping is disabled in tests, so we need 2 undos
+        buffer.undo(cx); // Undo the auto-indent
+        buffer.undo(cx); // Undo the original edit
+
         // Insert the block at a deeper indent level. The entire block is outdented.
-        buffer.undo(cx);
         buffer.edit([(Point::new(2, 0)..Point::new(2, 0), "        ")], None, cx);
         buffer.edit(
             [(Point::new(2, 8)..Point::new(2, 8), inserted_text)],