Lines
94.12 %
Functions
100 %
Branches
use super::*;
use crate::form::{Field, Form, FormKind};
use crate::modal::Modal;
use crate::widgets::{SelectOption, SelectWidget, Widget};
#[test]
fn select_widget_intents_navigate_options() {
let mut sw = SelectWidget::new();
sw.set_options(vec![
SelectOption {
id: "id-0".to_string(),
label: "Zero".to_string(),
},
id: "id-1".to_string(),
label: "One".to_string(),
]);
let mut app = make_app();
let form = Form {
fields: vec![Field {
label: "pick",
widget: Widget::Select(sw),
}],
focus: 0,
kind: FormKind::ConfigSet,
entity_id: None,
};
app.overlays.push(Modal::Form(form));
apply(&mut app, Intent::SelectNext);
match app.overlays.top() {
Some(Modal::Form(f)) => assert_eq!(f.fields[0].widget.value(), "id-1"),
_ => panic!("expected form modal"),
}
apply(&mut app, Intent::SelectPrev);
Some(Modal::Form(f)) => assert_eq!(f.fields[0].widget.value(), "id-0"),
fn select_insert_char_filters_and_value_is_filtered_id() {
id: "id-alpha".to_string(),
label: "Alpha".to_string(),
id: "id-beta".to_string(),
label: "Beta".to_string(),
id: "id-aleph".to_string(),
label: "Aleph".to_string(),
label: "from",
kind: FormKind::CommodityConvert,
// 'B' narrows to only "Beta"
apply(&mut app, Intent::InsertChar('B'));
Some(Modal::Form(f)) => assert_eq!(
f.fields[0].widget.value(),
"id-beta",
"only Beta matches 'B'"
),
// Backspace clears filter; all options visible; focused resets to 0 = Alpha
apply(&mut app, Intent::DeleteBackward);
"id-alpha",
"after filter pop all options visible, focused=0 is Alpha"