Fix failing tests

This commit is contained in:
K Simmons 2022-08-10 16:26:53 -07:00
parent 3bdf05c0cd
commit d68f227ec4
3 changed files with 40 additions and 8 deletions

View file

@ -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 // Clients A and B follow each other in split panes
workspace_a.update(cx_a, |workspace, cx| { workspace_a.update(cx_a, |workspace, cx| {
workspace.split_pane(workspace.active_pane().clone(), SplitDirection::Right, 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 workspace_a
.update(cx_a, |workspace, cx| { .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(); .unwrap();
workspace_b.update(cx_b, |workspace, cx| { workspace_b.update(cx_b, |workspace, cx| {
workspace.split_pane(workspace.active_pane().clone(), SplitDirection::Right, 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 workspace_b
.update(cx_b, |workspace, cx| { .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 .await
.unwrap(); .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 workspace_a
.update(cx_a, |workspace, cx| { .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) workspace.open_path((worktree_id, "3.txt"), true, cx)
}) })
.await .await
.unwrap(); .unwrap();
workspace_b.update(cx_b, |workspace, cx| {
workspace.activate_next_pane(cx);
});
workspace_b workspace_b
.update(cx_b, |workspace, cx| { .update(cx_b, |workspace, cx| {
workspace.activate_next_pane(cx);
assert_eq!(*workspace.active_pane(), pane_b1); assert_eq!(*workspace.active_pane(), pane_b1);
workspace.open_path((worktree_id, "4.txt"), true, cx) 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()) Some((worktree_id, "3.txt").into())
); );
workspace.activate_next_pane(cx); workspace.activate_next_pane(cx);
});
workspace_a.update(cx_a, |workspace, cx| {
assert_eq!( assert_eq!(
workspace.active_item(cx).unwrap().project_path(cx), workspace.active_item(cx).unwrap().project_path(cx),
Some((worktree_id, "4.txt").into()) Some((worktree_id, "4.txt").into())
); );
}); });
workspace_b.update(cx_b, |workspace, cx| { workspace_b.update(cx_b, |workspace, cx| {
assert_eq!( assert_eq!(
workspace.active_item(cx).unwrap().project_path(cx), workspace.active_item(cx).unwrap().project_path(cx),
Some((worktree_id, "4.txt").into()) Some((worktree_id, "4.txt").into())
); );
workspace.activate_next_pane(cx); workspace.activate_next_pane(cx);
});
workspace_b.update(cx_b, |workspace, cx| {
assert_eq!( assert_eq!(
workspace.active_item(cx).unwrap().project_path(cx), workspace.active_item(cx).unwrap().project_path(cx),
Some((worktree_id, "3.txt").into()) Some((worktree_id, "3.txt").into())

View file

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

View file

@ -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;
pub mod pane_group; pub mod pane_group;
pub mod sidebar; pub mod sidebar;
@ -3088,16 +3092,21 @@ mod tests {
workspace workspace
.split_pane(left_pane.clone(), SplitDirection::Right, cx) .split_pane(left_pane.clone(), SplitDirection::Right, cx)
.unwrap(); .unwrap();
workspace.add_item(Box::new(cx.add_view(|_| item_3_4.clone())), cx);
left_pane 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: // 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 // once for project entry 0, and once for project entry 2. After those two
// prompts, the task should complete. // prompts, the task should complete.
let close = workspace.update(cx, |workspace, cx| { let close = workspace.update(cx, |workspace, cx| {
cx.focus(left_pane.clone());
Pane::close_items(workspace, left_pane.clone(), cx, |_| true) Pane::close_items(workspace, left_pane.clone(), cx, |_| true)
}); });