diff options
author | Sebastian Thiel <sthiel@thoughtworks.com> | 2019-06-03 13:27:17 +0530 |
---|---|---|
committer | Sebastian Thiel <sthiel@thoughtworks.com> | 2019-06-03 13:27:17 +0530 |
commit | 0b3e158085d68ba43dc3ac034ce4f0b5df9d61e8 (patch) | |
tree | 589fd99289b18595d05abf67767b63ab78ee9260 /tests | |
parent | b3dc836baa00e36c56f823e9e5b3e9118fdd8b30 (diff) |
Unify sorting to start dealing with selections
Diffstat (limited to 'tests')
-rw-r--r-- | tests/interactive.rs | 27 |
1 files changed, 19 insertions, 8 deletions
diff --git a/tests/interactive.rs b/tests/interactive.rs index e6a1efe..9a923d9 100644 --- a/tests/interactive.rs +++ b/tests/interactive.rs @@ -1,5 +1,4 @@ mod app { - use dua::interactive::TreeIndex; use dua::{ interactive::{widgets::SortMode, EntryData, TerminalApp, Tree, TreeIndexType}, ByteFormat, Color, TraversalSorting, WalkOptions, @@ -44,32 +43,44 @@ mod app { Ok(()) } + fn node_by(app: &TerminalApp, id: TreeIndexType) -> &EntryData { + app.traversal.tree.node_weight(id.into()).unwrap() + } + #[test] fn simple_user_journey() -> Result<(), Error> { let long_root = "sample-02/dir"; let (mut terminal, mut app) = initialized_app_and_terminal(&["sample-02", long_root])?; + + // after initialization, we expect that... assert_eq!( app.state.sorting, SortMode::SizeDescending, - "it starts in descending order by size" + "it will sort entries in descending order by size" ); assert_eq!( - app.traversal - .tree - .node_weight(TreeIndex::new(11)) - .unwrap() - .name, + node_by(&app, 11).name, OsString::from(format!("{}/{}", FIXTURE_PATH, long_root)), "the roots are always listed with the given (possibly long) names", ); + assert_eq!( + node_by(&app, 1).name, + node_by( + &app, + app.state.selected.as_ref().unwrap().index() as TreeIndexType + ) + .name, + "it selects the first node in the list", + ); + // when hitting the S key app.process_events(&mut terminal, b"s".keys())?; assert_eq!( app.state.sorting, SortMode::SizeAscending, - "it sets the sort to size ascending" + "it sets the sort mode to ascending by size" ); Ok(()) |