Skip to content

Commit

Permalink
refactor
Browse files Browse the repository at this point in the history
- journey tests use string-based input when possible
- make clearer what `input` means by renaming it
  • Loading branch information
Byron committed Jan 21, 2024
1 parent 99b5443 commit 9d976d0
Show file tree
Hide file tree
Showing 3 changed files with 47 additions and 82 deletions.
8 changes: 4 additions & 4 deletions src/interactive/app/eventloop.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
)?;
Expand Down Expand Up @@ -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 {
Expand All @@ -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("") {
Expand Down
5 changes: 3 additions & 2 deletions src/interactive/app/state.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand All @@ -59,7 +60,7 @@ impl AppState {
scan: None,
stats: TraversalStats::default(),
walk_options,
input,
root_paths: input,
}
}
}
116 changes: 40 additions & 76 deletions src/interactive/app/tests/journeys_readonly.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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!(
Expand All @@ -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()),
Expand Down

0 comments on commit 9d976d0

Please sign in to comment.