From 0b3e158085d68ba43dc3ac034ce4f0b5df9d61e8 Mon Sep 17 00:00:00 2001 From: Sebastian Thiel Date: Mon, 3 Jun 2019 13:27:17 +0530 Subject: Unify sorting to start dealing with selections --- tests/interactive.rs | 27 +++++++++++++++++++-------- 1 file changed, 19 insertions(+), 8 deletions(-) (limited to 'tests') 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(()) -- cgit v1.2.3