use super::super::render;
use super::fixture::world;
use crate::cli_outbound::Cli;
const ORDER: [&str; 3] = ["flight-strip", "composer", "conversation-settings"];
const CENSUS: [&str; 5] = [
"420x320: [\"composer\", \"conversation-settings\"]",
"480x1400: [\"flight-strip\", \"composer\", \"conversation-settings\"]",
"800x500: [\"flight-strip\", \"composer\", \"conversation-settings\"]",
"1150x760: [\"flight-strip\", \"composer\", \"conversation-settings\"]",
"2560x1700: [\"flight-strip\", \"composer\", \"conversation-settings\"]",
];
fn seats(ctx: &egui::Context) -> Vec<(&'static str, egui::Rect)> {
ORDER
.iter()
.filter_map(|id| {
egui::containers::panel::PanelState::load(ctx, egui::Id::new(*id))
.map(|state| (*id, state.rect))
})
.collect()
}
fn out_of_order(seated: &[(&'static str, egui::Rect)]) -> Vec<String> {
seated
.windows(2)
.filter_map(|pair| match pair {
[(above, upper), (below, lower)] if upper.bottom() > lower.top() + 1.0 => {
Some(format!(
"{above} (bottom {}) is not above {below} (top {})",
upper.bottom(),
lower.top()
))
}
_ => None,
})
.collect()
}
fn stack(w: f32, h: f32) -> Vec<(&'static str, egui::Rect)> {
let (lernie, bl, bz) = (
Cli::new("yog-absent-lernie"),
Cli::new("yog-absent-bl"),
Cli::new("yog-absent-bz"),
);
let mut world = super::inbox_composer::quick(world());
let ws = world.ws.clone();
world.model.focus_agent(&ws, "c-1");
let _lock = std::fs::File::open(ws.join("inbox/c-1")).unwrap();
let _writer = std::fs::OpenOptions::new()
.append(true)
.open(ws.join("steps/c-1/001/response.json"))
.unwrap();
super::inbox_composer::converge_ws(&mut world);
let ctx = egui::Context::default();
let mut frame = |world: &mut super::fixture::World| {
let _ = ctx.run(crate::paint_probe::screen_sized(w, h), |ctx| {
render(ctx, &mut world.model, &mut world.state, &lernie, &bl, &bz);
});
};
for _ in 0..5 {
frame(&mut world);
}
world.drain(&mut frame);
ctx.data_mut(|data| {
for id in ORDER {
data.remove::<egui::containers::panel::PanelState>(egui::Id::new(id));
}
});
frame(&mut world);
seats(&ctx)
}
#[test]
fn the_settings_band_reads_below_the_input_box_at_every_window_size() {
let mut census = Vec::new();
let mut report = Vec::new();
for (w, h) in super::SIZES {
let seated = stack(w, h);
let names: Vec<&str> = seated.iter().map(|(id, _)| *id).collect();
census.push(format!("{w:.0}x{h:.0}: {names:?}"));
for pair in out_of_order(&seated) {
report.push(format!("at {w:.0}x{h:.0}: {pair}"));
}
}
assert!(report.is_empty(), "{}", report.join("\n"));
assert_eq!(census, CENSUS, "which bands each size seats has changed");
}
#[test]
fn the_reader_reports_the_order_the_ruling_retired() {
let ctx = egui::Context::default();
let _ = ctx.run(super::input(), |ctx| {
egui::CentralPanel::default().show(ctx, |ui| {
for id in ["composer", "conversation-settings", "flight-strip"] {
egui::TopBottomPanel::bottom(id).show_inside(ui, |ui| {
ui.label(id);
});
}
});
});
let found = out_of_order(&seats(&ctx));
assert!(
found
.iter()
.any(|pair| pair.contains("composer") && pair.contains("conversation-settings")),
"the retired order must be reported: {found:?}"
);
}