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:
+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