From 66c76d5469bc0ec113848b6dbfffd15ffa257cc7 Mon Sep 17 00:00:00 2001 From: Nathan Sobo Date: Wed, 9 Jun 2021 16:38:32 -0600 Subject: [PATCH] Test creating a new empty workspace and fix test compile errors --- gpui/src/app.rs | 6 ++++++ zed/src/workspace.rs | 28 +++++++++++++++++++++++++--- 2 files changed, 31 insertions(+), 3 deletions(-) diff --git a/gpui/src/app.rs b/gpui/src/app.rs index b11f5c63da..296eb50f10 100644 --- a/gpui/src/app.rs +++ b/gpui/src/app.rs @@ -264,6 +264,12 @@ impl TestAppContext { ); } + pub fn dispatch_global_action(&self, name: &str, arg: T) { + self.0 + .borrow_mut() + .dispatch_global_action(name, arg); + } + pub fn dispatch_keystroke( &self, window_id: usize, diff --git a/zed/src/workspace.rs b/zed/src/workspace.rs index 19932d122c..04d1b0f5a1 100644 --- a/zed/src/workspace.rs +++ b/zed/src/workspace.rs @@ -1085,9 +1085,10 @@ mod tests { async fn test_open_and_save_new_file(mut cx: gpui::TestAppContext) { let dir = TempDir::new("test-new-file").unwrap(); let app_state = cx.read(build_app_state); + let app_state2 = app_state.clone(); let (_, workspace) = cx.add_window(|cx| { let mut workspace = - Workspace::new(0, app_state.settings, app_state.language_registry, cx); + Workspace::new(0, app_state2.settings, app_state2.language_registry, cx); workspace.add_worktree(dir.path(), cx); workspace }); @@ -1103,8 +1104,9 @@ mod tests { tree.flush_fs_events(&cx).await; // Create a new untitled buffer + let app_state2 = app_state.clone(); let editor = workspace.update(&mut cx, |workspace, cx| { - workspace.open_new_file(&(), cx); + workspace.open_new_file(&app_state2, cx); workspace .active_item(cx) .unwrap() @@ -1112,6 +1114,7 @@ mod tests { .downcast::() .unwrap() }); + editor.update(&mut cx, |editor, cx| { assert!(!editor.is_dirty(cx.as_ref())); assert_eq!(editor.title(cx.as_ref()), "untitled"); @@ -1154,7 +1157,7 @@ mod tests { // Open the same newly-created file in another pane item. The new editor should reuse // the same buffer. workspace.update(&mut cx, |workspace, cx| { - workspace.open_new_file(&(), cx); + workspace.open_new_file(&app_state, cx); workspace.split_pane(workspace.active_pane().clone(), SplitDirection::Right, cx); assert!(workspace .open_entry((tree.id(), Path::new("the-new-name").into()), cx) @@ -1173,6 +1176,25 @@ mod tests { }) } + #[gpui::test] + async fn test_new_empty_workspace(mut cx: gpui::TestAppContext) { + cx.update(init); + + let app_state = cx.read(build_app_state); + cx.dispatch_global_action("workspace:new_file", app_state); + let window_id = *cx.window_ids().first().unwrap(); + let workspace = cx.root_view::(window_id).unwrap(); + workspace.update(&mut cx, |workspace, cx| { + let editor = workspace + .active_item(cx) + .unwrap() + .to_any() + .downcast::() + .unwrap(); + assert!(editor.read(cx).text(cx.as_ref()).is_empty()); + }); + } + #[gpui::test] async fn test_pane_actions(mut cx: gpui::TestAppContext) { cx.update(|cx| pane::init(cx));