diff options
author | Sebastian Thiel <sthiel@thoughtworks.com> | 2019-06-03 15:02:18 +0530 |
---|---|---|
committer | Sebastian Thiel <sthiel@thoughtworks.com> | 2019-06-03 15:20:14 +0530 |
commit | 25ceae2779e3e20b4ff4ac3d6149410e5f851775 (patch) | |
tree | a2935200a9bfd0eb03e7922545bfb821c6ab0611 /tests | |
parent | 748dfc353a7d8c7bbb6bbfb097bacec18b80e32a (diff) |
add 'o' navigation
add 'o'
Diffstat (limited to 'tests')
-rw-r--r-- | tests/interactive.rs | 52 |
1 files changed, 49 insertions, 3 deletions
diff --git a/tests/interactive.rs b/tests/interactive.rs index 50d80c8..8d5eb18 100644 --- a/tests/interactive.rs +++ b/tests/interactive.rs @@ -54,14 +54,29 @@ mod app { node_by_index(app, index_by_name(&app, name)) } - fn index_by_name(app: &TerminalApp, name: impl AsRef<OsStr>) -> TreeIndex { + fn index_by_name_and_size( + app: &TerminalApp, + name: impl AsRef<OsStr>, + size: Option<u64>, + ) -> TreeIndex { let name = name.as_ref(); let t: Vec<_> = app .traversal .tree .node_indices() .map(|idx| (idx, node_by_index(app, idx))) - .filter_map(|(idx, e)| if e.name == name { Some(idx) } else { None }) + .filter_map(|(idx, e)| { + if e.name == name + && match size { + Some(s) => s == e.size, + None => true, + } + { + Some(idx) + } else { + None + } + }) .collect(); match t.len() { 1 => t[0], @@ -69,11 +84,14 @@ mod app { n => panic!("Node named '{}' found {} times", name.to_string_lossy(), n), } } + fn index_by_name(app: &TerminalApp, name: impl AsRef<OsStr>) -> TreeIndex { + index_by_name_and_size(app, name, None) + } #[test] fn simple_user_journey() -> Result<(), Error> { let long_root = "sample-02/dir"; - let short_root = "sample-02"; + let short_root = "sample-01"; let (mut terminal, mut app) = initialized_app_and_terminal(&[short_root, long_root])?; // POST-INIT @@ -147,6 +165,34 @@ mod app { node_by_index(&app, *app.state.selected.as_ref().unwrap()), "it stays at the current cursor position as there is nowhere to go" ); + // when hitting the o key with a directory selected + app.process_events(&mut terminal, b"o".keys())?; + { + let new_root_idx = index_by_name(&app, fixture_str(short_root)); + assert_eq!( + new_root_idx, app.state.root, + "it enters the entry if it is a directory, changing the root" + ); + assert_eq!( + index_by_name(&app, "dir"), + *app.state.selected.as_ref().unwrap(), + "it selects the first entry in the directory" + ); + + // when trying to enter a file (a node with no children) + app.process_events(&mut terminal, b"jo".keys())?; + { + assert_eq!( + new_root_idx, app.state.root, + "it does not enter it, keeping the previous root" + ); + assert_eq!( + node_by_index(&app, index_by_name(&app, ".hidden.666")), + node_by_index(&app, *app.state.selected.as_ref().unwrap()), + "it does not change the selection" + ); + } + } } Ok(()) |