mod figure;
use super::super::render;
use super::fixture::World;
use super::fixture::wide::{ROWS, world_wide};
use crate::cli_outbound::Cli;
use crate::paint_probe;
use crate::ui_state::Panel;
const RATCHET_FRAMES: usize = 14;
fn settled(ctx: &egui::Context, world: &mut World, w: f32, h: f32) -> f32 {
let (lernie, bl, bz) = (
Cli::new("/yog-absent-lernie"),
Cli::new("/yog-absent-bl"),
Cli::new("/yog-absent-bz"),
);
let _ = ctx.run(paint_probe::screen_sized(w, h), |ctx| {
render(ctx, &mut world.model, &mut world.state, &lernie, &bl, &bz);
});
world.settle();
egui::containers::panel::PanelState::load(ctx, egui::Id::new("conversations"))
.expect("the panel stores its rect")
.rect
.width()
}
#[test]
fn the_conversation_column_opens_where_it_is_told_at_any_window_size() {
let mut report = Vec::new();
for (w, h) in super::SIZES {
let mut world = world_wide();
let ctx = egui::Context::default();
let ceiling = Panel::Conversations.max_size(w);
let opened = Panel::Conversations.default_size().min(ceiling);
let mut widths = Vec::new();
for _ in 0..RATCHET_FRAMES {
widths.push(settled(&ctx, &mut world, w, h));
}
if widths.iter().any(|width| (width - opened).abs() > 1.0) {
report.push(format!(
"at {w:.0}x{h:.0} the column left its {opened} pt opening (ceiling \
{ceiling}): {widths:?}"
));
}
let out = frame(&mut world, &ctx, w, h);
if !painted_a_wide_row(&out) {
report.push(format!(
"at {w:.0}x{h:.0} no wide row reached the column — the fixture is \
not being rendered and nothing here is being tested"
));
}
for seen in paint_probe::seen_of(&out) {
if seen.text.trim() == "…" && seen.shown.right() <= opened + 1.0 {
report.push(format!(
"at {w:.0}x{h:.0} a run in the column says only `…`, at {:?}",
seen.laid
));
}
}
}
assert!(report.is_empty(), "{}", report.join("\n"));
}
fn frame(world: &mut World, ctx: &egui::Context, w: f32, h: f32) -> egui::FullOutput {
let (lernie, bl, bz) = (
Cli::new("/yog-absent-lernie"),
Cli::new("/yog-absent-bl"),
Cli::new("/yog-absent-bz"),
);
ctx.run(paint_probe::screen_sized(w, h), |ctx| {
render(ctx, &mut world.model, &mut world.state, &lernie, &bl, &bz);
})
}
fn painted_a_wide_row(out: &egui::FullOutput) -> bool {
paint_probe::seen_of(out).into_iter().any(|seen| {
ROWS.iter().any(|(_, name, _)| {
let head: String = name.chars().take(12).collect();
!head.is_empty() && seen.text.starts_with(&head)
})
})
}
#[test]
fn a_boundary_dragged_to_a_sliver_stays_there_under_content_wider_than_the_column() {
let mut world = world_wide();
let ctx = egui::Context::default();
for _ in 0..5 {
settled(&ctx, &mut world, 1150.0, 760.0);
}
ctx.data_mut(|d| {
d.insert_persisted(
egui::Id::new("conversations"),
egui::containers::panel::PanelState {
rect: egui::Rect::from_min_size(egui::Pos2::ZERO, egui::vec2(40.0, 760.0)),
},
);
});
let dropped = settled(&ctx, &mut world, 1150.0, 760.0);
assert!(
dropped < 96.0,
"the drag must take: the column settled at {dropped}"
);
for _ in 0..4 {
let width = settled(&ctx, &mut world, 1150.0, 760.0);
assert!(
(width - dropped).abs() < 1.0,
"and it must stay dropped rather than walking back out: \
{dropped} → {width}"
);
}
}