summaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorSebastian Thiel <sthiel@thoughtworks.com>2019-06-14 14:31:24 +0800
committerSebastian Thiel <sthiel@thoughtworks.com>2019-06-14 14:41:23 +0800
commitc67abaec3c573dbfaf31be22693220a49a67b262 (patch)
treefe3ea594c86ae12e1f7dcf23c612aed43500082d /src
parenta128eb4a6e675f148a203ac66de075ee0c0def1c (diff)
Xi'an/China: first test to fully verify deletion
Diffstat (limited to 'src')
-rw-r--r--src/interactive/app/eventloop.rs7
-rw-r--r--src/interactive/app_test/journeys_with_writes.rs47
-rw-r--r--src/interactive/app_test/utils.rs6
3 files changed, 54 insertions, 6 deletions
diff --git a/src/interactive/app/eventloop.rs b/src/interactive/app/eventloop.rs
index 8f7487d..2d1edaa 100644
--- a/src/interactive/app/eventloop.rs
+++ b/src/interactive/app/eventloop.rs
@@ -9,7 +9,7 @@ use dua::{
};
use failure::Error;
use std::{io, path::PathBuf};
-use termion::input::{Keys, TermReadEventsAndRaw};
+use termion::event::Key;
use tui::backend::Backend;
use tui_react::Terminal;
@@ -69,14 +69,13 @@ impl TerminalApp {
};
Self::draw_window(&mut self.window, props, terminal)
}
- pub fn process_events<B, R>(
+ pub fn process_events<B>(
&mut self,
terminal: &mut Terminal<B>,
- keys: Keys<R>,
+ keys: impl Iterator<Item = Result<Key, io::Error>>,
) -> Result<WalkResult, Error>
where
B: Backend,
- R: io::Read + TermReadEventsAndRaw,
{
use termion::event::Key::*;
use FocussedPane::*;
diff --git a/src/interactive/app_test/journeys_with_writes.rs b/src/interactive/app_test/journeys_with_writes.rs
index 7900a4d..89e0924 100644
--- a/src/interactive/app_test/journeys_with_writes.rs
+++ b/src/interactive/app_test/journeys_with_writes.rs
@@ -2,11 +2,54 @@ use crate::interactive::app_test::utils::{
initialized_app_and_terminal_from_paths, WritableFixture,
};
use failure::Error;
+use pretty_assertions::assert_eq;
+use termion::event::Key;
+use termion::input::TermRead;
#[test]
fn basic_user_journey_with_deletion() -> Result<(), Error> {
let fixture = WritableFixture::from("sample-02");
- let (mut _terminal, mut _app) =
- initialized_app_and_terminal_from_paths(&[fixture.root.clone()])?;
+ let (mut terminal, mut app) = initialized_app_and_terminal_from_paths(&[fixture.root.clone()])?;
+
+ // With a selection of items
+ app.process_events(&mut terminal, b"doddd".keys())?;
+
+ assert_eq!(
+ app.window.mark_pane.as_ref().map(|p| p.marked().len()),
+ Some(4),
+ "expecting 4 selected entries, the parent dir, and some children"
+ );
+
+ assert_eq!(
+ fixture.as_ref().is_dir(),
+ true,
+ "expecting fixture root to exist"
+ );
+
+ // When selecting the marker window and pressing the combination to delete entries
+ app.process_events(
+ &mut terminal,
+ vec![Ok(Key::Char('\t')), Ok(Key::Ctrl('R'))].into_iter(),
+ )?;
+ assert_eq!(
+ fixture.as_ref().is_dir(),
+ false,
+ "the directory should have been deleted"
+ );
+ assert_eq!(
+ app.window.mark_pane.is_none(),
+ true,
+ "the marker pane is gone as all entries have been removed"
+ );
+ assert_eq!(
+ app.state.selected,
+ None,
+ "nothing is left to be selected"
+ );
+ assert_eq!(
+ app.state.root,
+ app.traversal.root_index,
+ "the only root left is the top-level"
+ );
Ok(())
}
diff --git a/src/interactive/app_test/utils.rs b/src/interactive/app_test/utils.rs
index 3abe26f..144a4cc 100644
--- a/src/interactive/app_test/utils.rs
+++ b/src/interactive/app_test/utils.rs
@@ -137,6 +137,12 @@ impl From<&'static str> for WritableFixture {
}
}
+impl AsRef<Path> for WritableFixture {
+ fn as_ref(&self) -> &Path {
+ &self.root
+ }
+}
+
pub fn fixture(p: impl AsRef<Path>) -> PathBuf {
Path::new(FIXTURE_PATH).join(p)
}