rcom/tests/filter_runtime.rs

63 lines
2.5 KiB
Rust
Raw Permalink Normal View History

use std::sync::Arc;
use std::time::{Duration, Instant};
use rcom::app::Command;
use rcom::domain::{Entry, EntryKind, Location};
use rcom::fs::BackendRegistry;
use rcom::session::Application;
use rcom::ssh::{ConnectionManager, DiscoveryResult, OpenSshConnector};
use rcom::test_support::{MemoryFs, RecordingFs};
#[tokio::test]
async fn matching_has_zero_listing_io_and_only_one_current_preview_read_after_deadline() {
let fs = MemoryFs::new()
.with_file(Location::local("/alpha.txt"), "alpha")
.with_file(Location::local("/beta.txt"), "beta");
let recording = Arc::new(RecordingFs::new(Arc::new(fs)));
let registry = BackendRegistry::new(recording.clone());
let connections = ConnectionManager::new(Arc::new(OpenSshConnector::default()), registry);
let (mut app, mut results) = Application::new(
Location::local("/"),
connections,
DiscoveryResult::default(),
);
app.state_mut_for_test().panes[0].entries = vec![
Entry::new("alpha.txt", EntryKind::File),
Entry::new("beta.txt", EntryKind::File),
];
app.state_mut_for_test().panes[0].selection.set(Some(0), 2);
let start = Instant::now();
app.dispatch_at(Command::OpenFilter, start);
app.dispatch_at(Command::FilterInput('b'), start + Duration::from_millis(1));
assert!(recording.operations().is_empty());
assert_eq!(app.pending_preview_count(), 1);
app.expire_pending_at(start + Duration::from_millis(41));
let command = tokio::time::timeout(Duration::from_secs(1), results.recv())
.await
.unwrap()
.unwrap();
assert!(matches!(command, Command::PreviewFinished(_)));
assert_eq!(recording.operations().len(), 2);
}
#[test]
fn local_and_ssh_locations_share_the_same_projection_contract() {
for location in [
Location::local("/work"),
Location::ssh(rcom::domain::HostAlias::new("fake"), "/work"),
] {
let mut app = rcom::app::AppState::new(location);
app.active_pane_mut().entries = vec![
Entry::new("Alpha", EntryKind::File),
Entry::new("beta", EntryKind::File),
];
app.active_pane_mut().selection.set(Some(0), 2);
app.reduce(Command::OpenFilter);
app.reduce(Command::FilterInput('a'));
assert_eq!(app.active_pane().entries.len(), 2);
app.reduce(Command::FilterInput('l'));
assert_eq!(app.active_pane().entries.len(), 1);
assert_eq!(app.active_pane().selected_entry().unwrap().name, "Alpha");
}
}