use super::super::clipped;
use super::toy;
use crate::ui::Model;
use egui_kittest::HarnessBuilder;
#[test]
fn a_control_scrolled_past_the_overlay_s_clip_is_not_a_fault() {
let clip = Some(egui::Rect::from_min_max(
egui::pos2(16.0, 100.0),
egui::pos2(384.0, 790.0),
));
assert!(clipped::scrolled((20.0, 800.0, 200.0, 820.0), clip));
assert!(clipped::scrolled((20.0, 10.0, 200.0, 90.0), clip));
assert!(!clipped::scrolled((20.0, 300.0, 200.0, 320.0), clip));
assert!(!clipped::scrolled((390.0, 800.0, 500.0, 820.0), clip));
assert!(!clipped::scrolled((20.0, 800.0, 200.0, 820.0), None));
}
#[test]
fn a_control_the_tree_gives_no_rectangle_is_a_fault() {
let why = clipped::fault(None, 100.0, 100.0).expect("no rectangle is a fault");
assert!(why.contains("no rectangle"), "{why}");
}
#[test]
fn a_control_with_an_empty_rectangle_is_a_fault() {
let why = clipped::fault(Some((10.0, 10.0, 10.0, 40.0)), 100.0, 100.0)
.expect("an empty rectangle is a fault");
assert!(why.contains("empty"), "{why}");
}
#[test]
fn a_control_wholly_outside_the_window_is_a_fault_on_every_edge() {
let window = (100.0_f32, 100.0_f32);
for bounds in [
(-50.0, 10.0, -1.0, 40.0),
(10.0, -50.0, 40.0, -1.0),
(101.0, 10.0, 140.0, 40.0),
(10.0, 101.0, 40.0, 140.0),
] {
let why = clipped::fault(Some(bounds), window.0, window.1)
.unwrap_or_else(|| panic!("{bounds:?} is outside the window"));
assert!(why.contains("wholly outside"), "{why}");
}
}
#[test]
fn the_walk_names_the_control_it_found_outside_the_window() {
let harness = toy("a control");
let said = clipped::complaints("toy", 4.0, 4.0, &harness);
assert!(
said.concat().contains("a control"),
"the complaint names the control: {said:?}"
);
assert!(said.concat().contains("wholly outside"), "{said:?}");
}
#[test]
fn a_label_outside_the_window_is_not_a_fault_where_a_control_is() {
let mut harness = HarnessBuilder::<Model>::default()
.with_size(egui::Vec2::new(200.0, 100.0))
.build_state(
|ctx: &egui::Context, _: &mut Model| {
egui::CentralPanel::default().show(ctx, |ui| {
ui.label("a sentence");
let _ = crate::ui::theme::paint::button(ui, "a control", true, "a toy");
});
},
Model::default(),
);
harness.run();
let said = clipped::complaints("toy", 4.0, 4.0, &harness).concat();
assert!(said.contains("a control"), "{said}");
assert!(!said.contains("a sentence"), "{said}");
}
#[test]
fn a_control_hanging_over_an_edge_is_not_a_fault() {
assert!(clipped::fault(Some((-10.0, -10.0, 5.0, 5.0)), 100.0, 100.0).is_none());
assert!(clipped::fault(Some((95.0, 95.0, 140.0, 140.0)), 100.0, 100.0).is_none());
}