Skip to content

Commit

Permalink
Xi'an/China: first test to fully verify deletion
Browse files Browse the repository at this point in the history
  • Loading branch information
Sebastian Thiel committed Jun 14, 2019
1 parent a128eb4 commit c67abae
Show file tree
Hide file tree
Showing 3 changed files with 54 additions and 6 deletions.
7 changes: 3 additions & 4 deletions src/interactive/app/eventloop.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down Expand Up @@ -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::*;
Expand Down
47 changes: 45 additions & 2 deletions src/interactive/app_test/journeys_with_writes.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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(())
}
6 changes: 6 additions & 0 deletions src/interactive/app_test/utils.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
Expand Down

0 comments on commit c67abae

Please sign in to comment.