@@ -264,6 +264,12 @@ impl TestAppContext {
);
}
+ pub fn dispatch_global_action<T: 'static + Any>(&self, name: &str, arg: T) {
+ self.0
+ .borrow_mut()
+ .dispatch_global_action(name, arg);
+ }
+
pub fn dispatch_keystroke(
&self,
window_id: usize,
@@ -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::<Editor>()
.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::<Workspace>(window_id).unwrap();
+ workspace.update(&mut cx, |workspace, cx| {
+ let editor = workspace
+ .active_item(cx)
+ .unwrap()
+ .to_any()
+ .downcast::<Editor>()
+ .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));