tests.rs
raw
use super::*;
use crate::clipboard::NoClipboard;
use crate::event::Modifiers;
fn press(combo: &mut ComboBox, key: Key) -> bool {
combo.on_key(
&KeyInput {
key,
modifiers: Modifiers::default(),
pressed: true,
},
&mut TextContext::hermetic([]),
&mut NoClipboard,
)
}
/// It is a text field first, and the field is the real one: the value goes
/// through to it rather than into a copy.
///
/// The *editing* is not re-tested here — it is `TextInput`'s, exercised by
/// `TextInput`'s own tests and end to end by the `.gdc` differential. What
/// this asserts is that a combo box holds no second buffer to drift from it.
#[test]
fn the_field_is_the_real_one() {
let mut combo = ComboBox::new(14.0);
combo.set_text("hello");
assert_eq!(combo.text(), "hello");
// An ordinary editing key reaches the field rather than being swallowed.
assert!(press(&mut combo, Key::End), "the field took it");
}
/// Down opens the list — the one key it takes that a plain field does not.
/// Checked before delegating, or the field would consume it as caret movement.
#[test]
fn down_asks_for_the_list_only_while_it_is_closed() {
let mut combo = ComboBox::new(14.0);
assert!(press(&mut combo, Key::Down));
assert_eq!(combo.take_emitted(), vec![EventData::MenuOpen]);
// With the list up, Down belongs to the list's own navigation.
combo.set_menu_open(true);
press(&mut combo, Key::Down);
assert!(
!combo.take_emitted().contains(&EventData::MenuOpen),
"an open list keeps its arrows"
);
}
/// The popup is described by the widget rather than discovered by the tree
/// downcasting to it — which is what lets a combo box host one at all.
#[test]
fn it_describes_its_own_popup() {
let combo = ComboBox::new(14.0);
let popup = combo.popup().expect("a combo box hosts a popup");
assert!(!popup.beside, "the list drops below the field");
assert!(popup.match_width, "and is as wide as it");
assert!(combo.defers_content(), "its rows are built when it opens");
}
#[test]
fn it_announces_itself_and_whether_it_is_open() {
let mut combo = ComboBox::new(14.0);
assert_eq!(combo.role(), accesskit::Role::ComboBox);
combo.set_menu_open(true);
let mut node = accesskit::Node::new(accesskit::Role::ComboBox);
combo.accessibility(&mut node);
assert!(node.is_expanded().unwrap_or(false));
}