summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorSebastian Thiel <sebastian.thiel@icloud.com>2024-01-21 16:57:51 +0100
committerSebastian Thiel <sebastian.thiel@icloud.com>2024-01-21 17:15:00 +0100
commit9d976d0d76fcf45d1e0672bc5c1533b000a46ebf (patch)
treecee9e52898f075bc7857b35a981843dfca0c624f
parent99b5443f2f8821b0a285320c8ec3f982722cfff8 (diff)
refactor
- journey tests use string-based input when possible - make clearer what `input` means by renaming it
-rw-r--r--src/interactive/app/eventloop.rs8
-rw-r--r--src/interactive/app/state.rs5
-rw-r--r--src/interactive/app/tests/journeys_readonly.rs116
3 files changed, 47 insertions, 82 deletions
diff --git a/src/interactive/app/eventloop.rs b/src/interactive/app/eventloop.rs
index 1f795b2..f03c55b 100644
--- a/src/interactive/app/eventloop.rs
+++ b/src/interactive/app/eventloop.rs
@@ -68,7 +68,7 @@ impl AppState {
let traverasal = BackgroundTraversal::start(
traversal.root_index,
&self.walk_options,
- self.input.clone(),
+ self.root_paths.clone(),
false,
true,
)?;
@@ -396,7 +396,7 @@ impl AppState {
let (paths, use_root_path, skip_root) = if self.navigation().view_root
== tree.traversal.root_index
- && self.input.len() > 1
+ && self.root_paths.len() > 1
{
(vec![path], true, false)
} else {
@@ -415,9 +415,9 @@ impl AppState {
Refresh::AllInView => {
let (paths, use_root_path, skip_root) = if self.navigation().view_root
== tree.traversal.root_index
- && self.input.len() > 1
+ && self.root_paths.len() > 1
{
- (self.input.clone(), true, false)
+ (self.root_paths.clone(), true, false)
} else {
let mut path = tree.path_of(self.navigation().view_root);
if path.to_str() == Some("") {
diff --git a/src/interactive/app/state.rs b/src/interactive/app/state.rs
index b7fa329..8762b93 100644
--- a/src/interactive/app/state.rs
+++ b/src/interactive/app/state.rs
@@ -42,7 +42,8 @@ pub struct AppState {
pub scan: Option<FilesystemScan>,
pub stats: TraversalStats,
pub walk_options: WalkOptions,
- pub input: Vec<PathBuf>,
+ /// The paths used in the initial traversal, at least 1.
+ pub root_paths: Vec<PathBuf>,
}
impl AppState {
@@ -59,7 +60,7 @@ impl AppState {
scan: None,
stats: TraversalStats::default(),
walk_options,
- input,
+ root_paths: input,
}
}
}
diff --git a/src/interactive/app/tests/journeys_readonly.rs b/src/interactive/app/tests/journeys_readonly.rs
index af1063b..cfa4375 100644
--- a/src/interactive/app/tests/journeys_readonly.rs
+++ b/src/interactive/app/tests/journeys_readonly.rs
@@ -133,90 +133,60 @@ fn simple_user_journey_read_only() -> Result<()> {
// Columns
{
- // hit the C key shows the entry count column
- app.process_events(
- &mut terminal,
- into_events([Event::Key(KeyEvent::new(
- KeyCode::Char('C'),
- KeyModifiers::NONE,
- ))]),
- )?;
- assert!(app.state.show_columns.contains(&Column::Count));
+ app.process_events(&mut terminal, into_codes("C"))?;
+ assert!(
+ app.state.show_columns.contains(&Column::Count),
+ "hit the C key to show the entry count column"
+ );
- // when hitting the C key again hides the entry count column
- app.process_events(
- &mut terminal,
- into_events([Event::Key(KeyEvent::new(
- KeyCode::Char('C'),
- KeyModifiers::NONE,
- ))]),
- )?;
- assert!(!app.state.show_columns.contains(&Column::Count));
+ app.process_events(&mut terminal, into_codes("C"))?;
+ assert!(
+ !app.state.show_columns.contains(&Column::Count),
+ "when hitting the C key again it hides the entry count column"
+ );
- // hit the M key shows the entry count column
- app.process_events(
- &mut terminal,
- into_events([Event::Key(KeyEvent::new(
- KeyCode::Char('M'),
- KeyModifiers::NONE,
- ))]),
- )?;
- assert!(app.state.show_columns.contains(&Column::MTime));
+ app.process_events(&mut terminal, into_codes("M"))?;
+ assert!(
+ app.state.show_columns.contains(&Column::MTime),
+ "hit the M key to show the entry count column"
+ );
- // when hitting the M key again hides the entry count column
- app.process_events(
- &mut terminal,
- into_events([Event::Key(KeyEvent::new(
- KeyCode::Char('M'),
- KeyModifiers::NONE,
- ))]),
- )?;
- assert!(!app.state.show_columns.contains(&Column::MTime));
+ app.process_events(&mut terminal, into_codes("M"))?;
+ assert!(
+ !app.state.show_columns.contains(&Column::MTime),
+ "when hitting the M key again it hides the entry count column"
+ );
}
// Glob pane open/close
{
- // '/' shows the glob pane
- app.process_events(
- &mut terminal,
- into_events([Event::Key(KeyEvent::new(
- KeyCode::Char('/'),
- KeyModifiers::NONE,
- ))]),
- )?;
- assert!(app.window.glob_pane.is_some());
+ app.process_events(&mut terminal, into_codes("/"))?;
+ assert!(app.window.glob_pane.is_some(), "'/' shows the glob pane");
- // ESC closes the glob pane
app.process_events(
&mut terminal,
into_events([Event::Key(KeyEvent::new(KeyCode::Esc, KeyModifiers::NONE))]),
)?;
- assert!(app.window.glob_pane.is_none());
+ assert!(app.window.glob_pane.is_none(), "ESC closes the glob pane");
}
- // Refresh finishes eventually
+ // explicit full refresh
{
- assert!(app.state.scan.is_none());
+ assert!(app.state.scan.is_none(), "no refresh in progress");
- // 'R' refreshes all entries in the view
- app.process_events(
- &mut terminal,
- into_events([Event::Key(KeyEvent::new(
- KeyCode::Char('R'),
- KeyModifiers::NONE,
- ))]),
- )?;
- assert!(app.state.scan.is_some());
+ app.process_events(&mut terminal, into_codes("R"))?;
+ assert!(
+ app.state.scan.is_some(),
+ "'R' refreshes all entries in the view"
+ );
- // refresh should finish eventually
- app.run_until_traversed(&mut terminal, into_events([]))?;
- assert!(app.state.scan.is_none());
+ app.run_until_traversed(&mut terminal, into_codes(""))?;
+ assert!(app.state.scan.is_none(), "refresh should finish eventually");
}
- // Refresh finishes eventually
+ // explicit partial refresh
{
- // Refresh is not running
- assert!(app.state.scan.is_none());
+ assert!(app.state.scan.is_none(), "no refresh in progress");
app.process_events(&mut terminal, into_codes("j"))?;
assert_eq!(
@@ -225,21 +195,15 @@ fn simple_user_journey_read_only() -> Result<()> {
"it moves the cursor down and selects the next item based on the current sort mode"
);
- // 'R' refreshes all entries in the view
- app.process_events(
- &mut terminal,
- into_events([Event::Key(KeyEvent::new(
- KeyCode::Char('R'),
- KeyModifiers::NONE,
- ))]),
- )?;
- assert!(app.state.scan.is_some());
+ app.process_events(&mut terminal, into_codes("r"))?;
+ assert!(
+ app.state.scan.is_some(),
+ "'r' refreshes all entries in the view"
+ );
- // Refresh should finish
app.run_until_traversed(&mut terminal, into_events([]))?;
- assert!(app.state.scan.is_none());
+ assert!(app.state.scan.is_none(), "Refresh should finish");
- // Previous selection is preserved
assert_eq!(
node_by_name(&app, fixture_str(long_root)),
node_by_index(&app, *app.state.navigation().selected.as_ref().unwrap()),