diff --git a/crates/gpui/src/app/test_app.rs b/crates/gpui/src/app/test_app.rs index 268fa891b563289b85195097d27e06d0b3e15680..34f3b85b0014dad3400350b7d994d65e4ffdd9da 100644 --- a/crates/gpui/src/app/test_app.rs +++ b/crates/gpui/src/app/test_app.rs @@ -286,7 +286,12 @@ impl TestApp { self.platform.did_prompt_for_new_path() } - /// Simulate answering a path selection dialog. + /// Check if a path selection prompt is pending. + pub fn did_prompt_for_paths(&self) -> bool { + self.platform.did_prompt_for_paths() + } + + /// Simulate answering a "Save" path selection dialog. pub fn simulate_new_path_selection( &self, select: impl FnOnce(&std::path::Path) -> Option, @@ -294,6 +299,14 @@ impl TestApp { self.platform.simulate_new_path_selection(select); } + /// Simulate answering an "Open" path selection dialog. + pub fn simulate_paths_selection( + &self, + select_paths: impl FnOnce(&crate::PathPromptOptions) -> Option>, + ) { + self.platform.simulate_paths_selection(select_paths); + } + /// Check if a prompt dialog is pending. pub fn has_pending_prompt(&self) -> bool { self.platform.has_pending_prompt() diff --git a/crates/gpui/src/app/test_context.rs b/crates/gpui/src/app/test_context.rs index d8f459df3c54200f07b4584eeb8e1ffa8415554b..642ba2c6a6c1fde688ca15fd01638c609cad7583 100644 --- a/crates/gpui/src/app/test_context.rs +++ b/crates/gpui/src/app/test_context.rs @@ -159,6 +159,11 @@ impl TestAppContext { self.test_platform.did_prompt_for_new_path() } + /// Checks whether there have been any path prompts received by the platform. + pub fn did_prompt_for_paths(&self) -> bool { + self.test_platform.did_prompt_for_paths() + } + /// returns a new `TestAppContext` re-using the same executors to interleave tasks. pub fn new_app(&self) -> TestAppContext { Self::build(self.dispatcher.clone(), self.fn_name) @@ -325,7 +330,7 @@ impl TestAppContext { self.test_platform.read_from_clipboard() } - /// Simulates choosing a File in the platform's "Open" dialog. + /// Simulates choosing a File in the platform's "Save" dialog. pub fn simulate_new_path_selection( &self, select_path: impl FnOnce(&std::path::Path) -> Option, @@ -333,6 +338,14 @@ impl TestAppContext { self.test_platform.simulate_new_path_selection(select_path); } + /// Simulates choosing paths in the platform's "Open" dialog. + pub fn simulate_paths_selection( + &self, + select_paths: impl FnOnce(&crate::PathPromptOptions) -> Option>, + ) { + self.test_platform.simulate_paths_selection(select_paths); + } + /// Simulates clicking a button in an platform-level alert dialog. #[track_caller] pub fn simulate_prompt_answer(&self, button: &str) { diff --git a/crates/gpui/src/platform/test/platform.rs b/crates/gpui/src/platform/test/platform.rs index a59b21f038a01b48686ee211919afd7c647b7331..a9b3112f3ce558adcae4ac6c12c7d44fc0db02ef 100644 --- a/crates/gpui/src/platform/test/platform.rs +++ b/crates/gpui/src/platform/test/platform.rs @@ -85,6 +85,10 @@ struct TestPrompt { pub(crate) struct TestPrompts { multiple_choice: VecDeque, new_path: VecDeque<(PathBuf, oneshot::Sender>>)>, + paths: VecDeque<( + crate::PathPromptOptions, + oneshot::Sender>>>, + )>, } impl TestPlatform { @@ -226,6 +230,23 @@ impl TestPlatform { pub(crate) fn did_prompt_for_new_path(&self) -> bool { !self.prompts.borrow().new_path.is_empty() } + + pub(crate) fn did_prompt_for_paths(&self) -> bool { + !self.prompts.borrow().paths.is_empty() + } + + pub(crate) fn simulate_paths_selection( + &self, + select_paths: impl FnOnce(&crate::PathPromptOptions) -> Option>, + ) { + let (options, tx) = self + .prompts + .borrow_mut() + .paths + .pop_front() + .expect("no pending paths prompt"); + tx.send(Ok(select_paths(&options))).ok(); + } } impl Platform for TestPlatform { @@ -348,9 +369,11 @@ impl Platform for TestPlatform { fn prompt_for_paths( &self, - _options: crate::PathPromptOptions, + options: crate::PathPromptOptions, ) -> oneshot::Receiver>>> { - unimplemented!() + let (tx, rx) = oneshot::channel(); + self.prompts.borrow_mut().paths.push_back((options, tx)); + rx } fn prompt_for_new_path(