use super::{ROW, bar, said, tick};
use crate::paint_probe::fills_of;
use crate::paint_probe::frame::Window;
use crate::test_support::window::seated;
use crate::ui::theme;
fn heading(ctx: &egui::Context) -> f32 {
let font = egui::TextStyle::Heading.resolve(&ctx.style());
ctx.fonts(|fonts| fonts.row_height(&font))
}
#[test]
fn the_pin_is_heading_sized_with_air_inside_the_seat() {
let ctx = egui::Context::default();
let mut model = seated();
let shut = bar(&tick(&ctx, &mut model, 0.0, None));
let tall = heading(&ctx);
let pin = shut
.iter()
.find(|run| run.text == theme::glyph::PIN)
.unwrap_or_else(|| panic!("the pin in {shut:?}"));
assert!(pin.laid.height() >= tall, "{:?}", pin.laid);
let plus = shut
.iter()
.find(|run| run.text == super::super::PLUS)
.unwrap_or_else(|| panic!("+ in {shut:?}"));
assert!(plus.laid.min.y >= pin.laid.max.y, "+ stands under the pin");
model.bar.pinned = true;
let unpin = theme::worded(theme::glyph::PIN, super::super::UNPIN);
let at = bar(&tick(&ctx, &mut model, 1.0, None))
.into_iter()
.find(|run| run.text == unpin)
.expect("the open pin")
.laid
.center();
tick(&ctx, &mut model, 1.1, Some(at));
let lit = tick(&ctx, &mut model, 1.2, Some(at));
let wash = fills_of(&lit)
.into_iter()
.find(|(rect, fill)| *fill == theme::hover() && rect.contains(at))
.map(|(rect, _)| rect)
.expect("the pin's seat lit");
assert!(
wash.height() >= tall + 2.0 * theme::space::S,
"the seat holds the air: {wash:?} against {tall}"
);
}
#[test]
fn the_pin_holds_it_open_and_says_what_it_would_do() {
let window = Window::new();
let mut model = seated();
let mut body = |ctx: &egui::Context| crate::ui::render(ctx, &mut model);
let shut = window.text(&mut body);
assert!(shut.lines().any(|line| line == theme::glyph::PIN), "{shut}");
crate::test_support::window::click(&window, theme::glyph::PIN, &mut body);
assert!(model.bar.pinned);
let ctx = egui::Context::default();
let pinned = said(&tick(&ctx, &mut model, 0.0, None));
let unpin = theme::worded(theme::glyph::PIN, super::super::UNPIN);
assert!(pinned.contains(&unpin), "{pinned:?}");
assert!(pinned.contains(&ROW.to_owned()), "{pinned:?}");
model.bar.pinned = false;
model.bar.left_at = Some(0.0);
let open = said(&tick(&ctx, &mut model, 0.5, None));
let pin = theme::worded(theme::glyph::PIN, super::super::PIN);
assert!(open.contains(&pin), "{open:?}");
}