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.
This commit is contained in:
Nathan Sobo 2022-04-05 12:08:25 -06:00
parent 3da8f7f944
commit e2bf89b1e8
3 changed files with 21 additions and 26 deletions

View file

@ -446,7 +446,7 @@ mod tests {
.unwrap(); .unwrap();
cx.read(|cx| workspace.read(cx).worktree_scans_complete(cx)) cx.read(|cx| workspace.read(cx).worktree_scans_complete(cx))
.await; .await;
cx.dispatch_action(window_id, vec![workspace.id()], Toggle); cx.dispatch_action(window_id, Toggle);
let finder = cx.read(|cx| { let finder = cx.read(|cx| {
workspace workspace
@ -457,19 +457,16 @@ mod tests {
.downcast::<FileFinder>() .downcast::<FileFinder>()
.unwrap() .unwrap()
}); });
let query_buffer = cx.read(|cx| finder.read(cx).query_editor.clone()); cx.dispatch_action(window_id, Input("b".into()));
cx.dispatch_action(window_id, Input("n".into()));
let chain = vec![finder.id(), query_buffer.id()]; cx.dispatch_action(window_id, Input("a".into()));
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()));
finder finder
.condition(&cx, |finder, _| finder.matches.len() == 2) .condition(&cx, |finder, _| finder.matches.len() == 2)
.await; .await;
let active_pane = cx.read(|cx| workspace.read(cx).active_pane().clone()); 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, SelectNext);
cx.dispatch_action(window_id, vec![workspace.id(), finder.id()], Confirm); cx.dispatch_action(window_id, Confirm);
active_pane active_pane
.condition(&cx, |pane, _| pane.active_item().is_some()) .condition(&cx, |pane, _| pane.active_item().is_some())
.await; .await;

View file

@ -426,15 +426,17 @@ impl TestAppContext {
cx cx
} }
pub fn dispatch_action<A: Action>( pub fn dispatch_action<A: Action>(&self, window_id: usize, action: A) {
&self, let mut cx = self.cx.borrow_mut();
window_id: usize, let responder_chain = cx
responder_chain: Vec<usize>, .presenters_and_platform_windows
action: A, .get(&window_id)
) { .unwrap()
self.cx .0
.borrow_mut() .borrow()
.dispatch_action_any(window_id, &responder_chain, &action); .dispatch_path(cx.as_ref());
cx.dispatch_action_any(window_id, &responder_chain, &action);
} }
pub fn dispatch_global_action<A: Action>(&self, action: A) { pub fn dispatch_global_action<A: Action>(&self, action: A) {

View file

@ -563,7 +563,7 @@ mod tests {
let worktree = cx.read(|cx| workspace.read(cx).worktrees(cx).next().unwrap()); let worktree = cx.read(|cx| workspace.read(cx).worktrees(cx).next().unwrap());
// Create a new untitled buffer // 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| { let editor = workspace.read_with(cx, |workspace, cx| {
workspace workspace
.active_item(cx) .active_item(cx)
@ -618,7 +618,7 @@ mod tests {
// Open the same newly-created file in another pane item. The new editor should reuse // Open the same newly-created file in another pane item. The new editor should reuse
// the same buffer. // 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 workspace
.update(cx, |workspace, cx| { .update(cx, |workspace, cx| {
workspace.split_pane(workspace.active_pane().clone(), SplitDirection::Right, 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(&params, cx)); let (window_id, workspace) = cx.add_window(|cx| Workspace::new(&params, cx));
// Create a new untitled buffer // 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| { let editor = workspace.read_with(cx, |workspace, cx| {
workspace workspace
.active_item(cx) .active_item(cx)
@ -732,11 +732,7 @@ mod tests {
); );
}); });
cx.dispatch_action( cx.dispatch_action(window_id, pane::Split(SplitDirection::Right));
window_id,
vec![pane_1.id()],
pane::Split(SplitDirection::Right),
);
cx.update(|cx| { cx.update(|cx| {
let pane_2 = workspace.read(cx).active_pane().clone(); let pane_2 = workspace.read(cx).active_pane().clone();
assert_ne!(pane_1, pane_2); assert_ne!(pane_1, pane_2);