use super::super::READY;
use crate::paint_probe::frame::Window;
use crate::test_support::window::seated;
use crate::ui::{Model, Notice, theme};
fn long() -> Notice {
Notice::InDoubt {
op: "message".to_owned(),
why: "the connection closed before the reply, after the engine had read the \
whole request and could have begun to act on every part of it"
.to_owned(),
}
}
fn words(text: &str) -> String {
text.split_whitespace().collect::<Vec<_>>().join(" ")
}
fn glass(model: &mut Model, w: f32, h: f32) -> Vec<crate::paint_probe::Seen> {
let window = Window::sized(w, h);
window.frame(Vec::new(), |ctx| crate::ui::render(ctx, model));
crate::test_support::window::seen(&window, |ctx| crate::ui::render(ctx, model))
}
#[test]
fn a_long_notice_stands_whole_above_the_rule_at_every_width() {
for (w, h) in [(1400.0, 900.0), (400.0, 800.0)] {
let mut model = seated();
model.notice = Some(long());
let seen = glass(&mut model, w, h);
let ink = theme::accent(theme::State::Error);
let said: Vec<_> = seen.iter().filter(|run| run.ink == ink).collect();
let read = words(&said.iter().map(|run| run.text.as_str()).collect::<String>());
assert_eq!(read, words(&long().line()), "at {w}: the whole sentence");
for run in &said {
assert_eq!(run.shown, run.laid, "at {w}: {:?} is cut", run.text);
assert!(run.laid.max.x <= w, "at {w}: {:?} runs off", run.text);
}
let rule = seen
.iter()
.filter(|run| run.text.starts_with("port t"))
.max_by(|a, b| a.laid.min.y.total_cmp(&b.laid.min.y))
.unwrap_or_else(|| panic!("at {w}: the rule's name is on the glass"));
let lowest = said.iter().map(|run| run.laid.max.y).fold(0.0, f32::max);
assert!(
lowest <= rule.laid.min.y,
"at {w}: the notice is above the rule"
);
let prompt = seen
.iter()
.filter(|run| run.text == theme::glyph::PROMPT && run.ink == theme::BRAND)
.map(|run| run.laid.max.y)
.fold(0.0, f32::max);
let highest = said.iter().map(|run| run.laid.min.y).fold(h, f32::min);
assert!(prompt <= highest, "at {w}: the notice is under the box");
assert!(
seen.iter().any(|run| run.text.starts_with("pro")),
"at {w}: the provider"
);
if w > 1000.0 {
assert!(
seen.iter().any(|run| run.text.contains("quiescent")),
"at {w}: the slot says the calm state"
);
assert!(
seen.iter()
.any(|run| run.text
== crate::test_support::window::dropped(super::super::NO_MODEL)),
"at {w}: the notice costs no fact"
);
}
}
}
#[test]
fn a_short_notice_stays_in_the_slot() {
let mut model = Model {
notice: Some(Notice::Said("the act landed".to_owned())),
..Model::default()
};
let seen = glass(&mut model, 1400.0, 900.0);
let note = seen
.iter()
.find(|run| run.text == "the act landed")
.expect("the notice is on the glass");
let name = seen
.iter()
.find(|run| run.text == super::super::ENGINES)
.expect("the rule's name is on the glass");
assert!((note.laid.center().y - name.laid.center().y).abs() < 2.0);
assert!(!seen.iter().any(|run| run.text == READY));
}