mirror of
https://github.com/zed-industries/zed.git
synced 2024-12-26 18:41:10 +00:00
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:
parent
3da8f7f944
commit
e2bf89b1e8
3 changed files with 21 additions and 26 deletions
|
@ -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::<FileFinder>()
|
||||
.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;
|
||||
|
|
|
@ -426,15 +426,17 @@ impl TestAppContext {
|
|||
cx
|
||||
}
|
||||
|
||||
pub fn dispatch_action<A: Action>(
|
||||
&self,
|
||||
window_id: usize,
|
||||
responder_chain: Vec<usize>,
|
||||
action: A,
|
||||
) {
|
||||
self.cx
|
||||
.borrow_mut()
|
||||
.dispatch_action_any(window_id, &responder_chain, &action);
|
||||
pub fn dispatch_action<A: 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<A: Action>(&self, action: A) {
|
||||
|
|
|
@ -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);
|
||||
|
|
Loading…
Reference in a new issue