mirror of
https://github.com/zed-industries/zed.git
synced 2026-05-31 19:05:00 +07:00
Merge branch 'zed-industries:main' into make-method-chaining
This commit is contained in:
commit
5db6e000cb
2 changed files with 105 additions and 6 deletions
|
|
@ -336,6 +336,20 @@ impl TestAppContext {
|
||||||
self.test_platform.simulate_new_path_selection(select_path);
|
self.test_platform.simulate_new_path_selection(select_path);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// Simulates responding to a `prompt_for_paths` ("Open") dialog.
|
||||||
|
pub fn simulate_path_prompt_response(
|
||||||
|
&self,
|
||||||
|
select_paths: impl FnOnce(&crate::PathPromptOptions) -> Option<Vec<std::path::PathBuf>>,
|
||||||
|
) {
|
||||||
|
self.test_platform
|
||||||
|
.simulate_path_prompt_response(select_paths);
|
||||||
|
}
|
||||||
|
|
||||||
|
/// Returns true if there's a path selection dialog pending.
|
||||||
|
pub fn did_prompt_for_paths(&self) -> bool {
|
||||||
|
self.test_platform.did_prompt_for_paths()
|
||||||
|
}
|
||||||
|
|
||||||
/// Simulates clicking a button in an platform-level alert dialog.
|
/// Simulates clicking a button in an platform-level alert dialog.
|
||||||
#[track_caller]
|
#[track_caller]
|
||||||
pub fn simulate_prompt_answer(&self, button: &str) {
|
pub fn simulate_prompt_answer(&self, button: &str) {
|
||||||
|
|
@ -1098,3 +1112,54 @@ impl AnyWindowHandle {
|
||||||
.unwrap()
|
.unwrap()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[cfg(test)]
|
||||||
|
mod tests {
|
||||||
|
use crate::{PathPromptOptions, TestAppContext};
|
||||||
|
use std::path::PathBuf;
|
||||||
|
|
||||||
|
#[gpui::test]
|
||||||
|
async fn test_simulate_path_prompt_response(cx: &mut TestAppContext) {
|
||||||
|
assert!(!cx.did_prompt_for_paths());
|
||||||
|
|
||||||
|
let receiver = cx.update(|cx| {
|
||||||
|
cx.prompt_for_paths(PathPromptOptions {
|
||||||
|
files: false,
|
||||||
|
directories: true,
|
||||||
|
multiple: true,
|
||||||
|
prompt: None,
|
||||||
|
})
|
||||||
|
});
|
||||||
|
assert!(cx.did_prompt_for_paths());
|
||||||
|
|
||||||
|
let selected = vec![PathBuf::from("/a"), PathBuf::from("/b")];
|
||||||
|
cx.simulate_path_prompt_response({
|
||||||
|
let selected = selected.clone();
|
||||||
|
move |options| {
|
||||||
|
assert!(options.multiple);
|
||||||
|
Some(selected)
|
||||||
|
}
|
||||||
|
});
|
||||||
|
assert!(!cx.did_prompt_for_paths());
|
||||||
|
|
||||||
|
let response = receiver.await.unwrap().unwrap();
|
||||||
|
assert_eq!(response, Some(selected));
|
||||||
|
}
|
||||||
|
|
||||||
|
#[gpui::test]
|
||||||
|
async fn test_simulate_path_prompt_cancellation(cx: &mut TestAppContext) {
|
||||||
|
let receiver = cx.update(|cx| {
|
||||||
|
cx.prompt_for_paths(PathPromptOptions {
|
||||||
|
files: true,
|
||||||
|
directories: false,
|
||||||
|
multiple: false,
|
||||||
|
prompt: None,
|
||||||
|
})
|
||||||
|
});
|
||||||
|
|
||||||
|
cx.simulate_path_prompt_response(|_options| None);
|
||||||
|
|
||||||
|
let response = receiver.await.unwrap().unwrap();
|
||||||
|
assert_eq!(response, None);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
|
||||||
|
|
@ -1,9 +1,10 @@
|
||||||
use crate::{
|
use crate::{
|
||||||
AnyWindowHandle, BackgroundExecutor, ClipboardItem, CursorStyle, DevicePixels,
|
AnyWindowHandle, BackgroundExecutor, ClipboardItem, CursorStyle, DevicePixels,
|
||||||
DummyKeyboardMapper, ForegroundExecutor, Keymap, NoopTextSystem, Platform, PlatformDisplay,
|
DummyKeyboardMapper, ForegroundExecutor, Keymap, NoopTextSystem, PathPromptOptions, Platform,
|
||||||
PlatformHeadlessRenderer, PlatformKeyboardLayout, PlatformKeyboardMapper, PlatformTextSystem,
|
PlatformDisplay, PlatformHeadlessRenderer, PlatformKeyboardLayout, PlatformKeyboardMapper,
|
||||||
PromptButton, ScreenCaptureFrame, ScreenCaptureSource, ScreenCaptureStream, SourceMetadata,
|
PlatformTextSystem, PromptButton, ScreenCaptureFrame, ScreenCaptureSource, ScreenCaptureStream,
|
||||||
Task, TestDisplay, TestWindow, ThermalState, WindowAppearance, WindowParams, size,
|
SourceMetadata, Task, TestDisplay, TestWindow, ThermalState, WindowAppearance, WindowParams,
|
||||||
|
size,
|
||||||
};
|
};
|
||||||
use anyhow::Result;
|
use anyhow::Result;
|
||||||
use collections::VecDeque;
|
use collections::VecDeque;
|
||||||
|
|
@ -85,6 +86,10 @@ struct TestPrompt {
|
||||||
pub(crate) struct TestPrompts {
|
pub(crate) struct TestPrompts {
|
||||||
multiple_choice: VecDeque<TestPrompt>,
|
multiple_choice: VecDeque<TestPrompt>,
|
||||||
new_path: VecDeque<(PathBuf, oneshot::Sender<Result<Option<PathBuf>>>)>,
|
new_path: VecDeque<(PathBuf, oneshot::Sender<Result<Option<PathBuf>>>)>,
|
||||||
|
paths: VecDeque<(
|
||||||
|
PathPromptOptions,
|
||||||
|
oneshot::Sender<Result<Option<Vec<PathBuf>>>>,
|
||||||
|
)>,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl TestPlatform {
|
impl TestPlatform {
|
||||||
|
|
@ -147,6 +152,33 @@ impl TestPlatform {
|
||||||
tx.send(Ok(select_path(&path))).ok();
|
tx.send(Ok(select_path(&path))).ok();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
pub(crate) fn simulate_path_prompt_response(
|
||||||
|
&self,
|
||||||
|
select_paths: impl FnOnce(&PathPromptOptions) -> Option<Vec<std::path::PathBuf>>,
|
||||||
|
) {
|
||||||
|
let (options, tx) = self
|
||||||
|
.prompts
|
||||||
|
.borrow_mut()
|
||||||
|
.paths
|
||||||
|
.pop_front()
|
||||||
|
.expect("no pending paths prompt");
|
||||||
|
let selection = select_paths(&options);
|
||||||
|
if let Some(paths) = &selection
|
||||||
|
&& !options.multiple
|
||||||
|
&& paths.len() > 1
|
||||||
|
{
|
||||||
|
panic!(
|
||||||
|
"selected {} paths for a prompt that does not allow multiple selection",
|
||||||
|
paths.len()
|
||||||
|
);
|
||||||
|
}
|
||||||
|
tx.send(Ok(selection)).ok();
|
||||||
|
}
|
||||||
|
|
||||||
|
pub(crate) fn did_prompt_for_paths(&self) -> bool {
|
||||||
|
!self.prompts.borrow().paths.is_empty()
|
||||||
|
}
|
||||||
|
|
||||||
#[track_caller]
|
#[track_caller]
|
||||||
pub(crate) fn simulate_prompt_answer(&self, response: &str) {
|
pub(crate) fn simulate_prompt_answer(&self, response: &str) {
|
||||||
let prompt = self
|
let prompt = self
|
||||||
|
|
@ -348,9 +380,11 @@ impl Platform for TestPlatform {
|
||||||
|
|
||||||
fn prompt_for_paths(
|
fn prompt_for_paths(
|
||||||
&self,
|
&self,
|
||||||
_options: crate::PathPromptOptions,
|
options: crate::PathPromptOptions,
|
||||||
) -> oneshot::Receiver<Result<Option<Vec<std::path::PathBuf>>>> {
|
) -> oneshot::Receiver<Result<Option<Vec<std::path::PathBuf>>>> {
|
||||||
unimplemented!()
|
let (tx, rx) = oneshot::channel();
|
||||||
|
self.prompts.borrow_mut().paths.push_back((options, tx));
|
||||||
|
rx
|
||||||
}
|
}
|
||||||
|
|
||||||
fn prompt_for_new_path(
|
fn prompt_for_new_path(
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue