From 05c8ec1a6e2ce9af3f55d75cb761cf3b66244bb8 Mon Sep 17 00:00:00 2001 From: Sebastian Thiel Date: Mon, 3 Jun 2019 12:03:43 +0530 Subject: The first test for user input, yeah! --- tests/interactive.rs | 27 +++++++++++++++++++++++++-- 1 file changed, 25 insertions(+), 2 deletions(-) (limited to 'tests') diff --git a/tests/interactive.rs b/tests/interactive.rs index 159f05e..1fb32da 100644 --- a/tests/interactive.rs +++ b/tests/interactive.rs @@ -1,10 +1,13 @@ mod app { - use dua::interactive::{EntryData, TerminalApp, Tree, TreeIndexType}; - use dua::{ByteFormat, Color, TraversalSorting, WalkOptions}; + use dua::{ + interactive::{widgets::SortMode, EntryData, TerminalApp, Tree, TreeIndexType}, + ByteFormat, Color, TraversalSorting, WalkOptions, + }; use failure::Error; use petgraph::prelude::NodeIndex; use pretty_assertions::assert_eq; use std::{ffi::OsString, fmt, path::Path}; + use termion::input::TermRead; use tui::backend::TestBackend; use tui::Terminal; @@ -38,6 +41,26 @@ mod app { Ok(()) } + #[test] + fn simple_user_journey() -> Result<(), Error> { + let (mut terminal, mut app) = initialized_app_and_terminal("sample-02")?; + assert_eq!( + app.state.sorting, + SortMode::SizeDescending, + "it starts in descending order by size" + ); + + // 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" + ); + + Ok(()) + } + fn initialized_app_and_terminal( fixture_path: &str, ) -> Result<(Terminal, TerminalApp), Error> { -- cgit v1.2.3