Code at the speed of thought – Zed is a high-performance, multiplayer code editor from the creators of Atom and Tree-sitter.
git_ui: Improve delete branch tests to verify underlying repository state (#51825)
ᴀᴍᴛᴏᴀᴇʀc44f13cca026
diff --git a/crates/fs/src/fake_git_repo.rs b/crates/fs/src/fake_git_repo.rsindex dd8442f7c01..91103953f0d 100644--- a/crates/fs/src/fake_git_repo.rs+++ b/crates/fs/src/fake_git_repo.rs@@ -392,6 +392,8 @@ impl GitRepository for FakeGitRepository {.map(|branch_name| {let ref_name = if branch_name.starts_with("refs/") {branch_name.into()+ } else if branch_name.contains('/') {+ format!("refs/remotes/{branch_name}").into()} else {format!("refs/heads/{branch_name}").into()};diff --git a/crates/git_ui/src/branch_picker.rs b/crates/git_ui/src/branch_picker.rsindex cc5f70e2d0f..329f8e91e9e 100644--- a/crates/git_ui/src/branch_picker.rs+++ b/crates/git_ui/src/branch_picker.rs@@ -1509,6 +1509,30 @@ mod tests {});cx.run_until_parked();+ let expected_branches = ["main", "feature-auth", "feature-ui", "develop"]+ .into_iter()+ .filter(|name| name != &branch_to_delete)+ .collect::<HashSet<_>>();+ let repo_branches = branch_list+ .update(cx, |branch_list, cx| {+ branch_list.picker.update(cx, |picker, cx| {+ picker+ .delegate+ .repo+ .as_ref()+ .unwrap()+ .update(cx, |repo, _cx| repo.branches())+ })+ })+ .await+ .unwrap()+ .unwrap();+ let repo_branches = repo_branches+ .iter()+ .map(|b| b.name())+ .collect::<HashSet<_>>();+ assert_eq!(&repo_branches, &expected_branches);+branch_list.update(cx, move |branch_list, cx| {branch_list.picker.update(cx, move |picker, _cx| {assert_eq!(picker.delegate.matches.len(), 3);@@ -1518,13 +1542,7 @@ mod tests {.iter().map(|be| be.name()).collect::<HashSet<_>>();- assert_eq!(- branches,- ["main", "feature-auth", "feature-ui", "develop"]- .into_iter()- .filter(|name| name != &branch_to_delete)- .collect::<HashSet<_>>()- );+ assert_eq!(branches, expected_branches);})});}@@ -1577,6 +1595,35 @@ mod tests {});cx.run_until_parked();+ let expected_branches = [+ "origin/main",+ "origin/feature-auth",+ "fork/feature-ui",+ "private/develop",+ ]+ .into_iter()+ .filter(|name| name != &branch_to_delete)+ .collect::<HashSet<_>>();+ let repo_branches = branch_list+ .update(cx, |branch_list, cx| {+ branch_list.picker.update(cx, |picker, cx| {+ picker+ .delegate+ .repo+ .as_ref()+ .unwrap()+ .update(cx, |repo, _cx| repo.branches())+ })+ })+ .await+ .unwrap()+ .unwrap();+ let repo_branches = repo_branches+ .iter()+ .map(|b| b.name())+ .collect::<HashSet<_>>();+ assert_eq!(&repo_branches, &expected_branches);+// Check matches, it should match one less branch than beforebranch_list.update(cx, move |branch_list, cx| {branch_list.picker.update(cx, move |picker, _cx| {@@ -1587,18 +1634,7 @@ mod tests {.iter().map(|be| be.name()).collect::<HashSet<_>>();- assert_eq!(- branches,- [- "origin/main",- "origin/feature-auth",- "fork/feature-ui",- "private/develop"- ]- .into_iter()- .filter(|name| name != &branch_to_delete)- .collect::<HashSet<_>>()- );+ assert_eq!(branches, expected_branches);})});}