use super::{render, widths};
use crate::paint_probe::frame::{Window, press};
use crate::test_support::window::{conv, own, painted, seated, seen, wall};
use crate::ui::{Chunk, Model};
mod drag;
mod narrow;
mod notice;
mod width;
#[test]
fn one_frame_paints_the_roster_the_list_the_conversation_and_the_composer() {
let mut model = seated();
let shown = painted(&mut model);
for expected in [
crate::ui::roster::HEADING,
"(this box's own engine)",
"home 2 conversations (named)",
"conversations",
"port the paint probe [quiescent] 42s",
"conversation",
"op",
"port it",
crate::ui::composer::SEND,
] {
assert!(
shown.contains(expected),
"{expected:?} is not on the glass:\n{shown}"
);
}
}
#[test]
fn an_empty_window_says_what_each_pane_is_waiting_for() {
let scratch = crate::test_support::Scratch::new();
let mut model = Model {
roster: crate::seat::channels(scratch.path()),
..Model::default()
};
let shown = painted(&mut model);
assert!(
shown.contains("nothing provisioned at"),
"the engines list says what it holds and why it is empty:\n{shown}"
);
assert!(
shown.contains("the seat mints nothing"),
"and names the act that fills it:\n{shown}"
);
let window = crate::paint_probe::frame::Window::new();
let runs = crate::test_support::window::seen(&window, |ctx| crate::ui::render(ctx, &mut model));
for empty in [
crate::ui::chat::NO_CONVERSATION,
crate::ui::composer::NOWHERE,
] {
let run = runs
.iter()
.find(|run| run.text == empty)
.unwrap_or_else(|| panic!("{empty:?} is on the glass whole"));
assert_eq!(run.ink, crate::ui::theme::INK_WEAK, "{empty:?}");
}
for expected in [
crate::ui::chat::NO_CONVERSATION,
crate::ui::composer::NOWHERE,
] {
assert!(
shown.contains(expected),
"{expected:?} is not on the glass:\n{shown}"
);
}
}
#[test]
fn a_narrow_window_paints_the_conversation_at_its_floor() {
let mut model = seated();
let window = Window::sized(900.0, 600.0);
let said = seen(&window, |ctx| render(ctx, &mut model))
.into_iter()
.find(|run| run.text == "port it")
.expect("the conversation is on the glass");
let list = widths(900.0);
assert!(
said.laid.min.x < list + 40.0,
"the chat pane begins where the list pane ends: {:?}",
said.laid
);
}
#[test]
fn the_roster_scrolls_and_a_walk_to_the_last_wall_puts_it_on_the_glass() {
let mut model = Model {
roster: vec![Chunk {
walls: (0..24).map(|i| wall(&format!("wall-{i:02}"))).collect(),
..own()
}],
..Model::default()
};
let window = Window::sized(900.0, 260.0);
let last = "wall-23";
let first = seen(&window, |ctx| render(ctx, &mut model));
assert!(
!first.iter().any(|run| run.text.starts_with(last)),
"the fold is real, or this test proves nothing"
);
for _ in 0..25 {
window.frame(vec![press(egui::Key::ArrowDown)], |ctx| {
render(ctx, &mut model);
});
}
assert_eq!(
model.aim.clone().map(|aim| aim.address),
Some("wall-23".to_owned())
);
window.frame(Vec::new(), |ctx| render(ctx, &mut model));
let shown = seen(&window, |ctx| render(ctx, &mut model));
assert!(
shown.iter().any(|run| run.text.starts_with(last)),
"the walked-to row is on the glass: {:?}",
shown.iter().map(|run| &run.text).collect::<Vec<&String>>()
);
}
#[test]
fn the_conversation_rows_scroll_and_a_walk_puts_one_on_the_glass() {
let mut model = Model {
convs: (0..24)
.map(|i| conv(&format!("id-{i:02}"), &format!("conv-{i:02}")))
.collect(),
conversation: None,
..seated()
};
let window = Window::sized(900.0, 260.0);
let last = crate::ui::convs::headline(&conv("id-23", "conv-23"));
assert!(
!seen(&window, |ctx| render(ctx, &mut model))
.iter()
.any(|run| run.text == last),
"the fold is real, or this test proves nothing"
);
for _ in 0..24 {
window.frame(vec![press(egui::Key::ArrowDown)], |ctx| {
render(ctx, &mut model);
});
}
window.frame(Vec::new(), |ctx| render(ctx, &mut model));
assert!(
seen(&window, |ctx| render(ctx, &mut model))
.iter()
.any(|run| run.text == last),
"the walked-to row is on the glass"
);
}