use super::idiom::{prose, result, running, with, working};
use super::line::head;
use crate::paint_probe::frame::{Window, locate_in};
use crate::paint_probe::{fills_of, seen_of, strokes_of};
use crate::settings::Toggle;
use crate::test_support::window::{click, said};
use crate::ui::Model;
use crate::ui::chat::COPY;
use crate::ui::theme::{self, Bubble, State, bubble, glyph, space};
fn call_line() -> String {
format!("{} read(src/ui.rs)", glyph::DONE)
}
fn opened(bubbles: bool) -> egui::FullOutput {
let mut model = with(vec![
said("op", "port it"),
working(),
result("Exit code: 0\nhello", false),
prose("the seam is real"),
]);
model.settings.set(Toggle::Bubbles, bubbles);
let window = Window::sized(1400.0, 900.0);
window.frame(Vec::new(), |ctx| crate::ui::render(ctx, &mut model));
for door in [head(false, [1, 1, 0, 0]), call_line()] {
click(&window, &door, |ctx| crate::ui::render(ctx, &mut model));
}
window.frame(Vec::new(), |ctx| crate::ui::render(ctx, &mut model))
}
fn at(output: &egui::FullOutput, text: &str) -> egui::Rect {
seen_of(output)
.into_iter()
.find(|run| run.text == text)
.unwrap_or_else(|| panic!("nothing on the glass reads {text:?}"))
.laid
}
fn least(
shapes: Vec<(egui::Rect, egui::Color32)>,
ink: egui::Color32,
inside: egui::Rect,
) -> Option<egui::Rect> {
shapes
.into_iter()
.filter(|(rect, painted)| *painted == ink && rect.contains_rect(inside))
.map(|(rect, _)| rect)
.min_by(|a, b| a.area().total_cmp(&b.area()))
}
#[test]
fn the_working_is_one_bubble_and_each_step_a_sub_bubble_inside_it() {
let output = opened(true);
let hairline = bubble(Bubble::Operator).1.color;
assert!(least(strokes_of(&output), hairline, at(&output, "port it")).is_some());
let line = at(&output, &call_line());
let working = least(strokes_of(&output), hairline, line).expect("the working's ring");
assert!(working.contains_rect(at(&output, &head(true, [1, 1, 0, 0]))));
let (surface, _) = bubble(Bubble::Step);
let step = least(fills_of(&output), surface, line).expect("the step's sub-bubble");
assert!(
working.shrink(space::XXS - 0.5).contains_rect(step),
"{step:?} inset in {working:?}"
);
let hello = seen_of(&output)
.into_iter()
.find(|run| run.text == "hello")
.expect("the output is on the glass");
assert_eq!(hello.family, egui::FontFamily::Monospace);
let (ground, _) = bubble(Bubble::Card);
let card = least(fills_of(&output), ground, hello.laid).expect("the card");
assert!(step.contains_rect(card), "{card:?} inside {step:?}");
let pill = theme::tint(State::Attention);
assert!(least(fills_of(&output), pill, at(&output, "exit 0")).is_some());
}
#[test]
fn bubbles_off_takes_the_nested_fills_and_strokes_away() {
let output = opened(false);
let hairline = bubble(Bubble::Operator).1.color;
let line = at(&output, &call_line());
assert!(least(strokes_of(&output), hairline, at(&output, "port it")).is_none());
assert!(least(strokes_of(&output), hairline, line).is_none());
assert!(least(fills_of(&output), bubble(Bubble::Step).0, line).is_none());
let card = |output: &egui::FullOutput| {
let hello = at(output, "hello");
fills_of(output)
.into_iter()
.filter(|(rect, ink)| *ink == bubble(Bubble::Card).0 && rect.contains_rect(hello))
.count()
};
assert!(
card(&output) < card(&opened(true)),
"no card under the output"
);
}
#[test]
fn copy_under_a_settled_turn_puts_its_prose_on_the_clipboard() {
let mut model = with(vec![said("op", "port it"), prose("the seam is real")]);
let window = Window::sized(1400.0, 900.0);
let mut copied = String::new();
let mut body = |ctx: &egui::Context| {
crate::ui::render(ctx, &mut model);
let said = ctx.output(|o| o.copied_text.clone());
if !said.is_empty() {
copied = said;
}
};
window.frame(Vec::new(), &mut body);
let door = locate_in(&window, COPY, &mut body).expect("the strip's door");
crate::paint_probe::frame::click(&window, door, &mut body);
assert_eq!(copied, "the seam is real");
let mut live: Model = with(vec![said("op", "port it"), running("so far")]);
let seen = seen_of(&window.frame(Vec::new(), |ctx| crate::ui::render(ctx, &mut live)));
assert!(
!seen.iter().any(|run| run.text == COPY),
"no strip while it runs"
);
}
#[test]
fn a_thought_in_flight_is_its_mark_and_name_over_its_words() {
let thinking = super::idiom::entry(crate::reply::transcript::EntryKind::Streaming {
thinking: "pondering the seam".to_owned(),
text: String::new(),
});
let mut model = with(vec![said("op", "port it"), thinking]);
let window = Window::sized(1400.0, 900.0);
window.frame(Vec::new(), |ctx| crate::ui::render(ctx, &mut model));
let output = window.frame(Vec::new(), |ctx| crate::ui::render(ctx, &mut model));
let mark = at(&output, glyph::NOTE);
let words = at(&output, "pondering the seam");
assert!(mark.max.y <= words.min.y + 1.0, "{mark:?} over {words:?}");
let surface = bubble(Bubble::Step).0;
assert!(least(fills_of(&output), surface, words).is_some());
}