use super::{ARM, DELETE, RETARGET, STOP, render};
use crate::paint_probe::frame::Window;
use crate::test_support::window::{click, pane, seated};
use crate::ui::{Aim, Model};
use serde_json::json;
fn subject(model: &Model) -> (Aim, String) {
(
model.aim.clone().expect("the fixture is aimed at a wall"),
model.conversation.clone().expect("and has one selected"),
)
}
fn press(model: &mut Model, label: &str) {
let (aim, agent) = subject(model);
let window = Window::new();
click(&window, label, |ctx| {
egui::CentralPanel::default().show(ctx, |ui| render(ui, model, &aim, &agent));
});
}
#[test]
fn the_row_offers_the_three_acts_and_says_what_the_box_arms() {
let mut model = seated();
let (aim, agent) = subject(&model);
let painted = pane(|ui| render(ui, &mut model, &aim, &agent));
for word in [STOP, RETARGET, DELETE, ARM] {
assert!(
painted.lines().any(|line| line == word),
"{word:?}:\n{painted}"
);
}
}
#[test]
fn each_act_composes_the_envelope_its_verb_row_builds() {
for (label, expected) in [
(
STOP,
json!({"op": "stop", "workspace": "home", "agent": "20260830T051200Z-a1b2"}),
),
(
RETARGET,
json!({"op": "retarget", "workspace": "home", "agent": "20260830T051200Z-a1b2"}),
),
(
DELETE,
json!({"op": "delete-agent", "workspace": "home",
"agent": "20260830T051200Z-a1b2", "typed": ""}),
),
] {
let mut model = seated();
press(&mut model, label);
assert_eq!(model.outbox, vec![expected], "{label}");
}
}
#[test]
fn the_typed_name_rides_the_deletion_verbatim_and_stays_the_operators() {
let mut model = seated();
model.typed = "port the paint probe".to_owned();
press(&mut model, DELETE);
assert_eq!(
model.outbox,
vec![json!({"op": "delete-agent", "workspace": "home",
"agent": "20260830T051200Z-a1b2", "typed": "port the paint probe"})]
);
assert_eq!(
model.typed, "port the paint probe",
"a delete the engine refuses while the conversation is live must not \
charge the operator a retype"
);
}
#[test]
fn the_acts_carry_the_address_the_channel_resolves() {
let mut model = Model {
aim: Some(Aim {
channel: "(this box's own engine)".to_owned(),
address: "elsewhere".to_owned(),
}),
..seated()
};
press(&mut model, STOP);
assert_eq!(model.outbox[0]["workspace"], json!("elsewhere"));
}
#[test]
fn painting_the_row_composes_nothing() {
let mut model = seated();
let (aim, agent) = subject(&model);
let _ = pane(|ui| render(ui, &mut model, &aim, &agent));
assert!(model.outbox.is_empty(), "{:?}", model.outbox);
}