From dcff2eebed4422f3103d99eac6bd91e56df327c6 Mon Sep 17 00:00:00 2001 From: Piotr Wach Date: Sat, 20 Jan 2024 12:07:23 +0000 Subject: Tests for refresh & selection --- src/interactive/app/terminal.rs | 6 ++-- src/interactive/app/tests/journeys_readonly.rs | 45 ++++++++++++++++++++++++++ 2 files changed, 47 insertions(+), 4 deletions(-) diff --git a/src/interactive/app/terminal.rs b/src/interactive/app/terminal.rs index 3cb98a6..2a8deb5 100644 --- a/src/interactive/app/terminal.rs +++ b/src/interactive/app/terminal.rs @@ -101,15 +101,13 @@ mod tests { B: Backend, { while self.state.scan.is_some() { - if let Some(res) = self.state.process_event( + self.state.process_event( &mut self.window, &mut self.traversal, &mut self.display, terminal, &events, - )? { - return Ok(res); - } + )?; } Ok(WalkResult { num_errors: self.stats.io_errors, diff --git a/src/interactive/app/tests/journeys_readonly.rs b/src/interactive/app/tests/journeys_readonly.rs index 09ac31a..04a16e7 100644 --- a/src/interactive/app/tests/journeys_readonly.rs +++ b/src/interactive/app/tests/journeys_readonly.rs @@ -173,6 +173,51 @@ fn simple_user_journey_read_only() -> Result<()> { assert!(app.window.glob_pane.is_none()); } + // Refresh finishes eventually + { + assert!(app.state.scan.is_none()); + + // '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()); + + // refresh should finish eventually + app.run_until_traversed(&mut terminal, into_events([]))?; + assert!(app.state.scan.is_none()); + } + + // Refresh finishes eventually + { + // Refresh is not running + assert!(app.state.scan.is_none()); + + app.process_events(&mut terminal, into_codes("j"))?; + assert_eq!( + node_by_name(&app, fixture_str(long_root)), + node_by_index(&app, *app.state.navigation().selected.as_ref().unwrap()), + "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()); + + // Refresh should finish + app.run_until_traversed(&mut terminal, into_events([]))?; + assert!(app.state.scan.is_none()); + + // 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()), + "previous selection is preserved after refresh" + ); + } + // Entry-Navigation { // when hitting the j key -- cgit v1.2.3