WIP: Add a condition method to model and view handles for use in tests
It returns a future that resolves when the provided predicate returns true. The predicate is called any time the handle's targeted entity calls notify. Still need to add a timeout and completely remove finsih_pending_tasks.
This commit is contained in:
+3
-2
@@ -16,10 +16,11 @@ path = "src/main.rs"
|
||||
anyhow = "1.0.38"
|
||||
arrayvec = "0.5.2"
|
||||
crossbeam-channel = "0.5.0"
|
||||
ctor = "0.1.20"
|
||||
dirs = "3.0"
|
||||
easy-parallel = "3.1.0"
|
||||
futures-core = "0.3"
|
||||
fsevent = {path = "../fsevent"}
|
||||
futures-core = "0.3"
|
||||
gpui = {path = "../gpui"}
|
||||
ignore = {git = "https://github.com/zed-industries/ripgrep", rev = "1d152118f35b3e3590216709b86277062d79b8a0"}
|
||||
lazy_static = "1.4.0"
|
||||
@@ -31,8 +32,8 @@ postage = {version = "0.4.1", features = ["futures-traits"]}
|
||||
rand = "0.8.3"
|
||||
rust-embed = "5.9.0"
|
||||
seahash = "4.1"
|
||||
serde = {version = "1", features = ["derive"]}
|
||||
simplelog = "0.9"
|
||||
serde = { version = "1", features = ["derive"] }
|
||||
smallvec = "1.6.1"
|
||||
smol = "1.2.5"
|
||||
|
||||
|
||||
+8
-1
@@ -1,4 +1,8 @@
|
||||
use crate::time::ReplicaId;
|
||||
use ctor::ctor;
|
||||
use log::LevelFilter;
|
||||
use rand::Rng;
|
||||
use simplelog::SimpleLogger;
|
||||
use std::{
|
||||
collections::BTreeMap,
|
||||
path::{Path, PathBuf},
|
||||
@@ -6,7 +10,10 @@ use std::{
|
||||
};
|
||||
use tempdir::TempDir;
|
||||
|
||||
use crate::time::ReplicaId;
|
||||
#[ctor]
|
||||
fn init_logger() {
|
||||
SimpleLogger::init(LevelFilter::Info, Default::default()).expect("could not initialize logger");
|
||||
}
|
||||
|
||||
#[derive(Clone)]
|
||||
struct Envelope<T: Clone> {
|
||||
|
||||
@@ -402,7 +402,21 @@ mod tests {
|
||||
|
||||
// Open the first entry
|
||||
workspace_view.update(&mut app, |w, ctx| w.open_entry(entries[0], ctx));
|
||||
app.finish_pending_tasks().await;
|
||||
|
||||
workspace_view
|
||||
.condition(&app, |workspace_view, ctx| {
|
||||
workspace_view.active_pane().read(ctx).items().len() == 1
|
||||
})
|
||||
.await;
|
||||
|
||||
// Open the second entry
|
||||
workspace_view.update(&mut app, |w, ctx| w.open_entry(entries[1], ctx));
|
||||
|
||||
workspace_view
|
||||
.condition(&app, |workspace_view, ctx| {
|
||||
workspace_view.active_pane().read(ctx).items().len() == 2
|
||||
})
|
||||
.await;
|
||||
|
||||
app.read(|ctx| {
|
||||
assert_eq!(
|
||||
@@ -410,36 +424,34 @@ mod tests {
|
||||
.read(ctx)
|
||||
.active_pane()
|
||||
.read(ctx)
|
||||
.items()
|
||||
.len(),
|
||||
1
|
||||
)
|
||||
});
|
||||
|
||||
// Open the second entry
|
||||
workspace_view.update(&mut app, |w, ctx| w.open_entry(entries[1], ctx));
|
||||
app.finish_pending_tasks().await;
|
||||
|
||||
app.read(|ctx| {
|
||||
let active_pane = workspace_view.read(ctx).active_pane().read(ctx);
|
||||
assert_eq!(active_pane.items().len(), 2);
|
||||
assert_eq!(
|
||||
active_pane.active_item().unwrap().entry_id(ctx),
|
||||
.active_item()
|
||||
.unwrap()
|
||||
.entry_id(ctx),
|
||||
Some(entries[1])
|
||||
);
|
||||
});
|
||||
|
||||
// Open the first entry again
|
||||
workspace_view.update(&mut app, |w, ctx| w.open_entry(entries[0], ctx));
|
||||
app.finish_pending_tasks().await;
|
||||
|
||||
{
|
||||
let entries = entries.clone();
|
||||
workspace_view
|
||||
.condition(&app, move |workspace_view, ctx| {
|
||||
workspace_view
|
||||
.active_pane()
|
||||
.read(ctx)
|
||||
.active_item()
|
||||
.unwrap()
|
||||
.entry_id(ctx)
|
||||
== Some(entries[0])
|
||||
})
|
||||
.await;
|
||||
}
|
||||
|
||||
app.read(|ctx| {
|
||||
let active_pane = workspace_view.read(ctx).active_pane().read(ctx);
|
||||
assert_eq!(active_pane.items().len(), 2);
|
||||
assert_eq!(
|
||||
active_pane.active_item().unwrap().entry_id(ctx),
|
||||
Some(entries[0])
|
||||
);
|
||||
});
|
||||
|
||||
// Open the third entry twice concurrently
|
||||
@@ -447,19 +459,12 @@ mod tests {
|
||||
w.open_entry(entries[2], ctx);
|
||||
w.open_entry(entries[2], ctx);
|
||||
});
|
||||
app.finish_pending_tasks().await;
|
||||
|
||||
app.read(|ctx| {
|
||||
assert_eq!(
|
||||
workspace_view
|
||||
.read(ctx)
|
||||
.active_pane()
|
||||
.read(ctx)
|
||||
.items()
|
||||
.len(),
|
||||
3
|
||||
);
|
||||
});
|
||||
workspace_view
|
||||
.condition(&app, |workspace_view, ctx| {
|
||||
workspace_view.active_pane().read(ctx).items().len() == 3
|
||||
})
|
||||
.await;
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user