From a0a50cb412ba23e97f010013153719132582676a Mon Sep 17 00:00:00 2001 From: Max Brunsfeld Date: Tue, 17 Jan 2023 17:37:52 -0800 Subject: [PATCH] Set up fake project paths correctly in tests --- crates/workspace/src/item.rs | 24 ++++++++++++--------- crates/workspace/src/pane.rs | 10 ++++----- crates/workspace/src/workspace.rs | 36 ++++++++++++++----------------- 3 files changed, 35 insertions(+), 35 deletions(-) diff --git a/crates/workspace/src/item.rs b/crates/workspace/src/item.rs index 9d5b94bddb8a99e4f7be34d62ac88d913c131f4e..1bc713b5fb45c2b5beca9d5a4e8c539d1ba5d53d 100644 --- a/crates/workspace/src/item.rs +++ b/crates/workspace/src/item.rs @@ -722,11 +722,12 @@ pub(crate) mod test { elements::Empty, AppContext, Element, ElementBox, Entity, ModelHandle, MutableAppContext, RenderContext, Task, View, ViewContext, ViewHandle, WeakViewHandle, }; - use project::{Project, ProjectEntryId, ProjectPath}; - use std::{any::Any, borrow::Cow, cell::Cell}; + use project::{Project, ProjectEntryId, ProjectPath, WorktreeId}; + use std::{any::Any, borrow::Cow, cell::Cell, path::Path}; pub struct TestProjectItem { pub entry_id: Option, + pub project_path: Option, } pub struct TestItem { @@ -740,7 +741,6 @@ pub(crate) mod test { pub is_singleton: bool, pub has_conflict: bool, pub project_items: Vec>, - pub project_path: Option, pub nav_history: Option, pub tab_descriptions: Option>, pub tab_detail: Cell>, @@ -756,7 +756,7 @@ pub(crate) mod test { } fn project_path(&self, _: &AppContext) -> Option { - None + self.project_path.clone() } } @@ -776,7 +776,6 @@ pub(crate) mod test { is_singleton: self.is_singleton, has_conflict: self.has_conflict, project_items: self.project_items.clone(), - project_path: self.project_path.clone(), nav_history: None, tab_descriptions: None, tab_detail: Default::default(), @@ -796,7 +795,6 @@ pub(crate) mod test { is_dirty: false, has_conflict: false, project_items: Vec::new(), - project_path: None, is_singleton: true, nav_history: None, tab_descriptions: None, @@ -831,15 +829,21 @@ pub(crate) mod test { self } - pub fn with_project_entry_ids( + pub fn with_project_items( mut self, - project_entry_ids: &[u64], + items: &[(u64, &str)], cx: &mut MutableAppContext, ) -> Self { self.project_items - .extend(project_entry_ids.iter().copied().map(|id| { + .extend(items.iter().copied().map(|(id, path)| { let id = ProjectEntryId::from_proto(id); - cx.add_model(|_| TestProjectItem { entry_id: Some(id) }) + cx.add_model(|_| TestProjectItem { + entry_id: Some(id), + project_path: Some(ProjectPath { + worktree_id: WorktreeId::from_usize(0), + path: Path::new(path).into(), + }), + }) })); self } diff --git a/crates/workspace/src/pane.rs b/crates/workspace/src/pane.rs index 4d5a73b2b33785dcbeaffc2f82efc83a328b42e2..de298e7be10cf01609c84de064967ad1aa764377 100644 --- a/crates/workspace/src/pane.rs +++ b/crates/workspace/src/pane.rs @@ -1861,7 +1861,7 @@ mod tests { let item = TestItem::new() .with_singleton(true) .with_label("buffer 1") - .with_project_entry_ids(&[1], cx); + .with_project_items(&[(1, "one.txt")], cx); Pane::add_item( workspace, @@ -1880,7 +1880,7 @@ mod tests { let item = TestItem::new() .with_singleton(true) .with_label("buffer 1") - .with_project_entry_ids(&[1], cx); + .with_project_items(&[(1, "1.txt")], cx); Pane::add_item( workspace, @@ -1899,7 +1899,7 @@ mod tests { let item = TestItem::new() .with_singleton(true) .with_label("buffer 2") - .with_project_entry_ids(&[2], cx); + .with_project_items(&[(2, "2.txt")], cx); Pane::add_item( workspace, @@ -1918,7 +1918,7 @@ mod tests { let item = TestItem::new() .with_singleton(false) .with_label("multibuffer 1") - .with_project_entry_ids(&[1], cx); + .with_project_items(&[(1, "1.txt")], cx); Pane::add_item( workspace, @@ -1937,7 +1937,7 @@ mod tests { let item = TestItem::new() .with_singleton(false) .with_label("multibuffer 1b") - .with_project_entry_ids(&[1], cx); + .with_project_items(&[(1, "1.txt")], cx); Pane::add_item( workspace, diff --git a/crates/workspace/src/workspace.rs b/crates/workspace/src/workspace.rs index c7aa0798a3d81f304013f3fd4287a456f06de9b3..a521d02b5fbbdcecd1f438d06ae1b169e887e2e3 100644 --- a/crates/workspace/src/workspace.rs +++ b/crates/workspace/src/workspace.rs @@ -2834,15 +2834,11 @@ mod tests { project.worktrees(cx).next().unwrap().read(cx).id() }); - let item1 = cx.add_view(&workspace, |_| { - let mut item = TestItem::new(); - item.project_path = Some((worktree_id, "one.txt").into()); - item + let item1 = cx.add_view(&workspace, |cx| { + TestItem::new().with_project_items(&[(1, "one.txt")], cx) }); - let item2 = cx.add_view(&workspace, |_| { - let mut item = TestItem::new(); - item.project_path = Some((worktree_id, "two.txt").into()); - item + let item2 = cx.add_view(&workspace, |cx| { + TestItem::new().with_project_items(&[(2, "two.txt")], cx) }); // Add an item to an empty pane @@ -2947,7 +2943,7 @@ mod tests { let item3 = cx.add_view(&workspace, |cx| { TestItem::new() .with_dirty(true) - .with_project_entry_ids(&[1], cx) + .with_project_items(&[(1, "1.txt")], cx) }); workspace.update(cx, |w, cx| { w.add_item(Box::new(item2.clone()), cx); @@ -2975,19 +2971,19 @@ mod tests { let item1 = cx.add_view(&workspace, |cx| { TestItem::new() .with_dirty(true) - .with_project_entry_ids(&[1], cx) + .with_project_items(&[(1, "1.txt")], cx) }); let item2 = cx.add_view(&workspace, |cx| { TestItem::new() .with_dirty(true) .with_conflict(true) - .with_project_entry_ids(&[2], cx) + .with_project_items(&[(2, "2.txt")], cx) }); let item3 = cx.add_view(&workspace, |cx| { TestItem::new() .with_dirty(true) .with_conflict(true) - .with_project_entry_ids(&[3], cx) + .with_project_items(&[(3, "3.txt")], cx) }); let item4 = cx.add_view(&workspace, |_| TestItem::new().with_dirty(true)); let pane = workspace.update(cx, |workspace, cx| { @@ -3067,10 +3063,10 @@ mod tests { let single_entry_items = (0..=4) .map(|project_entry_id| { cx.add_view(&workspace, |cx| { - TestItem::new() - .with_dirty(true) - .with_singleton(true) - .with_project_entry_ids(&[project_entry_id], cx) + TestItem::new().with_dirty(true).with_project_items( + &[(project_entry_id, &format!("{project_entry_id}.txt"))], + cx, + ) }) }) .collect::>(); @@ -3078,13 +3074,13 @@ mod tests { TestItem::new() .with_dirty(true) .with_singleton(false) - .with_project_entry_ids(&[2, 3], cx) + .with_project_items(&[(2, "2.txt"), (3, "3.txt")], cx) }); let item_3_4 = cx.add_view(&workspace, |cx| { TestItem::new() .with_dirty(true) .with_singleton(false) - .with_project_entry_ids(&[3, 4], cx) + .with_project_items(&[(3, "3.txt"), (4, "4.txt")], cx) }); // Create two panes that contain the following project entries: @@ -3163,7 +3159,7 @@ mod tests { }); let item = cx.add_view(&workspace, |cx| { - TestItem::new().with_project_entry_ids(&[1], cx) + TestItem::new().with_project_items(&[(1, "1.txt")], cx) }); let item_id = item.id(); workspace.update(cx, |workspace, cx| { @@ -3282,7 +3278,7 @@ mod tests { }); let item = cx.add_view(&workspace, |cx| { - TestItem::new().with_project_entry_ids(&[1], cx) + TestItem::new().with_project_items(&[(1, "1.txt")], cx) }); let pane = workspace.read_with(cx, |workspace, _| workspace.active_pane().clone()); let toolbar = pane.read_with(cx, |pane, _| pane.toolbar().clone());