From e2bf89b1e878b9fc2a097b2dfd5472b035f4d7f0 Mon Sep 17 00:00:00 2001 From: Nathan Sobo Date: Tue, 5 Apr 2022 12:08:25 -0600 Subject: [PATCH] Don't require a path in TestAppContext::dispatch_action Instead, derive it from the presenter. This makes tests easier to write and more reliable since we'll be accurately simulating the actual relationship between parent and child views. --- crates/file_finder/src/file_finder.rs | 15 ++++++--------- crates/gpui/src/app.rs | 20 +++++++++++--------- crates/zed/src/zed.rs | 12 ++++-------- 3 files changed, 21 insertions(+), 26 deletions(-) diff --git a/crates/file_finder/src/file_finder.rs b/crates/file_finder/src/file_finder.rs index 56fd255d82..471e43a0ed 100644 --- a/crates/file_finder/src/file_finder.rs +++ b/crates/file_finder/src/file_finder.rs @@ -446,7 +446,7 @@ mod tests { .unwrap(); cx.read(|cx| workspace.read(cx).worktree_scans_complete(cx)) .await; - cx.dispatch_action(window_id, vec![workspace.id()], Toggle); + cx.dispatch_action(window_id, Toggle); let finder = cx.read(|cx| { workspace @@ -457,19 +457,16 @@ mod tests { .downcast::() .unwrap() }); - let query_buffer = cx.read(|cx| finder.read(cx).query_editor.clone()); - - let chain = vec![finder.id(), query_buffer.id()]; - cx.dispatch_action(window_id, chain.clone(), Input("b".into())); - cx.dispatch_action(window_id, chain.clone(), Input("n".into())); - cx.dispatch_action(window_id, chain.clone(), Input("a".into())); + cx.dispatch_action(window_id, Input("b".into())); + cx.dispatch_action(window_id, Input("n".into())); + cx.dispatch_action(window_id, Input("a".into())); finder .condition(&cx, |finder, _| finder.matches.len() == 2) .await; let active_pane = cx.read(|cx| workspace.read(cx).active_pane().clone()); - cx.dispatch_action(window_id, vec![workspace.id(), finder.id()], SelectNext); - cx.dispatch_action(window_id, vec![workspace.id(), finder.id()], Confirm); + cx.dispatch_action(window_id, SelectNext); + cx.dispatch_action(window_id, Confirm); active_pane .condition(&cx, |pane, _| pane.active_item().is_some()) .await; diff --git a/crates/gpui/src/app.rs b/crates/gpui/src/app.rs index 7f0c3ffcde..76b5f3b631 100644 --- a/crates/gpui/src/app.rs +++ b/crates/gpui/src/app.rs @@ -426,15 +426,17 @@ impl TestAppContext { cx } - pub fn dispatch_action( - &self, - window_id: usize, - responder_chain: Vec, - action: A, - ) { - self.cx - .borrow_mut() - .dispatch_action_any(window_id, &responder_chain, &action); + pub fn dispatch_action(&self, window_id: usize, action: A) { + let mut cx = self.cx.borrow_mut(); + let responder_chain = cx + .presenters_and_platform_windows + .get(&window_id) + .unwrap() + .0 + .borrow() + .dispatch_path(cx.as_ref()); + + cx.dispatch_action_any(window_id, &responder_chain, &action); } pub fn dispatch_global_action(&self, action: A) { diff --git a/crates/zed/src/zed.rs b/crates/zed/src/zed.rs index d3ce28ff5b..843e56fd0e 100644 --- a/crates/zed/src/zed.rs +++ b/crates/zed/src/zed.rs @@ -563,7 +563,7 @@ mod tests { let worktree = cx.read(|cx| workspace.read(cx).worktrees(cx).next().unwrap()); // Create a new untitled buffer - cx.dispatch_action(window_id, vec![workspace.id()], OpenNew(app_state.clone())); + cx.dispatch_action(window_id, OpenNew(app_state.clone())); let editor = workspace.read_with(cx, |workspace, cx| { workspace .active_item(cx) @@ -618,7 +618,7 @@ mod tests { // Open the same newly-created file in another pane item. The new editor should reuse // the same buffer. - cx.dispatch_action(window_id, vec![workspace.id()], OpenNew(app_state.clone())); + cx.dispatch_action(window_id, OpenNew(app_state.clone())); workspace .update(cx, |workspace, cx| { workspace.split_pane(workspace.active_pane().clone(), SplitDirection::Right, cx); @@ -655,7 +655,7 @@ mod tests { let (window_id, workspace) = cx.add_window(|cx| Workspace::new(¶ms, cx)); // Create a new untitled buffer - cx.dispatch_action(window_id, vec![workspace.id()], OpenNew(app_state.clone())); + cx.dispatch_action(window_id, OpenNew(app_state.clone())); let editor = workspace.read_with(cx, |workspace, cx| { workspace .active_item(cx) @@ -732,11 +732,7 @@ mod tests { ); }); - cx.dispatch_action( - window_id, - vec![pane_1.id()], - pane::Split(SplitDirection::Right), - ); + cx.dispatch_action(window_id, pane::Split(SplitDirection::Right)); cx.update(|cx| { let pane_2 = workspace.read(cx).active_pane().clone(); assert_ne!(pane_1, pane_2);