From 9d976d0d76fcf45d1e0672bc5c1533b000a46ebf Mon Sep 17 00:00:00 2001 From: Sebastian Thiel Date: Sun, 21 Jan 2024 16:57:51 +0100 Subject: refactor - journey tests use string-based input when possible - make clearer what `input` means by renaming it --- src/interactive/app/eventloop.rs | 8 +- src/interactive/app/state.rs | 5 +- src/interactive/app/tests/journeys_readonly.rs | 116 +++++++++---------------- 3 files changed, 47 insertions(+), 82 deletions(-) (limited to 'src') 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, pub stats: TraversalStats, pub walk_options: WalkOptions, - pub input: Vec, + /// The paths used in the initial traversal, at least 1. + pub root_paths: Vec, } 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()), -- cgit v1.2.3