use super::super::render;
use super::fixture::{World, world};
use super::input;
use crate::cli_outbound::Cli;
use crate::model_pick::tests::TEMPLATE_PROVIDERS;
use crate::model_pick::{NEW_CONVERSATION_EXIT, RETARGET_EXIT};
use crate::paint_probe::Painted;
const FROZEN: &str = "this conversation is frozen on";
fn painted_seat(drifted: bool) -> (Vec<Painted>, egui::Rect) {
let mut world = world();
let ws = world.ws.clone();
world.model.focus_agent(&ws, "c-1");
if drifted {
std::fs::write(
world.model.state_root().join("cadence.yaml"),
"cadence:\n watcher:\n debounce_ms: 0\n",
)
.unwrap();
world.model.after_lernie_verb();
world.converge();
world.advance_config(TEMPLATE_PROVIDERS);
world.model.mark_dirty([ws]);
world.converge();
}
let ctx = egui::Context::default();
let (lernie, bl, bz) = (
Cli::new("yog-absent-lernie"),
Cli::new("yog-absent-bl"),
Cli::new("yog-absent-bz"),
);
let frame = |world: &mut World| {
ctx.run(input(), |ctx| {
render(ctx, &mut world.model, &mut world.state, &lernie, &bl, &bz);
})
};
let _ = frame(&mut world);
let _ = frame(&mut world);
world.drain(&mut |world| {
let _ = frame(world);
});
let mut out = None;
for _ in 0..4 {
out = Some(frame(&mut world));
}
let painted = crate::paint_probe::painted_of(&out.expect("four frames ran"));
let seat =
egui::containers::panel::PanelState::load(&ctx, egui::Id::new("conversation-settings"))
.expect("the settings panel stores its rect")
.rect;
(painted, seat)
}
fn one(painted: &[Painted], needle: &str) -> egui::Rect {
painted
.iter()
.find(|(text, _)| text.contains(needle))
.map_or_else(
|| panic!("{needle:?} is not on the glass"),
|(_, rect)| *rect,
)
}
fn any(painted: &[Painted], needle: &str) -> bool {
painted.iter().any(|(text, _)| text.contains(needle))
}
#[test]
fn a_drifted_conversation_offers_both_exits_beside_the_frozen_sentence() {
let (painted, seat) = painted_seat(true);
let clause = one(&painted, FROZEN);
let retarget = one(&painted, RETARGET_EXIT);
let fresh = one(&painted, NEW_CONVERSATION_EXIT);
for (what, rect) in [
("the frozen sentence", clause),
("the retarget exit", retarget),
("the new-conversation exit", fresh),
] {
assert!(
rect.top() >= seat.top() - 1.0,
"{what} belongs to the settings seat: {rect:?} vs {seat:?}"
);
}
assert!(
retarget.top() < clause.bottom() && clause.top() < retarget.bottom(),
"the retarget exit sits on the frozen sentence's own row: \
{retarget:?} vs {clause:?}"
);
assert!(
retarget.left() < fresh.left(),
"the keeping exit comes first: {retarget:?} vs {fresh:?}"
);
}
#[test]
fn an_undrifted_conversation_is_offered_no_exit_at_all() {
let (painted, _) = painted_seat(false);
assert!(!any(&painted, FROZEN), "no freeze is named");
assert!(!any(&painted, RETARGET_EXIT), "and no way out is offered");
assert!(!any(&painted, NEW_CONVERSATION_EXIT));
}