use crate::paint_probe::frame::Window;
use crate::reply::transcript::Transcript;
use crate::test_support::window::{said, seated, seen};
use crate::ui::Model;
fn lines(range: std::ops::RangeInclusive<usize>) -> Transcript {
Transcript {
entries: range
.map(|at| said("op", &format!("line {at:03}")))
.collect(),
}
}
fn glass(window: &Window, model: &mut Model) -> Vec<String> {
for _ in 0..3 {
window.frame(Vec::new(), |ctx| crate::ui::render(ctx, model));
}
on_the_glass(window, model)
}
fn on_the_glass(window: &Window, model: &mut Model) -> Vec<String> {
seen(window, |ctx| crate::ui::render(ctx, model))
.into_iter()
.map(|shown| shown.text)
.collect()
}
fn shows(glyphs: &[String], line: &str) -> bool {
glyphs.iter().any(|text| text == line)
}
fn desk() -> Window {
Window::sized(900.0, 700.0)
}
#[test]
fn a_selected_conversation_opens_on_its_tail_and_not_on_message_001() {
let mut model = seated();
model.transcript = lines(1..=60);
let glyphs = glass(&desk(), &mut model);
assert!(shows(&glyphs, "line 060"), "{glyphs:?}");
assert!(!shows(&glyphs, "line 001"), "{glyphs:?}");
}
#[test]
fn a_conversation_that_grows_while_the_reader_is_at_the_tail_keeps_the_tail() {
let window = desk();
let mut model = seated();
model.transcript = lines(1..=60);
glass(&window, &mut model);
model.transcript = lines(1..=75);
let glyphs = glass(&window, &mut model);
assert!(shows(&glyphs, "line 075"), "{glyphs:?}");
}
#[test]
fn scrolling_up_releases_the_follow_and_an_append_does_not_take_it_back() {
let window = desk();
let mut model = seated();
model.transcript = lines(1..=60);
glass(&window, &mut model);
wheel(&window, &mut model, 4000.0);
let glyphs = on_the_glass(&window, &mut model);
assert!(shows(&glyphs, "line 001"), "{glyphs:?}");
assert!(!shows(&glyphs, "line 060"), "{glyphs:?}");
model.transcript = lines(1..=75);
let glyphs = glass(&window, &mut model);
assert!(!shows(&glyphs, "line 075"), "{glyphs:?}");
}
fn wheel(window: &Window, model: &mut Model, up: f32) {
let over = egui::pos2(700.0, 300.0);
window.frame(vec![egui::Event::PointerMoved(over)], |ctx| {
crate::ui::render(ctx, model);
});
window.frame(
vec![egui::Event::MouseWheel {
unit: egui::MouseWheelUnit::Point,
delta: egui::vec2(0.0, up),
modifiers: egui::Modifiers::NONE,
}],
|ctx| crate::ui::render(ctx, model),
);
for _ in 0..12 {
window.frame(Vec::new(), |ctx| crate::ui::render(ctx, model));
}
}