diff --git a/Cargo.toml b/Cargo.toml index 7093648c..5dc93a09 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -20,3 +20,6 @@ console = "0.13.0" lazy_static = "1" tempfile = "3" zeroize = "1.1.1" + +[dev-dependencies] +enigo = "0.0.14" diff --git a/tests/select.rs b/tests/select.rs new file mode 100644 index 00000000..1662e494 --- /dev/null +++ b/tests/select.rs @@ -0,0 +1,30 @@ +use dialoguer::{theme::ColorfulTheme, Select}; + +use enigo::{Enigo, Key, KeyboardControllable}; +use std::thread; +use std::time::Duration; + +#[test] +fn basic_navigation_produces_correct_selection() { + let selections = &[ + "Ice Cream", + "Vanilla Cupcake", + "Chocolate Muffin", + "A Pile of sweet, sweet mustard", + ]; + + let mut enigo = Enigo::new(); + enigo.key_click(Key::Layout('j')); + enigo.key_down(Key::Return); + thread::sleep(Duration::from_millis(10)); + enigo.key_up(Key::Return); + + let selection = Select::with_theme(&ColorfulTheme::default()) + .with_prompt("Optionally pick your flavor") + .default(0) + .items(&selections[..]) + .interact_opt() + .unwrap(); + + assert_eq!(Some(1), selection); +}