mirror of
https://github.com/storytold/craft-libs.git
synced 2026-11-30 18:27:00 +01:00
The fixture's shown rect grows with whatever the row allocates, so a button that overflowed the column also widened it and the check passed. The room starts at x = 0, so the test now compares the button's right edge with the requested width.
39 lines
1.8 KiB
Rust
39 lines
1.8 KiB
Rust
//! A path row keeps its Browse button whole: the text field takes only the room the button leaves.
|
|
|
|
use craft_ui::contract::Bind;
|
|
use craft_ui::patterns::form_dialogs::PathRow;
|
|
use craft_ui::testing::{Fixture, trial};
|
|
use egui::vec2;
|
|
|
|
/// The row alone in a column `width` wide, over a long path.
|
|
fn row_in(width: f32) -> Fixture {
|
|
let mut fixture = Fixture::new(|ui| {
|
|
let mut path = "/Users/someone/Documents/exports/a/folder/with/a/long/name".to_owned();
|
|
let _ = PathRow::new("Export to:", Bind::bound(&mut path)).show(ui);
|
|
});
|
|
fixture.room(vec2(width, 120.0));
|
|
fixture.settle();
|
|
fixture
|
|
}
|
|
|
|
#[trial]
|
|
fn browse_shows_its_whole_label_inside_a_narrow_column() {
|
|
for width in [360.0, 260.0, 200.0] {
|
|
let fixture = row_in(width);
|
|
let label = fixture.texts().iter().find(|run| run.text == "Browse…").cloned();
|
|
let label = label
|
|
.unwrap_or_else(|| panic!("{width}: Browse… is painted: {:?}", fixture.texts().iter().map(|run| run.text.clone()).collect::<Vec<_>>()));
|
|
assert!(!label.elided, "{width}: the Browse label is not cut");
|
|
let button = fixture.by_label("Browse…").expect("the Browse button");
|
|
assert!(button.rect.right() <= width + 0.5, "{width}: the button {:?} ends inside the column of width {width}", button.rect);
|
|
assert!(
|
|
label.rect.left() >= button.rect.left() - 0.5 && label.rect.right() <= button.rect.right() + 0.5,
|
|
"{width}: the label {:?} lies inside the button {:?}",
|
|
label.rect,
|
|
button.rect
|
|
);
|
|
let field = fixture.by_label("Export to:").expect("the path field");
|
|
assert!(field.rect.right() <= button.rect.left(), "{width}: the field {:?} ends before the button {:?}", field.rect, button.rect);
|
|
}
|
|
}
|