use super::{render, widths};
use crate::paint_probe::Seen;
use crate::paint_probe::frame::Window;
use crate::test_support::window::{conv, seated, seen};
use crate::ui::Model;
const LONG: &str = "What changed in the last 20 commits of this repository? Write a concise changelog to CHANGES.md";
fn overrunning() -> Model {
let mut model = seated();
let mut row = conv("20260830T051200Z-a1b2", "port the paint probe");
row.preview = LONG.to_owned();
model.convs = vec![row];
model
}
fn glass(window: &Window, model: &mut Model) -> Vec<Seen> {
window.frame(Vec::new(), |ctx| render(ctx, model));
seen(window, |ctx| render(ctx, model))
}
fn run(glyphs: &[Seen], text: &str) -> Seen {
glyphs
.iter()
.find(|shown| shown.text == text)
.unwrap_or_else(|| panic!("nothing on the glass reads {text:?}"))
.clone()
}
#[test]
fn a_pane_that_was_narrow_takes_the_width_the_policy_gives_a_wider_window() {
let mut model = seated();
let mut window = Window::sized(800.0, 600.0);
glass(&window, &mut model);
window.resize(1440.0, 900.0);
let glyphs = glass(&window, &mut model);
let list = widths(1440.0);
let heading = run(&glyphs, crate::ui::chat::HEADING);
assert!(
heading.laid.min.x >= list - 8.0,
"the conversation starts where the list ends: {} against {list}",
heading.laid.min.x
);
}
#[test]
fn an_overrunning_preview_is_elided_rather_than_cut_and_reserves_no_dead_band() {
let mut model = overrunning();
let window = Window::sized(1440.0, 900.0);
let glyphs = glass(&window, &mut model);
let preview = glyphs
.iter()
.find(|shown| shown.text.starts_with("What changed in the last"))
.unwrap_or_else(|| panic!("the preview is not on the glass: {glyphs:?}"));
assert!(
preview.text.ends_with('…'),
"the run says it was cut: {:?}",
preview.text
);
assert!(
preview.laid.width() - preview.shown.width() < 1.0,
"and nothing of it was clipped away: laid {:?}, shown {:?}",
preview.laid,
preview.shown
);
let list = widths(1440.0);
let heading = run(&glyphs, crate::ui::chat::HEADING);
assert!(
heading.laid.min.x < list + 24.0,
"no band stands between the list and the conversation: {} against {list}",
heading.laid.min.x
);
}