use super::idiom::{glass, head, prose, result, running, with, working};
use crate::paint_probe::frame::Window;
use crate::paint_probe::{fills_of, seen_of, strokes_of};
use crate::test_support::window::{click, said};
use crate::ui::theme::{Bubble, bubble, glyph};
fn under(output: &egui::FullOutput, text: &str) -> Vec<egui::Color32> {
let runs: Vec<egui::Rect> = seen_of(output)
.into_iter()
.filter(|seen| seen.text == text)
.map(|seen| seen.laid)
.collect();
assert!(!runs.is_empty(), "nothing on the glass reads {text:?}");
fills_of(output)
.into_iter()
.filter(|(rect, _)| rect.width() > 300.0 && runs.iter().any(|run| rect.contains_rect(*run)))
.map(|(_, ink)| ink)
.collect()
}
fn fill(role: Bubble) -> egui::Color32 {
bubble(role).0
}
#[test]
fn each_block_stands_on_the_fill_its_role_wears_with_its_glyph_inside() {
let mut model = with(vec![
said("op", "port it"),
prose("first I will read"),
working(),
result("done", false),
prose("the seam is real"),
]);
let window = Window::sized(1400.0, 900.0);
window.frame(Vec::new(), |ctx| crate::ui::render(ctx, &mut model));
click(&window, &head(false, 1, 2), |ctx| {
crate::ui::render(ctx, &mut model);
});
let line = format!("{} model-a {} first I will read", glyph::MODEL, glyph::NOTE);
click(&window, &line, |ctx| {
crate::ui::render(ctx, &mut model);
});
let output = window.frame(Vec::new(), |ctx| crate::ui::render(ctx, &mut model));
let operator = fill(Bubble::Operator);
assert!(under(&output, "port it").contains(&operator));
assert!(
under(&output, glyph::PROMPT).contains(&operator),
"the glyph is inside the fill"
);
let (between, last) = (fill(Bubble::Intermediate), fill(Bubble::Final));
let first = under(&output, "first I will read");
assert!(
first.contains(&between) && !first.contains(&last),
"{first:?}"
);
let seam = under(&output, "the seam is real");
assert!(seam.contains(&last) && !seam.contains(&between), "{seam:?}");
assert!(under(&output, glyph::MODEL).contains(&last));
let head = seen_of(&output)
.into_iter()
.find(|seen| seen.text == head(true, 1, 2))
.expect("the working's line is on the glass")
.laid;
let (_, ring) = bubble(Bubble::Trail);
assert!(
strokes_of(&output)
.iter()
.any(|(rect, ink)| *ink == ring.color && rect.contains_rect(head)),
"the trail is ringed by the hairline"
);
}
#[test]
fn a_streaming_turn_s_prose_is_intermediate_until_it_settles() {
let (between, last) = (fill(Bubble::Intermediate), fill(Bubble::Final));
let mut streaming = with(vec![said("op", "port it"), running("so far")]);
let flying = under(&glass(&mut streaming), "so far");
assert!(
flying.contains(&between) && !flying.contains(&last),
"{flying:?}"
);
let mut settled = with(vec![said("op", "port it"), prose("so far")]);
let done = under(&glass(&mut settled), "so far");
assert!(done.contains(&last) && !done.contains(&between), "{done:?}");
}