mirror of
https://github.com/storytold/craft-libs.git
synced 2026-11-17 02:54:25 +00:00
35 lines
1.7 KiB
Rust
35 lines
1.7 KiB
Rust
//! The Tabs dialog's focus: it opens on the default interval, and Set moves into the new stop's row.
|
|
|
|
use craft_text::ui::tabs_dialog::TabStopsDialog;
|
|
use craft_ui::dialog::{DialogStack, StackDialog as _};
|
|
use craft_ui::testing::{Fixture, trial};
|
|
use std::cell::RefCell;
|
|
use std::rc::Rc;
|
|
|
|
/// Which of `labels` holds the focus.
|
|
fn focused<'a>(fixture: &Fixture, labels: &[&'a str]) -> Option<&'a str> {
|
|
let focused = craft_ui::testing::access::focused_key(fixture.tree());
|
|
labels.iter().copied().find(|label| fixture.by_label(label).is_some_and(|target| target.node == focused))
|
|
}
|
|
|
|
#[trial]
|
|
fn the_dialog_opens_on_the_default_interval_and_set_moves_into_the_new_stop() {
|
|
let dialog = Rc::new(RefCell::new(TabStopsDialog::new(Vec::new(), 36.0)));
|
|
let shown = dialog.clone();
|
|
let mut fixture = Fixture::new(move |ui| {
|
|
let _ = shown.borrow_mut().show(ui, &DialogStack::default());
|
|
});
|
|
fixture.idle(30);
|
|
let labels = ["Default tab stops:", "Tab stop position:", "Set"];
|
|
assert_eq!(focused(&fixture, &labels), Some("Default tab stops:"), "the dialog opens on its first field");
|
|
let set = fixture.by_label("Set").expect("Set is shown");
|
|
fixture.click(&set).idle(4);
|
|
assert_eq!(focused(&fixture, &labels), Some("Tab stop position:"), "Set moves the focus into the new stop's position");
|
|
let set = fixture.by_label("Set").expect("Set is shown");
|
|
fixture.click(&set).idle(4);
|
|
let key = craft_ui::testing::access::focused_key(fixture.tree());
|
|
assert_eq!(fixture.tree().name_of(key), Some("Tab stop position:"), "a second Set moves into a position field too");
|
|
let value = fixture.tree().value_of(key).unwrap_or_default();
|
|
assert!(value.contains("72"), "the focus is in the new row's field, at 72 pt: {value:?}");
|
|
}
|